JayBeams  0.1
Another project to have fun coding.
Classes | Namespaces | Macros | Functions
strtonum.hpp File Reference
#include <stdexcept>
#include <string>

Go to the source code of this file.

Classes

struct  jb::stn_traits< T >
 Traits to convert strings to numbers (e.g. More...
 

Namespaces

 jb
 The top-level namespace for the JayBeams library.
 

Macros

#define STN_TRAITS(T, F)
 

Functions

 jb::STN_TRAITS (int, std::stoi)
 
 jb::STN_TRAITS (unsigned long long, std::stoull)
 
 jb::STN_TRAITS (long long, std::stoll)
 
 jb::STN_TRAITS (unsigned long, std::stoul)
 
 jb::STN_TRAITS (long, std::stol)
 
 jb::STN_TRAITS (float, std::stof)
 
 jb::STN_TRAITS (double, std::stod)
 
template<typename T >
bool jb::strtonum (std::string const &s, T &r)
 Generic string to number conversion with validation. More...
 

Class Documentation

◆ jb::stn_traits

struct jb::stn_traits

template<typename T>
struct jb::stn_traits< T >

Traits to convert strings to numbers (e.g.

integers, floats, etc).

For most types this refactors repetitive code, but also allows specialization for specific types.

Definition at line 16 of file strtonum.hpp.

Macro Definition Documentation

◆ STN_TRAITS

#define STN_TRAITS (   T,
 
)
Value:
template <> \
struct stn_traits<T> { \
static T stot(std::string const& s, std::size_t& end) { \
return (F)(s, &end); \
} \
}

Definition at line 18 of file strtonum.hpp.