Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of boost. Click here for the latest Boost documentation.

Function template convert

boost::convert — Boost.Convert deployment interface with the default converter.


// In header: <boost/convert.hpp>

template<typename TypeOut, typename TypeIn> 
  boost::optional< TypeOut > convert(TypeIn const & value_in);


For example,

struct boost::cnv::by_default : public boost::cnv::cstream {};

// boost::cnv::cstream (through boost::cnv::by_default) is deployed
// as the default converter when no converter is provided explicitly.
boost::optional<int>    i = boost::convert<int>("12");
boost::optional<string> s = boost::convert<string>(123.456);