samedi 14 décembre 2019

How to route to different implementations according to whether an object is a rvalue reference or not? [duplicate]

This question already has an answer here:

For example, I have a class called MyClass and create an instance from it:

auto obj = MyClass()

I have two ways to call its method.

Option 1: call the method directly

obj.method()

Option 2: cast obj to rvalue reference first, then call the method

std::move(obj).method()

I was wondering whether it is possible to create different implementation of method between Option 1 and Option 2. Is there a way to route/overload the method according to whether an object is a rvalue reference or not?

Aucun commentaire:

Enregistrer un commentaire