Re: TR1 true_type and flase_type, how to combine?
On Apr 3, 8:43 am, Michiel.Salt...@tomtom.com wrote:
For type_traits, classes true_type and false_type have been defined.
These types are the equivalent of true and false, but for template
meta programming.
Not really: "true" and "false" are the metaprogramming equivalents to C
++'s true and false bool values, respectively. The true_type and
false_type are simply helper classes that allow a metaprogram
construct to "store" or "return" a particular bool value. In other
words, true_type and false_type are not intended to serve as some kind
of metaprogramming replacements for C++'s true and false bool values -
as you seem to be suggesting.
Hence, I'd also expect the equivanent of &&, || and !
Why? C++ metaprograms can simply use the built-in logical operators
with bool operands - just like any ordinary C++ program..
The implementation seems trivial:
template <typename L, typename R>
struct and_type{ };
template <>
struct and_type<true_type, true_type> : public true_type { };
template <>
struct and_type<true_type, false_type> : public false_type { };
template <>
C++ metaprogramming already has a reputation for obscurity. So the
last thing that the Standard Library really needs is a set of logical
operator metaprogramming templates to replace C++'s built-in, and
fully-working, logical operators.
This would allow us to assert properties like
and_type<is_base_of<T, U>, is_base_of<T, V> >
Just use the "&&" operator:
static_assert< is_base_of<T, U>::value && is_base_of<T, V>::value >
Have these been considered?
We can only hope that the answer is "no".
Greg
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]