mercredi 28 décembre 2016

rvalue reference binding to an lvalue for std::function types

Why there is no compilation error at (@) in below code? I thought lamb is an lvalue so it will not get bound to an rvalue reference.

using FunctionType = std::function<void()>;
using IntType = int;
struct Foo {
    void bar(FunctionType&&) {}
    void baz(IntType&&) {}
};

Foo foo;
foo.bar([]() {}); //OK
auto lamb = []() {};
foo.bar(lamb); //(@) No compilation error?!
foo.baz(5); //OK
int i = 5;
foo.baz(i); //Error

Aucun commentaire:

Enregistrer un commentaire