Wednesday 15 June 2011

c++ - Can I list-initialize a vector of move-only type? -


If I pass the following code through my GCC 4.7 snapshot, then it unique_ptr s Attempts to copy in vector

  #include & lt; Vector & gt; #include & lt; Memory & gt; Int main () {move_only = std :: unique_ptr & lt; Int> Std :: vector & lt; Move_only & gt; V {move_only (), move_only (), move_only ()}; }   

Obviously this can not work because std :: unique_ptr is not copyable:

Error: Use the deleted function 'std :: unique_ptr & lt; _Tp, _DP & gt; :: unique_prit (const std :: unique_ptr & lt; _Tp, _DP & gt; & amp;) [_Tp = int; _Dp = std :: default_delete; Std :: unique_ptr & lt; _Tp, _Dp & gt; = Std :: unique_ptr] '

Is GCC correct in trying to copy points from starters list?

In 18.9 & lt; Initializer_list & gt; The summary of clearly makes it clear that elements of the initial list are always passed through the context-reference. Unfortunately, there is no way to use move-semantic in the initial list elements in the current revision of the language. is.

Specifically, we have:

  typedef const e & amp; Context; Typeface Consistric E & amp; Const_reference; Type-tof cone e * iterator; TypeEfifCon EECTERATOR; Const e * start () const is not spontaneous; // First element const e * end () const is not spontaneous; // is a previous element     past

No comments:

Post a Comment