From b91367f8a3b6e712888988a15f1242b478a8fcdd Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 24 Jan 2019 21:09:07 +1100 Subject: [PATCH] Replace std::mem_fn with custom lambda in ranges --- src/ranges.hh | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/ranges.hh b/src/ranges.hh index 1089c94d9..88f6d2ef3 100644 --- a/src/ranges.hh +++ b/src/ranges.hh @@ -5,7 +5,6 @@ #include #include #include -#include #include "constexpr_utils.hh" @@ -191,10 +190,31 @@ inline auto transform(Transform t) }); } +template +struct is_pointer_like : std::false_type {}; + +template +struct is_pointer_like())>, std::decay_t>>> : std::true_type {}; + template -inline auto transform(M T::*m) +inline auto transform(M T::*member) { - return transform(std::mem_fn(std::forward(m))); + return transform([member](auto&& arg) -> decltype(auto) { + using Arg = decltype(arg); + using Member = decltype(member); + + auto get_object = [&] () mutable -> decltype(auto) { + if constexpr (is_pointer_like::value) + return *std::forward(arg); + else + return std::forward(arg); + }; + + if constexpr (std::is_member_function_pointer_v) + return (get_object().*member)(); + else + return get_object().*member; + }); } template