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 #56500 is a reply to message #56488] Fri, 19 March 2021 13:26 Go to previous message
mirek is currently offline  mirek
Messages: 14267
Registered: November 2005
Ultimate Member
Sometimes it is good to use r-value reference, as it gives you freedom in usage:

Vector<Vector<double>> AdjustVector(Vector<Vector<double>>&& vector){
	for(Vector<double>& vec : vector){
		for(double& d : vec) {
			d += 1.0;
		}
	}
	return pick(vector);
}

CONSOLE_APP_MAIN
{
	Vector<Vector<double>> x { { 1, 2 }, { 3, 4 } };
	
	auto y = AdjustVector(clone(x));
	
	DDUMP(x);
	DDUMP(y);
	
	y = AdjustVector(pick(x));

	DDUMP(x);
	DDUMP(y);
}


Mirek
 
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 03:50:18 CEST 2025

Total time taken to generate the page: 0.05174 seconds