Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost][proto] Type inference using transform
From: joel falcou (joel.falcou_at_[hidden])
Date: 2010-05-06 05:13:05


Moreover, your result are wrong

result_of<T()> will always return void.

You need somethign like:

struct arg_tag
{};

namespace proto = boost::proto;
namespace mpl = boost::mpl;

using namespace std;

template<int N>
struct arg
  : proto::or_<proto::nullary_expr<arg_tag, mpl::int_<N> > >
{};

template<typename T>
struct readonly
  : proto::callable {

  template<typename Sig>
  struct result;

  template<typename This,class X>
  struct result<This(X)>
  {
    typedef const T& type;
  };
};

template<typename T>
struct readwrite
  : proto::callable {

  template<typename Sig>
  struct result;

  template<typename This,class X>
  struct result<This(X)>
  {
    typedef T& type;
  };
};

template<int N, typename T>
struct argtype
  : proto::or_<
    proto::when<proto::assign<arg<N>, proto::_>, readwrite<T>(proto::_)>
  , proto::otherwise<readonly<T>(proto::_)>
>
{};

proto::nullary_expr<arg_tag, mpl::int_<0> >::type const _1 = {{}};
proto::nullary_expr<arg_tag, mpl::int_<1> >::type const _2 = {{}};

namespace boost { namespace proto
{
  template<class T> struct is_callable<readwrite<T> > : true_ {};
  template<class T> struct is_callable<readonly<T> > : true_ {};
}}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net