diff --git a/src/blackmisc/memotable.h b/src/blackmisc/memotable.h index a239840c30..497f195f0c 100644 --- a/src/blackmisc/memotable.h +++ b/src/blackmisc/memotable.h @@ -56,13 +56,13 @@ namespace BlackMisc class CMemoizer : private CMemoTable... { public: - //! If T is in Ts, return the index of member in the memo table. - template ::value, int> = 0> - int maybeMemoize(const T &member) { return this->CMemoTable::getIndex(member); } - - //! If T is not in Ts, return member. - template ::value, int> = 0> - const T &maybeMemoize(const T &member) { return member; } + //! If T is in Ts, return the index of member in the memo table. Otherwise, return member. + template + decltype(auto) maybeMemoize(const T &member) + { + if constexpr ((std::is_same_v || ...)) { return this->CMemoTable::getIndex(member); } + else { return std::as_const(member); } + } //! Return the values in the T table as a flat list. template @@ -78,23 +78,24 @@ namespace BlackMisc CSequence &getTable() { return *this; } //! If T is in Ts, return proxy that will assign to member through the value at the given index in the flat list. - template ::value, int> = 0> + //! Otherwise, return member as std::reference_wrapper. + template auto maybeUnmemoize(T &member) const { - struct Memo // clazy:exclude=rule-of-three + if constexpr ((std::is_same_v || ...)) { - int index; - T &member; - const CSequence &list; - int &get() { return index; } - ~Memo() { if (index >= 0) { member = list[index]; } } - }; - return Memo { -1, member, static_cast &>(*this) }; + struct Memo // clazy:exclude=rule-of-three + { + int index; + T &member; + const CSequence &list; + int &get() { return index; } + ~Memo() { if (index >= 0) { member = list[index]; } } + }; + return Memo { -1, member, static_cast &>(*this) }; + } + else { return std::ref(member); } } - - //! If T is not in Ts, return member as std::reference_wrapper. - template ::value, int> = 0> - auto maybeUnmemoize(T &member) const { return std::ref(member); } }; }; } diff --git a/src/blackmisc/typetraits.h b/src/blackmisc/typetraits.h index d78252c928..c5f21a5e66 100644 --- a/src/blackmisc/typetraits.h +++ b/src/blackmisc/typetraits.h @@ -154,12 +154,6 @@ namespace BlackMisc std::declval().unmarshallFromDbus(std::declval()))>> : public std::true_type {}; //! \endcond - /*! - * Trait that detects if a type is a member of a parameter pack. - */ - template - struct TIsOneOf : public std::disjunction...> {}; - /*! * Trait that detects if a type is QPrivateSignal. */