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 |
|
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 #57624 is a reply to message #57183] |
Mon, 11 October 2021 07:19 |
jjacksonRIAB
Messages: 223 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.
|
|
|
Goto Forum:
Current Time: Thu Sep 19 10:52:24 CEST 2024
Total time taken to generate the page: 0.02018 seconds
|