> -----Original Message-----
> From: Eric Lemings [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, June 24, 2008 6:01 PM
> To: [email protected]
> Subject: RE: Some internal aliases for __rw_integral_constant?
>
>
>
> > -----Original Message-----
> > From: Martin Sebor [mailto:[EMAIL PROTECTED] On Behalf Of
> Martin Sebor
> > Sent: Tuesday, June 24, 2008 5:11 PM
> > To: [email protected]
> > Subject: Re: Some internal aliases for __rw_integral_constant?
> >
> > Eric Lemings wrote:
> > >
> > > Propose adding the following defs (or something similar) to
> > > <rw/_meta_help.h> primarily for our own convenience:
> > >
> > > template <bool _Bool>
> > > class __rw_bool_const: public __rw_integral_constant<bool,
> > _Bool> {};
> >
> > I was going to suggest the same thing this morning when I noticed
> > how pervasive __rw_integral_constant<bool, _Bool> seems to be in
> > traits definitions (I count 41 occurrences) and thinking that it
> > would make them less verbose. (With a different spelling of _Bool
> > to avoid potential clashes with the C99 name.)
>
> Good point.
>
> >
> > I didn't because the only beneficiaries of the change would be us
> > (a fairly small notational convenience) and I wasn't sure the cost
> > in terms of the added complexity and compilation time was worth it.
> > I contemplated suggesting a macro for the same purpose instead but
> > decided against it on the assumption that it probably wouldn't be
> > very popular ;-) But now that the cat's out of the bag and you're
> > asking about alternatives let me throw it out there:
> >
> > #define _RWSTD_BOOL_CONST(B) _RW::__rw_integral_constant<bool, B>
> >
> > Usage:
> >
> > _RW::__rw_bool_const<bool, false>
> > vs
> > _RWSTD_BOOL_CONST (false)
> >
>
> Looks good to me. I'll just add _RWSTD_BOOL_CONST for now.
Okay, another proposal for inclusion though this particular utility
may be a stretch unless you understand variadic templates very well.
template <bool...>
struct __rw_and;
template <>
struct __rw_and<>: std::true_type {};
template <bool _Bool0, bool... _BoolN>
struct __rw_and<_Bool0, _BoolN...>
: _RWSTD_BOOL_CONST (_Bool0 && __rw_and<_BoolN...>::value)
{};
For example:
template <class... _TypesT>
struct tuple {
template <class... _TypesU>
struct __rw_is_compat
: __rw_and<std::is_convertible<_TypesT,
_TypesU>::value...> {
static_assert (sizeof... (_TypesT) == sizeof...
(_TypesU),
"tuple sizes must be equal");
};
};
Here are some quick tests that I tried out on it:
typedef tuple<char, int, long> T1;
std::cout << T1::__rw_is_compat<char, short, int>::value
<< std::endl;
std::cout << T1::__rw_is_compat<const char, const int, const
long>::value
<< std::endl;
std::cout << T1::__rw_is_compat<float, int, long>::value
<< std::endl;
std::cout << T1::__rw_is_compat<void*, int, long>::value
<< std::endl;
// fires the static assertion
//std::cout << T1::__rw_is_compat<char, short>::value
//<< std::endl;
Might just save that one for later but worth posting at least. :)
Brad.