@@ -73,7 +73,11 @@ struct mir_rcarray(T)
7373 static assert (Context.sizeof % 16 == 0 );
7474
7575 // /
76- private Context* _context;
76+ private T* _payload;
77+ private ref inout (Context* ) _context () inout scope return pure nothrow @nogc @trusted @property
78+ {
79+ return * cast (inout (Context* )* )&_payload;
80+ }
7781
7882 // private inout(Context)* _context() inout @trusted pure nothrow @nogc scope
7983 // {
@@ -86,7 +90,7 @@ struct mir_rcarray(T)
8690 // }
8791
8892 // /
89- this (this ) scope @safe pure nothrow @nogc
93+ this (this ) scope @trusted pure nothrow @nogc
9094 {
9195 import core.atomic : atomicOp;
9296 if (_context ! is null ) with (* _context)
@@ -111,8 +115,8 @@ struct mir_rcarray(T)
111115 T[] array;
112116 ()@trusted { array = (cast (T* )(_context + 1 ))[0 .. length]; }();
113117 xdestroy(array);
114- auto p = cast (void * ) _context;
115118 () @trusted {
119+ auto p = cast (void * ) _payload;
116120 with (* _context)
117121 {
118122 if (_delegateContext ! is null )
@@ -142,7 +146,7 @@ struct mir_rcarray(T)
142146 {
143147 // /
144148 pragma (inline, false )
145- ~this () scope nothrow @nogc
149+ ~this () scope nothrow @nogc @safe
146150 {
147151 dec();
148152 }
@@ -154,17 +158,17 @@ struct mir_rcarray(T)
154158 return initializeImpl (length, alignment, deallocate);
155159 }
156160
157- // // /
158- // this(ref typeof(this) rhs) @safe pure nothrow @nogc
159- // {
160- // this._context = rhs._context;
161- // this.__xpostblit;
162- // }
161+ // /
162+ this (ref typeof (this ) rhs) @safe pure nothrow @nogc
163+ {
164+ this ._context = rhs._context;
165+ this .__xpostblit;
166+ }
163167 }
164168 else
165169 {
166170 pragma (inline, false )
167- ~this () scope nothrow @nogc
171+ ~this () scope nothrow @nogc @safe
168172 {
169173 dec();
170174 }
@@ -240,13 +244,13 @@ struct mir_rcarray(T)
240244 }
241245
242246 // /
243- size_t length () @safe scope pure nothrow @nogc @property
247+ size_t length () @trusted scope pure nothrow @nogc @property
244248 {
245249 return _context ! is null ? _context.length : 0 ;
246250 }
247251
248252 // /
249- size_t counter () @safe scope pure nothrow @nogc @property
253+ size_t counter () @trusted scope pure nothrow @nogc @property
250254 {
251255 return _context ! is null ? _context.counter : 0 ;
252256 }
@@ -260,7 +264,7 @@ struct mir_rcarray(T)
260264 // /
261265 ref opIndex (size_t i) @trusted scope inout
262266 {
263- assert (_context );
267+ assert (_payload );
264268 assert (i < _context.length);
265269 return (cast (inout (T)* )(_context + 1 ))[i];
266270 }
@@ -277,17 +281,14 @@ struct mir_rcarray(T)
277281 return _context ! is null ? (cast (inout (T)* )(_context + 1 ))[0 .. _context.length] : null ;
278282 }
279283
280- mir_rcarray! (const T) lightConst() const @nogc nothrow @trusted
281- {
282- return cast (typeof (return )) this ;
283- }
284+ // /
285+ mir_rcarray! (const T) lightConst()() scope return const @nogc nothrow @trusted @property
286+ { return cast (typeof (return )) this ; }
284287
285- mir_rcarray! (immutable T) lightImmutable() immutable @nogc nothrow @trusted
286- {
287- return cast (typeof (return )) this ;
288- }
288+ mir_rcarray! (immutable T) lightImmutable()() scope return immutable @nogc nothrow @trusted @property
289+ { return cast (typeof (return )) this ; }
289290
290- size_t opDollar (size_t pos : 0 )() @safe scope pure nothrow @nogc
291+ size_t opDollar (size_t pos : 0 )() @trusted scope pure nothrow @nogc
291292 {
292293 return _context ! is null ? _context.length : 0 ;
293294 }
@@ -300,11 +301,15 @@ struct mir_rcarray(T)
300301 }
301302}
302303
304+ // / ditto
305+ alias RCArray = mir_rcarray;
306+
303307// /
308+ version (mir_test)
304309@safe pure @nogc
305310unittest
306311{
307- auto a = mir_rcarray ! double (10 );
312+ auto a = RCArray ! double (10 );
308313 foreach (i, ref e; a)
309314 e = i;
310315 auto b = a;
@@ -339,14 +344,13 @@ struct mir_rci(T)
339344 // }
340345
341346 // /
342- mir_rcarray ! T _array;
347+ RCArray ! T _array;
343348
344- // /
345- mir_rci! (const T) lightConst()() const @property
349+
350+ mir_rci! (const T) lightConst() scope return const @nogc nothrow @trusted @property
346351 { return typeof (return )(_iterator, _array.lightConst); }
347352
348- // /
349- mir_rci! (immutable T) lightImmutable()() immutable @property
353+ mir_rci! (immutable T) lightImmutable() scope return immutable @nogc nothrow @trusted @property
350354 { return typeof (return )(_iterator, _array.lightImmutable); }
351355
352356 // /
@@ -367,7 +371,7 @@ struct mir_rci(T)
367371 if (op == " -" || op == " +" )
368372 { mixin (" _iterator " ~ op ~ " = index;" ); }
369373
370- // /
374+ // /
371375 mir_rci! T opBinary (string op)(ptrdiff_t index)
372376 if (op == " +" || op == " -" )
373377 { return mir_rci! T(_iterator + index, _array); }
@@ -399,9 +403,10 @@ struct mir_rci(T)
399403alias RCI = mir_rci;
400404
401405// /
406+ version (mir_test)
402407@nogc unittest
403408{
404- import mir.ndslice;
409+ import mir.ndslice.slice ;
405410 import mir.rcarray;
406411 auto array = mir_rcarray! double (10 );
407412 auto slice = array.asSlice;
@@ -413,9 +418,10 @@ alias RCI = mir_rci;
413418}
414419
415420// /
421+ version (mir_test)
416422@nogc unittest
417423{
418- import mir.ndslice;
424+ import mir.ndslice.slice ;
419425 import mir.rcarray;
420426
421427 alias rcvec = Slice! (RCI ! double );
@@ -431,3 +437,30 @@ alias RCI = mir_rci;
431437 x = x.save;
432438 }
433439}
440+
441+ version (mir_test)
442+ @safe @nogc unittest
443+ {
444+ import mir.ndslice;
445+ import mir.rcarray;
446+
447+ @safe void bar(ref const mir_rcarray! (const double ) a, ref mir_rcarray! (const double ) b)
448+ {
449+ b = a;
450+ }
451+
452+ @safe void bari(ref immutable mir_rcarray! (immutable double ) a, ref mir_rcarray! (immutable double ) b)
453+ {
454+ b = a;
455+ }
456+
457+ @safe void foo(ref const RCI ! (const double ) a, ref RCI ! (const double ) b)
458+ {
459+ b = a;
460+ }
461+
462+ @safe void fooi(ref immutable RCI ! (immutable double ) a, ref RCI ! (immutable double ) b)
463+ {
464+ b = a;
465+ }
466+ }
0 commit comments