[ create a new paste ] login | about

Link: http://codepad.org/22GRQvnx    [ raw code | fork ]

C++, pasted on Jun 10:
#include <vector>
#include <iostream>

using namespace std;

//#include <nt2/nt2.hpp>

////////////////////////////////////////////////////////////////////////////////
// dsl.hpp
////////////////////////////////////////////////////////////////////////////////
#include <boost/proto/proto.hpp>

namespace nt2 { namespace containers
{
  namespace bp = boost::proto;

  // Table based grammmar
  struct table_grammar
    : bp::or_ < bp::terminal< std::vector<bp::_,bp::_> >
              , bp::and_< bp::terminal<bp::_>
                        , bp::if_<boost::is_arithmetic<bp::_value>()>
                        >
              , bp::nary_expr< bp::_, bp::vararg< table_grammar > >
//             , bp::and_< bp::nary_expr< bp::_, bp::vararg< grammar > >
//                       , bp::not_< meta::low_level<bp::_> >
//                       , bp::not_< meta::stream<bp::_,bp::_> >
//                       >
             > {};

  template<class Tag, class Xpr, class Dummy = bp::is_proto_expr> class table_expr;

  // Table generator
  struct table_generator
  {
    template<class Sig> struct result;

    template<class This, class Expr> struct result<This(Expr)>
    {
      // Explicitly add the tag to the expr type
      typedef typename bp::tag_of<Expr>::type tag_type;
      typedef table_expr<tag_type, Expr>            type;
    };

    template<class Expr>
    typename result<table_generator(Expr)>::type const
    operator()(Expr const &xpr) const
    {
      typename result<table_generator(Expr)>::type const that(xpr);
      return that;
    }
  };

  // Table domain
  struct domain : bp::domain<table_generator, table_grammar > {};

  // Table expression

  //#include <nt2/sdk/details/type_id.hpp>

  template<class Tag,class X, class Dummy>
  struct table_expr : bp::extends<X, table_expr<Tag,X,Dummy>, domain>
  {
    typedef bp::extends<X, table_expr<Tag,X>, domain> base_type;

    explicit table_expr(X const &expr = X()) : base_type(expr), mEnabler(false) {}

    mutable bool mEnabler;
  };

  template<class X, class Dummy>
  struct table_expr<bp::tag::assign,X,Dummy>
        : bp::extends<X, table_expr<bp::tag::assign,X,Dummy>, domain>
  {
    typedef bp::extends<X, table_expr<bp::tag::assign,X,Dummy>, domain> base_type;

    explicit table_expr(X const &expr = X()) : base_type(expr), mEnabler(true)
    {
      bp::right(*this).mEnabler = false;
    }

    ~table_expr()
    {
      if(mEnabler) bp::display_expr(*this);
    }

    mutable bool mEnabler;
  };
} }

////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////
//#include <nt2/sdk/settings/handler.hpp>
//#include <nt2/sdk/settings/process.hpp>

namespace nt2 { namespace containers
{
  template<class T/*, class Options = nt2::options()*/>
  struct  table
        : public table_expr < bp::tag::terminal
                            , typename bp::terminal< std::vector<T> >::type
                            >
  {
    typedef table_expr< bp::tag::terminal
                      , typename bp::terminal< std::vector<T> >::type
                      > parent;

    BOOST_PROTO_EXTENDS_USING_ASSIGN(parent)
  };

} }

namespace nt2
{
  using containers::table;
}

int main()
{
  nt2::table<float> k,l,m;
  m = l+k, l = 3*k, m*m*m;
}


Create a new paste based on this one


Comments: