std::is_copy_constructible, std::is_trivially_copy_constructible, std::is_nothrow_copy_constructible
Материал из cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
| Заголовочный файл <type_traits>
|
||
| template< class T > struct is_copy_constructible; |
(1) | (начиная с C++11) |
| template< class T > struct is_trivially_copy_constructible; |
(2) | (начиная с C++11) |
| template< class T > struct is_nothrow_copy_constructible; |
(3) | (начиная с C++11) |
Проверяет, является ли тип
2) CopyConstructible, т. е. имеет доступный явного или неявного конструктора копии. Если требование считается выполненным, член постоянной value равных true обеспечивается, в противном случае value является 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.
То же, что (1), но выражение конструктор копии не вызывает любая операция, которая не является тривиальной.
3) 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.
То же, что (1), но выражение конструктор копии 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.
Содержание |
Унаследован от std::integral_constant
Member constants
| value [static] |
true если T is copy-constructible , false иначе 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 константа-член) |
Member functions
| operator bool |
преобразует объект в bool, возвращает 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. (public функция-член) |
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> |
[править] Возможная реализация
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> {}; |
[править] Пример
#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'; }
Вывод:
Ex1 is copy-constructible? true Ex1 is trivially copy-constructible? false Ex2 is trivially copy-constructible? true Ex2 is nothrow copy-constructible? true
[править] См. также
| (C++11) (C++11) (C++11) |
проверяет, является ли тип имеет конструктор для конкретных аргументов Original: checks if a type has a constructor for specific arguments The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон класса) |
| проверяет, является ли тип имеет конструктор по умолчанию Original: checks if a type has a default constructor The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон класса) | |
| (C++11) (C++11) (C++11) |
проверяет, является ли тип имеет ход конструктора Original: checks if a type has a move constructor The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (шаблон класса) |