Namespaces
Variants

std:: is_copy_constructible, std:: is_trivially_copy_constructible, std:: is_nothrow_copy_constructible

From cppreference.net
Metaprogramming library
Type traits
Type categories
(C++11)
(C++11) ( DR* )
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
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
Definiert im Header <type_traits>
template < class T >
struct is_copy_constructible ;
(1) (seit C++11)
template < class T >
struct is_trivially_copy_constructible ;
(2) (seit C++11)
template < class T >
struct is_nothrow_copy_constructible ;
(3) (seit C++11)
Type-Trait Wert der Member-Konstante value
T ist ein referenzierbarer Typ T ist kein referenzierbarer Typ
(1) std:: is_constructible < T, const T & > :: value false
(2) std:: is_trivially_constructible < T, const T & > :: value
(3) std:: is_nothrow_constructible < T, const T & > :: value

Wenn T kein vollständiger Typ ist, (möglicherweise cv-qualifiziert) void , oder ein Array unbekannter Größe, ist das Verhalten undefiniert.

Wenn eine Instanziierung einer Vorlage oben direkt oder indirekt von einem unvollständigen Typ abhängt und diese Instanziierung ein anderes Ergebnis liefern könnte, wenn dieser Typ hypothetisch vervollständigt würde, ist das Verhalten undefiniert.

Wenn das Programm Spezialisierungen für irgendeine der auf dieser Seite beschriebenen Templates hinzufügt, ist das Verhalten undefiniert.

Inhaltsverzeichnis

Hilfsvariablen-Templates

template < class T >

inline constexpr bool is_copy_constructible_v =

is_copy_constructible < T > :: value ;
(seit C++17)
template < class T >

inline constexpr bool is_trivially_copy_constructible_v =

is_trivially_copy_constructible < T > :: value ;
(seit C++17)
template < class T >

inline constexpr bool is_nothrow_copy_constructible_v =

is_nothrow_copy_constructible < T > :: value ;
(seit C++17)

Geerbt von std:: integral_constant

Member-Konstanten

value
[static]
true wenn T kopierkonstruierbar ist, false andernfalls
(öffentliche statische Member-Konstante)

Member-Funktionen

operator bool
konvertiert das Objekt zu bool , gibt value zurück
(öffentliche Member-Funktion)
operator()
(C++14)
gibt value zurück
(öffentliche Member-Funktion)

Member-Typen

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

Mögliche Implementierung

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> {};
**Hinweis:** Der gesamte C++-Code innerhalb der `
`-Tags wurde gemäß den Anforderungen nicht übersetzt, da er:
- C++-spezifische Begriffe enthält
- Innerhalb von Code-Tags steht
- Technische Präzision erfordert
Die HTML-Struktur, Attribute und Formatierung bleiben vollständig erhalten.

Hinweise

In vielen Implementierungen überprüft is_nothrow_copy_constructible auch, ob der Destruktor wirft, da es effektiv noexcept ( T ( arg ) ) ist. Gleiches gilt für is_trivially_copy_constructible , das in diesen Implementierungen ebenfalls erfordert, dass der Destruktor trivial ist: GCC bug 51452 , LWG issue 2116 .

Beispiel

#include <string>
#include <type_traits>
struct S1
{
    std::string str; // Member hat einen nicht-trivialen Kopierkonstruktor
};
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 und nicht-werfend
};
static_assert(std::is_trivially_copy_constructible_v<S2>);
static_assert(std::is_nothrow_copy_constructible_v<S2>);
struct S3
{
    S3(const S3&) = delete; // explizit gelöscht
};
static_assert(!std::is_copy_constructible_v<S3>);
struct S4
{
    S4(S4&) {}; // kann const nicht binden, daher nicht kopierkonstruierbar
};
static_assert(!std::is_copy_constructible_v<S4>);
int main() {}

Fehlerberichte

Die folgenden verhaltensändernden Fehlerberichte wurden rückwirkend auf zuvor veröffentlichte C++-Standards angewendet.

DR Angewendet auf Verhalten wie veröffentlicht Korrektes Verhalten
LWG 2196 C++11 das Verhalten war unklar, falls const T & nicht gebildet werden kann der produzierte Wert ist false in diesem Fall

Siehe auch

prüft, ob ein Typ einen Konstruktor für bestimmte Argumente besitzt
(Klassentemplate)
prüft, ob ein Typ einen Standardkonstruktor besitzt
(Klassentemplate)
prüft, ob ein Typ aus einem Rvalue-Referenz konstruiert werden kann
(Klassentemplate)
spezifiziert, dass ein Objekt eines Typs kopierkonstruiert und bewegekonstruiert werden kann
(Konzept)