Re: c++0x: static_assert & concepts
SG ha scritto:
This is a quote from Kanny Kalev's article "Static Assertions":
( http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=343&rll=1
)
"The concepts proposal doesn???t eliminate the need for static
assertions in C++. [...] static assertions are useful in C++ programs
that do not use templates at all. [...]
So far, so good.
[...] static assertions, when used
together with the TR1 type_traits library, can diagnose type errors
that intrinsic support for concepts cannot, such as ensuring that the
template argument of basic_string shall be a POD type."
This I disagree. I don't see why concepts should be unable to ensure
POD-ness of the character type. Ok, we don't have a std::Pod concept
right now in the C++0x working paper, but we could have it, if it's
needed. Consider that even std::is_pod needs some compiler magic to be
implemented properly; a similar magic could be used to provide implicit
concept maps for an hypothetical std::Pod concept as it's already
required for std::StandardLayout and others.
This sounds like we still need traits classes. It's unfortunate that
the "boolean value" of a concept-check isn't easily acessible for meta
programming and static_assert. There is a way to turn an old-style
compile-time predicate (template<..> struct {..};) into a concept via
std::True. But it doesn't work the other way around, does it?
Yes, traits classes still have their use in the concept world.
We don't have a way as compact as std::True to do it, but turning a
concept into a trait class is not that difficult:
concept MyConcept { /* ... */ }
template <typename T>
struct is_my_concept : std::false_type {};
template <MyConcept T>
struct is_my_concept<T> : std::true_type {};
HTH,
Ganesh
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]