replace None with none

This commit is contained in:
ado 2020-12-26 00:56:39 +01:00
parent e406253694
commit bb6296ef6e

View File

@ -11,7 +11,7 @@
namespace ss { namespace ss {
struct None {}; struct none {};
template <typename...> template <typename...>
class composite; class composite;
@ -95,9 +95,9 @@ public:
// as optional, additionally, if a parameter is passed, and // as optional, additionally, if a parameter is passed, and
// that parameter can be invoked using the converted value, // that parameter can be invoked using the converted value,
// than it will be invoked in the case of a valid conversion // than it will be invoked in the case of a valid conversion
template <typename... Us, typename Fun = None> template <typename... Us, typename Fun = none>
composite<Ts..., std::optional<no_void_validator_tup_t<Us...>>> or_else( composite<Ts..., std::optional<no_void_validator_tup_t<Us...>>> or_else(
Fun&& fun = None{}) { Fun&& fun = none{}) {
using Value = no_void_validator_tup_t<Us...>; using Value = no_void_validator_tup_t<Us...>;
std::optional<Value> value; std::optional<Value> value;
try_convert_and_invoke<Value, Us...>(value, fun); try_convert_and_invoke<Value, Us...>(value, fun);
@ -106,8 +106,8 @@ public:
// same as or_else, but saves the result into a 'U' object // same as or_else, but saves the result into a 'U' object
// instead of a tuple // instead of a tuple
template <typename U, typename... Us, typename Fun = None> template <typename U, typename... Us, typename Fun = none>
composite<Ts..., std::optional<U>> or_else_object(Fun&& fun = None{}) { composite<Ts..., std::optional<U>> or_else_object(Fun&& fun = none{}) {
std::optional<U> value; std::optional<U> value;
try_convert_and_invoke<U, Us...>(value, fun); try_convert_and_invoke<U, Us...>(value, fun);
return composite_with(std::move(value)); return composite_with(std::move(value));
@ -138,7 +138,7 @@ public:
return {std::move(merged_values), parser_}; return {std::move(merged_values), parser_};
} }
template <typename U, typename... Us, typename Fun = None> template <typename U, typename... Us, typename Fun = none>
void try_convert_and_invoke(std::optional<U>& value, Fun&& fun) { void try_convert_and_invoke(std::optional<U>& value, Fun&& fun) {
if (!parser_.valid()) { if (!parser_.valid()) {
std::optional<U> new_value; std::optional<U> new_value;
@ -172,9 +172,9 @@ public:
// tries to convert a line and returns a composite which is // tries to convert a line and returns a composite which is
// able to try additional conversions in case of failure // able to try additional conversions in case of failure
template <typename... Ts, typename Fun = None> template <typename... Ts, typename Fun = none>
composite<std::optional<no_void_validator_tup_t<Ts...>>> try_next( composite<std::optional<no_void_validator_tup_t<Ts...>>> try_next(
Fun&& fun = None{}) { Fun&& fun = none{}) {
std::optional<no_void_validator_tup_t<Ts...>> value; std::optional<no_void_validator_tup_t<Ts...>> value;
auto new_value = get_next<Ts...>(); auto new_value = get_next<Ts...>();
if (valid()) { if (valid()) {
@ -193,9 +193,9 @@ private:
// false, the function sets an error, and allows the invoke of the // false, the function sets an error, and allows the invoke of the
// next possible conversion as if the validation of the current one // next possible conversion as if the validation of the current one
// failed // failed
template <typename Arg, typename Fun = None> template <typename Arg, typename Fun = none>
void try_invoke(Arg&& arg, Fun&& fun) { void try_invoke(Arg&& arg, Fun&& fun) {
constexpr bool is_none = std::is_same_v<std::decay_t<Fun>, None>; constexpr bool is_none = std::is_same_v<std::decay_t<Fun>, none>;
if constexpr (!is_none) { if constexpr (!is_none) {
using Ret = decltype(try_invoke_impl(arg, std::forward<Fun>(fun))); using Ret = decltype(try_invoke_impl(arg, std::forward<Fun>(fun)));
constexpr bool returns_void = std::is_same_v<Ret, void>; constexpr bool returns_void = std::is_same_v<Ret, void>;
@ -209,14 +209,14 @@ private:
} }
} }
// tries to invoke the function if not None // tries to invoke the function if not none
// it first tries to invoke the function without arguments, // it first tries to invoke the function without arguments,
// than with one argument if the function accepts the whole tuple // than with one argument if the function accepts the whole tuple
// as an argument, and finally tries to invoke it with the tuple // as an argument, and finally tries to invoke it with the tuple
// laid out as a parameter pack // laid out as a parameter pack
template <typename Arg, typename Fun = None> template <typename Arg, typename Fun = none>
auto try_invoke_impl(Arg&& arg, Fun&& fun) { auto try_invoke_impl(Arg&& arg, Fun&& fun) {
constexpr bool is_none = std::is_same_v<std::decay_t<Fun>, None>; constexpr bool is_none = std::is_same_v<std::decay_t<Fun>, none>;
if constexpr (!is_none) { if constexpr (!is_none) {
if constexpr (std::is_invocable_v<Fun>) { if constexpr (std::is_invocable_v<Fun>) {
return fun(); return fun();