diff --git a/source/stdcpp/list.d b/source/stdcpp/list.d index c86267e..5472729 100644 --- a/source/stdcpp/list.d +++ b/source/stdcpp/list.d @@ -29,6 +29,12 @@ else alias listNamespace = StdNamespace; } +//to set up interfaces common to both gcc and microsoft but not with clang runtime +version(CppRuntime_Gcc) + version = NonClang; +else version(CppRuntime_Microsoft) + version = NonClang; + enum def {value}; //for later use extern(C++, (listNamespace)): @@ -40,41 +46,84 @@ extern(C++, class) struct list(Type, Allocator) /// alias value_type = Type; - /// alias allocator_type = Allocator; - /// alias size_type = size_t; - /// alias pointer = Type*; - /// alias const_pointer = const(Type)*; - /// alias difference_type = ptrdiff_t; - /// ref list opAssign(); - /// @disable this() @safe pure nothrow @nogc scope; + //allocator ctor + this(ref const allocator!Type); + + /// Copy constructor + this(ref const list __x); + /// + extern(D) void assign(size_type n, const value_type item) + { + this.assign(n, item); + } + /// + void assign(size_type count, ref const value_type value); + /// + extern(D) void push_back(const Type item) + { + this.push_back(item); + } + /// + void push_back(ref const Type val); + /// + extern(D) void push_front(const Type item) + { + this.push_front(item); + } + /// + void push_front(ref const value_type val); + /// + void pop_front(); + /// + void pop_back(); + /// + void resize(size_type count); + + version(NonClang) + { + /// + ref inout(value_type) back() inout; + /// + ref inout(value_type) front() inout; + } + version (CppRuntime_Gcc) { - version (GLIBCXX_USE_CXX98_ABI) + extern(D) void remove(const value_type item) + { + this.remove(item); + } + /// + void remove(const ref value_type val); + /// + private struct node { - //allocator ctor - this(ref const allocator!Type); + node* prev; + node* next; + } + + private node A; + version (GLIBCXX_USE_CXX98_ABI) + { //list(n,value) ctor until c++11 this(size_type __n, ref const value_type value, ref const allocator!Type); - /// Copy constructor - this(ref const list!Type __x); - extern(D) this(size_type n) { value_type type_instance = value_type.init; @@ -82,39 +131,11 @@ extern(C++, class) struct list(Type, Allocator) this(n, type_instance, alloc_instance); } - extern(D) void assign(size_type n, const value_type item) - { - this.assign(n, item); - } - - extern(D) void push_back(const Type item) - { - this.push_back(item); - } - - extern(D) void push_front(const Type item) - { - this.push_front(item); - } - - extern(D) void remove(const value_type item) - { - this.remove(item); - } - - void assign(size_type count, ref const value_type value); - - ref list opAssign(ref const list!Type other); + ref list opAssign(ref const list other); //just const until c++11 allocator_type get_allocator() const; - ref value_type front(); - -// const(value_type) ref front() const; - - ref value_type back(); - pointer begin(); pointer end(); @@ -130,22 +151,12 @@ extern(C++, class) struct list(Type, Allocator) //insert halted for now - void push_back(ref const Type val); - - void pop_back(); - - void push_front(ref const value_type val); - - void pop_front(); - void swap(ref const list!Type other); void merge( ref const list!Type other); void merge(U)(ref const list!Type other, U comp); - void remove(const ref value_type val); - void reverse(); void sort(); @@ -153,29 +164,9 @@ extern(C++, class) struct list(Type, Allocator) size_type unique(); void sort(U)(U comp); - - private struct node - { - node* prev; - node* next; - } - // pre-c++11 doesn't keep track of its size - private node A; } else // !GLIBCXX_USE_CXX98_ABI { - this(def) - { - allocator!Type alloc_instance = allocator!(Type).init; - this(alloc_instance); - } - - //allocator ctor - this(ref const allocator!Type); - - // Copy constructor - this(ref const list!Type __x); - //list(n,value) ctor this(size_type __n, ref const value_type value, ref const allocator!Type); @@ -185,7 +176,7 @@ extern(C++, class) struct list(Type, Allocator) this(n, element, alloc_instance); } - this(ref const list!Type other, ref const allocator!Type); + this(ref const list other, ref const allocator!Type); //list(n) ctor this(size_type __n, ref const allocator!Type); @@ -196,42 +187,18 @@ extern(C++, class) struct list(Type, Allocator) this(n, alloc_instance); } - extern(D) void assign(size_type n, const value_type item) - { - this.assign(n, item); - } - - extern(D) void push_back(const Type item) - { - this.push_back(item); - } - - extern(D) void push_front(const Type item) - { - this.push_front(item); - } - extern(D) void resize(size_type n, const value_type item) { this.resize(n, item); } - extern(D) void remove(const value_type item) - { - this.remove(item); - } - - ref list opAssign(ref const list!Type other); + ref list opAssign(ref const list other); void assign(size_type count, ref const value_type value); //const nothrow since C++11 allocator_type get_allocator() const nothrow; - ref value_type front(); - - ref value_type back(); - pointer begin() nothrow; pointer end() nothrow; @@ -243,57 +210,29 @@ extern(C++, class) struct list(Type, Allocator) void clear() nothrow; - void push_back(ref const Type val); - - void pop_back(); - - void push_front(ref const value_type val); - - void pop_front(); - - void resize(size_type count); - void resize(size_type count, ref const value_type val); - void swap(ref const list!Type other) nothrow; + void swap(ref const list other) nothrow; - void merge( ref const list!Type other); - - void merge(U)(ref const list!Type other, U comp); + void merge( ref const list other); - void remove(const ref value_type val); + void merge(U)(ref const list other, U comp); void reverse() nothrow; void sort(); - void sort(U)(U comp); - - void unique(); - - void unique(U)(U p); + //todo: add sort(U)() size_type unique(); - size_type unique(U)(U p); + // todo: add size_type unique(U)(U p); - private struct node - { - node* prev; - node* next; - } - private node A; private size_type _M_size; //new list keeps track of it's size } } else version (CppRuntime_Clang) { - /// - this(ref const allocator!Type); - - /// Copy constructor - this(ref const list!Type __x); - this(size_type __n, ref const value_type value); /// extern(D) this(size_type n, const value_type element) @@ -307,23 +246,9 @@ extern(C++, class) struct list(Type, Allocator) /// this(size_type n); /// + ~this(); - /// - extern(D) void assign(size_type n, const value_type item) - { - this.assign(n, item); - } - /// - extern(D) void push_back(const Type item) - { - this.push_back(item); - } - /// - extern(D) void push_front(const Type item) - { - this.push_front(item); - } - /// + extern(D) void resize(size_type n, const value_type item) { this.resize(n, item); @@ -336,8 +261,6 @@ extern(C++, class) struct list(Type, Allocator) /// ref list opAssign(ref const list!Type other); /// - void assign(size_type count, ref const value_type value); - /// allocator_type get_allocator() const nothrow; /// ref value_type front() @@ -371,23 +294,13 @@ extern(C++, class) struct list(Type, Allocator) base.clear(); } - void push_back(ref const Type val); - /// - void pop_back(); - - void push_front(ref const value_type val); - /// - void pop_front(); - - void resize(size_type count); - void resize(size_type count, ref const value_type val); - void swap(ref const list!Type other) nothrow; + void swap(ref const list other) nothrow; - void merge( ref const list!Type other); + void merge( ref const list other); - void merge(U)(ref const list!Type other, U comp); + void merge(U)(ref const list other, U comp); void remove(const ref value_type val); @@ -395,21 +308,17 @@ extern(C++, class) struct list(Type, Allocator) void sort(); - void sort(U)(U comp); + // todo: void sort(U)(U comp); - void unique(); + size_type unique(); - void unique(U)(U p); + //todo: size_type unique(U)(U p); private __list_imp!(value_type, allocator!Type) base; } else version(CppRuntime_Microsoft) { - this(ref const allocator!Type); - - this(ref const list!Type __x); - this(size_type __n, ref const value_type value, ref const allocator!Type); extern(D) this(size_type n, const value_type element) @@ -424,23 +333,6 @@ extern(C++, class) struct list(Type, Allocator) this(size_type n); - ~this(); - - extern(D) void assign(size_type n, const value_type item) - { - this.assign(n, item); - } - - extern(D) void push_back(const Type item) - { - this.push_back(item); - } - - extern(D) void push_front(const Type item) - { - this.push_front(item); - } - extern(D) void resize(size_type n, const value_type item) { this.resize(n, item); @@ -448,14 +340,8 @@ extern(C++, class) struct list(Type, Allocator) ref list opAssign(ref const list!Type other); - void assign(size_type count, ref const value_type value); - allocator_type get_allocator() const nothrow; - ref value_type front(); - - ref value_type back(); - pointer begin() nothrow; pointer end() nothrow; @@ -466,37 +352,25 @@ extern(C++, class) struct list(Type, Allocator) void clear() nothrow; - void push_back(ref const Type val); - - void pop_back(); - - void push_front(ref const value_type val); - - void pop_front(); - - void resize(size_type count); - void resize(size_type count, ref const value_type val); - void swap(ref list!Type other) nothrow; + void swap(ref list other) nothrow; - void merge( ref list!Type other); + void merge( ref list other); - void merge(U)(ref list!Type other, U comp); + // todo: void merge(U)(ref list other, U comp); void reverse() nothrow; void sort(); - void sort(U)(U comp); - - void unique(); - - void unique(U)(U p); + //todo: void sort(U)(U comp); size_type unique(); - size_type unique(U)(U p); + ~this(); + + //todo :size_type unique(U)(U p); private struct node {