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 SomeRefTypeOfObjectwhich can store both lvalue, and rvalue the link to Object. baris 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 barthat can be called with any type Objector its derived classes / other objects that can be converted to Object(for example, if there barwere 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 barcreated 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. , , , , / ( , , ). , , ( , ).