@@ -50,9 +50,6 @@ extern(D):
50
50
// /
51
51
alias const_pointer = const (T)* ;
52
52
53
- // /
54
- alias as_array this ;
55
-
56
53
// / MSVC allocates on default initialisation in debug, which can't be modelled by D `struct`
57
54
@disable this ();
58
55
@@ -62,27 +59,52 @@ extern(D):
62
59
alias opDollar = length;
63
60
64
61
// /
65
- ref inout (T) front () inout pure nothrow @safe @nogc { return this [0 ]; }
62
+ size_t [2 ] opSlice (size_t dim : 0 )(size_t start, size_t end) const pure nothrow @safe @nogc { return [start, end]; }
63
+
64
+ // /
65
+ ref inout (T) opIndex (size_t index) inout pure nothrow @safe @nogc { return as_array[index]; }
66
+ // /
67
+ inout (T)[] opIndex (size_t [2 ] slice) inout pure nothrow @safe @nogc { return as_array[slice[0 ] .. slice[1 ]]; }
66
68
// /
67
- ref inout (T) back () inout pure nothrow @safe @nogc { return this [$ - 1 ] ; }
69
+ inout (T)[] opIndex () inout pure nothrow @safe @nogc { return as_array() ; }
68
70
71
+ // /
72
+ ref vector opAssign (U)(auto ref vector! (U, Alloc) s) { opAssign(s.as_array); return this ; }
73
+ // /
74
+ ref vector opAssign (T[] array)
75
+ {
76
+ clear();
77
+ reserve (array.length);
78
+ insert(0 , array);
79
+ return this ;
80
+ }
69
81
70
- // WIP...
82
+ // /
83
+ void opIndexAssign ()(auto ref T val, size_t index) { as_array[index] = val; }
84
+ // /
85
+ void opIndexAssign ()(auto ref T val, size_t [2 ] slice) { as_array[slice[0 ] .. slice[1 ]] = val; }
86
+ // /
87
+ void opIndexAssign (T[] val, size_t [2 ] slice) { as_array[slice[0 ] .. slice[1 ]] = val[]; }
88
+ // /
89
+ void opIndexAssign ()(auto ref T val) { as_array[] = val; }
90
+ // /
91
+ void opIndexAssign (T[] val) { as_array[] = val[]; }
71
92
72
- // this(size_type count);
73
- // this(size_type count, ref const(value_type) val);
74
- // this(size_type count, ref const(value_type) val, ref const(allocator_type) al);
75
- // this(ref const(vector) x);
76
- // this(iterator first, iterator last);
77
- // this(iterator first, iterator last, ref const(allocator_type) al = defaultAlloc);
78
- // this(const_iterator first, const_iterator last);
79
- // this(const_iterator first, const_iterator last, ref const(allocator_type) al = defaultAlloc);
80
- // this(T[] arr) { this(arr.ptr, arr.ptr + arr.length); }
81
- // this(T[] arr, ref const(allocator_type) al = defaultAlloc) { this(arr.ptr, arr.ptr + arr.length); }
82
- // this(const(T)[] arr) { this(arr.ptr, arr.ptr + arr.length); }
83
- // this(const(T)[] arr, ref const(allocator_type) al = defaultAlloc) { this(arr.ptr, arr.ptr + arr.length); }
93
+ // /
94
+ void opIndexOpAssign (string op)(auto ref T val, size_t index) { mixin (" as_array[index] " ~ op ~ " = val;" ); }
95
+ // /
96
+ void opIndexOpAssign (string op)(auto ref T val, size_t [2 ] slice) { mixin (" as_array[slice[0] .. slice[1]] " ~ op ~ " = val;" ); }
97
+ // /
98
+ void opIndexOpAssign (string op)(T[] val, size_t [2 ] slice) { mixin (" as_array[slice[0] .. slice[1]] " ~ op ~ " = val[];" ); }
99
+ // /
100
+ void opIndexOpAssign (string op)(auto ref T val) { mixin (" as_array[] " ~ op ~ " = val;" ); }
101
+ // /
102
+ void opIndexOpAssign (string op)(T[] val) { mixin (" as_array[] " ~ op ~ " = val[];" ); }
84
103
85
- // ref vector opAssign(ref const(vector) s);
104
+ // /
105
+ ref inout (T) front () inout pure nothrow @safe @nogc { return as_array[0 ]; }
106
+ // /
107
+ ref inout (T) back () inout pure nothrow @safe @nogc { return as_array[$- 1 ]; }
86
108
87
109
// /
88
110
ref vector opOpAssign (string op : " ~" )(auto ref T item) { push_back(forward! item); return this ; }
@@ -109,7 +131,7 @@ extern(D):
109
131
// /
110
132
this (DefaultConstruct) @nogc { _Alloc_proxy(); }
111
133
// /
112
- this (size_t count)
134
+ this ()( size_t count)
113
135
{
114
136
_Alloc_proxy();
115
137
_Buy(count);
@@ -125,7 +147,7 @@ extern(D):
125
147
_Get_data()._Mylast = _Ufill(_Get_data()._Myfirst, count, val);
126
148
}
127
149
// /
128
- this (T[] array)
150
+ this ()( T[] array)
129
151
{
130
152
_Alloc_proxy();
131
153
_Buy(array.length);
@@ -209,16 +231,17 @@ extern(D):
209
231
}
210
232
211
233
// /
212
- void clear () nothrow
234
+ void clear ()
213
235
{
214
236
_Base._Orphan_all();
215
237
_Destroy(_Get_data()._Myfirst, _Get_data ()._Mylast);
216
238
_Get_data()._Mylast = _Get_data()._Myfirst;
217
239
}
218
240
219
241
// /
220
- void resize (const size_type newsize)
242
+ void resize ()( const size_type newsize)
221
243
{
244
+ static assert (is (typeof ({static T i;})), T.stringof ~ " .this() is annotated with @disable." );
222
245
_Resize(newsize, (pointer _Dest, size_type _Count) => _Udefault(_Dest, _Count));
223
246
}
224
247
@@ -267,7 +290,7 @@ extern(D):
267
290
// nothing to do, avoid invalidating iterators
268
291
}
269
292
else if (_Count > _Unused_capacity())
270
- { // reallocate
293
+ { // reallocate
271
294
const size_type _Oldsize = size();
272
295
273
296
// if (_Count > max_size() - _Oldsize)
@@ -306,7 +329,7 @@ extern(D):
306
329
_Change_array(_Newvec, _Newsize, _Newcapacity);
307
330
}
308
331
else
309
- { // Attempt to provide the strong guarantee for EmplaceConstructible failure.
332
+ { // Attempt to provide the strong guarantee for EmplaceConstructible failure.
310
333
// If we encounter copy/move construction/assignment failure, provide the basic guarantee.
311
334
// (For one-at-back, this provides the strong guarantee.)
312
335
@@ -347,7 +370,7 @@ extern(D):
347
370
}
348
371
}
349
372
else
350
- { // affected elements don't overlap before/after
373
+ { // affected elements don't overlap before/after
351
374
pointer _Relocated = _Where + _Count;
352
375
_Get_data()._Mylast = _Utransfer! true (_Where, _Oldlast, _Relocated);
353
376
_Destroy(_Where, _Oldlast);
@@ -650,7 +673,7 @@ extern(D):
650
673
_Backout._Emplace_back(val);
651
674
return _Backout._Release();
652
675
}
653
- pointer _Udefault (pointer _Dest, size_t _Count)
676
+ pointer _Udefault ()( pointer _Dest, size_t _Count)
654
677
{
655
678
// TODO: if zero init, then fast-path to zeromem
656
679
auto _Backout = _Uninitialized_backout(_Dest);
@@ -716,10 +739,6 @@ extern(D):
716
739
{
717
740
static assert (false , " C++ runtime not supported" );
718
741
}
719
-
720
- private :
721
- // HACK: because no rvalue->ref
722
- __gshared static immutable allocator_type defaultAlloc;
723
742
}
724
743
725
744
0 commit comments