lundi 26 novembre 2018

rvalue qualified method and const expression

Let's say I have one object with ref qualified methods :

struct A {
  void f() &{}                  // 1
  void f() &&{}                 // 2
  constexpr void f() const &{}  // 3
  constexpr void f() const &&{} // 4 really usefull?
};

now I want to perform something like :

static_assert(A{}.f();); // call 2 instead of 4, so does not work
constexpr A a;
static_assert(a.f();); // call 3, so works

What am I missing here?

Aucun commentaire:

Enregistrer un commentaire