所以说,我想做一些constexpr
函数,我虽然可以使用bind
做到这一点。有什么我失踪? bind
为什么不能返回constexpr
?为什么我无法获得绑定?
考虑:
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;
};
我想:
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));
有什么我可以做,以使这项工作?
的问题可能是现在“为什么不能”,而是“为什么没有按“T”。它可能会,但事实并非如此。 –
@NathanOliver我认为这将是一个很好的答案。你介意张贴吗? –