c++ - Why Can't I constexpr a bind? -
so want make constexpr
functors, though using bind
. there i'm missing? why can't bind
return constexpr
?
given:
struct foo { int b() const { return _b; } int a() const { return _a; } int r() const { return _r; } const int _b; const int _a; const int _r; };
i want to:
constexpr auto sumb = bind(plus<int>(), placeholders::_1, bind(&foo::b, placeholders::_2)); constexpr auto suma = bind(plus<int>(), placeholders::_1, bind(&foo::a, placeholders::_2)); constexpr auto sumr = bind(plus<int>(), placeholders::_1, bind(&foo::r, placeholders::_2));
is there make work?
there no technical obstacle making bind
constexpr; example, sprout c++ libraries have constexpr-enabled bind.
however, implementations not permitted add constexpr function signatures not specified in standard, , there has not yet been proposal add constexpr bind
aware of (which parts of c++14 standard library , parts made constexpr?). unlikely 1 forthcoming, since bind
mostly superseded lambda expressions, of c++17 automatically constexpr:
constexpr auto sumb = [](int x, foo const& y) { return x + y.b(); };
Comments
Post a Comment