std::is_cop...assignable,(3)
π¦ std::is_cop...assignable,(3) π¦
okay bestie, this is the C++ Standard Libary page for the copy-assignable type traits β yes, the header really spells it βLibaryβ π. Weβre talking about std::is_copy_assignable, std::is_trivially_copy_assignable, and the nothrow one too. The pageβs own manual name is std::is_cop...assignable,(3), so thatβs the vibe. π
π NAME π
The NAME line is literally:
std::is_copy_assignable,std::is_trivially_copy_assignable, - std::is_copy_assignable,std::is_trivially_copy_assignable,
yes, it repeats itself and leaves out the nothrow trait in that line β thatβs just what the page says, bestie. π«Ά
πΈ Synopsis πΈ
Defined in header <type_traits>.
template< class T > (1) (since C++11)
struct is_copy_assignable;
template< class T > (2) (since C++11)
struct is_trivially_copy_assignable;
template< class T > (3) (since C++11)
struct is_nothrow_copy_assignable;
The value of the member constant value is:
- if
Tis a referenceable type:(1)βstd::is_assignable<T, const T&>::value(2)βstd::is_trivially_assignable<T, const T&>::value(3)βstd::is_nothrow_assignable<T, const T&>::value
- if
Tis not a referenceable type βfalseπ
π¨ undefined behavior alert: ifTis not a complete type, (possibly cv-qualified)void, or an array of unknown bound, the behavior is undefined. π¨ also 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. π¨ and if the program adds specializations for any of the templates described on this page, the behavior is undefined.
π Member constants π
valueβtrueifTis copy-assignable,falseotherwise;[static](public static member constant) β¨
β¨ Member functions β¨
operator boolβ converts the object tobool, returnsvalue(public member function)operator()β returnsvalue(C++14) (public member function)
π Member types π
value_typeβbooltypeβstd::integral_constant<bool, value>
π Possible implementation π
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> {};
π Notes π
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.
so likeβ¦ itβs not doing the full vibe check, just the assignment part. π
π Example π
The page says // Run this code before the snippet:
#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? true
int[2] is copy-assignable? false
int is nothrow copy-assignable? true
π¦ See also π¦
is_assignable/is_trivially_assignable/is_nothrow_assignableβ checks if a type has an assignment operator for a specific argument (class template); all three are(C++11)β¨is_move_assignable/is_trivially_move_assignable/is_nothrow_move_assignableβ checks if a type has a move assignment operator (class template); all three are(C++11)β¨
okay thatβs the whole page, bestie π«Ά Source: http://cppreference.com Β· Version/date: 2024.06.10 Β· Manual: std::is_cop...assignable,(3) π
β¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms