Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++14) |
Defined in header <type_traits> | ||
template<class T,class U> struct reference_constructs_from_temporary; | (since C++23) | |
LetV
bestd::remove_cv_t<U> ifU
is a scalar type orcvvoid
, orU
otherwise. IfT
is a reference type, and given a hypothetic expressione such thatdecltype(e) isV
, the variable definitionT ref(e); is well-formed andbinds a temporary object toref
, then provides the member constantvalue
equal totrue. Otherwise,value
isfalse.
IfT
is an lvalue reference type to a const- but not volatile-qualified object type or an rvalue reference type, bothstd::remove_reference_t<T> andstd::remove_reference_t<U> shall becomplete types,cvvoid, or anarrays 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 forstd::reference_constructs_from_temporary
orstd::reference_constructs_from_temporary_v
, the behavior is undefined.
Contents |
template<class T,class U> inlineconstexprbool reference_constructs_from_temporary_v= | (since C++23) | |
value [static] | true ifT is a reference type, aU value can be bound toT in direct-initialization, and a temporary object would be bound to the reference,false otherwise(public static member constant) |
operator bool | converts the object tobool, returnsvalue (public member function) |
operator() (C++14) | returnsvalue (public member function) |
Type | Definition |
value_type | bool |
type | std::integral_constant<bool, value> |
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 implementedCWG1696.
#include <type_traits> static_assert(std::reference_constructs_from_temporary_v<int&&,int>==true);static_assert(std::reference_constructs_from_temporary_v<constint&,int>==true);static_assert(std::reference_constructs_from_temporary_v<int&&,int&&>==false);static_assert(std::reference_constructs_from_temporary_v<constint&,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(){}
(C++11)(C++11)(C++11) | checks if a type has a constructor for specific arguments (class template)[edit] |
constructs a newtuple (public member function of std::tuple<Types...> )[edit] | |
constructs newpair (public member function of std::pair<T1,T2> )[edit] | |
(C++17) | construct an object with a tuple of arguments (function template)[edit] |