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 » Avoid Copy when adding a Tuple to a VectorMap
Avoid Copy when adding a Tuple to a VectorMap [message #57183] Sun, 06 June 2021 03:39 Go to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello,

I'm working with a VectorMap<int, Tuple<int, A>>
class A don't provid a copy constructor, only a Move constructor.
I would like to add a new Tuple to my vector map by moving a fresh class A.
But I don't succeed... Can someone help me ? (I would like to avoid creation of a class to replace tuple in this specific case)
#include <Core/Core.h>

using namespace Upp;

class A{
	public:
		A(int e) : d_e(e){}
		A(A&& a){d_e = a.d_e;}
		int d_e;
};

CONSOLE_APP_MAIN
{
	VectorMap<int, Tuple<int, A>> myVector;
	myVector(1, pick(Tuple<int,A>(1, 5)));
	Cout() << myVector.Get(1).b.d_e << EOL;
	//Error : call to implicitly deleted copy constructor of 'A'
}

Also, why there is no Create(Args...) function in VectorMap ? (like the one in ArrayMap)

[Updated on: Sun, 06 June 2021 04:04]

Report message to a moderator

Re: Avoid Copy when adding a Tuple to a VectorMap [message #57442 is a reply to message #57183] Fri, 13 August 2021 10:52 Go to previous messageGo to next message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 220
Registered: June 2011
Experienced Member
I realize this is an old post and you've already figured it out, but is there any reason you can't do

#include <Core/Core.h>

using namespace Upp;

class A : Moveable<A> {
    public:
        A(int e) : d_e(e){}
    //  A(A&& a){d_e = a.d_e;}
        int d_e;
};

CONSOLE_APP_MAIN
{
    VectorMap<int, Tuple<int, A>> myVector;
    myVector(1, pick(Tuple<int,A>(1, 5)));
    Cout() << myVector.Get(1).b.d_e << EOL;
    //Error : call to implicitly deleted copy constructor of 'A'
}
Re: Avoid Copy when adding a Tuple to a VectorMap [message #57624 is a reply to message #57183] Mon, 11 October 2021 07:19 Go to previous message
jjacksonRIAB is currently offline  jjacksonRIAB
Messages: 220
Registered: June 2011
Experienced Member
I just realized I didn't really answer your question, but this might help with what you're doing:

#include <Core/Core.h>

using namespace Upp;

class A : Moveable<A> {
    public:
        A(int e) : d_e(e){}
        int d_e;
};

CONSOLE_APP_MAIN
{
    VectorMap<int, Tuple<int, A>> myVector;
    myVector.AddPick(1, MakeTuple(1, A(5)) );
	
    Cout() << myVector.Get(1).b.d_e << EOL;
}


I know AddPick uses move constructor but I'm not sure what you get out of it, although you may find MakeTuple useful from a clarity standpoint.
Previous Topic: skylark
Next Topic: How to migrate my old packages to new version U++ in linux
Goto Forum:
  


Current Time: Sat Apr 20 03:30:23 CEST 2024

Total time taken to generate the page: 0.07107 seconds