#pragma once #include #include #include #include namespace mbgl { template class Enum { public: using Value = std::pair; 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 toEnum(const std::string& s) { auto it = std::find_if(begin, end, [&] (const auto& v) { return s == v.second; }); return it == end ? optional() : it->first; } private: static const Value* begin; static const Value* end; }; #define MBGL_DEFINE_ENUM(type, strings...) \ const constexpr Enum::Value type##_names[] = strings; \ template <> const Enum::Value* Enum::begin = std::begin(type##_names); \ template <> const Enum::Value* Enum::end = std::end(type##_names) } // namespace mbgl