Next

Chapter 1. The Boost Convert Library 2.0

Vladimir Batov

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

Table of Contents

Introduction
Design Notes
Getting Started
Getting Serious
Boost.Convert with Standard Algorithms
Converters
boost::lexical_cast-Based Converter
std::stringstream-Based Converter
Formatting Support
Locale Support
Integration of User-Defined Types
Performance
Type Requirements
The Default Constructible Type Requirement
Other Conversions
Convert Reference
Header <boost/convert/api.hpp>
Header <boost/convert/lexical_cast_converter.hpp>
Header <boost/convert/safebool.hpp>
Header <boost/convert/sstream_converter.hpp>
Header <boost/convert/string_sfinae.hpp>
Motivation
Acknowledgements
Index

Boost.Convert builds on the boost::lexical_cast design and experience and takes those conversion/transformation-related ideas further

  • to be applicable to a wider range of conversion-related deployment scenarios,
  • to provide a more flexible, extensible and configurable type-conversion framework.

Boost.Convert has a modular design and what it can ultimately do is to a large extend defined by a pluggable converter component. For example, one of the converters supplied with the proposal and discussed in the document is a std::stringstream-based converter. With that converter deployed Boost.Convert provides:

  • string-to-type and type-to-string conversions;
  • formatting support based on standard manipulators (like std::hex, std::scientific, etc.);
  • support for different locales;
  • char and wchar_t support;
  • flexible throwing and non-throwing failed-conversion behavior;
  • support for the fallback value to be returned when conversion/transformation fails;
  • two types of the conversion-failure check - quick/simple and generic;
  • means to deploy types that do no meet the Default Constructibility requirement;
  • support for standard algorithms.

Please note that the described framework is not part of the Boost library collection even though in this document it is referred to as Boost.Convert. It is done so in preparation for potential submission of the library to Boost.

Last revised: February 16, 2014 at 23:15:30 GMT


Next