Namespaces
Variants

std::meta::reference_converts_from_temporary

From cppreference.com
< cpp | meta
 
 
 
Reflection library
 
Reflection types and queries
Type properties
Type property queries
 
Defined in header <meta>
consteval bool reference_converts_from_temporary( std::meta::info dst,
                                                  std::meta::info src );
(since C++26)

Checks if a reference is bound to a temporary in copy-initialization

Let T and U be types represented by dst and src, respectively.

Equivalent to return std::reference_converts_from_temporary_v<T, U>;.

If T is an lvalue reference type to a const- but not volatile-qualified object type or an rvalue reference type, both std::remove_reference_t<T> and std::remove_reference_t<U> must be complete types, cv void, or an arrays of unknown bound; otherwise the program is ill-formed.

If an instantiation of a template above depends, directly or indirectly, on an incomplete type, and that instantiation could yield a different result if that type were hypothetically completed, the program is ill-formed.

Parameters

dst, src - reflection values to check

Return value

true if the reference type T is bound to a temporary of the type U as described above; otherwise false.

Exceptions

Throws std::meta::exception if either dst or src does not represent a type or type alias.

Notes

reference_converts_from_temporary can be used for rejecting some cases that always produce dangling references.

It is also possible to use member initializer list to reject binding a temporary object to a reference if the compiler has implemented CWG1696.

Example

#include <meta>

static_assert
(""
    and reference_converts_from_temporary(^^int&&, ^^int)
    and reference_converts_from_temporary(^^const int&, ^^int)
    and not reference_converts_from_temporary(^^int&&, ^^int&&)
    and not reference_converts_from_temporary(^^const int&, ^^int&&)
    and reference_converts_from_temporary(^^int&&, ^^long&&)
    and reference_converts_from_temporary(^^int&&, ^^long)
);

int main() {}

See also

checks if reflected type can be converted to the other type
(function) [edit]
(C++17)(C++23)
invokes any Callable object with given arguments and possibility to specify return type(since C++23)
(function template) [edit]
(C++11)
binds one or more arguments to a function object
(function template) [edit]
(C++17)
calls the provided functor with the arguments held by one or more variants
(function template) [edit]
constructs a new std::function instance
(public member function of std::function<R(Args...)>) [edit]
constructs a new std::move_only_function object
(public member function of std::move_only_function) [edit]
constructs the task object
(public member function of std::packaged_task<R(Args...)>) [edit]
checks if a reference is bound to a temporary in direct-initialization
(function) [edit]
checks if a reference is bound to a temporary in copy-initialization
(class template) [edit]