Re: Returning more than one value from a function
On Jul 3, 7:41 am, Mohitz <coolmoh...@gmail.com> wrote:
I can't really think of a single case where using std::pair
would be appropriate, except for emulating certain design errors
in the standard library. (If you're writing a container class,
it's best that it look as much as possible like a standard
container. Ditto for basic algorithms. So I use std::pair in
those.)
What is the harm in using pair<> to return two values from a function?
Readability. Unless the semantic of the values really is
"first" and "second", of course---pair<int,int> might be
appropriate for a function "throwTwoDice()". If you consider
something like std::map<>::value_type, however, the semantic
isn't first and second, but key and value, and using std::pair
for this is extremely bad design.
Saves the effort of defining a new struct.
Boy are you lazy:-). Seriously, what's the big deal about a new
struct, if it makes the code clearer?
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34