Use fold expressions (C++17 feature)

This commit is contained in:
Mat Sutcliffe
2021-04-16 21:33:27 +01:00
parent 7955d0a06e
commit b75e3859d4
3 changed files with 4 additions and 14 deletions

View File

@@ -165,13 +165,8 @@ namespace BlackMisc
template <typename T, typename F, size_t... Is> template <typename T, typename F, size_t... Is>
void tupleForEachPairImpl(T &&tuple, F &&visitor, std::index_sequence<Is...>) void tupleForEachPairImpl(T &&tuple, F &&visitor, std::index_sequence<Is...>)
{ {
// parameter pack swallow idiom // cppcheck-suppress accessForwarded
static_cast<void>(std::initializer_list<int> (static_cast<void>(std::forward<F>(visitor)(std::get<Is * 2>(std::forward<T>(tuple)), std::get<Is * 2 + 1>(std::forward<T>(tuple)))), ...);
{
//! \fixme C-style cast is needed due to a clang bug: https://bugs.llvm.org/show_bug.cgi?id=39375
// cppcheck-suppress accessForwarded
((void)(std::forward<F>(visitor)(std::get<Is * 2>(std::forward<T>(tuple)), std::get<Is * 2 + 1>(std::forward<T>(tuple)))), 0)...
});
} }
} }

View File

@@ -280,12 +280,7 @@ namespace BlackMisc
template <typename F> template <typename F>
static void forEachMember(F &&visitor) static void forEachMember(F &&visitor)
{ {
// parameter pack swallow idiom (static_cast<void>(std::forward<F>(visitor)(members().at(index<Is>()))), ...);
static_cast<void>(std::initializer_list<int>
{
//! \fixme C-style cast is needed due to a clang bug: https://bugs.llvm.org/show_bug.cgi?id=39375
((void)(std::forward<F>(visitor)(members().at(index<Is>()))), 0)...
});
} }
private: private:

View File

@@ -96,7 +96,7 @@ namespace BlackMisc
{ {
return [vs...](const auto &a, const auto &b) return [vs...](const auto &a, const auto &b)
{ {
return std::forward_as_tuple((a.*vs)()...) == std::forward_as_tuple((b.*vs)()...); return (((a.*vs)() == (b.*vs)()) && ...);
}; };
} }