Namespaces
Variants
Views
Actions

std::is_assignable, std::is_trivially_assignable, std::is_nothrow_assignable

From cppreference.com
< cpp‎ | types
Revision as of 17:49, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
Type support
Basic types
Fundamental types
Fixed width integer types (C++11)
Numeric limits
C numeric limits interface
Runtime type information
Type traits
Primary type categories
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
Type properties
(C++11)
(C++11)
(C++11)
(C++14)
Supported operations
is_assignableis_trivially_assignableis_nothrow_assignable
(C++11)(C++11)(C++11)
Relationships and property queries
(C++11)
(C++11)
(C++11)
(C++11)
Type modifications
(C++11)(C++11)(C++11)
Type transformations
(C++11)
(C++11)
(C++11)
Type trait constants
 

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <type_traits>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
template< class T, class U >
struct is_assignable;
</td>

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class T, class U >
struct is_trivially_assignable;
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
template< class T, class U >
struct is_nothrow_assignable;
</td>

<td > (3) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

1) If the expression std::declval<T>() = std::declval<U>() is well-formed in unevaluated context, provides the member constant value equal true. For any other type, value is false.

2) same as 1), but evaluation of the assignment expression will not call any operation that is not trivial.

3) same as 1), but the evaluation of the assignment expression will not call any operation that is not noexcept.

Contents

Inherited from std::integral_constant

Member constants

value
[static]
true if T is assignable from U , false otherwise
(public static member constant)

Member functions

operator bool
converts the object to bool, returns value
(public member function)

Member types

Type Definition
value_type bool
type std::integral_constant<bool, value>

Example

#include <iostream>
#include <string>
#include <type_traits>
struct Ex1 { int n; };
int main() {
    std::cout << std::boolalpha
              << "int is assignable from double? "
              << std::is_assignable<int, double>::value << '\n'
              << "int& is nothrow assignable from double? "
              << std::is_nothrow_assignable<int&, double>::value << '\n'
              << "string is assignable from double? "
              << std::is_assignable<std::string, double>::value << '\n'
              << "Ex1& is trivially assignable from const Ex1&? "
              << std::is_trivially_assignable<Ex1&, const Ex1&>::value << '\n';
}

Output:

int is assignable from double? false
int& is nothrow assignable from double? true
string is assignable from double? true
Ex1& is trivially assignable from const Ex1&? true

See also

checks if a type has a copy assignment operator
(class template) [edit]
checks if a type has a move assignment operator
(class template) [edit]