|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2003-11-15 22:18:29
Eric Friedman <ebf_at_[hidden]> writes:
> Peter Dimov wrote:
>
>> I'm somewhat amused by the possibilities that enable_if offers. Perhaps one
>> day we'll think of
>> template<class V> enable_if< is_instance_of< std::vector<_, _>, V>
>> >::type
>> f( V & v);
>> as a natural alternative to
>> template<class T, class A> void f( std::vector<T, A> & v );
>> but I doubt it. ;-)
>
> If we ever do, we can use mpl::lambda_match, which is in the sandbox:
>
> template <class V>
> typename enable_if<
> mpl::lambda_match< std::vector<_,_>, V >
> >::type
> f( V & v );
>
> Additionally, lambda_match supports more advanced functionality, such as
>
> template <class Double>
> typename enable_if<
> mpl::lambda_match< std::pair<_1,_1>, Double >
> >::type
> f( Double & d );
>
> Perhaps I should rename it to mpl::is_instance_of?
I rather like
mpl::pattern_match
Of course, next you'll have to be able to return an integral constant
wrapper which rates matches for closeness. IOW,
mpl::pattern_match<std::pair<int,int>, std::pair<int,int> >::value == 3
mpl::pattern_match<std::pair<int,_1>, std::pair<int,int> >::value == 2
mpl::pattern_match<std::pair<_1,_1>, std::pair<int,int> >::value == 2
mpl::pattern_match<std::pair<_1,_2>, std::pair<int,int> >::value == 1
or something ;-)
-- Dave Abrahams Boost Consulting www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk