std::declval (3) - Linux Manuals
std::declval: std::declval
NAME
Synopsis
Defined in header <utility>
template<class T> (since C++11)
typename std::add_rvalue_reference<T>::type declval() noexcept;
Converts any type T to a reference type, making it possible to use member functions in decltype expressions without the need to go through constructors.
declval is commonly used in templates where acceptable template parameters may have no constructor in common, but have the same member function whose return type is needed.
Note that because no definition exists for declval, it can only be used in unevaluated_contexts; it is an error to evaluate an expression that contains this function. Formally, the program is ill-formed if this function is odr-used.
Parameters
(none)
Return value
Cannot be called and thus never returns a value. The return type is T&& unless T is (possibly cv-qualified) void, in which case the return type is T.
Example
// Run this code
Output:
See also
decltype_specifier defines a type equivalent to the type of an expression (C++11)
result_of
invoke_result deduces the result type of invoking a callable object with a set of arguments
(C++11)(removed in C++20)
(C++17)