名前空間
変種
操作

std::is_copy_assignable, std::is_trivially_copy_assignable, std::is_nothrow_copy_assignable

From cppreference.com
< cpp‎ | types
 
 
メタプログラミングライブラリ
型特性
型のカテゴリ
(C++11)
(C++11)(DR*)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11)
(C++11) 
(C++11)
(C++11)
型のプロパティ
(C++11)
(C++11)
(C++14)
(C++11)(C++26で非推奨)
(C++11)(C++20まで*)
(C++11)(C++20で非推奨)
(C++11)
型特性定数
メタ関数
(C++17)
サポートされている操作
is_copy_assignableis_trivially_copy_assignableis_nothrow_copy_assignable
(C++11)(C++11)(C++11)

関係とプロパティクエリ
型の変更
(C++11)(C++11)(C++11)
型の変換
(C++11)(C++23で非推奨)
(C++11)(C++23で非推奨)
(C++11)
(C++11)(C++20まで*)(C++17)

(C++11)
(C++17)
コンパイル時有理数演算
コンパイル時整数シーケンス
 
ヘッダ <type_traits> で定義
template< class T >
struct is_copy_assignable;
(1) (C++11以降)
template< class T >
struct is_trivially_copy_assignable;
(2) (C++11以降)
template< class T >
struct is_nothrow_copy_assignable;
(3) (C++11以降)
 型特性  メンバ定数valueの値
Tは参照可能な型  Tは参照可能な型ではない
(1) std::is_assignable<T&, const T&>::value false
(2) std::is_trivially_assignable<T&, const T&>::value
(3) std::is_nothrow_assignable<T&, const T&>::value

T が不完全型、(cv修飾されている可能性のある)void、または不明な境界を持つ配列の場合、動作は未定義です。

上記のテンプレートのインスタンス化が、直接的または間接的に不完全な型に依存し、その型が仮に完全になった場合にそのインスタンス化が異なる結果を生み出す可能性がある場合、動作は未定義です。

プログラムがこのページで説明されているテンプレートのいずれかに特殊化を追加する場合、動作は未定義です。

目次

[編集] ヘルパー変数テンプレート

template< class T >

inline constexpr bool is_copy_assignable_v =

    is_copy_assignable<T>::value;
(C++17以降)
template< class T >

inline constexpr bool is_trivially_copy_assignable_v =

    is_trivially_copy_assignable<T>::value;
(C++17以降)
template< class T >

inline constexpr bool is_nothrow_copy_assignable_v =

    is_nothrow_copy_assignable<T>::value;
(C++17以降)

std::integral_constant から継承

メンバ定数

value
[static]
true if T is copy-assignable, false otherwise
(公開静的メンバ定数)

メンバ関数

operator bool
オブジェクトを bool に変換し、value を返します。
(public member function)
operator()
(C++14)
value を返します。
(public member function)

メンバ型

定義
value_type bool
type std::integral_constant<bool, value>

[編集] 実装の可能性

template<class T>
struct is_copy_assignable
    : std::is_assignable<typename std::add_lvalue_reference<T>::type,
                         typename std::add_lvalue_reference<const T>::type> {};
 
template<class T>
struct is_trivially_copy_assignable
    : std::is_trivially_assignable<typename std::add_lvalue_reference<T>::type,
                                   typename std::add_lvalue_reference<const T>::type> {};
 
template<class T>
struct is_nothrow_copy_assignable
    : std::is_nothrow_assignable<typename std::add_lvalue_reference<T>::type,
                                 typename std::add_lvalue_reference<const T>::type> {};

[編集] 注記

The trait std::is_copy_assignable is less strict than CopyAssignable because it does not check the type of the result of the assignment (which, for a CopyAssignable type, must be an lvalue of type T) and does not check the semantic requirement that the argument expression remains unchanged. It also does not check that T satisfies MoveAssignable, which is required of all CopyAssignable types.

[編集]

#include <iostream>
#include <type_traits>
#include <utility>
 
struct Foo { int n; };
 
int main()
{
    std::cout << std::boolalpha
              << "Foo is trivially copy-assignable? "
              << std::is_trivially_copy_assignable<Foo>::value << '\n'
              << "int[2] is copy-assignable? "
              << std::is_copy_assignable<int[2]>::value << '\n'
              << "int is nothrow copy-assignable? "
              << std::is_nothrow_copy_assignable<int>::value << '\n';
}

出力

Foo is trivially copy-assignable? true
int[2] is copy-assignable? false
int is nothrow copy-assignable? true

[編集] 不具合報告

以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。

DR 適用対象 公開された動作 正しい動作
LWG 2196 C++11 the behavior was unclear if const T& cannot be formed この場合、生成される値はfalseである

[編集] 関連項目

型が特定の引数に対する代入演算子を持つかをチェックする
(クラステンプレート) [編集]
型がムーブ代入演算子を持つかをチェックする
(クラステンプレート) [編集]
English 日本語 中文(简体) 中文(繁體)