@@ -63,49 +63,49 @@ extern(C++, class) struct basic_string(T, Traits = char_traits!T, Alloc = alloca
6363 this (const (T)* ptr, ref const (allocator_type) al = defaultAlloc);
6464 extern (D ) this (const (T)[] dstr) { this (dstr.ptr, dstr.length); }
6565 extern (D ) this (const (T)[] dstr, ref const (allocator_type) al = defaultAlloc) { this (dstr.ptr, dstr.length); }
66- ~this ();
66+ ~this () nothrow ;
6767
6868 ref basic_string opAssign (ref const (basic_string) s);
6969
7070 // Iterators
71- iterator begin () nothrow ;
72- const_iterator begin () const nothrow ;
73- const_iterator cbegin () const nothrow ;
71+ iterator begin () nothrow @trusted @nogc ;
72+ const_iterator begin () const nothrow @trusted @nogc ;
73+ const_iterator cbegin () const nothrow @trusted @nogc ;
7474
75- iterator end () nothrow ;
76- const_iterator end () const nothrow ;
77- const_iterator cend () const nothrow ;
75+ iterator end () nothrow @trusted @nogc ;
76+ const_iterator end () const nothrow @trusted @nogc ;
77+ const_iterator cend () const nothrow @trusted @nogc ;
7878
7979 // no reverse iterator for now.
8080
8181 // Capacity
82- size_type size () const nothrow ;
83- size_type length () const nothrow ;
84- size_type max_size () const nothrow ;
85- size_type capacity () const nothrow ;
82+ size_type size () const nothrow @trusted @nogc ;
83+ size_type length () const nothrow @trusted @nogc ;
84+ size_type max_size () const nothrow @trusted @nogc ;
85+ size_type capacity () const nothrow @trusted @nogc ;
8686
87- bool empty () const nothrow ;
87+ bool empty () const nothrow @trusted @nogc ;
8888
8989 void clear () nothrow ;
9090 void resize (size_type n);
9191 void resize (size_type n, T c);
92- void reserve (size_type n = 0 );
92+ void reserve (size_type n = 0 ) @trusted @nogc ;
9393 void shrink_to_fit ();
9494
9595 // Element access
96- ref T opIndex (size_type i);
97- ref const (T) opIndex (size_type i) const ;
98- ref T at (size_type i);
99- ref const (T) at (size_type i) const ;
96+ ref T opIndex (size_type i) @trusted @nogc ;
97+ ref const (T) opIndex (size_type i) const @trusted @nogc ;
98+ ref T at (size_type i) @trusted @nogc ;
99+ ref const (T) at (size_type i) const @trusted @nogc ;
100100
101- ref T back ();
102- ref const (T) back () const ;
103- ref T front ();
104- ref const (T) front () const ;
101+ ref T back () @trusted @nogc ;
102+ ref const (T) back () const @trusted @nogc ;
103+ ref T front () @trusted @nogc ;
104+ ref const (T) front () const @trusted @nogc ;
105105
106- const (T)* c_str () const nothrow ;
107- T* data () nothrow ;
108- const (T)* data () const nothrow ;
106+ const (T)* c_str () const nothrow @trusted @nogc ;
107+ T* data () nothrow @trusted @nogc ;
108+ const (T)* data () const nothrow @trusted @nogc ;
109109
110110 // Modifiers
111111 ref basic_string opOpAssign (string op : " +" )(ref const (basic_string) s);
@@ -189,8 +189,22 @@ extern(C++, class) struct basic_string(T, Traits = char_traits!T, Alloc = alloca
189189
190190 // D helpers
191191 alias as_array this ;
192- extern (D ) T[] as_array() { return data()[0 .. size()]; }
193- extern (D ) const (T)[] as_array() const { return data()[0 .. size()]; }
192+ extern (D ) T[] as_array() nothrow @safe @nogc { return this []; }
193+ extern (D ) const (T)[] as_array() const nothrow @safe @nogc { return this []; }
194+
195+ extern (D ) T[] opSlice () nothrow @safe @nogc { return data()[0 .. size()]; }
196+ extern (D ) const (T)[] opSlice () const nothrow @safe @nogc { return data()[0 .. size()]; }
197+ extern (D ) T[] opSlice (size_type start, size_type end) @safe { assert (start <= end && end <= size(), " Index out of bounds" ); return data ()[start .. end]; }
198+ extern (D ) const (T)[] opSlice (size_type start, size_type end) const @safe { assert (start <= end && end <= size(), " Index out of bounds" ); return data ()[start .. end]; }
199+ extern (D ) size_type opDollar(size_t pos)() const nothrow @safe @nogc { static assert (pos == 0 , " std::vector is one-dimensional" ); return size (); }
200+
201+ // support all the assignment variants
202+ extern (D ) void opSliceAssign (T value) { opSlice ()[] = value; }
203+ extern (D ) void opSliceAssign (T value, size_type i, size_type j) { opSlice (i, j)[] = value; }
204+ extern (D ) void opSliceUnary(string op)() if (op == " ++" || op == " --" ) { mixin (op ~ " opSlice()[];" ); }
205+ extern (D ) void opSliceUnary(string op)(size_type i, size_type j) if (op == " ++" || op == " --" ) { mixin (op ~ " opSlice(i, j)[];" ); }
206+ extern (D ) void opSliceOpAssign(string op)(T value) { mixin (" opSlice()[] " ~ op ~ " = value;" ); }
207+ extern (D ) void opSliceOpAssign(string op)(T value, size_type i, size_type j) { mixin (" opSlice(i, j)[] " ~ op ~ " = value;" ); }
194208
195209private :
196210 void [8 ] _ = void ; // to match sizeof(std::string) and pad the object correctly.
0 commit comments