Subject: [Boost-bugs] [Boost C++ Libraries] #7996: phoenix::bind does not protoify the bound arguments
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-02-06 18:10:14
#7996: phoenix::bind does not protoify the bound arguments
------------------------------------+---------------------------------------
Reporter: andysem | Owner: theller
Type: Bugs | Status: new
Milestone: To Be Determined | Component: phoenix
Version: Boost Release Branch | Severity: Problem
Keywords: phoenix bind proto log |
------------------------------------+---------------------------------------
I have a problem with Boost.Phoenix v3 bind implementation when used with
attribute keywords from Boost.Log. For some reason phoenix::bind does not
apply proto::detail::protoify to the bound arguments which breaks
compilation of some formatting expressions in Boost.Log.
Here's an example:
{{{
#include <boost/phoenix.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/value_ref.hpp>
namespace logging = boost::log;
namespace expr = boost::log::expressions;
namespace phoenix = boost::phoenix;
// Custom severity level formatting function
std::string severity_level_as_urgency(
logging::value_ref< logging::trivial::severity_level,
logging::trivial::tag::severity > const& level)
{
if (!level || level.get() == logging::trivial::info)
return "normal";
logging::trivial::severity_level lvl = level.get();
if (lvl < logging::trivial::info)
return "low";
else
return "critical";
}
int main(int, char*[])
{
logging::formatter fmt =
expr::stream << boost::phoenix::bind(&severity_level_as_urgency,
logging::trivial::severity);
return 0;
}
}}}
The example creates a formatter function object that should call
severity_level_as_urgency function to convert the severity level to string
and put its result into a stream.
trivial::severity is a keyword of type expr::attribute_keyword< ... >.
Keywords themselves should never actually be embedded into phoenix
expressions, instead I have attribute_actor that implements all the
necessary work to extract attribute values. I have specialized
proto::detail::protoify template for attribute_keyword (including
references and reference_wrappers thereof) so that it is automatically
converted to attribute_actor whenever it participates in expressions. But
it doesn't work with the above code, Boost.Phoenix embeds
attribute_keyword as is into the expression. This results
in the error I attached to the ticket.
I realize that proto::detail::protoify is not for public use and may not
be intended for my use case but I did not find any other way to implement
what I described. Anyway, I think bind should treat bound arguments as
child subexpressions and protoify them.
To compile the test code you will have to checkout Boost.Log from SVN:
{{{
svn co https://boost-log.svn.sourceforge.net/svnroot/boost-log/branches
/bleeding-edge -r 822 boost-log
}}}
Then the relevant directories have to be linked/copied into the Boost
tree.
PS: The issue came from the mailing list:
[http://lists.boost.org/Archives/boost/2013/02/200701.php]
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/7996> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:11 UTC