title: Evaluating result of boost::phoenix::insert
body: <p>I'm having difficulties trying to evaluate the result of <code>boost::phoenix::insert</code> which inserts elements into a map. Similar to the regular <code>std::map::insert</code> the actor object returned by <code>boost::phoenix::insert</code> also returns a <code>std::pair&lt;Iterator where, bool result&gt;</code>. I'm interested in the second element of that pair to check if the insert was successful. A heavily striped down code example illustrating the issue is as follows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;boost/phoenix/fusion.hpp&gt;
  #include &lt;boost/phoenix/phoenix.hpp&gt;
  #include &lt;boost/fusion/include/all.hpp&gt;
  #include &lt;boost/fusion/include/std_pair.hpp&gt;
  
  int main(int, char*[])
  {
    namespace phx = boost::phoenix;
    using phx::arg_names::arg1;
    using phx::arg_names::arg2;
  
    std::map&lt;int, int&gt; map;
    std::pair&lt;int, int&gt; value(1, 2);
  
    if (phx::at_c&lt;1&gt;(phx::insert(arg1, arg2))(map, value)) // &lt;- Error here
      std::cout &lt;&lt; "Success" &lt;&lt; std::endl;
    else
      std::cout &lt;&lt; "Fail" &lt;&lt; std::endl;
  
    return 0;
  }
  </code></pre>
  
  <p>I get the following error using MSVC2012 and boost 1.53:</p>
  
  <pre><code>error C2440: 'return' : cannot convert from 'const bool' to 'bool &amp;'
  &lt;some-path&gt;\include\boost\proto\transform\call.hpp:258
  </code></pre>
  
  <p>clang3.2 reports the same error:</p>
  
  <pre><code>Compilation finished with errors:
  In file included from source.cpp:2:
  In file included from /usr/local/include/boost/phoenix/fusion.hpp:14:
  In file included from /usr/local/include/boost/phoenix/fusion/at.hpp:14:
  In file included from /usr/local/include/boost/phoenix/core/expression.hpp:10:
  In file included from /usr/local/include/boost/phoenix/core/as_actor.hpp:10:
  In file included from /usr/local/include/boost/phoenix/core/actor.hpp:17:
  In file included from /usr/local/include/boost/phoenix/core/domain.hpp:12:
  In file included from /usr/local/include/boost/proto/matches.hpp:43:
  In file included from /usr/local/include/boost/proto/transform/when.hpp:22:
  /usr/local/include/boost/proto/transform/call.hpp:255:24: error: binding of reference to type 'bool' to a value of type 'const bool' drops qualifiers
                  return typename detail::poly_function_traits&lt;Fun, Fun(a0, a1)&gt;::function_type()(
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /usr/local/include/boost/phoenix/core/meta_grammar.hpp:74:24: note: in instantiation of member function 'boost::proto::call&lt;boost::proto::functional::at (boost::phoenix::evaluator (*)(boost::proto::_child_c&lt;1&gt;), boost::proto::_value (*)(boost::proto::_child_c&lt;0&gt;))&gt;::impl2&lt;const boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::tag::at_c, boost::proto::argsns_::list2&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;mpl_::int_&lt;1&gt; &gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list3&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::stl::insert&gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0&gt; &gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;2&gt; &gt;, 0&gt; &gt; &gt;, 3&gt; &gt; &gt;, 2&gt; &gt; &amp;, boost::phoenix::vector3&lt;const boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::tag::at_c, boost::proto::argsns_::list2&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;mpl_::int_&lt;1&gt; &gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list3&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::stl::insert&gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0&gt; &gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;2&gt; &gt;, 0&gt; &gt; &gt;, 3&gt; &gt; &gt;, 2&gt; &gt; *, std::map&lt;int, int, std::less&lt;int&gt;, std::allocator&lt;std::pair&lt;const int, int&gt; &gt; &gt; &amp;, std::pair&lt;int, int&gt; &amp;&gt; &amp;, const boost::phoenix::default_actions &amp;, false&gt;::operator()' requested here
                  return what()(e, phoenix::env(s), actions(s));
                         ^
  /usr/local/include/boost/phoenix/core/meta_grammar.hpp:34:9: note: in instantiation of member function 'boost::phoenix::evaluator::impl&lt;const boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::tag::at_c, boost::proto::argsns_::list2&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;mpl_::int_&lt;1&gt; &gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list3&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::stl::insert&gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0&gt; &gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;2&gt; &gt;, 0&gt; &gt; &gt;, 3&gt; &gt; &gt;, 2&gt; &gt; &amp;, const boost::phoenix::vector2&lt;boost::phoenix::vector3&lt;const boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::tag::at_c, boost::proto::argsns_::list2&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;mpl_::int_&lt;1&gt; &gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list3&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::stl::insert&gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0&gt; &gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;2&gt; &gt;, 0&gt; &gt; &gt;, 3&gt; &gt; &gt;, 2&gt; &gt; *, std::map&lt;int, int, std::less&lt;int&gt;, std::allocator&lt;std::pair&lt;const int, int&gt; &gt; &gt; &amp;, std::pair&lt;int, int&gt; &amp;&gt; &amp;, const boost::phoenix::default_actions &amp;&gt; &amp;, boost::proto::envns_::empty_env&gt;::operator()' requested here
          BOOST_PROTO_TRANSFORM(evaluator)
          ^
  /usr/local/include/boost/proto/transform/impl.hpp:228:9: note: expanded from macro 'BOOST_PROTO_TRANSFORM'
          BOOST_PROTO_TRANSFORM_(PrimitiveTransform, void)                                                        \
          ^
  /usr/local/include/boost/proto/transform/impl.hpp:213:16: note: expanded from macro 'BOOST_PROTO_TRANSFORM_'
          return boost::proto::detail::apply_transform&lt;transform_type(Expr const &amp;, State const &amp;)&gt;()(e, s, d);   \
                 ^
  /usr/local/include/boost/phoenix/core/meta_grammar.hpp:139:16: note: in instantiation of function template specialization 'boost::phoenix::evaluator::operator()&lt;const boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::tag::at_c, boost::proto::argsns_::list2&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;mpl_::int_&lt;1&gt; &gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list3&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::stl::insert&gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0&gt; &gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;2&gt; &gt;, 0&gt; &gt; &gt;, 3&gt; &gt; &gt;, 2&gt; &gt; &amp;, const boost::phoenix::vector2&lt;boost::phoenix::vector3&lt;const boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::tag::at_c, boost::proto::argsns_::list2&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;mpl_::int_&lt;1&gt; &gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list3&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::stl::insert&gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0&gt; &gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;2&gt; &gt;, 0&gt; &gt; &gt;, 3&gt; &gt; &gt;, 2&gt; &gt; *, std::map&lt;int, int, std::less&lt;int&gt;, std::allocator&lt;std::pair&lt;const int, int&gt; &gt; &gt; &amp;, std::pair&lt;int, int&gt; &amp;&gt; &amp;, const boost::phoenix::default_actions &amp;&gt; &amp;&gt;' requested here
          return e(expr, ctx);
                 ^
  /usr/local/include/boost/phoenix/core/detail/preprocessed/actor_operator_10.hpp:31:385: note: in instantiation of function template specialization 'boost::phoenix::eval&lt;boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::tag::at_c, boost::proto::argsns_::list2&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;mpl_::int_&lt;1&gt; &gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list3&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::stl::insert&gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0&gt; &gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;2&gt; &gt;, 0&gt; &gt; &gt;, 3&gt; &gt; &gt;, 2&gt; &gt;, boost::phoenix::vector2&lt;boost::phoenix::vector3&lt;const boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::tag::at_c, boost::proto::argsns_::list2&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;mpl_::int_&lt;1&gt; &gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list3&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::stl::insert&gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0&gt; &gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;2&gt; &gt;, 0&gt; &gt; &gt;, 3&gt; &gt; &gt;, 2&gt; &gt; *, std::map&lt;int, int, std::less&lt;int&gt;, std::allocator&lt;std::pair&lt;const int, int&gt; &gt; &gt; &amp;, std::pair&lt;int, int&gt; &amp;&gt; &amp;, const boost::phoenix::default_actions &amp;&gt; &gt;' requested here
          template &lt;typename This, typename A0 , typename A1&gt; struct result&lt;This(A0 &amp; , A1 &amp;)&gt; : result_of::actor&lt;proto_base_expr, A0 &amp; , A1 &amp;&gt; {}; template &lt;typename A0 , typename A1&gt; typename result_of::actor&lt;proto_base_expr, A0 &amp; , A1 &amp;&gt;::type operator()(A0 &amp; a0 , A1 &amp; a1) const { typedef vector3&lt; const actor&lt;Expr&gt; *, A0 &amp; , A1 &amp; &gt; env_type; env_type env = {this, a0 , a1}; return phoenix::eval(*this, phoenix::context(env, default_actions())); } template &lt;typename A0 , typename A1&gt; typename result_of::actor&lt;proto_base_expr, A0 &amp; , A1 &amp;&gt;::type operator()(A0 &amp; a0 , A1 &amp; a1) { typedef vector3&lt; const actor&lt;Expr&gt; *, A0 &amp; , A1 &amp; &gt; env_type; env_type env = {this, a0 , a1}; return phoenix::eval(*this, phoenix::context(env, default_actions())); } template &lt;typename This, typename A0 , typename A1&gt; struct result&lt;This(A0 &amp; , A1 const&amp;)&gt; : result_of::actor&lt;proto_base_expr, A0 &amp; , A1 const&amp;&gt; {}; template &lt;typename A0 , typename A1&gt; typename result_of::actor&lt;proto_base_expr, A0 &amp; , A1 const&amp;&gt;::type operator()(A0 &amp; a0 , A1 const&amp; a1) const { typedef vector3&lt; const actor&lt;Expr&gt; *, A0 &amp; , A1 const&amp; &gt; env_type; env_type env = {this, a0 , a1}; return phoenix::eval(*this, phoenix::context(env, default_actions())); } template &lt;typename A0 , typename A1&gt; typename result_of::actor&lt;proto_base_expr, A0 &amp; , A1 const&amp;&gt;::type operator()(A0 &amp; a0 , A1 const&amp; a1) { typedef vector3&lt; const actor&lt;Expr&gt; *, A0 &amp; , A1 const&amp; &gt; env_type; env_type env = {this, a0 , a1}; return phoenix::eval(*this, phoenix::context(env, default_actions())); } template &lt;typename This, typename A0 , typename A1&gt; struct result&lt;This(A0 const&amp; , A1 &amp;)&gt; : result_of::actor&lt;proto_base_expr, A0 const&amp; , A1 &amp;&gt; {}; template &lt;typename A0 , typename A1&gt; typename result_of::actor&lt;proto_base_expr, A0 const&amp; , A1 &amp;&gt;::type operator()(A0 const&amp; a0 , A1 &amp; a1) const { typedef vector3&lt; const actor&lt;Expr&gt; *, A0 const&amp; , A1 &amp; &gt; env_type; env_type env = {this, a0 , a1}; return phoenix::eval(*this, phoenix::context(env, default_actions())); } template &lt;typename A0 , typename A1&gt; typename result_of::actor&lt;proto_base_expr, A0 const&amp; , A1 &amp;&gt;::type operator()(A0 const&amp; a0 , A1 &amp; a1) { typedef vector3&lt; const actor&lt;Expr&gt; *, A0 const&amp; , A1 &amp; &gt; env_type; env_type env = {this, a0 , a1}; return phoenix::eval(*this, phoenix::context(env, default_actions())); } template &lt;typename This, typename A0 , typename A1&gt; struct result&lt;This(A0 const&amp; , A1 const&amp;)&gt; : result_of::actor&lt;proto_base_expr, A0 const&amp; , A1 const&amp;&gt; {}; template &lt;typename A0 , typename A1&gt; typename result_of::actor&lt;proto_base_expr, A0 const&amp; , A1 const&amp;&gt;::type operator()(A0 const&amp; a0 , A1 const&amp; a1) const { typedef vector3&lt; const actor&lt;Expr&gt; *, A0 const&amp; , A1 const&amp; &gt; env_type; env_type env = {this, a0 , a1}; return phoenix::eval(*this, phoenix::context(env, default_actions())); } template &lt;typename A0 , typename A1&gt; typename result_of::actor&lt;proto_base_expr, A0 const&amp; , A1 const&amp;&gt;::type operator()(A0 const&amp; a0 , A1 const&amp; a1) { typedef vector3&lt; const actor&lt;Expr&gt; *, A0 const&amp; , A1 const&amp; &gt; env_type; env_type env = {this, a0 , a1}; return phoenix::eval(*this, phoenix::context(env, default_actions())); }
                                                                                                                                                                                                                                                                                                                                                                                                  ^
  source.cpp:16:44: note: in instantiation of function template specialization 'boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::tag::at_c, boost::proto::argsns_::list2&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;mpl_::int_&lt;1&gt; &gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::phoenix::detail::tag::function_eval, boost::proto::argsns_::list3&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::stl::insert&gt;, 0&gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;1&gt; &gt;, 0&gt; &gt;, boost::phoenix::actor&lt;boost::proto::exprns_::basic_expr&lt;boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term&lt;boost::phoenix::argument&lt;2&gt; &gt;, 0&gt; &gt; &gt;, 3&gt; &gt; &gt;, 2&gt; &gt;::operator()&lt;std::map&lt;int, int, std::less&lt;int&gt;, std::allocator&lt;std::pair&lt;const int, int&gt; &gt; &gt;, std::pair&lt;int, int&gt; &gt;' requested here
    if (phx::at_c&lt;1&gt;(phx::insert(arg1, arg2))(map, value))
                                             ^
  1 error generated.
  </code></pre>
  
  <p>I'm about to run out of ideas how to correctly evaluating the result of insert. Any help would be appreciated.</p>
  
  <p>Edit:
  The wider context of my question is that I'm trying to parse a C++ like enumeration using boost::spirit::qi. Any examples I found which try to achieve the same do not check for duplicate enumeration members. Here a code snip with the two relevant rules:</p>
  
  <pre><code>  enumerationMember = identifier[at_c&lt;0&gt;(_val) = _1] &gt;
      // If there is an explicit value defined use it.
      ((lit('=') &gt; int_[at_c&lt;1&gt;(_val) = _1]) |
      // Otherwise use the value of argument _r1 instead.
      eps[at_c&lt;1&gt;(_val) = _r1]);
    enumeration = lit("enum") &gt; typeName[at_c&lt;0&gt;(_val) = _1] &gt; lit(':') &gt;
      enumerationType[at_c&lt;1&gt;(_val) = _1] &gt; braceOpen &gt;
      // Initialize _a with 0.
      eps[_a = 0] &gt;
      // Zero or one comma separated list of members.
      -(enumerationMember(_a)[//_pass = boost::phoenix::at_c&lt;1&gt;( &lt;- I'm looking for something like this..
        insert(at_c&lt;2&gt;(_val), _1)]
        // Set _a to the value of the last member + 1.
        [_a = at_c&lt;1&gt;(_1) + 1]
        % lit(',')) &gt;
      braceClose;
  </code></pre>