vendredi 28 juillet 2017

Why Can't I constexpr a bind?

So say that I want to make some constexpr functors, I though I could do this using bind. Is there something I'm missing? Why can't bind return a 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 something I could do to make this work?

Aucun commentaire:

Enregistrer un commentaire