mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-17 02:45:33 +08:00
Use std::invoke instead of pointer-to-member syntax
This will allow transparent use of the same API with both pointers to member functions and pointers to member data.
This commit is contained in:
@@ -32,7 +32,7 @@ namespace BlackMisc
|
|||||||
return [vs...](const auto &object)
|
return [vs...](const auto &object)
|
||||||
{
|
{
|
||||||
bool equal = true;
|
bool equal = true;
|
||||||
tupleForEachPair(std::make_tuple(vs...), [ & ](auto member, const auto &value) { equal = equal && (object.*member)() == value; });
|
tupleForEachPair(std::make_tuple(vs...), [ & ](auto member, const auto &value) { equal = equal && std::invoke(member, object) == value; });
|
||||||
return equal;
|
return equal;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -47,36 +47,36 @@ 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 std::forward_as_tuple(std::invoke(vs, a)...) < std::forward_as_tuple(std::invoke(vs, b)...);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Returns a function object that returns the value returned by one of it's argument member functions.
|
* Returns a function object that returns the value returned by one of it's argument member functions.
|
||||||
*/
|
*/
|
||||||
template <class T, class R>
|
template <class T>
|
||||||
auto MemberTransform(R(T::*memberFunc)() const)
|
auto MemberTransform(T memberFunc)
|
||||||
{
|
{
|
||||||
return [memberFunc](const T &object) { return (object.*memberFunc)(); };
|
return [memberFunc](const auto &object) { return std::invoke(memberFunc, object); };
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Returns a predicate that returns true if the isValid() method of the value returned from one of its member functions returns true.
|
* Returns a predicate that returns true if the isValid() method of the value returned from one of its member functions returns true.
|
||||||
*/
|
*/
|
||||||
template <class T, class R>
|
template <class T>
|
||||||
auto MemberValid(R(T::*memberFunc)() const)
|
auto MemberValid(T memberFunc)
|
||||||
{
|
{
|
||||||
return [memberFunc](const T &object) { return (object.*memberFunc)().isValid(); };
|
return [memberFunc](const auto &object) { return std::invoke(memberFunc, object).isValid(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* Returns a predicate that returns true if the value returned by its argument's member function can be found in a captured container.
|
* Returns a predicate that returns true if the value returned by its argument's member function can be found in a captured container.
|
||||||
* \warning The container is captured by reference, so be careful that it remains valid for the lifetime of the predicate.
|
* \warning The container is captured by reference, so be careful that it remains valid for the lifetime of the predicate.
|
||||||
*/
|
*/
|
||||||
template <class T, class R, class C>
|
template <class T, class C>
|
||||||
auto MemberIsAnyOf(R(T::*memberFunc)() const, const C &container)
|
auto MemberIsAnyOf(T memberFunc, const C &container)
|
||||||
{
|
{
|
||||||
return [memberFunc, &container](const T &object) { return container.contains((object.*memberFunc)()); };
|
return [memberFunc, &container](const auto &object) { return container.contains(std::invoke(memberFunc, object)); };
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -96,7 +96,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
return [vs...](const auto &a, const auto &b)
|
return [vs...](const auto &a, const auto &b)
|
||||||
{
|
{
|
||||||
return (((a.*vs)() == (b.*vs)()) && ...);
|
return ((std::invoke(vs, a) == std::invoke(vs, b)) && ...);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -515,9 +515,9 @@ namespace BlackMisc
|
|||||||
|
|
||||||
//! Split up the sequence into subsequences of elements having the same value for the given key.
|
//! Split up the sequence into subsequences of elements having the same value for the given key.
|
||||||
template <class Key>
|
template <class Key>
|
||||||
auto separateBy(Key k) const -> QMap<decltype(std::declval<T>().*k), CSequence>
|
auto separateBy(Key k) const -> QMap<decltype(std::invoke(k, std::declval<T>())), CSequence>
|
||||||
{
|
{
|
||||||
return separateBy([k](const T &v) { return v.*k; });
|
return separateBy([k](const T &v) { return std::invoke(k, v); });
|
||||||
}
|
}
|
||||||
|
|
||||||
//! \private Calls detach on the internal QVector.
|
//! \private Calls detach on the internal QVector.
|
||||||
|
|||||||
Reference in New Issue
Block a user