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 » U++ Library support » U++ Core » Problem with Vector::Add (pick/clone semantics)
Re: Problem with Vector::Add (pick/clone semantics) [message #52217 is a reply to message #52213] Fri, 09 August 2019 20:12 Go to previous messageGo to previous message
Novo is currently offline  Novo
Messages: 1361
Registered: December 2006
Ultimate Contributor
I personally would say that this is not a bug. This is a feature. Smile
clone was intentionally removed from Add to prevent implicit cloning.
Basically, std::initializer_list will create a temporary const object and after that it will force you to create another copy of it. This is an unnecessary allocation.
U++ is warning you about that and offering you other tools like
	VectorMap<String, Vector<String>> MY_MAP;
	MY_MAP.Add("s1", Vector<String>{"s11", "s12", "s13", "s14"});

In this case objects will be moved.

Ideally, it would be great to have a set of overloaded operators VectorMap& operator()(const K& k, const T& v)

More details on this problem can be found here.
A comment to this article has an interesting code snippet:
template<std::size_t N>
Vec(T(&&a)[N])
  : _vect(std::make_move_iterator(std::begin(a)), std::make_move_iterator(std::end(a)))
{}
Extra braces needed though, but somebody may find this more idiomatic:
Vec<int> v {{1, 2}};


Regards,
Novo
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Vector< Vector<int> > compilation error
Next Topic: SHA1 Doesn't work any more for data over 65536 bytes
Goto Forum:
  


Current Time: Sat Jun 01 22:03:16 CEST 2024

Total time taken to generate the page: 0.03410 seconds