From 2f2317552c1fb3ba6e164edc90eb882e47f7f47a Mon Sep 17 00:00:00 2001 From: Alexandru Razvan Caciulescu Date: Thu, 30 Mar 2017 22:51:01 +0300 Subject: [PATCH] WIP: stl_pair --- mak/COPY | 1 + mak/DOCS | 1 + src/core/stdcpp/stl_pair.d | 65 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 src/core/stdcpp/stl_pair.d diff --git a/mak/COPY b/mak/COPY index 3b5fa33d98..44b4e349ad 100644 --- a/mak/COPY +++ b/mak/COPY @@ -46,6 +46,7 @@ COPY=\ \ $(IMPDIR)\core\stdcpp\typeinfo.d \ $(IMPDIR)\core\stdcpp\exception.d \ + $(IMPDIR)\core\stdcpp\stl_pair.d \ \ $(IMPDIR)\core\sys\darwin\execinfo.d \ $(IMPDIR)\core\sys\darwin\pthread.d \ diff --git a/mak/DOCS b/mak/DOCS index c7f630d1ca..b2beccf308 100644 --- a/mak/DOCS +++ b/mak/DOCS @@ -38,6 +38,7 @@ DOCS=\ \ $(DOCDIR)\core_stdcpp_exception.html \ $(DOCDIR)\core_stdcpp_typeinfo.html \ + $(DOCDIR)\core_stdcpp_stl_pair.html \ \ $(DOCDIR)\core_sync_barrier.html \ $(DOCDIR)\core_sync_condition.html \ diff --git a/src/core/stdcpp/stl_pair.d b/src/core/stdcpp/stl_pair.d new file mode 100644 index 0000000000..be535b0796 --- /dev/null +++ b/src/core/stdcpp/stl_pair.d @@ -0,0 +1,65 @@ +module core.stdcpp.stl_pair; + +version (CRuntime_Glibc) { + extern (C++, std) struct pair(T1, T2) { + + alias first_type = T1; + alias second_type = T2; + + T1 first; + T2 second; + + this(T1 x, T2 y) { first = x; second = y; } + + this(U1, U2)(auto ref U1 x, auto ref U2 y) { + if (isConvertible!(U1, T1) && isConvertible!(U2, T2)) { + first = x; + second = y; + } + } + + this(U1, U2)(auto ref pair!(U1, U2) p) { + first = p.first; second = p.second; + } + + this(U1, U2)(auto ref const pair!(U1, U2) p) { + first = p.first; second = p.second; + } + + void swap(ref pair rhs); + + void opAssign(U1, U2)(auto ref pair!(U1, U2) rhs) { + first = rhs.first; + second = rhs.second; + } + + void opAssign(U1, U2)(auto ref const pair!(U1, U2) rhs) { + first = rhs.first; + second = rhs.second; + } + + bool opEquals(P)(auto ref P rhs) { + return first == rhs.first && second == rhs.second; + } + + bool opEquals(P)(auto ref P rhs) const { + return first == rhs.first && second == rhs.second; + } + + int opCmp(P)(auto ref P rhs) { + if (first < rhs.first) return -1; + if (first > rhs.first) return 1; + return second < rhs.second ? -1 : second > rhs.second; + } + int opCmp(P)(auto ref P rhs) const { + if (first < rhs.first) return -1; + if (first > rhs.first) return 1; + return second < rhs.second ? -1 : second > rhs.second; + } + + // WIP: attempt just link without implementation, mangling issues + pair!(T1, T2) make_pair(T1, T2)(auto ref T1 v1, auto ref T2 v2) + { return pair!(T1, T2)(v1, v2);} + + } +}