|
Boost : |
Subject: Re: [boost] review request: addition to type_traits library of has_operator_xxx
From: Jeffrey Lee Hellrung, Jr. (jhellrung_at_[hidden])
Date: 2010-11-17 12:25:34
On 11/17/2010 6:58 AM, Stewart, Robert wrote:
> Jeffrey Lee Hellrung, Jr. wrote:
>>
>> One thing that I've either found useful is to have an additional
>> template parameter in addition to the parameter types and the return
>> type, which is a Boost.MPL metapredicate intended to be
>> applied to the actual result of the operation. The trait then
>> evaluates to true only if the actual result type satisfies the given
>> Boost.MPL metapredicate.
>
> Perhaps checking for convertible-to-return-type could be the default predicate rather than adding another template parameter?
How do you envision the interface then? Are you suggesting that the
convertible-to-return-type type and the Boost.MPL metapredicate occupy
the same template parameter?
To be clear, I'm suggesting something like
template< class T0, class T1 = T0, class Result = void, class ResultCond
= boost::mpl::always< boost::true_type > >
struct is_less_than_comparable;
It seems to me that, by far, the common case is checking convertibility
to some given type, so I think it makes sense to make the common case
syntactically simple.
If you want to avoid the extra template parameter, maybe you can wrap
the predicate in something which could be detected in the Result
template parameter, e.g.,
template< class P > struct operator_predicate;
and then specialize is_less_than_comparable for that wrapper, so that
the whole thing is
template< class T0, class T1 = T0, class Result = void >
struct is_less_than_comparable { ... };
template< class T0, class T1, class P >
struct is_less_than_comparable< T0, T1, operator_predicate<P> > { ... };
Is this kind of what you had in mind? I personally prefer adding an
extra template parameter.
- Jeff
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk