- lib:
boost/libs/convert
- repo:
boostorg/convert
- commit:
b96c1277
, 2017-04-02
convert<TO>(TI const& v_in, Converter const& cvt) -> optional<TO>
- main APIconvert<TO>(TI const& v_in) -> optional<TO>
- Use a default-constructed default converter. Default converter should be declared ascnv::by_default
by user.- Converter can be wrapped by
boost::ref
.
convert<TO>(TI const& v_in, Converter const& cvt, throw_on_failure) -> TO
- throw on failure.convert<TO>(TI const& v_in, Converter const& cvt, F const& fallback) -> TO
-F
is convertible toTO
.convert<TO>(TI const& v_in, Converter const& cvt, F fallback) -> TO
-F()
is convertible toTO
.
cnv::apply<TO, TI>(Converter const& cvt) -> cnv::reference<Converter, TO, TI>
Similar to[cvt, fallback](TI const& v_in){ return convert<TO>(v_in cvt).value_or(fallback.value()); }
cnv::apply<TO>(Converter const& cvt) -> cnv::reference<Converter, TO, void>
Similar to[cvt, fallback](auto const& v_in){ return convert<TO>(v_in, cvt).value_or(fallback.value()); }
Thus the returned reference
is a functor can be used by algorithms.
Header <boost/convert/detail/is_converter.hpp>
template <typename T, typename TI, typename TO> concept bool is_cnv =
( is_class_v<T> || is_function_v<T> ) &&
requires (T const& cnv, TI const & i, optional<TO>& o) { { cnv(i, o) }; }
Header <boost/convert/base.hpp>
and <boost/convert/parameters.hpp>
Base class cnv::cnvbase<DerivedConverter>
, provide basic support for string-oriented conversion.
- Auto support string-like types:
char
andwchar_t
pointer and array- Any class with accessible member named
begin
andend
- Conversible types are
int
,uint
,long
,ulong
,short
,ushort
,float
,double
, andlong double
. - Require derived class to implement
to_str
andstr_to
.
adjust
,base
,fill
,locale
,notation
,precision
,skipws
,uppercase
,width
- Provides
operator()(Keyword value) -> DerivedConverter&
API (locale
andnotation
are unsupported)- Option values are stored as
cnvbase
data members.
- Option values are stored as
skipws
is handled before callstr_to
of derived class.- A temporary buffer is used to accept output of
to_str
, then perform format adjustmentuppercase
,width
,adjust
,fill
are handled
base
,precision
are left to derived converter class to handle.
Provide conversion when input value can be >>
to optional<TO>
.
Header <boost/convert/lexical_cast.hpp>
Just wrap a call to lexical_cast
, catch any exception and left the optional
empty.
Not derived from cnvbase
.
Header <boost/convert/spirit.hpp>
Use Boost.Spirit builtin parsers and generators for required type.
Does not handle the base
and precision
options
Header <boost/convert/stream.hpp>
and <boost/make_default.hpp>
- Wrap a
basic_stringstream<CharT>
to perform conversion for strings, not copyable, but movable. - Not derived from
cnvbase
, but supports all keyword parameters, which are set on underlyingstringstream
instance. - Also accept standard manipulators and
std::locale
byoperator()
. - The converted-to type use
make_default
to create temporary object. - Typedefs for
char
andwchar_t
are provided ascnv::cstream
andcnv::wstream
.
Header <boost/convert/printf.hpp>
- Use
snprintf
andsscanf
to implementto_str
andstr_to
- Supports
precision
, and supportsbase
for 10, 16, and 8 for integer types, don't supportbase
for floats. - The converted-to type use
make_default
to create temporary object.
Header <boost/convert/printf.hpp>
- Use
snprintf
andsscanf
to implementto_str
andstr_to
- Supports arbitrary
base
for integer I/O, recognize0x
and0
format. - Supports
precison
forfloat
anddouble
output. float
anddouble
input is implemented bystrtold
, and only supportchar
strings.
Header <boost/convert/detail/is_fun.hpp>
template <typename T, typename TO> concept bool is_fun =
! is_convertible_v<T, TO> && requires (T const& f) { { f() } -> TO; };
Header <boost/convert/detail/has_member.hpp>
template <typename T> concept trait_name = requires (T t) { t.member_name; };
Header <boost/convert/detail/is_callable.hpp>
template <typename T, typename Sig> concept trait_name = false;
template <typename T, typename R, typename ...A> concept trait_name<T, R(A...)> =
requires (T t, A...a) { { t.member_name(a...) } -> R; };
<boost/config.hpp>
,<boost/detail/workaround.hpp>
<boost/optional.hpp>
<boost/mpl/bool.hpp>
<boost/mpl/vector.hpp>
,<boost/mpl/find.hpp>
- used bycnv::printf
.
<boost/type_traits/remove_const.hpp>
<boost/type_traits/make_unsigned.hpp>
,<boost/type_traits/is_same.hpp>
<boost/type_traits.hpp>
<boost/range/iterator.hpp>
<boost/ref.hpp>
<boost/utility/enable_if.hpp>
<boost/core/noncopyable.hpp>
- required bycnv::basic_stream
.
<boost/function_types/is_function_pointer.hpp>
<boost/function_types/function_arity.hpp>
<boost/function_types/result_type.hpp>
<boost/parameter/keyword.hpp>
<boost/lexical_cast.hpp>
- required bycnv::lexical_cast
.
<boost/spirit/include/qi.hpp>
,<boost/spirit/include/karma.hpp>
- required bycnv::spirit
.
<boost/math/special_functions/round.hpp>
- required bycnv::strtol
.
- Proposals
- P0117R0 - Generic
to_string
/to_wstring
functions
- P0117R0 - Generic