if-then-else
suggest changeThe type std::conditional (C++11, in the header <type_traits>) selects one type or the other from a compile-time boolean value:
template<typename T>
struct ValueOrPointer
{
typename std::conditional<(sizeof(T) > sizeof(void*)), T*, T>::type vop;
};
This class template stores a pointer to T when T is larger than a pointer;
otherwise, it stores T directly. Consequently,
sizeof(ValueOrPointer<T>) is no greater than sizeof(void*).
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents