Boost logo

Boost :

From: Maurizio Vitale (mav_at_[hidden])
Date: 2007-06-14 23:34:37

        I've found more about the root problem in my code. A pattern for a terminal was not matching and
the thus the transform for unary_expr was applied.

In the code included, I define a class, K_aux, which inherits from meta_expression<typename proto::terminal<K<mpl::int_<N> >,
Normally, objects of type K_aux match a pattern terminal<K<proto::_> >. I'm still fuzzy on why two layers of the type are
skipped, but I'm fine with it.

Now, if K_aux defines a type named type (e.g. effectively becoming a nullary metafunction) the pattern doesn't match anymore.
If this is intentional or unavoidable it should be mentioned in the docs. In boldface.

Btw, the entire exercise is to get real compile time constants. I can change the name of the typedef'd type and use code similar to
this, but if there was a better way I'd liek to hear.



===File ~/dev/proto_pdl/pe5.cpp=============================
#include <iostream>
#include <boost/xpressive/proto/proto.hpp>
#include <boost/xpressive/proto/debug.hpp>

#include <boost/type_traits.hpp>

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

template<typename> struct meta_expression;

struct meta_domain : proto::domain<proto::generator<meta_expression> > {};

template <typename Expr>
struct meta_expression : proto::extends<Expr, meta_expression<Expr>, meta_domain> {
  typedef proto::extends<Expr, meta_expression<Expr>, meta_domain> base_type;
  meta_expression (Expr const& expr = Expr()) : base_type (expr) {}
  using base_type::operator =;

template<typename N> struct K { typedef N type; };
template<int N>
struct K_aux : meta_expression<typename proto::terminal< K<mpl::int_<N> > >::type> {
// typedef mpl::int_<N> type;

#define const_(N) (K_aux<N> ())

template<typename N> std::ostream& operator << (std::ostream& os, const K<N> k) { os << "const"; return os; }

struct meta_grammar : proto::or_ <
  proto::terminal<K<proto::_> >,
    proto::not_<proto::terminal<proto::_> >,
    proto::unary_expr<proto::_, proto::_>

template<typename Expr>
void is_meta_expression (const Expr& expr) {
  std::cout << "Expression:\n";
  proto::display_expr (expr);
    if (proto::matches<Expr, meta_grammar>::value)
    std::cout << "matches meta grammar\n\n";
    std::cout << "doesn't matches meta grammar\n\n";

int main (int,char**) {
  is_meta_expression (const_ (1));

/// Local Variables:
/// mode:c++
/// comment-column:60
/// fill-column:150
/// compilation-read-command:nil
/// compile-command:"g++ -I. -ope5 pe5.cpp"
/// End:


Boost list run by bdawes at, gregod at, cpdaniel at, john at