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?


Edit:

The correct amount of time tested after one time, the difference between the two calling is different, but very small . The solution is probably a suspicious micro-optimization for my situation. Even then, there is an interesting mental exercise.

Use:

  # include & lt; Boost / call_traits.hpp & gt; Template & lt; Typename T & gt; Zero Most Functionality (Promotion: Call_Tytes  :: param_type t) {// Usage 'T'}  

Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -