std::meta::reference_converts_from_temporary - cppreference.com

From cppreference.com

constevalboolreference_converts_from_temporary(std::meta::infodst,std::meta::infosrc);(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 returnstd::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

Run this code

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

is_convertible_typeis_nothrow_convertible_type

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

checks if reflected type can be converted to the other type
(function)

[edit]

invokeinvoke_r

(C++17)(C++23)

invokes any

Callable

object with given arguments and possibility to specify return type(since C++23)
(function template)

[edit]

bind

(C++11)

binds one or more arguments to a function object
(function template)

[edit]

visit

(C++17)

calls the provided functor with the arguments held by one or more variants
(function template)

[edit]

(constructor)

constructs a new std::function instance
(public member function of std::function<R(Args...)>)

[edit]

(constructor)

constructs a new std::move_only_function object
(public member function of std::move_only_function)

[edit]

(constructor)

constructs the task object
(public member function of std::packaged_task<R(Args...)>)

[edit]

reference_constructs_from_temporary

(C++26)

checks if a reference is bound to a temporary in

direct-initialization

(function)

[edit]

reference_converts_from_temporary

(C++23)

checks if a reference is bound to a temporary in

copy-initialization

(class template)

[edit]