std::is_copy_constructible, std::is_trivially_copy_constructible, std::is_nothrow_copy_constructible
Aus cppreference.com
<metanoindex/>
<tbody> </tbody>| definiert in 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) |
1)
Prüft, ob eine Art
CopyConstructible ist, dh eine zugängliche explizite oder implizite Copy-Konstruktor. Wenn die Bedingung erfüllt ist, ein Mitglied konstanten value gleich true bereitgestellt wird, sonst value ist false .Original:
Checks whether a type is
CopyConstructible, i.e. has an accessible explicit or implicit copy constructor. If the requirement is met, a member constant value equal true is provided, otherwise value is false.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
Same as (1), aber die Kopie Konstruktor Ausdruck nicht nennen jede Operation, die nicht trivial ist .
Original:
Same as (1), but the copy constructor expression does not call any operation that is not trivial.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
3)
Same as (1), aber die Kopie Konstruktor Ausdruck noexcept .
Original:
Same as (1), but the copy constructor expression is noexcept.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Inherited from std::integral_constant
Member constants
value [statisch] |
true wenn T is copy-constructible , false anders Original: true if T is copy-constructible , false otherwise The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (public static Mitglied konstanten) |
Member functions
operator bool |
wandelt das Objekt bool, gibt value Original: converts the object to bool, returns value The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (öffentliche Elementfunktion) |
Member types
Type
Original: Type The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Definition |
value_type
|
bool
|
type
|
std::integral_constant<bool, value>
|
Mögliche Implementierung
template<class T>
struct is_copy_constructible :
std::is_constructible<T, const typename std::add_lvalue_reference<T>::type> {};
template<class T>
struct is_trivially_copy_constructible :
std::is_trivially_constructible<T, const typename std::add_lvalue_reference<T>::type> {};
template<class T>
struct is_nothrow_copy_constructible :
std::is_nothrow_constructible<T, const typename std::add_lvalue_reference<T>::type> {};
|
Beispiel
#include <iostream>
#include <type_traits>
struct Ex1 {
std::string str; // member has a non-trivial copy ctor
};
struct Ex2 {
int n;
Ex2(const Ex2&) = default; // trivial and non-throwing
};
int main() {
std::cout << std::boolalpha << "Ex1 is copy-constructible? "
<< std::is_copy_constructible<Ex1>::value << '\n'
<< "Ex1 is trivially copy-constructible? "
<< std::is_trivially_copy_constructible<Ex1>::value << '\n'
<< "Ex2 is trivially copy-constructible? "
<< std::is_trivially_copy_constructible<Ex2>::value << '\n'
<< "Ex2 is nothrow copy-constructible? "
<< std::is_nothrow_copy_constructible<Ex2>::value << '\n';
}
Output:
Ex1 is copy-constructible? true
Ex1 is trivially copy-constructible? false
Ex2 is trivially copy-constructible? true
Ex2 is nothrow copy-constructible? true
