diff --git a/src/core/stdcpp/allocator.d b/src/core/stdcpp/allocator.d index 991f70848df..015445ad50d 100644 --- a/src/core/stdcpp/allocator.d +++ b/src/core/stdcpp/allocator.d @@ -6,6 +6,7 @@ * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). * (See accompanying file LICENSE) * Authors: Guillaume Chatelet + * Manu Evans * Source: $(DRUNTIMESRC core/stdcpp/allocator.d) */ @@ -17,4 +18,4 @@ extern(C++, std): * Allocators are classes that define memory models to be used by some parts of * the C++ Standard Library, and most specifically, by STL containers. */ -struct allocator(T) { } +extern(C++, class) struct allocator(T) { } diff --git a/src/core/stdcpp/string.d b/src/core/stdcpp/string.d index b8879404a7f..72afbb69f7d 100644 --- a/src/core/stdcpp/string.d +++ b/src/core/stdcpp/string.d @@ -6,6 +6,7 @@ * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). * (See accompanying file LICENSE) * Authors: Guillaume Chatelet + * Manu Evans * Source: $(DRUNTIMESRC core/stdcpp/string.d) */ @@ -32,6 +33,7 @@ pragma(lib, "stdc++"); /////////////////////////////////////////////////////////////////////////////// import core.stdcpp.allocator; +import core.stdc.stddef; extern(C++, std): @@ -45,17 +47,17 @@ struct char_traits(CharT) {} * The basic_string is the generalization of class string for any character * type. */ -struct basic_string(T, TRAITS = char_traits!T, ALLOC = allocator!T) +extern(C++, class) struct basic_string(T, Traits = char_traits!T, Alloc = allocator!T) { - enum size_t npos = size_t.max; + enum size_type npos = size_type.max; alias value_type = T; - alias traits_type = TRAITS; - alias allocator_type = ALLOC; + alias traits_type = Traits; + alias allocator_type = Alloc; alias reference = ref T; alias const_reference = ref const(T); alias pointer = T*; - alias const_pointer = const(T*); + alias const_pointer = const(T)*; alias iterator = pointer; alias const_iterator = const_pointer; // alias reverse_iterator @@ -63,270 +65,143 @@ struct basic_string(T, TRAITS = char_traits!T, ALLOC = allocator!T) alias difference_type = ptrdiff_t; alias size_type = size_t; - // Ctor/dtor - pragma(mangle, "_ZNSsC1Ev") - @disable this(); - - pragma(mangle, "_ZNSsC1ERKSs") - this(ref const this); - - pragma(mangle, "_ZNSsC1EPKcRKSaIcE") - this(const(T*) _, ref const allocator_type _ = defaultAlloc); - - pragma(mangle, "_ZNSsD1Ev") + // ctor/dtor +// pragma(mangle, "_ZNSsC1ERKSs") +// this(ref const(this)); + this(const(T)* ptr, size_type count); + this(const(T)* ptr, size_type count, ref const(allocator_type) al = defaultAlloc); + this(const(T)* ptr); + this(const(T)* ptr, ref const(allocator_type) al = defaultAlloc); + extern(D) this(const(T)[] dstr) { this(dstr.ptr, dstr.length); } + extern(D) this(const(T)[] dstr, ref const(allocator_type) al = defaultAlloc) { this(dstr.ptr, dstr.length); } ~this(); - pragma(mangle, "_ZNSsaSERKSs") - ref basic_string opAssign(ref const basic_string s); + ref basic_string opAssign(ref const(basic_string) s); // Iterators - pragma(mangle, "_ZNSs5beginEv") iterator begin() nothrow; + const_iterator begin() const nothrow; + const_iterator cbegin() const nothrow; - pragma(mangle, "_ZNKSs5beginEv") - const_iterator begin() nothrow const; - - pragma(mangle, "_ZNKSs6cbeginEv") - const_iterator cbegin() nothrow const; - - pragma(mangle, "_ZNSs3endEv") iterator end() nothrow; - - pragma(mangle, "_ZNKSs3endEv") - const_iterator end() nothrow const; - - pragma(mangle, "_ZNKSs4cendEv") - const_iterator cend() nothrow const; + const_iterator end() const nothrow; + const_iterator cend() const nothrow; // no reverse iterator for now. // Capacity - pragma(mangle, "_ZNKSs4sizeEv") - size_t size() nothrow const; - - pragma(mangle, "_ZNKSs6lengthEv") - size_t length() nothrow const; - - pragma(mangle, "_ZNKSs8max_sizeEv") - size_t max_size() nothrow const; + size_type size() const nothrow; + size_type length() const nothrow; + size_type max_size() const nothrow; + size_type capacity() const nothrow; - pragma(mangle, "_ZNKSs8capacityEv") - size_t capacity() nothrow const; + bool empty() const nothrow; - pragma(mangle, "_ZNKSs5emptyEv") - bool empty() nothrow const; - - pragma(mangle, "_ZNSs5clearEv") void clear() nothrow; - - pragma(mangle, "_ZNSs6resizeEm") - void resize(size_t n); - - pragma(mangle, "_ZNSs6resizeEmc") - void resize(size_t n, T c); - - pragma(mangle, "_ZNSs7reserveEm") - void reserve(size_t n = 0); - - pragma(mangle, "_ZNSs13shrink_to_fitEv") + void resize(size_type n); + void resize(size_type n, T c); + void reserve(size_type n = 0); void shrink_to_fit(); // Element access - pragma(mangle, "_ZNSsixEm") - ref T opIndex(size_t i); + ref T opIndex(size_type i); + ref const(T) opIndex(size_type i) const; + ref T at(size_type i); + ref const(T) at(size_type i) const; - pragma(mangle, "_ZNKSsixEm") - ref const(T) opIndex(size_t i) const; - - pragma(mangle, "_ZNSs2atEm") - ref T at(size_t i); - - pragma(mangle, "_ZNKSs2atEm") - ref const(T) at(size_t i) const; - - pragma(mangle, "_ZNSs4backEv") ref T back(); - - pragma(mangle, "_ZNKSs4backEv") ref const(T) back() const; - - pragma(mangle, "_ZNSs5frontEv") ref T front(); - - pragma(mangle, "_ZNKSs5frontEv") ref const(T) front() const; - // Modifiers - pragma(mangle, "_ZNSspLERKSs") - ref basic_string opOpAssign(string op)(ref const basic_string _) if (op == "+"); - - pragma(mangle, "_ZNSspLEPKc") - ref basic_string opOpAssign(string op)(const(T*) _) if (op == "+"); - - pragma(mangle, "_ZNSspLEc") - ref basic_string opOpAssign(string op)(T _) if (op == "+"); - - pragma(mangle, "_ZNSs6appendEmc") - ref basic_string append(size_t n, char c); - - pragma(mangle, "_ZNSs6appendEPKc") - ref basic_string append(const char* s); - - pragma(mangle, "_ZNSs6appendEPKcm") - ref basic_string append(const char* s, size_t n); - - pragma(mangle, "_ZNSs6appendERKSs") - ref basic_string append(ref const basic_string str); + const(T)* c_str() const nothrow; + T* data() nothrow; + const(T)* data() const nothrow; - pragma(mangle, "_ZNSs6appendERKSsmm") - ref basic_string append(ref const basic_string str, size_t subpos, size_t sublen); + // Modifiers + ref basic_string opOpAssign(string op : "+")(ref const(basic_string) s); + ref basic_string opOpAssign(string op : "+")(const(T)* s); + ref basic_string opOpAssign(string op : "+")(T s); + extern(D) ref basic_string opOpAssign(string op : "~")(ref const(basic_string) s) { this += s; return this; } + extern(D) ref basic_string opOpAssign(string op : "~")(const(T)* s) { this += s; return this; } + extern(D) ref basic_string opOpAssign(string op : "~")(const(T)[] s) { auto t = basic_string(s.ptr, s.length); this += t; return this; } + extern(D) ref basic_string opOpAssign(string op : "~")(T s) { this += s; return this; } + + ref basic_string append(size_type n, T c); + ref basic_string append(const(T)* s); + ref basic_string append(const(T)* s, size_type n); + ref basic_string append(ref const(basic_string) str); + ref basic_string append(ref const(basic_string) str, size_type subpos, size_type sublen); + extern(D) ref basic_string append(const(T)[] s) { append(s.ptr, s.length); return this; } - pragma(mangle, "_ZNSs9push_backEc") void push_back(T c); - pragma(mangle, "_ZNSs6assignEmc") - ref basic_string assign(size_t n, char c); - - pragma(mangle, "_ZNSs6assignEPKc") - ref basic_string assign(const char* s); - - pragma(mangle, "_ZNSs6assignEPKcm") - ref basic_string assign(const char* s, size_t n); - - pragma(mangle, "_ZNSs6assignERKSs") - ref basic_string assign(ref const basic_string str); - - pragma(mangle, "_ZNSs6assignERKSsmm") - ref basic_string assign(ref const basic_string str, size_t subpos, size_t sublen); - - pragma(mangle, "_ZNSs6insertEmRKSs") - ref basic_string insert (size_t pos, ref const basic_string str); - - pragma(mangle, "_ZNSs6insertEmRKSsmm") - ref basic_string insert (size_t pos, ref const basic_string str, size_t subpos, size_t sublen); - - pragma(mangle, "_ZNSs6insertEmPKc") - ref basic_string insert (size_t pos, const char* s); + ref basic_string assign(size_type n, T c); + ref basic_string assign(const(T)* s); + ref basic_string assign(const(T)* s, size_type n); + ref basic_string assign(ref const(basic_string) str); + ref basic_string assign(ref const(basic_string) str, size_type subpos, size_type sublen); + extern(D) ref basic_string assign(const(T)[] s) { assign(s.ptr, s.length); return this; } - pragma(mangle, "_ZNSs6insertEmPKcm") - ref basic_string insert (size_t pos, const char* s, size_t n); + ref basic_string insert(size_type pos, ref const(basic_string) str); + ref basic_string insert(size_type pos, ref const(basic_string) str, size_type subpos, size_type sublen); + ref basic_string insert(size_type pos, const(T)* s); + ref basic_string insert(size_type pos, const(T)* s, size_type n); + ref basic_string insert(size_type pos, size_type n, T c); + extern(D) ref basic_string insert(size_type pos, const(T)[] s) { insert(pos, s.ptr, s.length); return this; } - pragma(mangle, "_ZNSs6insertEmmc") - ref basic_string insert (size_t pos, size_t n, char c); - - pragma(mangle, "_ZNSs5eraseEmm") - ref basic_string erase(size_t pos = 0, size_t len = npos); + ref basic_string erase(size_type pos = 0, size_type len = npos); // replace // swap - pragma(mangle, "_ZNSs8pop_backEv") void pop_back(); // String operations - pragma(mangle, "_ZNKSs5c_strEv") - const(T*) c_str() nothrow const; - - pragma(mangle, "_ZNKSs4dataEv") - const(T*) data() nothrow const; - - pragma(mangle, "_ZNKSs4copyEPcmm") - size_t copy(T* s, size_t len, size_t pos = 0) const; - - pragma(mangle, "_ZNKSs4findERKSsm") - size_t find(ref const basic_string str, size_t pos = 0) nothrow const; - - pragma(mangle, "_ZNKSs4findEPKcm") - size_t find(const(T*) s, size_t pos = 0) const; - - pragma(mangle, "_ZNKSs4findEPKcmm") - size_t find(const(T*) s, size_t pos, size_type n) const; - - pragma(mangle, "_ZNKSs4findEcm") - size_t find(T c, size_t pos = 0) nothrow const; - - pragma(mangle, "_ZNKSs5rfindERKSsm") - size_t rfind(ref const basic_string str, size_t pos = npos) nothrow const; - - pragma(mangle, "_ZNKSs5rfindEPKcm") - size_t rfind(const(T*) s, size_t pos = npos) const; - - pragma(mangle, "_ZNKSs5rfindEPKcmm") - size_t rfind(const(T*) s, size_t pos, size_t n) const; - - pragma(mangle, "_ZNKSs5rfindEcm") - size_t rfind(T c, size_t pos = npos) nothrow const; - - pragma(mangle, "_ZNKSs13find_first_ofERKSsm") - size_t find_first_of(ref const basic_string str, size_t pos = 0) nothrow const; - - pragma(mangle, "_ZNKSs13find_first_ofEPKcm") - size_t find_first_of(const(T*) s, size_t pos = 0) const; - - pragma(mangle, "_ZNKSs13find_first_ofEPKcmm") - size_t find_first_of(const(T*) s, size_t pos, size_t n) const; - - pragma(mangle, "_ZNKSs13find_first_ofEcm") - size_t find_first_of(T c, size_t pos = 0) nothrow const; - - pragma(mangle, "_ZNKSs12find_last_ofERKSsm") - size_t find_last_of(ref const basic_string str, size_t pos = npos) nothrow const; - - pragma(mangle, "_ZNKSs12find_last_ofEPKcm") - size_t find_last_of(const(T*) s, size_t pos = npos) const; - - pragma(mangle, "_ZNKSs12find_last_ofEPKcmm") - size_t find_last_of(const(T*) s, size_t pos, size_t n) const; - - pragma(mangle, "_ZNKSs12find_last_ofEcm") - size_t find_last_of(T c, size_t pos = npos) nothrow const; - - pragma(mangle, "_ZNKSs17find_first_not_ofERKSsm") - size_t find_first_not_of(ref const basic_string str, size_t pos = 0) nothrow const; - - pragma(mangle, "_ZNKSs17find_first_not_ofEPKcm") - size_t find_first_not_of(const(T*) s, size_t pos = 0) const; - - pragma(mangle, "_ZNKSs17find_first_not_ofEPKcmm") - size_t find_first_not_of(const(T*) s, size_t pos, size_t n) const; - - pragma(mangle, "_ZNKSs17find_first_not_ofEcm") - size_t find_first_not_of(T c, size_t pos = 0) nothrow const; - - pragma(mangle, "_ZNKSs16find_last_not_ofERKSsm") - size_t find_last_not_of(ref const basic_string str, size_t pos = npos) nothrow const; - - pragma(mangle, "_ZNKSs16find_last_not_ofEPKcm") - size_t find_last_not_of(const(T*) s, size_t pos = npos) const; - - pragma(mangle, "_ZNKSs16find_last_not_ofEPKcmm") - size_t find_last_not_of(const(T*) s, size_t pos, size_t n) const; - - pragma(mangle, "_ZNKSs16find_last_not_ofEcm") - size_t find_last_not_of(T c, size_t pos = npos) nothrow const; - - pragma(mangle, "_ZNKSs6substrEmm") - basic_string substr(size_t pos = 0, size_t len = npos) const; - - pragma(mangle, "_ZNKSs7compareERKSs") - int compare(ref const basic_string str) nothrow const; - - pragma(mangle, "_ZNKSs7compareEmmRKSs") - int compare(size_t pos, size_t len, ref const basic_string str) const; - - pragma(mangle, "_ZNKSs7compareEmmRKSsmm") - int compare(size_t pos, size_t len, ref const basic_string str, size_t subpos, size_t sublen) const; - - pragma(mangle, "_ZNKSs7compareEPKc") - int compare(const(T*) s) const; - - pragma(mangle, "_ZNKSs7compareEmmPKc") - int compare(size_t pos, size_t len, const(T*) s) const; - - pragma(mangle, "_ZNKSs7compareEmmPKcm") - int compare(size_t pos, size_t len, const(T*) s, size_t n) const; + size_type copy(T* s, size_type len, size_type pos = 0) const; + + size_type find(ref const(basic_string) str, size_type pos = 0) const nothrow; + size_type find(const(T)* s, size_type pos = 0) const; + size_type find(const(T)* s, size_type pos, size_type n) const; + size_type find(T c, size_type pos = 0) const nothrow; + + size_type rfind(ref const(basic_string) str, size_type pos = npos) const nothrow; + size_type rfind(const(T)* s, size_type pos = npos) const; + size_type rfind(const(T)* s, size_type pos, size_type n) const; + size_type rfind(T c, size_type pos = npos) const nothrow; + + size_type find_first_of(ref const(basic_string) str, size_type pos = 0) const nothrow; + size_type find_first_of(const(T)* s, size_type pos = 0) const; + size_type find_first_of(const(T)* s, size_type pos, size_type n) const; + size_type find_first_of(T c, size_type pos = 0) const nothrow; + + size_type find_last_of(ref const(basic_string) str, size_type pos = npos) const nothrow; + size_type find_last_of(const(T)* s, size_type pos = npos) const; + size_type find_last_of(const(T)* s, size_type pos, size_type n) const; + size_type find_last_of(T c, size_type pos = npos) const nothrow; + + size_type find_first_not_of(ref const(basic_string) str, size_type pos = 0) const nothrow; + size_type find_first_not_of(const(T)* s, size_type pos = 0) const; + size_type find_first_not_of(const(T)* s, size_type pos, size_type n) const; + size_type find_first_not_of(T c, size_type pos = 0) const nothrow; + + size_type find_last_not_of(ref const(basic_string) str, size_type pos = npos) const nothrow; + size_type find_last_not_of(const(T)* s, size_type pos = npos) const; + size_type find_last_not_of(const(T)* s, size_type pos, size_type n) const; + size_type find_last_not_of(T c, size_type pos = npos) const nothrow; + + basic_string substr(size_type pos = 0, size_type len = npos) const; + + int compare(ref const(basic_string) str) const nothrow; + int compare(size_type pos, size_type len, ref const(basic_string) str) const; + int compare(size_type pos, size_type len, ref const(basic_string) str, size_type subpos, size_type sublen) const; + int compare(const(T)* s) const; + int compare(size_type pos, size_type len, const(T)* s) const; + int compare(size_type pos, size_type len, const(T)* s, size_type n) const; // D helpers - const(T[]) asArray() const { return c_str()[0 .. size()]; } + alias as_array this; + extern(D) T[] as_array() { return data()[0 .. size()]; } + extern(D) const(T)[] as_array() const { return data()[0 .. size()]; } private: void[8] _ = void; // to match sizeof(std::string) and pad the object correctly. @@ -334,4 +209,6 @@ private: } alias basic_string!char std_string; -alias basic_string!wchar std_wstring; +alias basic_string!wchar_t std_wstring; +alias basic_string!wchar std_u16string; +alias basic_string!dchar std_u32string; diff --git a/src/core/stdcpp/vector.d b/src/core/stdcpp/vector.d index d563d964551..8ffcb212e96 100644 --- a/src/core/stdcpp/vector.d +++ b/src/core/stdcpp/vector.d @@ -6,6 +6,7 @@ * $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0). * (See accompanying file LICENSE) * Authors: Guillaume Chatelet + * Manu Evans * Source: $(DRUNTIMESRC core/stdcpp/vector.d) */ @@ -32,14 +33,14 @@ import core.stdcpp.allocator; extern(C++, std): -struct vector(T, ALLOC = allocator!T) +extern(C++, class) struct vector(T, Alloc = allocator!T) { alias value_type = T; - alias allocator_type = ALLOC; + alias allocator_type = Alloc; alias reference = ref T; alias const_reference = ref const(T); alias pointer = T*; - alias const_pointer = const(T*); + alias const_pointer = const(T)*; alias iterator = pointer; alias const_iterator = const_pointer; // alias reverse_iterator @@ -47,111 +48,70 @@ struct vector(T, ALLOC = allocator!T) alias difference_type = ptrdiff_t; alias size_type = size_t; - // Ctor/dtor - pragma(mangle, "_ZNSt6vectorIiSaIiEEC1Ev") - this(); - - pragma(mangle, "_ZNSt6vectorIiSaIiEEC2EmRKS0_") - this(size_type n, ref const allocator_type _ = defaultAlloc); - - pragma(mangle, "_ZNSt6vectorIiSaIiEEC2EmRKiRKS0_") - this(size_type n, ref const value_type val, ref const allocator_type _ = defaultAlloc); - - pragma(mangle, "_ZNSt6vectorIiSaIiEEC2ERKS1_") - this(ref const vector x); - - pragma(mangle, "_ZNSt6vectorIiSaIiEED1Ev") + // ctor/dtor + this(size_type count); + this(size_type count, ref const(value_type) val); + this(size_type count, ref const(value_type) val, ref const(allocator_type) al = defaultAlloc); + this(ref const(vector) x); + this(iterator first, iterator last); + this(iterator first, iterator last, ref const(allocator_type) al = defaultAlloc); + this(const_iterator first, const_iterator last); + this(const_iterator first, const_iterator last, ref const(allocator_type) al = defaultAlloc); + extern(D) this(T[] arr) { this(arr.ptr, arr.ptr + arr.length); } + extern(D) this(T[] arr, ref const(allocator_type) al = defaultAlloc) { this(arr.ptr, arr.ptr + arr.length); } + extern(D) this(const(T)[] arr) { this(arr.ptr, arr.ptr + arr.length); } + extern(D) this(const(T)[] arr, ref const(allocator_type) al = defaultAlloc) { this(arr.ptr, arr.ptr + arr.length); } ~this(); - // pragma(mangle, "_ZNSt6vectorIiSaIiEEaSERKS1_") - // ref vector opAssign(ref const vector s); + ref vector opAssign(ref const(vector) s); // Iterators - pragma(mangle, "_ZNSt6vectorIiSaIiEE5beginEv") iterator begin(); - - pragma(mangle, "_ZNKSt6vectorIiSaIiEE5beginEv") const_iterator begin() const; - - pragma(mangle, "_ZNKSt6vectorIiSaIiEE6cbeginEv") const_iterator cbegin() const; - - pragma(mangle, "_ZNSt6vectorIiSaIiEE3endEv") iterator end(); - - pragma(mangle, "_ZNKSt6vectorIiSaIiEE3endEv") const_iterator end() const; - - pragma(mangle, "_ZNKSt6vectorIiSaIiEE4cendEv") const_iterator cend() const; // no reverse iterator for now. // Capacity - pragma(mangle, "_ZNKSt6vectorIiSaIiEE4sizeEv") - size_t size() const; - - pragma(mangle, "_ZNKSt6vectorIiSaIiEE8max_sizeEv") - size_t max_size() const; - - pragma(mangle, "_ZNKSt6vectorIiSaIiEE8capacityEv") - size_t capacity() const; + size_type size() const; + size_type max_size() const; + size_type capacity() const; - pragma(mangle, "_ZNKSt6vectorIiSaIiEE5emptyEv") bool empty() const; - pragma(mangle, "_ZNSt6vectorIiSaIiEE5clearEv") void clear(); - - pragma(mangle, "_ZNSt6vectorIiSaIiEE6resizeEm") - void resize(size_t n); - - pragma(mangle, "_ZNSt6vectorIiSaIiEE6resizeEmRKi") - void resize(size_t n, T c); - - pragma(mangle, "_ZNSt6vectorIiSaIiEE7reserveEm") - void reserve(size_t n = 0); - - pragma(mangle, "_ZNSt6vectorIiSaIiEE13shrink_to_fitEv") + void resize(size_type n); + void resize(size_type n, T c); + void reserve(size_type n = 0); void shrink_to_fit(); // Element access - pragma(mangle, "_ZNSt6vectorIiSaIiEEixEm") - ref T opIndex(size_t i); - - pragma(mangle, "_ZNKSt6vectorIiSaIiEEixEm") - ref const(T) opIndex(size_t i) const; + T* data() nothrow; + const(T)* data() const nothrow; - pragma(mangle, "_ZNSt6vectorIiSaIiEE2atEm") - ref T at(size_t i); + ref T opIndex(size_type i); + ref const(T) opIndex(size_type i) const; + ref T at(size_type i); + ref const(T) at(size_type i) const; - pragma(mangle, "_ZNKSt6vectorIiSaIiEE2atEm") - ref const(T) at(size_t i) const; - - pragma(mangle, "_ZNSt6vectorIiSaIiEE4backEv") ref T back(); - - pragma(mangle, "_ZNKSt6vectorIiSaIiEE4backEv") ref const(T) back() const; - - pragma(mangle, "_ZNSt6vectorIiSaIiEE5frontEv") ref T front(); - - pragma(mangle, "_ZNKSt6vectorIiSaIiEE5frontEv") ref const(T) front() const; // Modifiers - pragma(mangle, "_ZNSt6vectorIiSaIiEE9push_backEOi") - void push_back(ref const T _); - - pragma(inline, true) - void push_back(const T _) { push_back(_);} // forwards to ref version + void push_back(ref const(T) _); + extern(D) void push_back(const(T) el) { push_back(el); } // forwards to ref version - pragma(mangle, "_ZNSt6vectorIiSaIiEE8pop_backEv") void pop_back(); // D helpers - const(T[]) asArray() const { return c_str()[0 .. size()]; } + alias as_array this; + extern(D) T[] as_array() { return data()[0 .. size()]; } + extern(D) const(T)[] as_array() const { return data()[0 .. size()]; } private: void[24] _ = void; // to match sizeof(std::vector) and pad the object correctly.