Converters

template<typename T>
inline T convert(std::string_view sv)

Converts input strings into values of different types.

Provides a larger wrapper for the std::from_chars, and extends the functionality to more data types

Parameters:

sv – A string_view (implicitly converted from std::strings) representing a value to be converted

Returns:

A value of type T corresponding to the input string

Accepted Conversion Types

The following types are accepted template parameters:

  • Any integral type (int, short, size_t, long, etc)

  • Booleans

  • Double and float

  • std::string

  • char

  • std:::vector of any accepted type

Details

Basic Usage

int a = convert<int>("2"); //a = 2
double b = convert<double>("-2"); //b=-2.0
auto c = convert<std::vector<int>>("[5 8 7 87]"," "); // c = {5,8,7,87};
std::string d = convert<std::string>("hi"); // d = "hi";