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 » Map with unique keys and transfer semantics?
Re: Map with unique keys and transfer semantics? [message #46473 is a reply to message #46472] Sat, 14 May 2016 06:26 Go to previous messageGo to previous message
Lance is currently offline  Lance
Messages: 527
Registered: March 2007
Contributor
for an idea of what I explained

#include <Core/Core.h>

using namespace Upp;

template <class K, class T>
struct UMap : VectorMap<K, T>{
	T&       Add(const K& k, const T& x)            { return value[FindAdd(k)]=x; }
	T&       AddPick(const K& k, T rval_ x)         { return value[FindAdd(k)]=pick(x); }
	T&       Add(const K& k)                        { return value[FindAdd(k)]=K(); }
};

CONSOLE_APP_MAIN
{
	UMap<int, String> map;
	String s="Hello, world!";
	
	
	map.Add(1)="Hello";
	DUMPC(map);
	// unfortunately String doens't have move assignment(xfer) operator
	// so the following downgraded to Add
	map.AddPick(1, pick(s));
	DUMPC(map);
	map.Add(1,"Unique Vector Map");
	DUMPC(map);
}

 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Problems with AddPick operator| in Vector
Next Topic: Run a slow process in another thread to not block GUI
Goto Forum:
  


Current Time: Mon May 13 21:19:45 CEST 2024

Total time taken to generate the page: 0.01741 seconds