#pragma once #include #include "types.h" namespace convert { template struct to_impl_t; template struct to_impl_t { static Type func(const Type& value) { return value; } }; template<> struct to_impl_t { static std::string func(bool value) { return value ? "true" : "false"; } }; template<> struct to_impl_t { static bool func(const std::string& value) { return value == "true" ? true : value == "false" ? false : throw std::invalid_argument(__FUNCTION__); } }; template<> struct to_impl_t { static std::string func(signed char value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(unsigned char value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(short value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(unsigned short value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(int value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(unsigned int value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(long value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(unsigned long value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(long long value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(unsigned long long value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(float value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(double value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(long double value) { return std::to_string(value); } }; template<> struct to_impl_t { static std::string func(size2i value) { return std::to_string(value.width) + "x" + std::to_string(value.height); } }; template<> struct to_impl_t { static std::string func(position2i value) { return std::to_string(value.x) + ":" + std::to_string(value.y); } }; template<> struct to_impl_t { static int func(const std::string& value) { return std::stoi(value); } }; template<> struct to_impl_t { static unsigned int func(const std::string& value) { return (unsigned long)std::stoul(value); } }; template<> struct to_impl_t { static long func(const std::string& value) { return std::stol(value); } }; template<> struct to_impl_t { static unsigned long func(const std::string& value) { return std::stoul(value); } }; template<> struct to_impl_t { static long long func(const std::string& value) { return std::stoll(value); } }; template<> struct to_impl_t { static unsigned long long func(const std::string& value) { return std::stoull(value); } }; template<> struct to_impl_t { static float func(const std::string& value) { return std::stof(value); } }; template<> struct to_impl_t { static double func(const std::string& value) { return std::stod(value); } }; template<> struct to_impl_t { static long double func(const std::string& value) { return std::stold(value); } }; template<> struct to_impl_t { static size2i func(const std::string& value) { const auto& data = fmt::split(value, { "x" }); return { std::stoi(data[0]), std::stoi(data[1]) }; } }; template<> struct to_impl_t { static position2i func(const std::string& value) { const auto& data = fmt::split(value, { ":" }); return { std::stoi(data[0]), std::stoi(data[1]) }; } }; template ReturnType to(FromType value) { return to_impl_t, std::remove_all_extents_t>::func(value); } }