summaryrefslogtreecommitdiff
path: root/include/mbgl/util/enum.hpp
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-03-09 15:10:24 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-03-09 17:32:24 -0800
commit42ad77a888110382919d326b1d791cee7a4914bf (patch)
tree54266e38eaa360d1b908b544b39ccce7e09fcc25 /include/mbgl/util/enum.hpp
parentb2b5f9e571e9fedfd682081a3832db7618b1049a (diff)
downloadqtlocation-mapboxgl-42ad77a888110382919d326b1d791cee7a4914bf.tar.gz
[core] Avoid -Wundefined-var-template warnings with clang 3.9+
Diffstat (limited to 'include/mbgl/util/enum.hpp')
-rw-r--r--include/mbgl/util/enum.hpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/include/mbgl/util/enum.hpp b/include/mbgl/util/enum.hpp
index 48ffda463e..369ca86bfd 100644
--- a/include/mbgl/util/enum.hpp
+++ b/include/mbgl/util/enum.hpp
@@ -11,26 +11,26 @@ namespace mbgl {
template <typename T>
class Enum {
public:
- using Value = std::pair<const T, const char *>;
-
- static const char * toString(T t) {
- auto it = std::find_if(begin, end, [&] (const auto& v) { return t == v.first; });
- assert(it != end); return it->second;
- }
-
- static optional<T> toEnum(const std::string& s) {
- auto it = std::find_if(begin, end, [&] (const auto& v) { return s == v.second; });
- return it == end ? optional<T>() : it->first;
- }
-
-private:
- static const Value* begin;
- static const Value* end;
+ static const char * toString(T);
+ static optional<T> toEnum(const std::string&);
};
-#define MBGL_DEFINE_ENUM(type, strings...) \
-const constexpr Enum<type>::Value type##_names[] = strings; \
-template <> const Enum<type>::Value* Enum<type>::begin = std::begin(type##_names); \
-template <> const Enum<type>::Value* Enum<type>::end = std::end(type##_names)
+#define MBGL_DEFINE_ENUM(T, values...) \
+ \
+static const constexpr std::pair<const T, const char *> T##_names[] = values; \
+ \
+template <> \
+const char * Enum<T>::toString(T t) { \
+ auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \
+ [&] (const auto& v) { return t == v.first; }); \
+ assert(it != std::end(T##_names)); return it->second; \
+} \
+ \
+template <> \
+optional<T> Enum<T>::toEnum(const std::string& s) { \
+ auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \
+ [&] (const auto& v) { return s == v.second; }); \
+ return it == std::end(T##_names) ? optional<T>() : it->first; \
+}
} // namespace mbgl