std::is_trivial
Материал из 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_trivial; |
(начиная с C++11) | |
Если
T является тривиальным типа (то есть, скалярного типа, тривиально копируемой класса с тривиальным конструктором по умолчанию, или массиве такого типа / класса, возможно, резюме квалифицированных), обеспечивает постоянный член value равных true. Для любого другого типа, value является false.Original:
If
T is a trivial type (that is, a scalar type, a trivially copyable class with a trivial default constructor, or array of such type/class, possibly cv-qualified), provides the member constant value equal true. For any other type, 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.
Содержание |
Унаследован от std::integral_constant
Member constants
| value [static] |
true если T is a trivial type , false иначе Original: true if T is a trivial type , 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> |
[править] Notes
Только объекты (в том числе массивы) тривиального типа могут быть созданы с помощью вызова std::malloc.
Original:
Only objects (including arrays) of trivial type may be created by a call to std::malloc.
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.
[править] Возможная реализация
template< class T > struct is_trivial : std::integral_constant< bool, std::is_trivially_copyable<T>::value && std::is_trivially_default_constructible<T>::value > {}; |
[править] Пример
#include <iostream> #include <type_traits> struct A { int m; }; struct B { B() {} }; int main() { std::cout << std::boolalpha; std::cout << std::is_trivial<A>::value << '\n'; std::cout << std::is_trivial<B>::value << '\n'; }
Вывод:
true false
[править] См. также
| (C++11) |
checks if a type is trivially copyable (шаблон класса) |