diff --git a/include/boolinq/boolinq.h b/include/boolinq/boolinq.h index 542c5d2..aece8de 100644 --- a/include/boolinq/boolinq.h +++ b/include/boolinq/boolinq.h @@ -14,26 +14,22 @@ #include #include -// - -// The result_of was deprecated since C++20, so redefine it using invoke_result -#if (defined(_MSC_VER) && _MSVC_LANG >= 202002L) || __cplusplus >= 202002L -namespace std -{ - template - struct result_of; - - template - struct result_of<_Callable(_Args...)> - { - using type = std::invoke_result<_Callable, _Args...>::type; - }; -} -#endif +namespace boolinq { -// + namespace priv { + // The result_of was removed since C++20 by not all but some compilers. + // For the sake of compatibility, use own define but in private subspace + // to avoid collisions with std in case of using both std and boolinq. + template + struct result_of; + + template + struct result_of<_Callable(_Args...)> { + typedef decltype(std::declval<_Callable>()(std::declval<_Args>()...)) type; + }; + } -namespace boolinq { + // struct LinqEndException {}; @@ -211,7 +207,7 @@ namespace boolinq { ); } - template::type> + template::type> Linq, int>, _TRet> select_i(F apply) const { return Linq, int>, _TRet>( @@ -225,7 +221,7 @@ namespace boolinq { ); } - template::type> + template::type> Linq, int>, _TRet> select(F apply) const { return select_i([apply](T value, int /*index*/) { return apply(value); }); @@ -260,7 +256,7 @@ namespace boolinq { template< typename F, - typename _TRet = typename std::result_of::type, + typename _TRet = typename priv::result_of::type, typename _TRetVal = typename _TRet::value_type > Linq, _TRet, int, bool>, _TRetVal> selectMany_i(F apply) const @@ -291,7 +287,7 @@ namespace boolinq { template< typename F, - typename _TRet = typename std::result_of::type, + typename _TRet = typename priv::result_of::type, typename _TRetVal = typename _TRet::value_type > Linq, _TRet, int, bool>, _TRetVal> selectMany(F apply) const @@ -301,7 +297,7 @@ namespace boolinq { template< typename F, - typename _TKey = typename std::result_of::type, + typename _TKey = typename priv::result_of::type, typename _TValue = Linq, int>, T> // where(predicate) > Linq, Linq, std::unordered_set<_TKey> >, std::pair<_TKey, _TValue> > groupBy(F apply) const @@ -325,7 +321,7 @@ namespace boolinq { ); } - template::type> + template::type> Linq, std::unordered_set<_TRet> >, T> distinct(F transform) const { return Linq, std::unordered_set<_TRet> >, T>( @@ -418,7 +414,7 @@ namespace boolinq { return start; } - template::type> + template::type> _TRet sum(F transform) const { return aggregate<_TRet>(_TRet(), [transform](_TRet accumulator, T value) { @@ -432,7 +428,7 @@ namespace boolinq { return sum([](T value) { return TRet(value); }); } - template::type> + template::type> _TRet avg(F transform) const { int count = 0;