element inside a vector without encapsulating with ptr ?
ex : vector<IBase&&>
What i want to achieve is :
method({CChild(optionA),CChild(optionC),...})
If I understand correctly xvalue is not meant to be stored, so they are not compatible with vectors, you can use std::intializer_list for that (or variadic template function).
Wonder if you are seeking element; std::vector<>::at
To be transfered / moved. As long is template, problem is the same. I believe standart said object(ADT) should behave like simple data type or some sort. something like : method({(int)'A',(int)'C',...)}).
Yes, but xvalues are used to represent values that basically can be not valid the next instruction, and they don't have addresses. But vectors on the other hand made for storing objects (they allocate the buffer and such), and even if you want to use verctors just to pass parameters so they won't expire during it's lifetime the vector need to treat them as you want to store them. On the other hand there are things especially designed to pass values like this like std:: initializer_list, that don't try to prolong objects lifetime. I haven't worked with them much, but I heard that they can be used to pass objects to be moved.
And about variadics, why problem is the same? You can pass each object instead of passing list of them
both are the same problem for accepting abstract from concrete xvalue as variadic argument/collection.
Nah, seems that I wasn't right about std::initializer_list. That strange, but.. well.. IDK https://stackoverflow.com/questions/8193102/initializer-list-and-move-semantics But about templates something like this should work https://wandbox.org/permlink/DHYXR8c4iB9d1BZn upd: removed extra default constructor
Interesting! Can you write the declaration to your specimen function.. (return-type) method(arg/parms); Actual declaration that you expect.
What I want : method(CChild(opt1),CChild(opt3),...) from abstract. method(IBase&& ...) or method(const IBase& ...)
Earlier you did put {}, which was presumed you intent to pass “raw elements dynamically” bycoting pass/call-by-value or reference. Now those {} gone?
Still the same problem.
Обсуждают сегодня