lundi 1 avril 2019

Noncopyable initializer_list alternatives

I know that trying to use a std::initializer_list<NonCopyable> leads to an error because the elements are copied into the temporary array represented by the initializer_list. I have also read some explanation on why it would not be alright to have rvalue references in the list, which I'm fine with.

The problem is that I would like to pass noncopyable things not in order to move from them, but only const-access them, so the argument about rvalues does not apply. What can I do to retain, if possible, the list initialization syntax and the reference semantics (no wrappers, no raw pointers)?

NonCopyable a{...}, b{...};
ListInitialized c{a, b};

I think I'm missing something extremely obvious here.

Aucun commentaire:

Enregistrer un commentaire