Douglas Gregor wrote:
> Yep. We just need:
> 
> template<typename T> T get();
> 
> template<typename Functor, typename R, typename T1, typename T2, ..., 
>          typename TN>
> struct is_callable :
>   
> mpl::bool_c<__is_well_formed(static_cast<R>(get<Functor>()(get<T1>(), 
> get<T2>(), ..., get<TN>())))>
> {
> };

Hmm, interesting, so if this actually worked, we would be happy:

    #include "boost/static_assert.hpp"

    typedef char (&no_tag)[1];
    typedef char (&yes_tag)[2];

    template< long > struct sink { typedef sink type; };
    template<typename T> T get();

    template< typename Functor, typename R, typename T1 >
    no_tag is_callable_helper(...);

    template< typename Functor, typename R, typename T1 >
    yes_tag is_callable_helper(
            typename sink< 
                  sizeof(static_cast<R>(get<Functor>()( get<T1>() )))
                >::type*
        );

    template<
        typename Functor, typename R, typename T1
        >
    struct is_callable
    {
        BOOST_STATIC_CONSTANT(bool
            , value = sizeof(is_callable_helper<Functor,R,T1>(0)) 
                == sizeof(yes_tag)
            );
    };


    struct her {};
    struct my { int operator()(int); };

    BOOST_STATIC_ASSERT((!is_callable<int,int,int>::value));
    BOOST_STATIC_ASSERT((!is_callable<her,int,int>::value));
    BOOST_STATIC_ASSERT((is_callable<my,int,int>::value));

?


> 
> The reason I mention is_instantiable instead of __is_well_formed 
> is that is_instantiable can keep a class template interface, whereas 
> __is_well_formed would require a new grammar production.

>From http://aspn.activestate.com/ASPN/Mail/Message/1412095 I've got an
impression that implementors are not too concerned about it.

After all, '__is_well_formed' might be as easy to implement as this:

    void process_is_well_formed( args )
    {
        try
        {
            process_sizeof( args );
            args.expression_result = true;
        }
        catch (compiler_error const& )
        {
            args.expression_result = false;
        }
    }

:)

Aleksey
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to