title: cannot construct std::string from placeholder in Boost.Spirit
body: <p>I have started working on a Boost.Spirit based simple parser that will parse a C++-like file (the only C++-ish part is the built-in template types; e.g. <code>map&lt;string, smart_ptr&lt;int&gt;&gt; name_object_map;</code> - but this is built-in the compiler, and user cannot declare template classes). Nevertheless, the grammar is intended to contain data structure declarations, and not expressions, except the constant expressions that are used for initialization of enumerator declarations; <code>enum E { a = 4 * 5 + 3 };</code> is valid. This is not currently a problem for me, because I couldn't parse <code>E</code> the way I want yet :)</p>
  
  <p>I have made the following yesterday, after reading the docs and examples, but it doesn't compile:</p>
  
  <pre><code>#include &lt;boost/spirit/include/phoenix.hpp&gt;
  #include &lt;boost/spirit/include/qi.hpp&gt;
  #include &lt;boost/spirit/include/qi_char_class.hpp&gt;
  #include &lt;cassert&gt;
  #include &lt;memory&gt;
  #include &lt;string&gt;
  #include &lt;utility&gt;
  
  struct context {};
  
  class foo {
    std::string name;
    const context *ctx;
  
  public:
    foo(const std::string &amp;name, const context *ctx) : name(name), ctx(ctx) {}
  };
  
  using foo_ref = std::shared_ptr&lt;foo&gt;;
  
  template &lt;typename Iterator&gt;
  struct skipper : boost::spirit::qi::grammar&lt;Iterator&gt; {
    skipper() : skipper::base_type(start) {
      using namespace boost::spirit;
      qi::char_type char_;
      ascii::space_type space;
  
      start = space                             // tab/space/cr/lf
              | "/*" &gt;&gt; *(char_ - "*/") &gt;&gt; "*/" // C-style comments
          ;
    }
  
    boost::spirit::qi::rule&lt;Iterator&gt; start;
  };
  
  template &lt;typename Iterator&gt;
  struct the_parser : boost::spirit::qi::grammar&lt;Iterator, std::vector&lt;foo_ref&gt;(),
                                                 skipper&lt;Iterator&gt;&gt; {
    the_parser() : the_parser::base_type(start), current_context(&amp;root) {
      using namespace boost::spirit;
      namespace phx = boost::phoenix;
  
      identifier = qi::lexeme[qi::alpha &gt;&gt; *qi::alnum];
      start = *(foo_decl); // currently, no semantic action attached.
                           // This will create the root decl in ast.
  
      foo_decl = (lit("foo") &gt;&gt; identifier)[qi::_val = std::make_shared&lt;foo&gt;(
                                                 qi::_1, current_context)] &gt;&gt;
                 qi::char_('{') &gt;&gt; qi::char_('}') &gt;&gt; qi::char_(';');
      BOOST_SPIRIT_DEBUG_NODES((identifier)(start)(foo_decl));
    }
    boost::spirit::qi::rule&lt;Iterator, std::string(), skipper&lt;Iterator&gt;&gt;
        identifier;
    boost::spirit::qi::rule&lt;Iterator, std::vector&lt;foo_ref&gt;(), skipper&lt;Iterator&gt;&gt;
        start;
    boost::spirit::qi::rule&lt;Iterator, foo_ref(), skipper&lt;Iterator&gt;&gt; foo_decl;
    context root;
    const context *current_context;
  };
  
  int main() {
    the_parser&lt;std::string::const_iterator&gt; parser;
    std::vector&lt;foo_ref&gt; root;
  
    const std::string content = "foo john_doe { };";
    auto first = content.cbegin(), last = content.cend();
    bool r = boost::spirit::qi::phrase_parse(
        first, last, parser, skipper&lt;std::string::const_iterator&gt;(), root);
    assert(r &amp;&amp; first == last);
  }
  </code></pre>
  
  <p>Compiling this with clang on Mac (the first line is <code>std::make_shared</code>):</p>
  
  <pre><code>error: no matching constructor for initialization of 'foo'
            __second_(_VSTD::forward&lt;_Args2&gt;(_VSTD::get&lt;_I2&gt;(__second_args))...)
            ^         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ...
  note: candidate constructor not viable: no known conversion from 'const boost::phoenix::actor&lt;boost::spirit::argument&lt;0&gt; &gt;' to 'const std::string' (aka
    'const basic_string&lt;char, char_traits&lt;char&gt;, allocator&lt;char&gt; &gt;') for 1st argument
    foo(const std::string &amp;name, const context *ctx) : name(name), ctx(ctx) {}
    ^
  </code></pre>
  
  <p>In <code>foo_decl</code>s semantic action, it cannot construct a <code>foo</code> (through <code>std::make_shared</code>), because the first attribute's result cannot be converted to <code>std::string</code>. However, if I add a class member <code>std::string s</code>, and do this instead, it works:</p>
  
  <pre><code>foo_decl = (lit("foo") &gt;&gt; identifier)[boost::phoenix::ref(s) = qi::_1] &gt;&gt;
                   qi::char_('{') &gt;&gt; qi::char_('}') &gt;&gt; qi::char_(';');
  </code></pre>
  
  <p>Likewise, if I try to <code>std::cout</code> it, I can see <code>john_doe</code> is printed.</p>
  
  <p>If I bind a member function call with phoenix, it also works:</p>
  
  <pre><code>foo_decl = (lit("foo") &gt;&gt; identifier)[qi::_val =
                     boost::phoenix::bind(&amp;the_parser, this, qi::_1)] &gt;&gt;
             qi::char_('{') &gt;&gt; qi::char_('}') &gt;&gt; qi::char_(';');
  
  foo_ref make_foo(const std::string &amp;n) {
    return std::make_shared(n, current_context);
  }
  </code></pre>
  
  <p>These last three workarounds mean that there is an implicit conversion sequence from <code>decltype(qi::_1)</code> to <code>std::string</code>; isn't this correct?</p>
  
  <p>I would be very happy, if you could show me my mistake or the gap in my understanding of how semantic actions, and placeholders work. It looks very strange to me as to why <code>std::make_shared</code> doesn't work.</p>
  
  <p>Thank you!</p>