
On 9/4/07, Graham Reitz <graham.cpp@gmail.com> wrote:
One of my colleagues has asked me, "why not use a simple struct over a tuple?"
Unfortunately, I couldn't give a convincing answer, which means I probably don't understand tuple well enough.
What is a good way to respond to this? Then we can identify when it makes better sense to use a struct versus a tuple.
It probably depends on the application, but tuples are nice for returning multiple values from a function. For example boost::tuple<float,float,float> min_mode_max(const std::vector<float>& v) { float min,mode,max; ... return boost::make_tuple(min,mode,max); } std::vector<float> data = read_data('file.txt'); float min,mode,max; boost::tie(min,mode,max) = min_mode_max(data); std::cout << min << " " << mode << " " << max << std::endl; There are many other ways you could do this, but I like the tuple version. Chris