#pragma once #include #include #include #include #include constexpr auto all = std::numeric_limits::max(); namespace math { template::value, bool> = true> constexpr auto is_between(typeof(lb) x) -> bool { return (ub > x) && (x > lb); } } template T get_input(const std::string& prompt, const std::string& on_error, std::function validator) noexcept { T user_input{}; try { while (true) { printf("%s", prompt.c_str()); std::cin >> user_input; if (std::cin.fail() || !validator(user_input)) { std::cout << on_error << std::endl; std::cin.clear(); std::cin.ignore(all, '\n'); continue; } break; } return user_input; } catch (std::exception&) { return user_input; } /* This should not happen ..... cin/cout are not configured to throw...*/ } template T get_input(const std::string& prompt) { return get_input(prompt, "", [](auto) {return true; }); }