std::meta::reference_constructs_from_temporary - cppreference.com

From cppreference.com

constevalboolreference_constructs_from_temporary(std::meta::infodst,std::meta::infosrc);(since C++26)Checks if a reference is bound to a temporary in

direct-initialization

.

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

Equivalent to returnstd::reference_constructs_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_constructs_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

Run this code

#include<meta>static_assert(""andreference_constructs_from_temporary(^^int&&,^^int)andreference_constructs_from_temporary(^^constint&,^^int)andnotreference_constructs_from_temporary(^^int&&,^^int&&)andnotreference_constructs_from_temporary(^^constint&,^^int&&)andreference_constructs_from_temporary(^^int&&,^^long&&)andreference_constructs_from_temporary(^^int&&,^^long));intmain(){}See also

is_constructible_typeis_trivially_constructible_typeis_nothrow_constructible_type

(C++26)(C++26)(C++26)

checks if reflected type has a constructor for specific arguments
(function template)

[edit]

(constructor)

constructs a new tuple
(public member function of std::tuple<Types...>)

[edit]

(constructor)

constructs new pair
(public member function of std::pair<T1,T2>)

[edit]

make_from_tuple

(C++17)

construct an object with a tuple of arguments
(function template)

[edit]

reference_converts_from_temporary

(C++26)

checks if a reference is bound to a temporary in

copy-initialization

(function)

[edit]

reference_constructs_from_temporary

(C++23)

checks if a reference is bound to a temporary in

direct-initialization

(class template)

[edit]