std::is_cop...structible,(3)
π NAME π
Okay so this is the page for std::is_copy_constructible, std::is_trivially_copy_constructible, and std::is_nothrow_copy_constructible from the C++ Standard Library β the manual label is std::is_cop...structible,(3). The literal NAME line in this copy is: std::is_copy_constructible,std::is_trivially_copy_constructible, - std::is_copy_constructible,std::is_trivially_copy_constructible, (yes bestie, thatβs exactly how itβs written π
).
β¨ Synopsis β¨
Defined in header <type_traits>.
template< class T > (1) (since C++11)
struct is_copy_constructible;
template< class T > (2) (since C++11)
struct is_trivially_copy_constructible;
template< class T > (3) (since C++11)
struct is_nothrow_copy_constructible;
The vibe here is all about the value of the member constant value, and the table is giving Type trait, T is a referenceable type, and T is not a referenceable type energy:
(1)is_copy_constructibleβ ifTis a referenceable type,valueisstd::is_constructible<T, const T&>::value.(2)is_trivially_copy_constructibleβ ifTis a referenceable type,valueisstd::is_trivially_constructible<T, const T&>::value; ifTis not a referenceable type,false.(3)is_nothrow_copy_constructibleβ ifTis a referenceable type,valueisstd::is_nothrow_constructible<T, const T&>::value; ifTis not a referenceable type,false.
IfTis not a complete type, (possibly cv-qualified)void, or an array of unknown bound, the behavior is undefined. No cap, thatβs the rule π
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. Periodt π
π Member constants π
valueβtrueifTis copy-constructible,falseotherwise;[static](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 πΈ
value_typeβbooltypeβstd::integral_constant<bool, value>
π₯ Possible implementation π₯
Hereβs the possible implementation, bestie β iconic template energy:
template<class T>
struct is_copy_constructible :
std::is_constructible<T, typename std::add_lvalue_reference<
typename std::add_const<T>::type>::type> {};
template<class T>
struct is_trivially_copy_constructible :
std::is_trivially_constructible<T, typename
std::add_lvalue_reference<
typename std::add_const<T>::type>::type> {};
template<class T>
struct is_nothrow_copy_constructible :
std::is_nothrow_constructible<T, typename
std::add_lvalue_reference<
typename std::add_const<T>::type>::type> {};
π Notes π
In many implementations, is_nothrow_copy_constructible also checks if the destructor throws because it is effectively noexcept(T(arg)). Same applies to is_trivially_copy_constructible, which, in these implementations, also requires that the destructor is trivial: GCC bug 51452, LWG issue 2116.
π Example π
// Run this code
#include <string>
#include <type_traits>
struct S1
{
std::string str; // member has a non-trivial copy constructor
};
static_assert(std::is_copy_constructible_v<S1>);
static_assert(!std::is_trivially_copy_constructible_v<S1>);
struct S2
{
int n;
S2(const S2&) = default; // trivial and non-throwing
};
static_assert(std::is_trivially_copy_constructible_v<S2>);
static_assert(std::is_nothrow_copy_constructible_v<S2>);
struct S3
{
S3(const S3&) = delete; // explicitly deleted
};
static_assert(!std::is_copy_constructible_v<S3>);
struct S4
{
S4(S4&) {}; // can't bind const, hence not a copy-constructible
};
static_assert(!std::is_copy_constructible_v<S4>);
int main() {}
π See also π
is_constructible(C++11),is_trivially_constructible(C++11),is_nothrow_constructible(C++11)β checks if a type has a constructor for specific arguments (class template).is_default_constructible(C++11),is_trivially_default_constructible(C++11),is_nothrow_default_constructible(C++11)β checks if a type has a default constructor (class template).is_move_constructible(C++11),is_trivially_move_constructible(C++11),is_nothrow_move_constructible(C++11)β checks if a type can be constructed from an rvalue reference (class template).copy_constructible(C++20)β specifies that an object of a type can be copy constructed and move constructed (concept).
Thatβs the whole page, bestie π«Ά β source: http://cppreference.com, dated 2024.06.10, with the page label std::is_cop...structible,(3). Slay β¨
π¦ 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