Boost logo

Boost Users :

Subject: Re: [Boost-users] [boost][proto] Type inference using transform
From: Manjunath Kudlur (keveman_at_[hidden])
Date: 2010-05-06 13:25:07


On Thu, May 6, 2010 at 2:13 AM, joel falcou <joel.falcou_at_[hidden]> wrote:
> Moreover, your result are wrong
>
> result_of<T()> will always return void.
>
> You need somethign like:

Thanks, Joel. (Note to self : RTFM more often :)). I also discovered
that I didn't have to make the readonly and readwrite classes
templated. The following also works :

struct readonly
  : proto::callable {

  template<typename Sig>
  struct result;

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

struct readwrite
  : proto::callable {

  template<typename Sig>
  struct result;

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

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

Manjunath
http://nonchalantlytyped.net/blog/musings/

> 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 mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>


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