c++ - How can I use templates to determine the appropriate argument passing method? -
As I understand it, when someone sends an object to a function that is larger than a register, then it It is better to pass (context) context, eg: void foo (const std :: string and bar) {...} It avoids potentially demonic rationality. However, when passing in a way that fits in a register, passing it as a const (context) is the most redundant, and at the slowest speed: void foo (const int & bar) {...} My problem is, I want to know when I am using the best of both worlds Get a template class that needs to be passed around any type: template & lt; Typename T & gt; Square Fu {Public: // Good for a complex type, bad for small types of zero times (CONST T & BAD); // Good for small types, but the complex type of waste will copy void bar2 (T-Baaz); }; Is there a template decision method that allows me to choose the right type? Something like that will let me, zero times (const_nocopy :: type baz); Will choose a better method on that type of basis...