Home » U++ Library support » U++ Core » VectorMap.Get (Problem fetching value of vectormap second time)
Re: VectorMap.Get [message #45232 is a reply to message #45231] |
Tue, 13 October 2015 16:38 |
|
Klugier
Messages: 1076 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello Deep,
Try to clone your vector. I think in your case there is move operation for some reason. Maybe someone that knows better that mechanism can describe it for you. On the other hand I have got compilation error of your example in the latest upp. Code that should work:
#include <Core/Core.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
Vector<int> v1;
VectorMap<String, Vector<int>> Vm;
v1.Clear();
v1.Add(0);
v1.Add(3);
Vm.Add("key1", v1); // <- Vector was copied
v1.Clear();
v1.Add(10);
v1.Add(31);
v1.Add(41);
Vm.Add("key2", v1); // <- Vector was copied
Vector<int> v2;
v2 = clone(Vm.Get("key1")); // <- Without clone, probably move operation
DUMP(v2);
v2.Clear();
v2 = clone(Vm.Get("key2"));
DUMP(v2);
v2.Clear();
v2 = clone(Vm.Get("key1"));
DUMP(v2);
}
Here is my log values:
v2 = [0, 3]
v2 = [10, 31, 41]
v2 = [0, 3]
------------------------------------------------------------ --
P.S.
Maybe you should put space after comma. In my opinion declaration like: VectorMap<String, Vector<int>> is more readable that VectorMap<String,Vector<int>> .
Sincerely,
Klugier
U++ - one framework to rule them all.
[Updated on: Tue, 13 October 2015 16:47] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Thu May 16 03:52:47 CEST 2024
Total time taken to generate the page: 0.02450 seconds
|