
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