{"id":6252,"date":"2021-11-18T21:08:53","date_gmt":"2021-11-18T21:08:53","guid":{"rendered":"https:\/\/www.modernescpp.com\/index.php\/the-type-traits-library-type-checks\/"},"modified":"2023-06-26T09:22:14","modified_gmt":"2023-06-26T09:22:14","slug":"the-type-traits-library-type-checks","status":"publish","type":"post","link":"https:\/\/www.modernescpp.com\/index.php\/the-type-traits-library-type-checks\/","title":{"rendered":"The Type-Traits Library: Type Checks"},"content":{"rendered":"<p>The type-traits library is part of C++11 and supports type checks, type comparisons, and type modifications at compile time. The library has over 100 functions but grows with each new C++ standard release. Today, I present the type checks.<\/p>\n<p><!--more--><\/p>\n<p>&nbsp;<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-6251\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2021\/11\/templatesTypeTraits.png\" alt=\"templatesTypeTraits\" width=\"650\" height=\"412\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2021\/11\/templatesTypeTraits.png 918w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2021\/11\/templatesTypeTraits-300x190.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2021\/11\/templatesTypeTraits-768x487.png 768w\" sizes=\"auto, (max-width: 650px) 100vw, 650px\" \/><\/p>\n<h2>Type Checks<\/h2>\n<p>Each type belongs precisely to one of the fourteen primary type categories.<\/p>\n<h3>Primary Type Categories<\/h3>\n<p>Here are all of them:<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_void;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_floating_point;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_array;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_pointer;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_null_pointer;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_member_object_pointer;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_member_function_pointer;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_enum;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_union;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_class;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_function;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_lvalue_reference;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_rvalue_reference;\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>The following program gives an example of a type fulfilling the check for each one of these primary type categories.<\/p>\n<p>&nbsp;<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #009999;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ primaryTypeCategories.cpp<\/span><br \/><br \/>#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;type_traits&gt;<\/span>\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">struct<\/span> A {\r\n  <span style=\"color: #007788; font-weight: bold;\">int<\/span> a;\r\n  <span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">f<\/span>(<span style=\"color: #007788; font-weight: bold;\">int<\/span>) { <span style=\"color: #006699; font-weight: bold;\">return<\/span> <span style=\"color: #ff6600;\">2011<\/span>; }\r\n};\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">enum<\/span> E {\r\n  e<span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">1<\/span>,\r\n};\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">union<\/span> U {\r\n  <span style=\"color: #007788; font-weight: bold;\">int<\/span> u;\r\n};\r\n\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #cc00ff;\">main<\/span>() {\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">using<\/span> <span style=\"color: #006699; font-weight: bold;\">namespace<\/span> std;\r\n  \r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span>  boolalpha <span style=\"color: #555555;\">&lt;&lt;<\/span>  <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_void<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">void<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                               <span style=\"color: #0099ff; font-style: italic;\">\/\/ true                           <\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">short<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                          <span style=\"color: #0099ff; font-style: italic;\">\/\/ true<\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_floating_point<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">double<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                   <span style=\"color: #0099ff; font-style: italic;\">\/\/ true<\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_array<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span> []<span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                            <span style=\"color: #0099ff; font-style: italic;\">\/\/ true<\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_pointer<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">*&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                            <span style=\"color: #0099ff; font-style: italic;\">\/\/ true<\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_null_pointer<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">nullptr_t<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                  <span style=\"color: #0099ff; font-style: italic;\">\/\/ true<\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_member_object_pointer<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span> A<span style=\"color: #555555;\">::*&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span>  <span style=\"color: #cc3300;\">'\\n'<\/span>;         <span style=\"color: #0099ff; font-style: italic;\">\/\/ true<\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_member_function_pointer<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span> (A<span style=\"color: #555555;\">::*<\/span>)(<span style=\"color: #007788; font-weight: bold;\">int<\/span>)<span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>; <span style=\"color: #0099ff; font-style: italic;\">\/\/ true<\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_enum<span style=\"color: #555555;\">&lt;<\/span>E<span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                                  <span style=\"color: #0099ff; font-style: italic;\">\/\/ true<\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_union<span style=\"color: #555555;\">&lt;<\/span>U<span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                                 <span style=\"color: #0099ff; font-style: italic;\">\/\/ true <\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_class<span style=\"color: #555555;\">&lt;<\/span>string<span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                            <span style=\"color: #0099ff; font-style: italic;\">\/\/ true<\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_function<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span> <span style=\"color: #555555;\">*<\/span> (<span style=\"color: #007788; font-weight: bold;\">double<\/span>)<span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                 <span style=\"color: #0099ff; font-style: italic;\">\/\/ true\t<\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_lvalue_reference<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&amp;&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                   <span style=\"color: #0099ff; font-style: italic;\">\/\/ true<\/span>\r\n  cout <span style=\"color: #555555;\">&lt;&lt;<\/span> is_rvalue_reference<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&amp;&amp;&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;                  <span style=\"color: #0099ff; font-style: italic;\">\/\/ true<\/span>\r\n  \r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<\/p>\n<h4>How Does this Magic Work?<\/h4>\n<p>This technique is based on templates and template specialization, a few conventions, and much typing. I wrote a simplified version of the function template<code> std::integral. std::integral<\/code> to check if a given type is an integral type. I ignore <code>const<\/code> or <code>volatile<\/code> qualifiers.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #0099ff; font-style: italic;\">\/\/ integral.cpp<\/span>\r\n\r\n<span style=\"color: #009999;\">#include &lt;iostream&gt;<\/span>\r\n<span style=\"color: #009999;\">#include &lt;type_traits&gt;<\/span>\r\n\r\n<span style=\"color: #006699; font-weight: bold;\">namespace<\/span> rgr{\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span><span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span>, T v<span style=\"color: #555555;\">&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> integral_constant {\r\n      <span style=\"color: #006699; font-weight: bold;\">static<\/span> constexpr T value <span style=\"color: #555555;\">=<\/span> v;\r\n      <span style=\"color: #006699; font-weight: bold;\">typedef<\/span> T value_type;\r\n      <span style=\"color: #006699; font-weight: bold;\">typedef<\/span> integral_constant type;\r\n      constexpr <span style=\"color: #006699; font-weight: bold;\">operator<\/span> value_type() <span style=\"color: #006699; font-weight: bold;\">const<\/span> noexcept { <span style=\"color: #006699; font-weight: bold;\">return<\/span> value; }\r\n      constexpr value_type <span style=\"color: #006699; font-weight: bold;\">operator<\/span>()() <span style=\"color: #006699; font-weight: bold;\">const<\/span> noexcept { <span style=\"color: #006699; font-weight: bold;\">return<\/span> value; } <span style=\"color: #0099ff; font-style: italic;\">\/\/since c++14<\/span>\r\n  };\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">typedef<\/span> integral_constant<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">bool<\/span>, <span style=\"color: #336666;\">true<\/span><span style=\"color: #555555;\">&gt;<\/span> true_type;                       <span style=\"color: #0099ff; font-style: italic;\">\/\/ (2)<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">typedef<\/span> integral_constant<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">bool<\/span>, <span style=\"color: #336666;\">false<\/span><span style=\"color: #555555;\">&gt;<\/span> false_type;\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> false_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">bool<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">char<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">signed<\/span> <span style=\"color: #007788; font-weight: bold;\">char<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">unsigned<\/span> <span style=\"color: #007788; font-weight: bold;\">char<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">wchar_t<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">short<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};                              <span style=\"color: #0099ff; font-style: italic;\">\/\/ (3)<\/span>\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">long<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">long<\/span> <span style=\"color: #007788; font-weight: bold;\">long<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">unsigned<\/span> <span style=\"color: #007788; font-weight: bold;\">short<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">unsigned<\/span> <span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">unsigned<\/span> <span style=\"color: #007788; font-weight: bold;\">long<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n\r\n  <span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;&gt;<\/span>\r\n  <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">unsigned<\/span> <span style=\"color: #007788; font-weight: bold;\">long<\/span> <span style=\"color: #007788; font-weight: bold;\">long<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #555555;\">:<\/span> <span style=\"color: #006699; font-weight: bold;\">public<\/span> true_type{};\r\n  \r\n}\r\n\r\n<span style=\"color: #007788; font-weight: bold;\">int<\/span> main(){\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>boolalpha <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"std::is_integral&lt;int&gt;::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"rgr::is_integral&lt;int&gt;::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> rgr<span style=\"color: #555555;\">::<\/span>is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">int<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;    <span style=\"color: #0099ff; font-style: italic;\">\/\/ (1)<\/span>\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"std::is_integral&lt;double&gt;::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">double<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"rgr::is_integral&lt;double&gt;::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> rgr<span style=\"color: #555555;\">::<\/span>is_integral<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">double<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"std::true_type::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>true_type<span style=\"color: #555555;\">::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"rgr::true_type::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> rgr<span style=\"color: #555555;\">::<\/span>true_type<span style=\"color: #555555;\">::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"std::false_type::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>false_type<span style=\"color: #555555;\">::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"rgr::false_type::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> rgr<span style=\"color: #555555;\">::<\/span>false_type<span style=\"color: #555555;\">::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"std::integral_constant&lt;bool, true&gt;::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>integral_constant<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">bool<\/span>, <span style=\"color: #336666;\">true<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"rgr::integral_constant&lt;bool, true&gt;::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> rgr<span style=\"color: #555555;\">::<\/span>integral_constant<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">bool<\/span>, <span style=\"color: #336666;\">true<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"std::integral_constant&lt;bool, false&gt;::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> std<span style=\"color: #555555;\">::<\/span>integral_constant<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">bool<\/span>, <span style=\"color: #336666;\">false<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">\"rgr::integral_constant&lt;bool, false&gt;::value: \"<\/span> <span style=\"color: #555555;\">&lt;&lt;<\/span> rgr<span style=\"color: #555555;\">::<\/span>integral_constant<span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #007788; font-weight: bold;\">bool<\/span>, <span style=\"color: #336666;\">false<\/span><span style=\"color: #555555;\">&gt;::<\/span>value <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;  \r\n  \r\n  std<span style=\"color: #555555;\">::<\/span>cout <span style=\"color: #555555;\">&lt;&lt;<\/span> <span style=\"color: #cc3300;\">'\\n'<\/span>;\r\n  \r\n}\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>I use in my implementation the namespace <code>rgr<\/code> and compare it with type-traits functions in the namespace <code>std<\/code>. The invocation of the function template<code>&nbsp;rgr::is_integral&lt;int&gt;::value<\/code> (1) causes the invocation of the expression <code>rgr::true_type::value<\/code> (2) because<code> integral&lt;int&gt;<\/code> is derived from <code>true_type<\/code> (3). <code>rgr::true_type::value<\/code> is an alias for <code>rgr::integral_constant&lt;bool, true&gt;::value<\/code> (2). I use in the example&nbsp;the static <code>constexpr<\/code> value of the class <code>integral_constant<\/code>.<code> integral_constant<\/code> is the base class of the type-traits functions.<\/p>\n<p>For completeness, here is the output of the program. My implementation gives the same results, such as functions from the type-traits library.<\/p>\n<p>&nbsp;<img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4987\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/integral.png\" alt=\"integral\" width=\"550\" height=\"324\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/integral.png 632w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/integral-300x177.png 300w\" sizes=\"auto, (max-width: 550px) 100vw, 550px\" \/><\/p>\n<p>I use in my function templates<code> rgr::is_integra<\/code>l <code>::value<\/code> as return. You maybe remember this convention from my previous post, &#8220;<a href=\"https:\/\/www.modernescpp.com\/index.php\/template-metaprogramming-how-it-works\">Template Metaprogramming &#8211; How it works<\/a>&#8220;? Right!&nbsp; My function templates <code>rgr::is_integral<\/code> are metafunctions and use template metaprogramming&#8217;s naming conventions. Since C++17, there is, for conventions, a helper class for<code> ::value<\/code>. This helper class is based on variable templates.<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #006699; font-weight: bold;\">template<\/span><span style=\"color: #555555;\">&lt;<\/span> <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span> <span style=\"color: #555555;\">&gt;<\/span>\r\n<span style=\"color: #006699; font-weight: bold;\">inline<\/span> constexpr <span style=\"color: #007788; font-weight: bold;\">bool<\/span> is_integral_v <span style=\"color: #555555;\">=<\/span> is_integral<span style=\"color: #555555;\">&lt;<\/span>T<span style=\"color: #555555;\">&gt;::<\/span>value\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Variable templates are essentially a family of variables. Due to this helper class, you can write<code> std::integral_v&lt;T&gt;<\/code> instead of <code>std::integral&lt;T&gt;::value<\/code>.&nbsp; This shortened notation works for all function templates of the type traits library.<\/p>\n<p>Composite type categories are then assembled from those primary type categories.<\/p>\n<h3>Composite Type Categories<\/h3>\n<p>There are seven composite type categories. The following table shows them.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\" size-full wp-image-4988\" src=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/CompositeTypeCategories.png\" alt=\"CompositeTypeCategories\" width=\"600\" height=\"459\" style=\"display: block; margin-left: auto; margin-right: auto;\" srcset=\"https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/CompositeTypeCategories.png 915w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/CompositeTypeCategories-300x229.png 300w, https:\/\/www.modernescpp.com\/wp-content\/uploads\/2016\/10\/CompositeTypeCategories-768x587.png 768w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p>In additionally, to the primary type categories and the composite type categories, the type traits library provides type properties and type property queries. For completeness, here are they.<\/p>\n<h3>Type Properties<\/h3>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_const;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_volatile;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_trivial;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_trivially_copyable;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_standard_layout;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_empty;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_polymorphic;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_abstract;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_final;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_aggregate;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_signed;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_unsigned;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_bounded_array;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_unbounded_array;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_scoped_enum;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span>, class... Args<span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_constructible;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_default_constructible;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_copy_constructible;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_move_constructible;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span>, <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">U<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_assignable;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_copy_assignable;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_move_assignable;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span>, <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">U<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_swappable_with;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_swappable;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_destructible;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span>, class... Args<span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_trivially_constructible;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_trivially_default_constructible;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_trivially_copy_constructible;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_trivially_move_constructible;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span>, <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">U<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_trivially_assignable;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_trivially_copy_assignable;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_trivially_move_assignable;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_trivially_destructible;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span>, class... Args<span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_nothrow_constructible;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_nothrow_default_constructible;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_nothrow_copy_constructible;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_nothrow_move_constructible;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span>, <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">U<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_nothrow_assignable;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_nothrow_copy_assignable;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_nothrow_move_assignable;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span>, <span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">U<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_nothrow_swappable_with;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_nothrow_swappable;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> is_nothrow_destructible;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> has_virtual_destructor;\r\n \r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> has_unique_object_representations;\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<p>Many of the meta-functions like <code>std::is_trivially_copyable<\/code> have trivially in their name. That means that the compiler provides this method. Requesting a method from the compiler with the keyword <code>default<\/code> is also trivial.<\/p>\n<h3>Type Property Queries<\/h3>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #f0f3f3; overflow: auto; width: auto; gray;border-width: .1em .1em .1em .8em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> alignment_of;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> rank;\r\n<span style=\"color: #006699; font-weight: bold;\">template<\/span> <span style=\"color: #555555;\">&lt;<\/span><span style=\"color: #006699; font-weight: bold;\">class<\/span> <span style=\"color: #00aa88; font-weight: bold;\">T<\/span>, <span style=\"color: #007788; font-weight: bold;\">unsigned<\/span> I <span style=\"color: #555555;\">=<\/span> <span style=\"color: #ff6600;\">0<\/span><span style=\"color: #555555;\">&gt;<\/span> <span style=\"color: #006699; font-weight: bold;\">struct<\/span> extent;\r\n<\/pre>\n<\/div>\n<p>&nbsp;<\/p>\n<h2>What&#8217;s next?<\/h2>\n<p>Did you notice the function<code> std::is_same<\/code> in the composite type category s<code>td::is_fundamenta<\/code>l? <code>std::is_same<\/code> is it special because it provides type comparisons at compile time? I will write about type comparison at compile time in my next post.<\/p>\n<p>&nbsp;<\/p>\n<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The type-traits library is part of C++11 and supports type checks, type comparisons, and type modifications at compile time. The library has over 100 functions but grows with each new C++ standard release. Today, I present the type checks.<\/p>\n","protected":false},"author":21,"featured_media":6251,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[376],"tags":[419],"class_list":["post-6252","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-templates","tag-type-traits"],"_links":{"self":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6252","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=6252"}],"version-history":[{"count":1,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6252\/revisions"}],"predecessor-version":[{"id":6691,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/posts\/6252\/revisions\/6691"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media\/6251"}],"wp:attachment":[{"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=6252"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=6252"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.modernescpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=6252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}