I'm having some trouble with nested let blocks in Boost Phoenix when an "inner" local variable hides an "outer" local variable. Even with the "Visibility" example from the documentation here, shown here:

#include <iostream>
#include <boost/phoenix.hpp>

namespace phoenix = boost::phoenix;
using namespace phoenix::local_names;

int main(int argc, char *argv[])
{
  phoenix::let(_x = 1, _y = ", World")
  [
    phoenix::let(_x = "Hello") // hides the outer _x
    [
      std::cout << _x << _y // prints "Hello, World"
    ]
  ]();

  return 0;
}

I receive errors starting with:

GCC:   "error: function returning an array"
Clang: "error: function cannot return array type 'result_type' (aka 'char [6]')"

Does anyone know how I can "shadow" such a variable within the scope of an inner let block in Phoenix? I'm currently using Ubuntu 13.04 with GCC version 4.8 snapshot; Clang 3.2; Boost 1.49; and also Boost 1.53.

有帮助吗?

解决方案

That's most definitely a bug in Phoenix. The following compiles:

int y = 0;
int x = (phoenix::let(_a = 1, _b = 2)[phoenix::let(_b = _1)[ _a ]])(y);

The following does not:

int y = 0;
int x = (phoenix::let(_a = 1, _b = 2)[phoenix::let(_b = 3)[ _a ]])(y);

Bizarre. Could you file a bug at https://svn.boost.org/trac/boost/ (click "New Ticket"). Thanks. (Note: I'm not the maintainer.)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top