diff --git a/include/aka_static_if.hh b/include/aka_static_if.hh index 369f653dc..d148527a5 100644 --- a/include/aka_static_if.hh +++ b/include/aka_static_if.hh @@ -1,108 +1,106 @@ // Copyright (c) 2016 Vittorio Romeo // License: AFL 3.0 | https://opensource.org/licenses/AFL-3.0 // http://vittorioromeo.info | vittorio.romeo@outlook.com #ifndef AKANTU_AKA_STATIC_IF_HH #define AKANTU_AKA_STATIC_IF_HH #ifndef AKANTU_ITERATORS_NAMESPACE #define AKANTU_ITERATORS_NAMESPACE akantu #endif #include #define FWD(...) ::std::forward(__VA_ARGS__) namespace AKANTU_ITERATORS_NAMESPACE { template auto static_if(TPredicate /*unused*/) noexcept; namespace impl { template struct static_if_impl; template struct static_if_result; template auto make_static_if_result(TF && f) noexcept; template <> struct static_if_impl { template auto & else_(TF && /*unused*/) noexcept { // Ignore `else_`, as the predicate is true. return *this; } template auto & else_if(TPredicate /*unused*/) noexcept { // Ignore `else_if`, as the predicate is true. return *this; } template auto then(TF && f) noexcept { // We found a matching branch, just make a result and // ignore everything else. return make_static_if_result(FWD(f)); } }; template <> struct static_if_impl { template auto & then(TF && /*unused*/) noexcept { // Ignore `then`, as the predicate is false. return *this; } template auto else_(TF && f) noexcept { // (Assuming that `else_` is after all `else_if` calls.) // We found a matching branch, just make a result and // ignore everything else. return make_static_if_result(FWD(f)); } template auto else_if(TPredicate /*unused*/) noexcept { return static_if(TPredicate{}); } template auto operator()(Ts &&... /*unused*/) noexcept { // If there are no `else` branches, we must ignore calls // to a failed `static_if` matching. } }; template struct static_if_result : TFunctionToCall { // Perfect-forward the function in the result instance. template - explicit static_if_result(TFFwd && f) noexcept : TFunctionToCall(FWD(f)) {} - - static_if_result(const static_if_result & /* unused */) = delete; - static_if_result(static_if_result && /* unused */) = delete; + explicit static_if_result(TFFwd && f) noexcept // NOLINT + : TFunctionToCall(FWD(f)) {} // Ignore everything, we found a result. template auto & then(TF && /*unused*/) noexcept { return *this; } template auto & else_if(TPredicate /*unused*/) noexcept { return *this; } template auto & else_(TF && /*unused*/) noexcept { return *this; } }; template auto make_static_if_result(TF && f) noexcept { return static_if_result{FWD(f)}; } } // namespace impl template auto static_if(TPredicate /*unused*/) noexcept { return impl::static_if_impl{}; } #undef FWD } // namespace AKANTU_ITERATORS_NAMESPACE #endif /* AKANTU_AKA_STATIC_IF_HH */