Boost C++ Libraries

...one 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 to view this page for the latest version.
Next

Chapter 1. Boost.Convert 2.0

Vladimir Batov

Distributed under the Boost Software License, Version 1.0. See copy at http://www.boost.org/LICENSE_1_0.txt.

Table of Contents

Rationale
Introduction
Getting Started
Basic Deployment
Flexibility and Adaptability to Change
Basic Conversion-Failure Detection
Better Error Detection
Default Converter
Alternative Interface
Converters
Integration of User-Defined Types
Boost.Convert with Standard Algorithms
Performance
Converters Compared
Boost.Convert Overhead
The Bigger Picture
Beyond Basic Conversions
Converters in Detail
boost::cnv::lexical_cast Converter
boost::cnv::stream Converter
Formatting Support
Numeric Base
Field Width, Fill Character and Adjustment
Leading Whitespace Characters
Format of Boolean Values
Locale Support
Supported String Types
Wide String
Custom String Types
The Default Constructible Type Requirement
boost::cnv::strtol Converter
Basic Deployment
Formatting Support
Numeric Base (bin, oct, dec, hex)
Field Width, Fill Character and Adjustment
Leading Whitespace Characters
Floating-Point Precision
Supported String Types
Wide String
Custom String Types
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
Design Notes
Requirements
Converter Signature
User Interface Signature
Supporting Tools
boost::cnv::range
boost::cnv::is_range
BOOST_DECLARE_HAS_MEMBER
BOOST_DECLARE_IS_CALLABLE
Supported Compilers
Acknowledgements
Boost.Convert C++ Reference
Header <boost/convert.hpp>
Header <boost/convert/base.hpp>
Header <boost/convert/charconv.hpp>
Header <boost/convert/lexical_cast.hpp>
Header <boost/convert/parameters.hpp>
Header <boost/convert/printf.hpp>
Header <boost/convert/spirit.hpp>
Header <boost/convert/stream.hpp>
Header <boost/convert/strtol.hpp>
Header <boost/make_default.hpp>
Index
[Important] Important

Requires C++11 and up.

I was using textual configuration files extensively and was also processing and preparing considerable amounts of data in XML. Consequently, I had a need for an extendible library that would provide a uniform interface to convert various data between their internal binary representations and external (predominantly textual) representations.

The boost::lexical_cast library (with its orthogonal and extendible design) looked very promising compared to others (see The String Formatters of Manor Farm by H. Sutter for the discussion of alternatives). Unfortunately,

  • many deployed user types simply did not meet boost::lexical_cast requirements (namely, Default Constructibility);
  • failure to convert a user-provided configuration parameter was not that rare or exceptional to justify the hassle and the overhead of exception processing; consequently, additional flexibility (if, when and how) in handling conversion failures was needed;
  • additional conversion-related functionality (such as formatting and locale support) were needed.

The original hope was to see boost::lexical_cast extended to be applicable to a wider range of deployment scenarios. However, after discussions with Kevlin Henney (the boost::lexical_cast author) and in the Boost Developers forum it was collectively decided that the desired extensions were not compatible with the original design and the idea of what boost::lexical_cast embodied and, therefore, a new component with richer interface and functionality was needed. That decision resulted in the development of Boost.Convert described in this document.

Last revised: August 04, 2022 at 02:53:20 GMT


Next