[ create a new paste ] login | about

Link: http://codepad.org/VOokOm6i    [ raw code | output | fork ]

C++, pasted on May 22:
#include <iostream>
#include <vector>
#include <boost/ref.hpp>

struct Foo
{
    int i;
};

std::vector<boost::reference_wrapper<const Foo> > foos;

void store(const Foo& container)
{
    foos.push_back(boost::cref(container));
}

int main()
{
    Foo f = {5};

    const Foo f1(f);

    store(f);
    store(f);
    store(f);
    store(f1);

    std::cout << foos[0].get().i << "\n";
    std::cout << foos[1].get().i << "\n";
    std::cout << foos[2].get().i << "\n";
    std::cout << foos[3].get().i << "\n";
}


Output:
1
2
3
4
5
5
5
5


Create a new paste based on this one


Comments: