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

New lexcical_cast header. More...

#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_integral_v< std::remove_pointer_t< From > > >>
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< long long, From, void, std::enable_if_t< std::is_same_v< From, const char * >||std::is_same_v< From, char * > > >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< long long, std::string >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< To, From, std::enable_if_t< std::is_integral_v< To > &&std::is_signed_v< To > &&!std::is_same_v< To, long long > >, std::enable_if_t< std::is_same_v< From, const char * >||std::is_same_v< From, char * > > >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< To, std::string, std::enable_if_t< std::is_integral_v< To > &&std::is_signed_v< To > &&!std::is_same_v< To, long long > > >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< To, From, std::enable_if_t< std::is_floating_point_v< To > >, std::enable_if_t< std::is_same_v< From, const char * >||std::is_same_v< From, char * > > >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< To, std::string, std::enable_if_t< std::is_floating_point_v< To > > >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< unsigned long long, From, void, std::enable_if_t< std::is_same_v< From, const char * >||std::is_same_v< From, char * > > >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< unsigned long long, std::string >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< To, From, std::enable_if_t< std::is_unsigned_v< To > &&!std::is_same_v< To, unsigned long long > >, std::enable_if_t< std::is_same_v< From, const char * >||std::is_same_v< From, char * > > >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< To, std::string, std::enable_if_t< std::is_unsigned_v< To > > >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< bool, std::string >
 Specialized conversion class. More...
 
struct  implementation::lexical_caster< bool, From, void, std::enable_if_t< std::is_same_v< From, const char * >||std::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 53 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 86 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 103 of file lexical_cast.hpp.

Referenced by t_translation::string_to_builder_number_().