New lexcical_cast header. More...
#include <optional>
#include <cstdlib>
#include <limits>
#include <string>
#include <sstream>
#include <type_traits>
Go to the source code of this file.
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) |
Throws an exception for debugging. More... | |
#define | LEXICAL_CAST_HPP_INCLUDED |
#define | DEBUG_THROW(id) 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... | |
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.
#define DEBUG_THROW | ( | id | ) |
Throws an exception for debugging.
id | The unique name to identify the function. |
Definition at line 43 of file test_lexical_cast.cpp.
Referenced by implementation::lexical_caster< To, From, ToEnable, FromEnable >::operator()(), implementation::is_integral_v< std::remove_pointer_t< From > > >>::operator()(), implementation::lexical_caster< long long, From, void, std::enable_if_t< std::is_same_v< From, const char * >||std::is_same_v< From, char * > > >::operator()(), implementation::lexical_caster< long long, std::string >::operator()(), 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 * > > >::operator()(), 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 > > >::operator()(), 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 * > > >::operator()(), implementation::lexical_caster< To, std::string, std::enable_if_t< std::is_floating_point_v< To > > >::operator()(), 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 * > > >::operator()(), implementation::lexical_caster< unsigned long long, std::string >::operator()(), 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 * > > >::operator()(), implementation::lexical_caster< To, std::string, std::enable_if_t< std::is_unsigned_v< To > > >::operator()(), implementation::lexical_caster< bool, std::string >::operator()(), and implementation::lexical_caster< bool, From, void, std::enable_if_t< std::is_same_v< From, const char * >||std::is_same_v< From, char * > > >::operator()().
#define LEXICAL_CAST_HPP_INCLUDED |
#define LEXICAL_CAST_HPP_INCLUDED |
Definition at line 31 of file test_lexical_cast.cpp.
|
inline |
Lexical cast converts one type to another.
To | The type to convert to. |
From | The type to convert from. |
value | The value to convert. |
bad_lexical_cast | if the cast was unsuccessful. |
Definition at line 86 of file lexical_cast.hpp.
Referenced by config::apply_diff(), config::clear_diff_track(), events::console_handler::do_control(), events::console_handler::do_controller(), gui2::dialogs::editor_generate_map::get_seed(), help::help_text_area::handle_jump_cfg(), gui2::dialogs::preferences_dialog::initialize_callbacks(), editor::editor_display::layout(), gui2::dialogs::help_browser::on_topic_select(), implementation::lexical_caster< long long, From, void, std::enable_if_t< std::is_same_v< From, const char * >||std::is_same_v< From, char * > > >::operator()(), 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 * > > >::operator()(), 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 * > > >::operator()(), config_attribute_value::string_visitor::operator()(), 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 * > > >::operator()(), 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 * > > >::operator()(), implementation::lexical_caster< bool, From, void, std::enable_if_t< std::is_same_v< From, const char * >||std::is_same_v< From, char * > > >::operator()(), commandline_options::parse_to_uint_string_string_tuples_(), commandline_options::parse_to_uint_string_tuples_(), progressive_pair< int >::progressive_pair(), and ai::config_value_translator< T >::value_to_cfg().
|
inline |
Lexical cast converts one type to another with a fallback.
To | The type to convert to. |
From | The type to convert from. |
value | The value to convert. |
fallback | The fallback value to return if the cast fails. |
Definition at line 103 of file lexical_cast.hpp.
Referenced by t_translation::string_to_builder_number_().