c++ - Accept lvalue ref or rvalue ref -
I want to write some functions that take a object
as one of its arguments It does not matter whether it is by Lavalue or Rivalue referee - but definitely not by value and of course only one object
seems like I have two options for it:
void foo (object & amp; o) {// stuff} void foo (object & amp; o) {foo (o); } // It's okay for my use-case
or using universal contexts:
template & lt; Typename t, typename u & gt; Decays_to = typename std :: is_same & lt; Using std :: decay_t & lt; T & gt;, U & gt; :: type; Template & lt; Typename T & gt; Std :: enable_if_t & lt; Decays_to & lt; T, Object & gt; :: value & gt;
But the more options I need in the first option, and the second option involves writing a group template stuff that I think is much more (I read something Also for o
- oh, just joking, in fact only one object
)
Is there a better way to resolve it or am I troubled by any of these? Do I feel less about this?
The usual way of accepting both lewd and queue is to create a function, which is a conference reference Takes. This means that you can not call non-contact functions on the object, but if you want to temporarily pass the queues, then calling non-contact functions will not make any sense in any way.
Comments
Post a Comment