return a set container

Hi!
Just wanted to know if there is an easy and non memory heavy way of returning a set container that cannot alter the original container (or a reference to it or pointer, you get the idea)

1
2
3
4
5
//The elements I want to create a get function for
std::set<Order> m_SellOrders, m_BuyOrders;

// current prototype
std::set<Order> getSellOrders(){return std::set<Order> temp = m_SellOrders;};


but I'm guessing the prototype is kinda heavy on memory, any tips?
Return a const reference to it if you don't ever need to change it.
that easy huh?

I just thought that a const reference just refers to the same element.

But the element itself still could be altered or am I way off?
Something like this maybe..

struct Foo
{
const set<Order>& GetSet() { return m_SellOrders; }
set<Order> m_SellOrders;
};
1
2
3
4
5
int x;
int copy = x; //a copy of x, can be modified independently of x
const int c_int = x; //a copy of x, can't be modified, independent of x
int& ref_int = x; //alias to x, meaning this is basically a different way to refer to x
const int& cref_int = x; //alias to x, cannot be modified, but if x changes it will change 


Does this clear it up?
Yes it does, thanks a lot. Now I learnt something very useful :D

Thanks!
Topic archived. No new replies allowed.