Похожие чаты

Hi there, Are there anyway to store an xvalue reference as

element inside a vector without encapsulating with ptr ?
ex : vector<IBase&&>
What i want to achieve is :
method({CChild(optionA),CChild(optionC),...})

11 ответов

23 просмотра

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

John- Автор вопроса
Pavel
If I understand correctly xvalue is not meant to b...

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',...)}).

John
To be transfered / moved. As long is template, pro...

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.

John
To be transfered / moved. As long is template, pro...

And about variadics, why problem is the same? You can pass each object instead of passing list of them

John- Автор вопроса
Pavel
And about variadics, why problem is the same? You ...

both are the same problem for accepting abstract from concrete xvalue as variadic argument/collection.

John
To be transfered / moved. As long is template, pro...

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

John
To be transfered / moved. As long is template, pro...

Interesting! Can you write the declaration to your specimen function.. (return-type) method(arg/parms); Actual declaration that you expect.

John- Автор вопроса
Aakash Saini
Interesting! Can you write the declaration to your...

What I want : method(CChild(opt1),CChild(opt3),...) from abstract. method(IBase&& ...) or method(const IBase& ...)

John
What I want : method(CChild(opt1),CChild(opt3),......

Earlier you did put {}, which was presumed you intent to pass “raw elements dynamically” bycoting pass/call-by-value or reference. Now those {} gone?

John- Автор вопроса

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта