Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.
/ druntime Public archive
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mak/COPY
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 1 addition & 0 deletions mak/DOCS
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
65 changes: 65 additions & 0 deletions src/core/stdcpp/stl_pair.d
Original file line number Diff line number Diff line change
@@ -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);}

}
}