> -----Original Message-----
> From: Martin Sebor [mailto:[EMAIL PROTECTED] On Behalf Of Martin Sebor
> Sent: Thursday, June 26, 2008 2:12 PM
> To: [email protected]
> Subject: Re: __rw_and (Was RE: Some internal aliases for
> __rw_integral_constant?)
>
> Eric Lemings wrote:
> >
> >
> >> -----Original Message-----
> >> From: Martin Sebor [mailto:[EMAIL PROTECTED] On Behalf Of
> Martin Sebor
> >> Sent: Thursday, June 26, 2008 12:32 PM
> >> To: [email protected]
> >> Subject: Re: __rw_and (Was RE: Some internal aliases for
> >> __rw_integral_constant?)
> >>
> > ...
> >> I can't say I understand this use case. What's S meant to
> represent?
> >
> > That was just a contrived example; not intended to be realistic.
>
> Sorry, but I find it difficult to think about the utility of a feature
> without a realistic example.
Understandable. Hmm, I can't think of a realistic example off hand for
the explicit/finite context.
The ones I have for the variadic contexts though are in fact used in the
tuple code I'm writing.
>
...
> >
> >> template <class T, int I>
> >> struct S:
> >> __rw_conditional<__rw_is_class<T>::value && 0 !=
> I, T, ???>
> >> { };
> >>
> >> (Or enable_if instead of conditional, depending on what you want
> >> to do with S).
> >>
> >>> template <class... T> struct O {
> >>> template <class... U> struct I
> >>> : __rw_and<std::is_convertible<T, U>::value...> {}; //
> >>> variable arguments
> >> Same here.
> >
> > Try writing that without __rw_and. :) I did. Well, tried
> at least.
> > It is NOT easy. In fact, this was the main reason I wrote
> the __rw_and
> > class template to begin with.
>
> I would if I knew what I is supposed to be/do.
"Given two type lists T and U (such as variadic template arguments),
determine a.) if the length of the type lists is the same, and b.) for
each pair of types Ti and Ui where 0 <= i <= sizeof... (T), type Ui is
convertible to type Ti."
Not easy an easy problem to solve (if at all) without variadic
templates.
>
> >
> >>> };
> >>>
> >>> The other reason is portability. Case in point. Travis
> >> recently ran
> >>> into a problem where the compiler rejected a simple
> >> constant expression
> >>> like `sizeof (T) < sizeof (U)' but worked with the metafunction
> >>> equivalent of `__rw_less_than<sizeof (T), sizeof (U)>::value'.
> >> This sounds like an argument for __rw_less_than, not for __rw_and.
> >>
> >> Btw., I'm not opposed to __rw_and in principle. I just want to see
> >> some of its uses and the rationale for it (in case there's a better
> >> or simpler way of doing the same thing).
> >
> > The "is_convertible" use case is the best rationale for it
> that I can
> > think of.
>
> std::is_convertible? But that doesn't make use of anything that
> resembles __rw_and.
I meant the __rw_and use case that employed is_convertible as terms in
the logical expression.
>
> > Such metafunctions essentially allow type traits to be used
> > on type _lists_ rather than individual types; e.g.,
> >
> > template <class... Types>
> > struct all_integral_types
> > : __rw_and<std::is_integral<Types>::value...> {};
> >
> > I dunno 'bout you, but I think that's pretty darn cool. :)
> Oh, and a
> > lot simpler than the alternative. (I'm not convinced there even is
> > one.)
>
> Is this the alternative you're looking for?
>
> template <class... Types>
> struct all_integral_types;
>
> template <class T>
> struct all_integral_types<T>: is_integral<T> { };
>
> template <class T, class... Types>
> struct all_integral_types<T, Types...>
> : const_integral<bool, is_integral<T>::value
> &&
> all_integral_types<Types...>::value>
> { };
Yes, that's type kind of code that this is meant to simplify: writing
one template rather than three.
Also, I was referring to alternatives for binary (relational) type
traits.
Brad.