summaryrefslogtreecommitdiff
path: root/src/sexpr/variant.tcc
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2014-07-23 23:55:41 -0700
committerBen Longbons <b.r.longbons@gmail.com>2014-08-05 17:41:35 -0700
commita7f64f0b39cb7141f16608c171b20bee452fd024 (patch)
tree6ceb293db3488161d4d5a620536560506e63134f /src/sexpr/variant.tcc
parent7abac74323e2566173ea586e9acadac1ebf59098 (diff)
downloadtmwa-a7f64f0b39cb7141f16608c171b20bee452fd024.tar.gz
tmwa-a7f64f0b39cb7141f16608c171b20bee452fd024.tar.bz2
tmwa-a7f64f0b39cb7141f16608c171b20bee452fd024.tar.xz
tmwa-a7f64f0b39cb7141f16608c171b20bee452fd024.zip
In magic, use Variant for all the old anonymous nested unions
Diffstat (limited to 'src/sexpr/variant.tcc')
-rw-r--r--src/sexpr/variant.tcc18
1 files changed, 14 insertions, 4 deletions
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<size_t v>
+ 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<class W, class V>
constexpr static size_t get_state_for()
{
- return std::remove_reference<V>::type::DataType::template index<W>();
+ return not_negative_one<std::remove_reference<V>::type::DataType::template index<W>()>();
}
};
@@ -104,7 +114,7 @@ namespace sexpr
try
{
data.template construct<C, A...>(std::forward<A>(a)...);
- state = Union<D, T...>::template index<C>();
+ state = not_negative_one<Union<D, T...>::template index<C>()>();
}
catch(...)
{
@@ -244,7 +254,7 @@ namespace sexpr
template<class E>
E *Variant<D, T...>::get_if()
{
- if (state == Union<D, T...>::template index<E>())
+ if (state == not_negative_one<Union<D, T...>::template index<E>()>())
return data.template get<E>();
return nullptr;
}
@@ -253,7 +263,7 @@ namespace sexpr
template<class E>
const E *Variant<D, T...>::get_if() const
{
- if (state == Union<D, T...>::template index<E>())
+ if (state == not_negative_one<Union<D, T...>::template index<E>()>())
return data.template get<E>();
return nullptr;
}