DryChem 1.0.0
A generic, compile-time C++ toolbox with no dependencies for the modern computational chemistry project.
Loading...
Searching...
No Matches
lexicalCast.hpp File Reference
#include <sstream>
#include <string>
#include <type_traits>
#include <utility>
#include "common-utils/errors/utils/errorHandling.hpp"
#include "common-utils/errors/utils/errorTypes.hpp"

Go to the source code of this file.

Namespaces

namespace  CppUtils
 
namespace  CppUtils::Strings
 

Macros

#define DEFINE_LEXI_CAST_OVERLOAD(TYPE, ABBREVIATION)
 

Functions

template<typename T, typename CharTraits = std::char_traits<char>>
auto CppUtils::Strings::lexical_cast (const std::basic_string< char, CharTraits > &str)
 
template<typename TO, typename FROM, typename = std::enable_if_t<std::is_pointer_v<std::decay_t<FROM>>>>
auto CppUtils::Strings::lexical_cast (FROM &&str)
 

Macro Definition Documentation

◆ DEFINE_LEXI_CAST_OVERLOAD

#define DEFINE_LEXI_CAST_OVERLOAD ( TYPE,
ABBREVIATION )
Value:
template<> \
inline auto ::CppUtils::Strings::lexical_cast<TYPE, std::char_traits<char>>(const std::string& str) \
{ \
return std::sto##ABBREVIATION(str); \
}

A macro for creating specializations of the lexical_cast<> template where the standard library already has functions specificically for this purpose.

Note
A full specialization is possible here because it doesn't matter if the input string is case-sensitive or not, all we're looking for are the integers that make up the number.