U++ framework
Do not panic. Ask here before giving up.

Home » U++ Library support » U++ Core » Problem with Vector::Add (pick/clone semantics)
Re: Problem with Vector::Add (pick/clone semantics) [message #52218 is a reply to message #52213] Sat, 10 August 2019 06:33 Go to previous messageGo to previous message
Novo is currently offline  Novo
Messages: 1431
Registered: December 2006
Ultimate Contributor
Actually, it is possible to move data from std::initializer_list with a little hack:
template <typename T>
struct Foo {
	Foo(std::initializer_list<T> init) {
		for(const T& i : init)
			v.Add(pick(const_cast<T&>(i)));
	}
//	Foo(std::initializer_list<T> init) {
//		for(const T& i : init)
//			v.Add(i);
//	}
	
	Vector<T> v;
};

struct Boo : Moveable<Boo> {
	Boo() {}
	Boo(const Boo&) = default;
	Boo(Boo&&) = delete;
};

CONSOLE_APP_MAIN
{
	Foo<Vector<int>> f = {{1}};
//	Foo<Boo> f = {Boo()};
}

The problem is that this will require all types to have a move constructor.
A move constructor can be detected via std::is_move_constructible, but I couldn't figure out how to apply SFINAE to a constructor.

IMHO, all this code complexity is unnecessary in this case.


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: Tue May 26 12:39:47 GMT+2 2026

Total time taken to generate the page: 0.00631 seconds