declval Questions

3

The standard library utility declval is defined as: template<class T> add_rvalue_reference_t<T> declval() noexcept; To add a rvalue reference here seemed like a good idea, if you think...
Holyhead asked 3/6, 2021 at 17:40

1

Solved

Code as below or on godbolt compiles with gcc and MSVC but fails with clang. I couldn't find if/where it is forbidden in the standard. In my opinion it should be supported. So who is correct on thi...
Smoothspoken asked 18/11, 2022 at 8:39

1

Solved

I have been trying to understand the implementation of std::reference_wrapper, from here, which is as follows: namespace detail { template <class T> constexpr T& FUN(T& t) noexcept { ...
Mould asked 2/1, 2022 at 23:58

1

I see some code examples where the type used to instantiate the std::declval template function is specified as a reference type rather than just a type, as in: std::declval<T &>() as opp...
Stipule asked 28/4, 2021 at 20:18

2

Solved

The code below comes from libstdc++-v3 std::type_traits, which is an implementation of std::declval: template<typename _Tp, typename _Up = _Tp&&> // template 1 _Up __declval(int); ...
Rosiorosita asked 25/9, 2020 at 8:54

2

Solved

Consider this example (coming from here): #include <type_traits> #include <iostream> template <typename U> struct A { }; struct B { template <typename F = int> A&l...
Tressietressure asked 10/12, 2019 at 13:12

1

Solved

I am trying to do something like this (in c++11): #include <utility> template <typename T> struct base { using type = decltype( std::declval<T>().foo() ); }; struct bar : base...
Tl asked 7/6, 2019 at 16:7

1

Solved

Looking at libstdc++ source code, I found the following declval implementation: template<typename _Tp, typename _Up = _Tp&&> _Up __declval(int); // (1) template<typename _Tp> ...

1

Solved

I have a function and I need to test whether I can pass an argument of a given type to it. For example: template<typename T, auto F> decltype(F(declval<T>{})) foo(); Calling foo<i...
Katlin asked 1/3, 2019 at 15:11

2

Solved

With c++17 we have fancy new is_invocable and fancy new prvalues that aren't really values. This permits you to create an object without having to first logically construct it, then elide the cons...
Tambourine asked 9/1, 2018 at 18:32

1

Solved

I am trying to understand how std::declval<T>() works. I know how to use it, and know what it does, mainly allows you to use decltype without constructing the object, like decltype(std::decl...
Callaghan asked 16/2, 2015 at 0:5

3

Solved

std::declval is a compile-time utility used to construct an expression for the purpose of determining its type. It is defined like this: template< class T > typename std::add_rvalue_referenc...
Intercostal asked 7/9, 2014 at 5:44

4

Solved

changing a type into a reference to a type, allows one to access the members of the type without creating an instance of the type. This seems to be true for both lvalue references and rvalue refere...
Hann asked 30/11, 2013 at 17:20
1

© 2022 - 2024 — McMap. All rights reserved.