|
|
|
@ -10,13 +10,13 @@ constexpr auto all = std::numeric_limits<std::streamsize>::max();
|
|
|
|
|
|
|
|
|
|
namespace math
|
|
|
|
|
{
|
|
|
|
|
template<auto lb, typeof(lb) ub, std::enable_if_t<std::is_integral<typeof(lb)>::value, bool> = true>
|
|
|
|
|
template<auto lb, typeof(lb) ub> [[maybe_unused]]
|
|
|
|
|
constexpr auto is_between(typeof(lb) x) -> bool { return (ub > x) && (x > lb); }
|
|
|
|
|
template<auto lb, std::enable_if_t<std::is_integral<typeof(lb)>::value, bool> = true>
|
|
|
|
|
template<auto lb> [[maybe_unused]]
|
|
|
|
|
constexpr auto is_larger(typeof(lb) x) -> bool { return (x > lb); }
|
|
|
|
|
template<auto ub, std::enable_if_t<std::is_integral<typeof(ub)>::value, bool> = true>
|
|
|
|
|
template<auto ub> [[maybe_unused]]
|
|
|
|
|
constexpr auto is_smaller(typeof(ub) x) -> bool { return (ub > x); }
|
|
|
|
|
template<typename T, std::enable_if_t<std::is_integral<typeof(T)>::value, bool> = true>
|
|
|
|
|
template<typename T> [[maybe_unused]]
|
|
|
|
|
auto numerical_suffix(T value) -> std::string
|
|
|
|
|
{
|
|
|
|
|
std::string suffixes[4] = {"th", "st", "nd", "rd"};
|
|
|
|
@ -30,7 +30,7 @@ namespace math
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
|
template<typename T> [[maybe_unused]]
|
|
|
|
|
T get_input(const std::string& prompt, const std::string& on_error, std::function<bool(T)> validator) noexcept
|
|
|
|
|
{
|
|
|
|
|
T user_input{};
|
|
|
|
@ -54,5 +54,5 @@ T get_input(const std::string& prompt, const std::string& on_error, std::functio
|
|
|
|
|
catch (std::exception&) { return user_input; } /* This should not happen ..... cin/cout are not configured to throw...*/
|
|
|
|
|
}
|
|
|
|
|
struct always_true_validator { template<typename T> bool operator()(T) const { return true; }};
|
|
|
|
|
template<typename T>
|
|
|
|
|
template<typename T> [[maybe_unused]]
|
|
|
|
|
T get_input(const std::string& prompt) { return get_input<T>(prompt, "", always_true_validator()); }
|