xref: /netbsd-src/external/gpl3/gcc/dist/libphobos/libdruntime/core/stdcpp/type_traits.d (revision 0a3071956a3a9fdebdbf7f338cf2d439b45fc728)
1 /**
2  * D header file for interaction with C++ std::type_traits.
3  *
4  * Copyright: Copyright Digital Mars 2018.
5  * License: Distributed under the
6  *      $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0).
7  *    (See accompanying file LICENSE)
8  * Authors:   Manu Evans
9  * Source:    $(DRUNTIMESRC core/stdcpp/type_traits.d)
10  */
11 
12 module core.stdcpp.type_traits;
13 
14 extern(C++, "std"):
15 
16 ///
integral_constant(T,T Val)17 struct integral_constant(T, T Val)
18 {
19     ///
20     enum T value = Val;
21     ///
22     alias value_type = T;
23     ///
24     alias type = typeof(this);
25 }
26 
27 ///
28 alias bool_constant(bool b) = integral_constant!(bool, b);
29 
30 // Useful for dealing with enable_if constraints.
31 ///
32 alias true_type  = bool_constant!true;
33 ///
34 alias false_type = bool_constant!false;
35 
36 ///
is_empty(T)37 struct is_empty(T)
38 {
39     static if (is(T == struct))
40         private enum __is_empty = T.tupleof.length == 0;
41     else
42         private enum __is_empty = false;
43 
44     ///
45     enum bool value = __is_empty;
46     ///
47     alias value_type = bool;
48     ///
49     alias type = integral_constant!(bool, value);
50 }
51