mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
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
This commit is contained in:
parent
b59e94cebf
commit
6a81ba6b23
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user