PrevUpHomeNext

boost::cnv::charconv Converter

Basic Deployment
Formatting Support
Numeric Base (bin, oct, dec, hex)
Field Width, Fill Character and Adjustment
Leading Whitespace Characters
Floating-Point Precision
Floating-Point Notation
Supported String Types
Custom String Types
[Important] Important

Requires C++17 and up.

The converter is a wrapper around std::to_chars and std::from_chars and offers great performance with some formatting support. The converter only supports char-based strings. Written by Dvir Yitzchaki.

#include <boost/convert.hpp>
#include <boost/convert/charconv.hpp>

using std::string;
using boost::convert;

namespace cnv = boost::cnv;
namespace arg = boost::cnv::parameter;

struct cnv::by_default : boost::cnv::charconv {};

string const     bad_str = "not an int";
string const     std_str = "-11";
char const* const  c_str = "-12";
boost::string_view v_str = boost::string_view(c_str, 2);

BOOST_TEST( -1 == convert<int>(bad_str).value_or(-1));
BOOST_TEST(-11 == convert<int>(std_str).value());
BOOST_TEST(-12 == convert<int>(  c_str).value());
BOOST_TEST( -1 == convert<int>(  v_str).value_or(0));


PrevUpHomeNext