Re: TR1 true_type and flase_type, how to combine?
In article
<79d26476-2b20-452d-b1fd-3acb1a359681@8g2000hsu.googlegroups.com>,
<Michiel.Salters@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. Hence, I'd also expect the equivanent of &&, || and !
Yet I can't find any mention of them?
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 <>
struct and_type<false_type, true_type> : public false_type { };
template <>
struct and_type<false_type, falsee_type> : public false_type { };
etcetera. This would allow us to assert properties like
and_type<is_base_of<T, U>, is_base_of<T, V> >
Have these been considered?
Regards,
Michiel Salters
template <class T,class U> struct and_;
template <class T,class U> struct or_;
template <class T> struct not_;
template <class T,class U T t, U u>
struct and_
<
integral_constant<T,t>,
integral_constant<U,u>
:integral_constant<bool, t &&u>{};
similiar for or_ and not_, In fact you might want
to allow anding or oring upto N integral constants in
one invocation of and_ and or_ like boost::mpl allows,
that is
typedef or_
<
and_<A,B,C>,
and_<C,D>,
and_<E,F,G,H>
result;
this is derived from an integral_constant<bool, b> where b is
the value of A&&B && C || C && D || E && F && G && H.
a lot less messy than just the rpn of the expression.
I would prefer this latter approach as it makes boolean expression
in template args easier to read than the raw rpn translation would
do.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]