From a7f64f0b39cb7141f16608c171b20bee452fd024 Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Wed, 23 Jul 2014 23:55:41 -0700 Subject: In magic, use Variant for all the old anonymous nested unions --- src/sexpr/variant.tcc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/sexpr/variant.tcc') diff --git a/src/sexpr/variant.tcc b/src/sexpr/variant.tcc index 424a8f1..ce820bf 100644 --- a/src/sexpr/variant.tcc +++ b/src/sexpr/variant.tcc @@ -24,6 +24,16 @@ namespace tmwa { namespace sexpr { + template + constexpr + size_t not_negative_one() + { + return v; + } + template<> + constexpr + size_t not_negative_one<-1>() = delete; + class VariantFriend { public: @@ -77,7 +87,7 @@ namespace sexpr template constexpr static size_t get_state_for() { - return std::remove_reference::type::DataType::template index(); + return not_negative_one::type::DataType::template index()>(); } }; @@ -104,7 +114,7 @@ namespace sexpr try { data.template construct(std::forward(a)...); - state = Union::template index(); + state = not_negative_one::template index()>(); } catch(...) { @@ -244,7 +254,7 @@ namespace sexpr template E *Variant::get_if() { - if (state == Union::template index()) + if (state == not_negative_one::template index()>()) return data.template get(); return nullptr; } @@ -253,7 +263,7 @@ namespace sexpr template const E *Variant::get_if() const { - if (state == Union::template index()) + if (state == not_negative_one::template index()>()) return data.template get(); return nullptr; } -- cgit v1.2.3-60-g2f50