Home » Community » Newbie corner » Issues using 2015.2 version
Re: Issues using 2015.2 version [message #45929 is a reply to message #45891] |
Wed, 27 January 2016 22:42   |
mr_ped
Messages: 826 Registered: November 2005 Location: Czech Republic - Praha
|
Experienced Contributor |
|
|
Do you really want to pass full copy?
I think for example for "Save" a const reference is much better, i.e.:
int SaveMasterRecord(const Vector<String> & t);
About the sort... you probably want to keep "pairs" intact?
Then you can again use const reference as input for the function.
But maybe you should check for the built-in Sort, like this:
Vector<int> pairs{1, 4, 2, 3};
Vector<int> sortedPairs = clone(pairs);
Sort(sortedPairs, [](const int & a, const int & b){return a < b;} );
// lambda expression used for simple "a is less than b" predicate here
// to give you idea, how you can code your own comparator for "Pair" type
//(the "less than" is default predicate of Upp::Sort(T & container); )
So if you would define operator < in Pair class, you would be able to write:
Vector<Pair> sortedPairs = clone(pairs);
Sort(sortedPairs);
Anyway, passing full copy of Vector to function does make little sense to me, only when you actually store the parameter somewhere... but in most cases you want either just to read the data (const Vector & v), or you want to
manipulate them, but the owner of the Vector is still the caller, so you want to operate on his instance: (Vector & v);
|
|
|
 |
|
Issues using 2015.2 version
By: Giorgio on Thu, 21 January 2016 11:31
|
 |
|
Re: Issues using 2015.2 version
|
 |
|
Re: Issues using 2015.2 version
By: Giorgio on Thu, 21 January 2016 13:48
|
 |
|
Re: Issues using 2015.2 version
By: Lance on Thu, 21 January 2016 18:34
|
 |
|
Re: Issues using 2015.2 version
|
 |
|
Re: Issues using 2015.2 version
By: forlano on Tue, 26 January 2016 23:32
|
 |
|
Re: Issues using 2015.2 version
By: mirek on Wed, 27 January 2016 07:27
|
 |
|
Re: Issues using 2015.2 version
By: forlano on Wed, 27 January 2016 21:10
|
 |
|
Re: Issues using 2015.2 version
By: Giorgio on Fri, 22 January 2016 15:08
|
 |
|
Re: Issues using 2015.2 version
By: mr_ped on Sat, 23 January 2016 12:08
|
 |
|
Re: Issues using 2015.2 version
By: Oblivion on Sat, 23 January 2016 22:59
|
 |
|
Re: Issues using 2015.2 version
By: Giorgio on Mon, 25 January 2016 09:48
|
 |
|
Re: Issues using 2015.2 version
By: mr_ped on Wed, 27 January 2016 22:42
|
 |
|
Re: Issues using 2015.2 version
By: forlano on Thu, 28 January 2016 15:42
|
 |
|
Re: Issues using 2015.2 version
By: forlano on Sat, 30 January 2016 14:03
|
Goto Forum:
Current Time: Mon May 05 01:34:03 CEST 2025
Total time taken to generate the page: 0.00817 seconds
|