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. |
| Defined in header <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.
目錄 |
Inherited from std::integral_constant
Member constants
| value [靜態的] </ SPAN></div></div>
|
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. (公共靜態成員常量) |
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. (公共成員函數) |
Member types
| 類型
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> |
</div>
[编辑] 可能的實現
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'; }
Output:
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. (類模板) |