Hi all,
I am using Boost.Proto with Boost 1.42.0 and Visual Studio 2005/2008. I try to handle literal strings in the context of my DSEL:
struct CContext
{
...
template<>
struct eval::type> >
{
typedef void result_type;
result_type operator()(CExpression::type> Expr, CContext& Ctx) const
{
return;
}
};
...
};
But the eval for literal strings is never matched. Instead the general proto::tag::terminal eval is matched which is defined afterwards. I tried several variations like char const[proto::N] and the like, without success. What am I missing here?
A full example follows at the end.
Regards,
Steffen
------------------------------
#include <iostream>
#include
namespace proto = boost::proto;
struct CTerminal;
struct CGrammar
: proto::or_<
proto::shift_right,
proto::terminalproto::_ >
{
};
struct CDomain;
template <typename TExpr>
struct CExpression
: proto::extends
{
typedef proto::extends base_type;
CExpression(const TExpr& Expr = TExpr())
: base_type(Expr)
{
}
};
struct CDomain
: proto::domain
{
};
struct CTerminal
: CExpression
{
typedef proto::terminal<int>::type expr_type;
CTerminal()
: CExpression(expr_type::make(int(0)))
{
}
template <typename TExpr>
void operator=(TExpr& Expr)
{
CContext Ctx;
proto::eval(Expr, Ctx);
return;
}
};
// typedef CExpression::type> TLiteralString;
// typedef CExpression::type> TLiteralString;
typedef CExpression::type> TLiteralString;
struct CContext
{
template
struct eval
{
};
template<>
struct eval<CTerminal>
{
typedef void result_type;
result_type operator()(const CTerminal& Expr, CContext& Ctx) const
{
std::cout << "CTerminal\n";
return;
}
};
// why is the literal string not matched by this eval???
template<>
struct eval<TLiteralString>
{
typedef void result_type;
result_type operator()(TLiteralString Expr, CContext& Ctx) const
{
std::cout << "Literal string \"" << proto::value(Expr) << "\"\n";
return;
}
};
// instead the literal string matches this
template<typename TExpr>
struct eval
{
typedef void result_type;
result_type operator()(const TExpr& Expr, CContext& Ctx) const
{
std::cout << "*** Terminal \"" << proto::value(Expr) << "\"\n";
std::cout << "*** " << typeid(Expr).name() << "\n";
std::cout << "*** " << typeid(TLiteralString).name() << "\n";
return;
}
};
template<typename TExpr>
struct eval
{
typedef void result_type;
result_type operator()(const TExpr& Expr, CContext& Ctx) const
{
std::cout << "ShiftRight\n";
proto::eval(proto::left(Expr), Ctx);
proto::eval(proto::right(Expr), Ctx);
return;
}
};
};
int main(int argc, char* argv[])
{
CTerminal Foo, Bar;
Foo = Bar >> "keyword";
return 0;
}
--
Sicherer, schneller und einfacher. Die aktuellen Internet-Browser -
jetzt kostenlos herunterladen! http://portal.gmx.net/de/go/atbrowser