Ferdinand Prantl wrote:
I use boost::any for serialization and deserialization of both user-provided values and hard-coded constants. Stream output has to be done a little clumsily by a custom operator<<() which consists of a big if/elseif code block deciding what to do according to boost::any::type().
Would it be helpful to you if boost::any would have a function to
retrieve its value "as a string"? I /think/ such a function,
any::str(), could be implemented quite easily, as a pure virtual
function of any::placeholder, implemented within any::holder<ValueType>
as follows:
virtual const std::string str() const
{
using any_implementation_details::operator<<;
std::ostringstream stream;
stream << held;
return stream.str();
}
The namespace any_implementation_details would have an empty default
implementation of operator<<:
namespace any_implementation_details
{
template
Thank you very much for your deep insight!
You're welcome :-) Kind regards, Niels PS, For those who missed it, there's another thread on this iussue at the Boost developers' mailing list, "[boost] An elegant way to initialize an instance of boost::anywith a C-style string constant", http://thread.gmane.org/gmane.comp.lib.boost.devel/177324