]> git.cworth.org Git - vogl/blob - src/extlib/loki/include/loki/yasli/yasli_traits.h
Initial vogl checkin
[vogl] / src / extlib / loki / include / loki / yasli / yasli_traits.h
1 #ifndef YASLI_TRAITS_H_
2 #define YASLI_TRAITS_H_
3
4 // $Id: yasli_traits.h 754 2006-10-17 19:59:11Z syntheticpp $
5
6
7
8
9 namespace yasli_nstd
10 {
11 /*
12 template <bool b, class T = void>
13 struct enable_if {};
14
15 template <class T>
16 struct enable_if<true, T> { typedef T type; };
17 */
18
19 //!! TYPE SELECTORS
20 //Used in place of enable_if:
21 //not so neat or so versitile but they do compile
22 template<bool condition, class if_true, class if_false>
23 struct type_selector
24 {
25         typedef if_true result;
26 };
27
28 template<class if_true, class if_false>
29 struct type_selector<false, if_true, if_false>
30 {
31         typedef if_false result;
32 };
33
34 // Types for differentiating compile-time choices
35 typedef char (&yes_t)[1];
36 typedef char (&no_t)[2];
37
38 // Credit goes to Boost;
39 // also found in the C++ Templates book by Vandevoorde and Josuttis
40
41 //!! Wouldn't compile with these inside is_class
42 template <class U>
43 yes_t class_test(int U:: *);
44 template <class U>
45 no_t class_test(...);
46
47 template <class T> struct is_class
48 {
49         enum { value = (sizeof(class_test<T>(0)) == sizeof(yes_t)) };
50 };
51
52 template <typename T> struct is_pointer
53 {
54         enum { value = false };
55 };
56
57 template <typename T> struct is_pointer<T *>
58 {
59         enum { value = true };
60 };
61
62 template <typename T> struct is_memcopyable
63 {
64         enum { value = int(!is_class<T>::value) };
65 };
66
67
68 template <typename T> struct is_memmoveable
69 {
70         enum { value = int(!is_class<T>::value) };
71 };
72
73
74 // For moving
75 enum move_t { move };
76
77 } // namespace yasli_nstd
78
79 #endif // YASLI_TRAITS_H_