Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » Newbie corner » Pass data of Vector<Vector<double>> into a function call
Re: Pass data of Vector<Vector<double>> into a function call [message #56488 is a reply to message #56482] Wed, 17 March 2021 23:57 Go to previous messageGo to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello,

if you want to clone your vector, you can simply use clone :

This exemple show a function taking a vector<vector<double>> in entry cloning it, add 1 to all of double, then return it by moving the clone.
#include <Core/Core.h>

using namespace Upp;

Vector<Vector<double>> PrintVector(const Vector<Vector<double>>& vector);


CONSOLE_APP_MAIN
{
	//original vector of vector of double
	Vector<Vector<double>> original{{2.0,3.0},{4.0,5.0}};
	
	//pick allow you to move a value between variable without having to do copy
	Vector<Vector<double>> ret = pick(PrintVector(original));
	
	//We print the vector and all is double
	for(const Vector<double>& vec : ret){
		for(const double& d : vec){
			Cout() << d;
		}
		Cout() << "\n";
	}
}

Vector<Vector<double>> PrintVector(const Vector<Vector<double>>& vector){
	//Clone allow you to clone a variable (the class you want to copy must have a copy constructor)
	Vector<Vector<double>> myClone = clone(vector);
	
	//We add + 1 to all double of our clone
	for(Vector<double>& vec : myClone){
		for(double& d : vec){
			d += 1.0;
		}
	}
	
	//we return our clone not by copying but by moving it
	return pick(myClone);
}

 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Multiply a scalar to every element of a vector
Next Topic: FileIn and Buffer cannot be composed in a class?
Goto Forum:
  


Current Time: Thu Aug 07 04:06:53 CEST 2025

Total time taken to generate the page: 0.05566 seconds