rangeless::fn
rangeless::tsv::to_num Class Reference

Utility to parse numbers. More...

#include <fn.hpp>

Public Member Functions

 to_num (const to_num &)=delete
 
to_numoperator= (const to_num &)=delete
 
 to_num (const char *str)
 
template<typename Str >
 to_num (const Str &str)
 
template<typename Enum , typename std::enable_if< std::is_enum< Enum >::value >::type * = nullptr>
 operator Enum () const &&
 Conversion to an enum or enum-class. More...
 
template<typename Number , typename std::enable_if< std::is_arithmetic< Number >::value >::type * = nullptr>
 operator Number () const &&
 Conversion to an arithmetic type. More...
 
 operator bool () const &&
 Convert to uint8_t first; throw unless 0 or 1; return as bool. More...
 

Detailed Description

Utility to parse numbers.

This is a dispatcher for std::strto* functions with additional functionality: throws std::domain_error if can't parse, or out of bounds, or input has trailing non-whitespaces, or the destination type is unsigned and the input is a negative number.

bouble a = tsv::to_num(""); // throws - expected a number
double b = tsv::to_num(" 123xyz"); // throws - trailing garbage not allowed
int8_t c = tsv::to_num(" 12345 "); // throws - out of range
float d = tsv::to_num("12e-456"); // throws - underflow
uint16_t e = tsv::to_num("-1"); // throws - negative number while destination is unsigned

Definition at line 4851 of file fn.hpp.

Constructor & Destructor Documentation

◆ to_num() [1/3]

rangeless::tsv::to_num::to_num ( const to_num )
delete

◆ to_num() [2/3]

rangeless::tsv::to_num::to_num ( const char *  str)
inlineexplicit

Definition at line 4857 of file fn.hpp.

◆ to_num() [3/3]

template<typename Str >
rangeless::tsv::to_num::to_num ( const Str &  str)
inlineexplicit

Definition at line 4863 of file fn.hpp.

Member Function Documentation

◆ operator bool()

rangeless::tsv::to_num::operator bool ( ) const &&
inline

Convert to uint8_t first; throw unless 0 or 1; return as bool.

Definition at line 4898 of file fn.hpp.

◆ operator Enum()

template<typename Enum , typename std::enable_if< std::is_enum< Enum >::value >::type * = nullptr>
rangeless::tsv::to_num::operator Enum ( ) const &&
inline

Conversion to an enum or enum-class.

Definition at line 4870 of file fn.hpp.

◆ operator Number()

template<typename Number , typename std::enable_if< std::is_arithmetic< Number >::value >::type * = nullptr>
rangeless::tsv::to_num::operator Number ( ) const &&
inline

Conversion to an arithmetic type.

Definition at line 4879 of file fn.hpp.

◆ operator=()

to_num& rangeless::tsv::to_num::operator= ( const to_num )
delete

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