Commit 6a81ba6b authored by Davis King's avatar Davis King

Added missing requires clause to the get() function of the type_safe_union.

It will now cause a compile time error if called inappropriately.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%403382
parent b59e94ce
......@@ -301,7 +301,26 @@ namespace dlib
}
}
template <typename T> T& get() { construct<T>(); return *reinterpret_cast<T*>(mem.get()); }
template <typename T>
T& get(
)
{
// ERROR: You are trying to get a type of object that isn't currently
// in the type_safe_union.
COMPILE_TIME_ASSERT(( is_same_type<T,T1>::value ||
is_same_type<T,T2>::value ||
is_same_type<T,T3>::value ||
is_same_type<T,T4>::value ||
is_same_type<T,T5>::value ||
is_same_type<T,T6>::value ||
is_same_type<T,T7>::value ||
is_same_type<T,T8>::value ||
is_same_type<T,T9>::value ||
is_same_type<T,T10>::value
));
construct<T>(); return *reinterpret_cast<T*>(mem.get());
}
};
......
......@@ -120,6 +120,8 @@ namespace dlib
T& get(
);
/*!
requires
- T must be one of the types given to this object's template arguments
ensures
- #is_empty() == false
- #contains<T>() == true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment