Как сделать выражение функции boost-proto растопимым? - PullRequest
1 голос
/ 21 ноября 2011

Я прошёл учебник по boost-proto и столкнулся с этой проблемой на примере функции lazy pow. Это пример кода:

// Define a pow_fun function object
template<int Exp> // , typename Func>
struct pow_fun
{
    typedef double result_type;
    double operator()(double d) const
    {
        return pow(d, Exp);
    }
};

// Define a lazy pow() function for the calculator DSEL.
// Can be used as: pow< 2 >(_1)
template<int Exp, typename Arg>
typename proto::result_of::make_expr<
    proto::tag::function  // Tag type
  , pow_fun<Exp>          // First child (by value)
  , Arg const &           // Second child (by reference)
>::type const
mypow(Arg const &arg)
{
    return proto::make_expr<proto::tag::function>(
        pow_fun<Exp>()    // First child (by value)
      , boost::ref(arg)   // Second child (by reference)
    );    
}

Теперь, если я попытаюсь

proto::display_expr( mypow<2>(_1) );

компилятор жалуется, что у него нет оператора << для выражение функции. Как мне определить один? </p>

Спасибо.

Ошибка компилятора:

/ usr / include / boost / proto / debug.hpp: 146: ошибка: нет совпадения для 'operator <<' в 'std :: operator << [с _Traits = std :: char_traits] (((std: : basic_ostream> &) ((std :: basic_ostream> *) std :: operator << [with _Traits = std :: char_traits] (((std :: basic_ostream> &) ((std :: basic_ostream> *) std: : operator << [with _Traits = std :: char_traits] (((std :: basic_ostream> &) ((std :: basic_ostream> *) std :: operator << [with _CharT = char, _Traits = std :: char_traits ] (((std :: basic_ostream> &) ((std :: ostream *) ((const boost :: proto :: functions :: display_expr *) this) -> boost :: proto :: functions :: display_expr :: sout_)), std :: setw (((const boost :: proto :: functions :: display_expr *) this) -> boost :: proto :: функционал :: display_expr :: глубины_)))), ((( boost :: proto :: functions :: display_expr *) это) -> boost :: proto :: функционал :: display_expr :: first_? ((const char *) ""): ((const char *) ",") )))), boost :: proto :: tag :: proto_tag_name ((boost :: proto :: tag :: терминал (), boost :: proto :: tag :: терминал ()))))), (( const char *) "(")) << boost :: proto :: va lue [с Expr = boost :: proto :: exprns _ :: expr>, 0l>] (((const boost :: proto :: exprns _ :: expr>, 0l> &) ((const boost :: proto :: exprns_ :: expr>, 0l> *) expr))) '

1 Ответ

2 голосов
/ 25 ноября 2011

Какая прототипная версия? Последние не требуют перегрузки << больше и по умолчанию typeid для отображения имени, если это необходимо. Не могли бы вы опубликовать фактическое сообщение об ошибке? </p>

...