#include <vector>
#include <iostream>


std::vector<int> 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 <boost/progress.hpp>

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<int> > f;
                f.v = foo();
                l += print( f.v );
            }
        }
        std::cout << "total, in case you care: " << l << std::endl;
    }
    return 0;
}

std::vector<int> foo_impl()
{
    const int sz = 3000;
    std::vector<int> v;
    for( int i = 0; i != sz; ++i )
        v.push_back( i );
    return v;
}

std::vector<int> foo()
{
    static std::vector<int> v( foo_impl() );
    return v;
}



