#include <type_traits>
#include <utility>
namespace ns_crap
{
struct Fruit;
} // namespace ns_crap
template <int V, typename T, const ns_crap::Fruit& O>
struct MapEntry
{
static constexpr int value = V;
using type = T;
static constexpr const ns_crap::Fruit& object = O;
};
template <int> struct from_val;
template <typename> struct from_type;
template <const ns_crap::Fruit&> struct from_crap;
#define MAKE_MAP_ENTRY(value, type, object) \
template <> struct from_val<value> : MapEntry<value, type, object> {}; \
template <> struct from_type<type> : MapEntry<value, type, object> {}; \
template <> struct from_crap<object> : MapEntry<value, type, object> {};
namespace ns_val
{
const int APPLE = 0;
const int PINEAPPLE = 1;
const int PEAR = 2;
} // namespace ns_val
namespace ns_types
{
struct Apple {};
struct Pineapple {};
struct Pear {};
} // namespace ns_types
namespace ns_crap
{
struct Fruit
{
static const Fruit Apple;
static const Fruit Pinapple;
static const Fruit Pear;
};
const Fruit Fruit::Apple;
const Fruit Fruit::Pinapple;
const Fruit Fruit::Pear;
} // namespace ns_crap
MAKE_MAP_ENTRY(ns_val::APPLE, ns_types::Apple, ns_crap::Fruit::Apple)
MAKE_MAP_ENTRY(ns_val::PINEAPPLE, ns_types::Pineapple, ns_crap::Fruit::Pinapple)
MAKE_MAP_ENTRY(ns_val::PEAR, ns_types::Pear, ns_crap::Fruit::Pear)
// getting values
static_assert(from_val<ns_val::APPLE>::value == ns_val::APPLE, "");
static_assert(from_type<ns_types::Pineapple>::value == ns_val::PINEAPPLE, "");
static_assert(from_crap<ns_crap::Fruit::Pear>::value == ns_val::PEAR, "");
// getting types
static_assert(std::is_same<from_val<ns_val::APPLE>::type, ns_types::Apple>::value, "");
static_assert(std::is_same<from_type<ns_types::Pineapple>::type, ns_types::Pineapple>::value, "");
static_assert(std::is_same<from_crap<ns_crap::Fruit::Pear>::type, ns_types::Pear>::value, "");
// getting objects
static_assert(&from_val<ns_val::APPLE>::object == &ns_crap::Fruit::Apple, "");
static_assert(&from_type<ns_types::Pineapple>::object == &ns_crap::Fruit::Pinapple, "");
static_assert(&from_crap<ns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