I have two related questions, both related to how to handle lvalue and rvalue links evenly.
Virtual function case:
struct Foo {
Object m_object;
virtual void bar(SomeRefTypeOfObject object);
};
Basically, I want to receive SomeRefTypeOfObject
which can store both lvalue, and rvalue the link to Object
. bar
is a big function, and it will use one operator m_object = object;
to store the value Object
(copy or move operation depending on the type of stored link). The reason is because I want to avoid two functions bar
(for each reference type). Is there anything in the standard library that can do this conveniently and efficiently, or do I need to roll my own solution? If I need to roll my decision, what would a good implementation look like?
Template function case:
struct Foo {
Object m_object;
template <...>
void bar(... object);
};
I would like to have a template bar
that can be called with any type Object
or its derived classes / other objects that can be converted to Object
(for example, if there bar
were two overloaded functions with parameters const Object &
and Object &&
), but are created using only const Object &
and Object &&
. Thus, I do not want to be bar
created for every derived type. What is the clearest way to do this? I suppose I will need some form of SFINAE.
: m_object = object;
, bar
. , , , , / ( , , ). , , ( , ).