Type traits | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Compile-time rational arithmetic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Compile-time integer sequences | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(C++14) |
Defined in header <type_traits> | ||
template<class T> struct is_rvalue_reference; | (since C++11) | |
std::is_rvalue_reference
is aUnaryTypeTrait.
Checks whetherT
is an rvalue reference type. Provides the member constantvalue which is equal totrue, ifT
is an rvalue reference type. Otherwise,value is equal tofalse.
If the program adds specializations forstd::is_rvalue_reference
orstd::is_rvalue_reference_v
, the behavior is undefined.
Contents |
T | - | a type to check |
template<class T> constexprbool is_rvalue_reference_v= is_rvalue_reference<T>::value; | (since C++17) | |
value [static] | true ifT is an rvalue reference type,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> |
template<class T>struct is_rvalue_reference:std::false_type{};template<class T>struct is_rvalue_reference<T&&>:std::true_type{}; |
#include <iostream>#include <type_traits> class A{}; static_assert( std::is_rvalue_reference_v<A>==false and std::is_rvalue_reference_v<A&>==false and std::is_rvalue_reference_v<A&&>!=false and std::is_rvalue_reference_v<char>==false and std::is_rvalue_reference_v<char&>==false and std::is_rvalue_reference_v<char&&>!=false); template<typename T>void test(T&& x){ static_assert(std::is_same_v<T&&, decltype(x)>);std::cout<<"T\t"<< std::is_rvalue_reference<T>::value<<'\n';std::cout<<"T&&\t"<< std::is_rvalue_reference<T&&>::value<<'\n';std::cout<<"decltype(x)\t"<< std::is_rvalue_reference<decltype(x)>::value<<'\n';} int main(){std::cout<<std::boolalpha;std::cout<<"A\t"<< std::is_rvalue_reference<A>::value<<'\n';std::cout<<"A&\t"<< std::is_rvalue_reference<A&>::value<<'\n';std::cout<<"A&&\t"<< std::is_rvalue_reference<A&&>::value<<'\n';std::cout<<"char\t"<< std::is_rvalue_reference<char>::value<<'\n';std::cout<<"char&\t"<< std::is_rvalue_reference<char&>::value<<'\n';std::cout<<"char&&\t"<< std::is_rvalue_reference<char&&>::value<<'\n'; std::cout<<"\ntest(42)\n"; test(42); std::cout<<"\ntest(x)\n";int x=42; test(x);}
Output:
AfalseA&falseA&&truecharfalsechar&falsechar&&true test(42)TfalseT&&truedecltype(x)true test(x)TfalseT&&falsedecltype(x)false
(C++11) | checks if a type is anlvalue reference (class template)[edit] |
(C++11) | checks if a type is either anlvalue reference orrvalue reference (class template)[edit] |