ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
RE: [boost] 'function' idea
by Aleksey Gurtovoy other posts by this author
Nov 11 2002 9:56AM messages near this date
[boost] Re: Proposed Boost Assert -- once again | Re: [boost] 'function' idea
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
Thread:
Aleksey Gurtovoy
Douglas Gregor

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved