Skip to content

Commit fe13aef

Browse files
author
Robin Miller
committed
Replace auto with explicit type
It seems that the older c++ version was deducing auto as a initializer_list rather than a size_t Fixes #161
1 parent 7ff8fd9 commit fe13aef

File tree

1 file changed

+41
-15
lines changed

1 file changed

+41
-15
lines changed

source/meta/type_traits.h

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// Copyright (C) Michigan State University, 2016-2017.
33
// Released under the MIT Software license; see doc/LICENSE
44
//
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).
67

78
#ifndef EMP_TYPE_TRAITS_H
89
#define EMP_TYPE_TRAITS_H
@@ -16,37 +17,62 @@
1617
namespace emp {
1718

1819
// 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 }; };
2320
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+
}
2540

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+
};
2951
template <typename T>
3052
using remove_ptr_type_t = typename remove_ptr_type<T>::type;
3153
// @CAO: Make sure we are dealing with const and volitile pointers correctly.
3254

3355
// 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 {
3558
static constexpr bool Same() { return false; }
3659
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); }
3861
};
39-
template <typename T> struct ptr_pair<T,T> {
62+
template <typename T>
63+
struct ptr_pair<T, T> {
4064
static constexpr bool Same() { return true; }
4165
static constexpr bool SameBase() { return true; }
4266
static constexpr bool ConvertOK(T *) { return true; }
4367
};
44-
template <typename T> struct ptr_pair<T, const T> {
68+
template <typename T>
69+
struct ptr_pair<T, const T> {
4570
static constexpr bool Same() { return false; }
4671
static constexpr bool SameBase() { return true; }
4772
static constexpr bool ConvertOK(T *) { return true; }
4873
};
49-
template <typename T> struct ptr_pair<const T, T> {
74+
template <typename T>
75+
struct ptr_pair<const T, T> {
5076
static constexpr bool Same() { return false; }
5177
static constexpr bool SameBase() { return true; }
5278
static constexpr bool ConvertOK(T *) { return false; }
@@ -451,7 +477,7 @@ namespace emp {
451477

452478
template <typename Needle, typename Haystack,
453479
template <typename, typename> class... Cmp>
454-
static constexpr auto variadic_index_of_v{
480+
static constexpr size_t variadic_index_of_v{
455481
variadic_index_of<Needle, Haystack, Cmp...>::value};
456482

457483
namespace __impl_variadics_type_traits {

0 commit comments

Comments
 (0)