After answering this question I was trying to find is_complete
template in Boost library and I realized that there is no such template in Boost.TypeTraits. Why there is no such template in Boost library? How it should look like?
//! Check whether type complete
template<typename T>
struct is_complete
{
static const bool value = ( sizeof(T) > 0 );
};
...
// so I could use it in such a way
BOOST_STATIC_ASSERT( boost::is_complete<T>::value );
The code above is not correct, because it is illegal to apply sizeof
to an incomplete type. What will be a good solution? Is it possible to apply SFINAE in this case somehow?
Well, this problem couldn't be solved in general without violating the ODR rule, but there is there a platform specific solution which works for me.
U
is complete or not,is_complete<U>
always specifies the same type. If you now go and useis_complete<U>
in two different translation units, the value member would possibly have a different value each time and the compiler is free in what value it uses. This is not valid i think, but i can't find a statement of the Standard about this :( Would be glad if you could find out.vector<int>
for example andvector
is only declared but not defined, then the check for completeness will yield to an implicit instantiation, and if the definition is not available will issue an hard error that's not covered by sfinae (the error is not in the "immediate context").