Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

      From cppreference.com
      <cpp‎ |types
       
       
      Metaprogramming library
      Type traits
      Type categories
      (C++11)
      (C++11)(DR*)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11)
      (C++11) 
      Type properties
      (C++11)
      (C++11)
      (C++14)
      (C++11)(deprecated in C++26)
      (C++11)(until C++20*)
      (C++11)(deprecated in C++20)
      (C++11)
      Type trait constants
      Metafunctions
      (C++17)
      Supported operations
      is_copy_assignableis_trivially_copy_assignableis_nothrow_copy_assignable
      (C++11)(C++11)(C++11)

      Relationships and property queries
      Type modifications
      Type transformations
      (C++11)(deprecated in C++23)
      (C++11)(deprecated in C++23)
      (C++11)
      (C++11)(until C++20*)(C++17)

      Compile-time rational arithmetic
      Compile-time integer sequences
       
      Defined in header<type_traits>
      template<class T>
      struct is_copy_assignable;
      (1)(since C++11)
      template<class T>
      struct is_trivially_copy_assignable;
      (2)(since C++11)
      template<class T>
      struct is_nothrow_copy_assignable;
      (3)(since C++11)
       Type trait The value of the member constantvalue
      T is areferenceable type T is not a referenceable type 
      (1)std::is_assignable<T&,const T&>::valuefalse
      (2)std::is_trivially_assignable<T&,const T&>::value
      (3)std::is_nothrow_assignable<T&,const T&>::value

      IfT is not a complete type, (possibly cv-qualified)void, or an array of unknown bound, 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 for any of the templates described on this page, the behavior is undefined.

      Contents

      [edit]Helper variable templates

      template<class T>

      inlineconstexprbool is_copy_assignable_v=

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

      inlineconstexprbool is_trivially_copy_assignable_v=

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

      inlineconstexprbool is_nothrow_copy_assignable_v=

          is_nothrow_copy_assignable<T>::value;
      (since C++17)
      [edit]

      Inherited fromstd::integral_constant

      Member constants

      value
      [static]
      true ifT is copy-assignable,false otherwise
      (public static member constant)

      Member functions

      operator bool
      converts the object tobool, returnsvalue
      (public member function)
      operator()
      (C++14)
      returnsvalue
      (public member function)

      Member types

      Type Definition
      value_typebool
      typestd::integral_constant<bool, value>

      [edit]Possible implementation

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

      [edit]Notes

      The traitstd::is_copy_assignable is less strict thanCopyAssignable because it does not check the type of the result of the assignment (which, for aCopyAssignable type, must be an lvalue of typeT) and does not check the semantic requirement that the argument expression remains unchanged. It also does not check thatT satisfiesMoveAssignable, which is required of allCopyAssignable types.

      [edit]Example

      Run this code
      #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';}

      Output:

      Foo is trivially copy-assignable? trueint[2] is copy-assignable? falseint is nothrow copy-assignable? true

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 2196C++11the behavior was unclear ifconst T& cannot be formedthe value produced isfalse in this case

      [edit]See also

      checks if a type has an assignment operator for a specific argument
      (class template)[edit]
      checks if a type has a move assignment operator
      (class template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/types/is_copy_assignable&oldid=177620"

      [8]ページ先頭

      ©2009-2025 Movatter.jp