
2012/11/5 Antony Polukhin <antoshkka@gmail.com>
I don't have an answer to your question, except this has been suggested before - and got shot down because the definition of is_complete<T> would need to change depending where it was instantiated - and you can't do
2012/11/5 John Maddock <boost.regex@virgin.net>: that
(one definition rule).
Searching for is_complete in Internet gave me a non-compiling function that even in theory can not work with abstract classes.
In my proposal ODR is bypassed by the set of 'Misc' parameters:
template <class T, class T1, class T2, class T3> void test_function() { // Parameters after T are used to cheat on ODR is_complete<T, T1, T2, T3, boost::mpl::int_<__LINE__> >::value; }
BTW if all you want is an assertion that a type is complete then:
BOOST_STATIC_ASSERT(sizeof(T));
would do the trick.
That is exactly what I`m trying not to do:
template <bool IsAwailable> struct stl_specific_work{ static void act() { throw std::logic_error("Attempt to use ctype<char16_t> for non 'C' locale: your STL implementation does not specialize ctype<char16_t>"); } };
template <> struct stl_specific_work<true>{ static void act() { // Some work with ctype<char16_t> } };
if (std::locale() != std::locale::classic()) { stl_specific_work< !is_complete<ctype<char16_t> /*, SomeMoreTemplateParameters*/
::value >::act(); }
I need to work with ctype<char16_t> if it is available. Without is_complete<> I would be required to forbid ctype<char16_t> usage even on platforms that do support it and even if user provided it`s own implementation.
IMO defer what should fail in compile time to runtime is not a good idea generally. It' the programmar who should know "your STL implementation does not specialize ctype<char16_t>" not the end user. And BOOST_STATIC_ASSERT won't prevent you from providing ctype<char16_t> support as it should compile on the platforms that do support it.