|
2 | 2 | // Copyright (C) Michigan State University, 2016-2017.
|
3 | 3 | // Released under the MIT Software license; see doc/LICENSE
|
4 | 4 | //
|
5 |
| -// Extensions on the standard library type traits to handle Empirical classes (such as Ptr). |
| 5 | +// Extensions on the standard library type traits to handle Empirical classes |
| 6 | +// (such as Ptr). |
6 | 7 |
|
7 | 8 | #ifndef EMP_TYPE_TRAITS_H
|
8 | 9 | #define EMP_TYPE_TRAITS_H
|
|
16 | 17 | namespace emp {
|
17 | 18 |
|
18 | 19 | // Customized type traits
|
19 |
| - template <typename T> struct is_ptr_type { enum { value = false }; }; |
20 |
| - template <typename T> struct is_ptr_type<T*> { enum { value = true }; }; |
21 |
| - template <typename T> struct is_ptr_type<T* const> { enum { value = true }; }; |
22 |
| - template <typename T> struct is_ptr_type<Ptr<T>> { enum { value = true }; }; |
23 | 20 | template <typename T>
|
24 |
| - constexpr bool is_ptr_type_v(const T&) { return is_ptr_type<T>::value; } |
| 21 | + struct is_ptr_type { |
| 22 | + enum { value = false }; |
| 23 | + }; |
| 24 | + template <typename T> |
| 25 | + struct is_ptr_type<T *> { |
| 26 | + enum { value = true }; |
| 27 | + }; |
| 28 | + template <typename T> |
| 29 | + struct is_ptr_type<T *const> { |
| 30 | + enum { value = true }; |
| 31 | + }; |
| 32 | + template <typename T> |
| 33 | + struct is_ptr_type<Ptr<T>> { |
| 34 | + enum { value = true }; |
| 35 | + }; |
| 36 | + template <typename T> |
| 37 | + constexpr bool is_ptr_type_v(const T &) { |
| 38 | + return is_ptr_type<T>::value; |
| 39 | + } |
25 | 40 |
|
26 |
| - template <typename T> struct remove_ptr_type { }; // Not ponter; should break! |
27 |
| - template <typename T> struct remove_ptr_type<T*> { using type = T; }; |
28 |
| - template <typename T> struct remove_ptr_type<Ptr<T>> { using type = T; }; |
| 41 | + template <typename T> |
| 42 | + struct remove_ptr_type {}; // Not ponter; should break! |
| 43 | + template <typename T> |
| 44 | + struct remove_ptr_type<T *> { |
| 45 | + using type = T; |
| 46 | + }; |
| 47 | + template <typename T> |
| 48 | + struct remove_ptr_type<Ptr<T>> { |
| 49 | + using type = T; |
| 50 | + }; |
29 | 51 | template <typename T>
|
30 | 52 | using remove_ptr_type_t = typename remove_ptr_type<T>::type;
|
31 | 53 | // @CAO: Make sure we are dealing with const and volitile pointers correctly.
|
32 | 54 |
|
33 | 55 | // Can we convert the first pointer into the second?
|
34 |
| - template <typename T1, typename T2> struct ptr_pair { |
| 56 | + template <typename T1, typename T2> |
| 57 | + struct ptr_pair { |
35 | 58 | static constexpr bool Same() { return false; }
|
36 | 59 | static constexpr bool SameBase() { return false; }
|
37 |
| - static bool ConvertOK(T1 * ptr) { return dynamic_cast<T2*>(ptr); } |
| 60 | + static bool ConvertOK(T1 *ptr) { return dynamic_cast<T2 *>(ptr); } |
38 | 61 | };
|
39 |
| - template <typename T> struct ptr_pair<T,T> { |
| 62 | + template <typename T> |
| 63 | + struct ptr_pair<T, T> { |
40 | 64 | static constexpr bool Same() { return true; }
|
41 | 65 | static constexpr bool SameBase() { return true; }
|
42 | 66 | static constexpr bool ConvertOK(T *) { return true; }
|
43 | 67 | };
|
44 |
| - template <typename T> struct ptr_pair<T, const T> { |
| 68 | + template <typename T> |
| 69 | + struct ptr_pair<T, const T> { |
45 | 70 | static constexpr bool Same() { return false; }
|
46 | 71 | static constexpr bool SameBase() { return true; }
|
47 | 72 | static constexpr bool ConvertOK(T *) { return true; }
|
48 | 73 | };
|
49 |
| - template <typename T> struct ptr_pair<const T, T> { |
| 74 | + template <typename T> |
| 75 | + struct ptr_pair<const T, T> { |
50 | 76 | static constexpr bool Same() { return false; }
|
51 | 77 | static constexpr bool SameBase() { return true; }
|
52 | 78 | static constexpr bool ConvertOK(T *) { return false; }
|
@@ -451,7 +477,7 @@ namespace emp {
|
451 | 477 |
|
452 | 478 | template <typename Needle, typename Haystack,
|
453 | 479 | template <typename, typename> class... Cmp>
|
454 |
| - static constexpr auto variadic_index_of_v{ |
| 480 | + static constexpr size_t variadic_index_of_v{ |
455 | 481 | variadic_index_of<Needle, Haystack, Cmp...>::value};
|
456 | 482 |
|
457 | 483 | namespace __impl_variadics_type_traits {
|
|
0 commit comments