@@ -63,49 +63,49 @@ extern(C++, class) struct basic_string(T, Traits = char_traits!T, Alloc = alloca
63
63
this (const (T)* ptr, ref const (allocator_type) al = defaultAlloc);
64
64
extern (D ) this (const (T)[] dstr) { this (dstr.ptr, dstr.length); }
65
65
extern (D ) this (const (T)[] dstr, ref const (allocator_type) al = defaultAlloc) { this (dstr.ptr, dstr.length); }
66
- ~this ();
66
+ ~this () nothrow ;
67
67
68
68
ref basic_string opAssign (ref const (basic_string) s);
69
69
70
70
// 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 ;
74
74
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 ;
78
78
79
79
// no reverse iterator for now.
80
80
81
81
// 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 ;
86
86
87
- bool empty () const nothrow ;
87
+ bool empty () const nothrow @trusted @nogc ;
88
88
89
89
void clear () nothrow ;
90
90
void resize (size_type n);
91
91
void resize (size_type n, T c);
92
- void reserve (size_type n = 0 );
92
+ void reserve (size_type n = 0 ) @trusted @nogc ;
93
93
void shrink_to_fit ();
94
94
95
95
// 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 ;
100
100
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 ;
105
105
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 ;
109
109
110
110
// Modifiers
111
111
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
189
189
190
190
// D helpers
191
191
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;" ); }
194
208
195
209
private :
196
210
void [8 ] _ = void ; // to match sizeof(std::string) and pad the object correctly.
0 commit comments