std::meta::reference_constructs_from_temporary - cppreference.com
Namespaces
Variants

std::meta::reference_constructs_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_constructs_from_temporary( std::meta::info dst,
                                                    std::meta::info src );
(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 return std::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

#include <meta>

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

int main() {}

See also