template< class T, class U >
struct reference_constructs_from_temporary;
Let V
be std::remove_cv_t<U> if U
is a scalar type or cv void
, or U
otherwise. If T
is a reference type, and given a hypothetic expression e such that decltype(e) is V
, the variable definition T ref(e); is well-formed and binds a temporary object to ref
, then provides the member constant value
equal to true. Otherwise, value
is false.
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> shall be complete types, cv void, or an arrays of unknown bound; otherwise the behavior is undefined.
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 behavior is undefined.
If the program adds specializations for std::reference_constructs_from_temporary
or std::reference_constructs_from_temporary_v
, the behavior is undefined.
inline constexpr bool reference_constructs_from_temporary_v =
T
is a reference type, a U
value can be bound to T
in direct-initialization, and a temporary object would be bound to the reference, false otherwise
std::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.
[edit] Example#include <type_traits> static_assert(std::reference_constructs_from_temporary_v<int&&, int> == true); static_assert(std::reference_constructs_from_temporary_v<const int&, int> == true); static_assert(std::reference_constructs_from_temporary_v<int&&, int&&> == false); static_assert(std::reference_constructs_from_temporary_v<const int&, int&&> == false); static_assert(std::reference_constructs_from_temporary_v<int&&, long&&> == true); static_assert(std::reference_constructs_from_temporary_v<int&&, long> == true); int main() {}[edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4