|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2004-09-11 06:57:27
Daniel Wallin <dalwan01_at_[hidden]> writes:
> David Abrahams wrote:
>> Daniel Wallin <dalwan01_at_[hidden]> writes:
>>>I have been toying with a more general solution to this problem, where
>>>one can do things like:
>>>
>>> check_dereference<T, is_convertible<mpl::_, U&> >
>>> check_add<T, T, is_convertible<mpl::_, T> >
>>>
>>> etc.
>> That *might* be impressive if I could tell what those expressions
>> were
>> supposed to mean ;-)
>
> The metafunction class
I don't see a metafunction class here. Don't you mean "lambda expression?"
> is applied to the result type of the operation,
> and is required to have boolean result. For instance:
>
> struct X
> {
> void operator+(X const&) const;
> X operator+(int) const;
> };
>
> template<class T> struct Y : mpl::false_ {};
> template<> struct Y<X> : mpl::true_ {};
>
> check_add<X, X, Y<mpl::_> >::type // X + X, invokes Y<void> -> false
> check_add<X, int, Y<mpl::_> >::type // X + int, invoked Y<X> -> true
>
> Using this we could express more complicated concept checks. For
> instance:
>
> "The Lvalue Iterator concept adds the requirement that the return type
> of operator* type be a reference to the value type of the iterator."
>
> template<class Iterator>
> struct is_iterator_lvalue_dereferencable
> : check_dereference<
> Iterator
> , is_same<
> mpl::_
> , typename iterator_value<Iterator>::type&
> >
> >
> {
> };
Oh, very nice! Now it's impressive. :-)
-- Dave Abrahams Boost Consulting http://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