#include #include std::vector foo(); template< class V > long print( const V& v ) { long l = 0; if (!v.empty()) l += v[v.size() / 2]; return l; } template< class V > struct Foo { V v; }; #include int main() { const int sz = 100000; { std::cout << "priming the I/O channel" << std::endl; long l = 0; std::cout << "pass rvalue by reference: "; { boost::progress_timer t; for( int i = 0; i != sz; ++i ) l += print( foo() ); } std::cout << "total, in case you care: " << l << std::endl; std::cout << "--------------------------------" << std::endl; } { std::cout << "store rvalue, then pass by reference: "; long l = 0; { boost::progress_timer t; for( int i = 0; i != sz; ++i ) { Foo< std::vector > f; f.v = foo(); l += print( f.v ); } } std::cout << "total, in case you care: " << l << std::endl; } return 0; } std::vector foo_impl() { const int sz = 3000; std::vector v; for( int i = 0; i != sz; ++i ) v.push_back( i ); return v; } std::vector foo() { static std::vector v( foo_impl() ); return v; }