Will a good C++ compiler optimize a reference away?
问题 I want to write a template function that does something with a std::stack<T> and an instance of T , e.g.: template<class StackType> inline bool some_func( StackType const &s, typename StackType::value_type const &v ) { // ... } The reason I pass v by reference is of course to optimize for the case where StackType::value_type is a struct or class and not copy an entire object by value. However, if StackType::value_type is a "simple" type like int , then it's of course better simply to pass it