How do I use BOOST_HOF_LIFT and BOOST_HOF_LIFT_CLASS with MSVC?

145 views Asked by At

(This is in part a follow up to this question of mine.)

As I've written in this self-answer, I've discovered that Boost offers a macro to wrap a template function in a function object so it can be passed to higher-order functions:

#include <boost/hof.hpp>
#include <cassert>
#include <algorithm>

// Declare the class `max_f`
BOOST_HOF_LIFT_CLASS(max_f, std::max);

int main() {
    auto my_max = BOOST_HOF_LIFT(std::max);
    assert(my_max(3, 4) == std::max(3, 4));
    assert(max_f()(3, 4) == std::max(3, 4));
}

The point is that things don't quite work well with MSVC, and the problem hits me especially when some of the template parameters cannot be deduced and corresponding arguments must be provided explicitly, as is the case for std::get, just to make an example.

The following works with GCC, but errors with MSVC

template<int N>
auto constexpr getNth_a = BOOST_HOF_LIFT(std::get<N>);
// usage
std::tuple<int,int> t{1,2};
getNth_a<0>(t); // errors with MSVC

So I tried BOOST_HOF_LIFT_CLASS instead, but I can't get it working when templated, not even in GCC:

template<int N>
BOOST_HOF_LIFT_CLASS(getNth_b, std::get<N>);
// attempted usage
std::tuple<int,int> t{1,2};
getNth_b<0>(t); // doens't even work with GCC

Here's a demo.

0

There are 0 answers