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   |
Novo
Messages: 1430 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
|
|
|
Goto Forum:
Current Time: Fri Jul 18 03:50:27 CEST 2025
Total time taken to generate the page: 0.04126 seconds
|