Ookii.CommandLine for C++  2.0.0
Static Public Member Functions | List of all members
ookii::lexical_convert< T, CharType, Traits, Alloc > Struct Template Reference

Template class used to convert strings to strongly typed argument values. More...

#include <ookii/string_helper.h>

Static Public Member Functions

static std::optional< T > from_string (std::basic_string_view< CharType, Traits > value, const std::locale &loc={})
 Convert a string to the specified type. More...
 

Detailed Description

template<typename T, typename CharType, typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
struct ookii::lexical_convert< T, CharType, Traits, Alloc >

Template class used to convert strings to strongly typed argument values.

This base template uses a stringstream to do the conversion, relying on stream extraction operator>> for the provided type. The template can be specialized to provide conversion of custom types.

Template Parameters
TThe type to convert to.
CharTypeThe character type used.
TraitsThe character traits to use. Defaults to std::char_traits<CharType>.
AllocThe allocator to use. Defaults to std::allocator<CharType>.

Member Function Documentation

◆ from_string()

template<typename T , typename CharType , typename Traits = std::char_traits<CharType>, typename Alloc = std::allocator<CharType>>
static std::optional<T> ookii::lexical_convert< T, CharType, Traits, Alloc >::from_string ( std::basic_string_view< CharType, Traits >  value,
const std::locale &  loc = {} 
)
inlinestatic

Convert a string to the specified type.

Parameters
valueThe string value to convert.
locThe locale to use for conversion.
Returns
The converted value, or std::nullopt if conversion failed.

The documentation for this struct was generated from the following file: