description | title | ms.date | ms.assetid | helpviewer_keywords | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: <type_traits> functions |
<type_traits> functions |
11/04/2016 |
dce4492f-f3e4-4d5e-bdb4-5875321254ec |
|
is_assignable
is_copy_assignable
is_copy_constructible
is_default_constructible
is_move_assignable
is_move_constructible
is_nothrow_move_assignable
is_nothrow_swappable
is_nothrow_swappable_with
is_swappable
is_swappable_with
is_trivially_copy_assignable
is_trivially_move_assignable
is_trivially_move_constructible
Tests whether a value of From type can be assigned to a To type.
template <class To, class From>
struct is_assignable;
To
The type of the object that receives the assignment.
From
The type of the object that provides the value.
The unevaluated expression declval<To>() = declval<From>()
must be well-formed. Both From and To must be complete types, void
, or arrays of unknown bound.
Tests whether type has can be copied on assignment.
template <class Ty>
struct is_copy_assignable;
Ty
The type to query.
An instance of the type predicate holds true if the type Ty is a class that has a copy assignment operator, otherwise it holds false. Equivalent to is_assignable<Ty&, const Ty&>.
Tests if type has a copy constructor.
template <class Ty>
struct is_copy_constructible;
Ty
The type to query.
An instance of the type predicate holds true if the type Ty is a class that has a copy constructor, otherwise it holds false.
#include <type_traits>
#include <iostream>
struct Copyable
{
int val;
};
struct NotCopyable
{
NotCopyable(const NotCopyable&) = delete;
int val;
};
int main()
{
std::cout << "is_copy_constructible<Copyable> == " << std::boolalpha
<< std::is_copy_constructible<Copyable>::value << std::endl;
std::cout << "is_copy_constructible<NotCopyable> == " << std::boolalpha
<< std::is_copy_constructible<NotCopyable>::value << std::endl;
return (0);
}
is_copy_constructible<Copyable> == true
is_copy_constructible<NotCopyable > == false
Tests if a type has a default constructor.
template <class Ty>
struct is_default_constructible;
T
The type to query.
An instance of the type predicate holds true if the type T is a class type that has a default constructor, otherwise it holds false. This is equivalent to the predicate is_constructible<T>
. Type T must be a complete type, void
, or an array of unknown bound.
#include <type_traits>
#include <iostream>
struct Simple
{
Simple() : val(0) {}
int val;
};
struct Simple2
{
Simple2(int v) : val(v) {}
int val;
};
int main()
{
std::cout << "is_default_constructible<Simple> == " << std::boolalpha
<< std::is_default_constructible<Simple>::value << std::endl;
std::cout << "is_default_constructible<Simple2> == " << std::boolalpha
<< std::is_default_constructible<Simple2>::value << std::endl;
return (0);
}
is_default_constructible<Simple> == true
is_default_constructible<Simple2> == false
Tests if the type can be move assigned.
template <class T>
struct is_move_assignable;
T
The type to query.
A type is move assignable if an rvalue reference to the type can be assigned to a reference to the type. The type predicate is equivalent to is_assignable<T&, T&&>
. Move assignable types include referenceable scalar types and class types that have either compiler-generated or user-defined move assignment operators.
Tests whether the type has a move constructor.
template <class T>
struct is_move_constructible;
T
The type to be evaluated
A type predicate that evaluates to true if the type T can be constructed by using a move operation. This predicate is equivalent to is_constructible<T, T&&>
.
Tests whether type has a nothrow
move assignment operator.
template <class Ty>
struct is_nothrow_move_assignable;
Ty
The type to query.
An instance of the type predicate holds true if the type Ty has a nothrow move assignment operator, otherwise it holds false.
template <class T> struct is_nothrow_swappable;
template <class T, class U> struct is_nothrow_swappable_with;
template <class T> struct is_swappable;
template <class T, class U> struct is_swappable_with;
Tests whether the type has a trivial copy assignment operator.
template <class Ty>
struct is_trivially_copy_assignable;
T
The type to query.
An instance of the type predicate holds true if the type T is a class that has a trivial copy assignment operator, otherwise it holds false.
An assignment constructor for a class T is trivial if it is implicitly provided, the class T has no virtual functions, the class T has no virtual bases, the classes of all the non-static data members of class type have trivial assignment operators, and the classes of all the non-static data members of type array of class have trivial assignment operators.
Tests whether the type has a trivial move assignment operator.
template <class Ty>
struct is_trivially_move_assignable;
Ty
The type to query.
An instance of the type predicate holds true if the type Ty is a class that has a trivial move assignment operator, otherwise it holds false.
A move assignment operator for a class Ty is trivial if:
it is implicitly provided
the class Ty has no virtual functions
the class Ty has no virtual bases
the classes of all the non-static data members of class type have trivial move assignment operators
the classes of all the non-static data members of type array of class have trivial move assignment operators
Tests if type has trivial move constructor.
template <class Ty>
struct is_trivially_move_constructible;
Ty
The type to query.
An instance of the type predicate holds true if the type Ty is a class that has a trivial move constructor, otherwise it holds false.
A move constructor for a class Ty is trivial if:
it is implicitly declared
its parameter types are equivalent to those of an implicit declaration
the class Ty has no virtual functions
the class Ty has no virtual bases
the class has no volatile non-static data members
all the direct bases of the class Ty have trivial move constructors
the classes of all the non-static data members of class type have trivial move constructors
the classes of all the non-static data members of type array of class have trivial move constructors