The Battle for Wesnoth  1.19.7+dev
Classes | Namespaces | Macros | Functions
lexical_cast.hpp File Reference

New lexcical_cast header. More...

#include "utils/charconv.hpp"
#include "utils/optional_fwd.hpp"
#include <cstdlib>
#include <limits>
#include <string>
#include <sstream>
#include <type_traits>
Include dependency graph for lexical_cast.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  bad_lexical_cast
 Thrown when a lexical_cast fails. More...
 
struct  implementation::lexical_caster< To, From, ToEnable, FromEnable >
 Base class for the conversion. More...
 
struct  implementation::is_arithmetic_v< From > >>
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< bool, std::string_view, void, void >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< To, std::string_view, std::enable_if_t< std::is_arithmetic_v< To > >, void >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< To, std::string, std::enable_if_t< std::is_arithmetic_v< To > >, void >
 Specialized conversion class. More...
 
struct  implementation::is_same_v< From, char * > >>
 Specialized conversion class. More...
 

Namespaces

 implementation
 Contains the implementation details for lexical_cast and shouldn't be used directly.
 

Macros

#define LEXICAL_CAST_HPP_INCLUDED
 
#define DEBUG_THROW(id)
 

Functions

template<typename To , typename From >
To lexical_cast (From value)
 Lexical cast converts one type to another. More...
 
template<typename To , typename From >
To lexical_cast_default (From value, To fallback=To())
 Lexical cast converts one type to another with a fallback. More...
 

Detailed Description

New lexcical_cast header.

For debugging you can include this header in a namespace (to honor ODR) and have a set of functions that throws exceptions instead of doing the real job. This is done for the unit tests but should normally not be done.

Definition in file lexical_cast.hpp.

Macro Definition Documentation

◆ DEBUG_THROW

#define DEBUG_THROW (   id)

Definition at line 55 of file lexical_cast.hpp.

◆ LEXICAL_CAST_HPP_INCLUDED

#define LEXICAL_CAST_HPP_INCLUDED

Definition at line 30 of file lexical_cast.hpp.

Function Documentation

◆ lexical_cast()

template<typename To , typename From >
To lexical_cast ( From  value)
inline

Lexical cast converts one type to another.

Template Parameters
ToThe type to convert to.
FromThe type to convert from.
Parameters
valueThe value to convert.
Returns
The converted value.
Exceptions
bad_lexical_castif the cast was unsuccessful.

Definition at line 88 of file lexical_cast.hpp.

◆ lexical_cast_default()

template<typename To , typename From >
To lexical_cast_default ( From  value,
To  fallback = To() 
)
inline

Lexical cast converts one type to another with a fallback.

Template Parameters
ToThe type to convert to.
FromThe type to convert from.
Parameters
valueThe value to convert.
fallbackThe fallback value to return if the cast fails.
Returns
The converted value.

Definition at line 105 of file lexical_cast.hpp.

Referenced by t_translation::string_to_builder_number_().