diff --git a/Examples/test-suite/c/Makefile.in b/Examples/test-suite/c/Makefile.in index 92773fd7a..b9df15b25 100644 --- a/Examples/test-suite/c/Makefile.in +++ b/Examples/test-suite/c/Makefile.in @@ -65,10 +65,8 @@ FAILING_CPP_TESTS := \ li_boost_shared_ptr_bits \ li_boost_shared_ptr_director \ li_boost_shared_ptr_template \ - li_std_combinations \ li_std_deque \ li_std_map \ - li_std_pair \ li_std_pair_using \ li_std_wstring \ li_windows \ diff --git a/Examples/test-suite/c/li_std_pair_runme.c b/Examples/test-suite/c/li_std_pair_runme.c new file mode 100644 index 000000000..fbd41feea --- /dev/null +++ b/Examples/test-suite/c/li_std_pair_runme.c @@ -0,0 +1,42 @@ +#include "li_std_pair/li_std_pair_wrap.h" +#include + +int main() { + { + IntPair* intPair = makeIntPair(7, 6); + assert(IntPair_first_get(intPair)==7 && IntPair_second_get(intPair)==6); + + assert(product1(intPair) == 42); + assert(product2(intPair) == 42); + assert(product3(intPair) == 42); + + IntPair_delete(intPair); + } + + { + IntPair* intPairPtr = makeIntPairPtr(7, 6); + assert(IntPair_first_get(intPairPtr)==7 && IntPair_second_get(intPairPtr)==6); + + assert(product1(intPairPtr) == 42); + assert(product2(intPairPtr) == 42); + assert(product3(intPairPtr) == 42); + } + + { + IntPair* intPairRef = makeIntPairRef(7, 6); + assert(IntPair_first_get(intPairRef)==7 && IntPair_second_get(intPairRef)==6); + + assert(product1(intPairRef) == 42); + assert(product2(intPairRef) == 42); + assert(product3(intPairRef) == 42); + } + + { + IntPair* intPairConstRef = makeIntPairConstRef(7, 6); + assert(IntPair_first_get(intPairConstRef)==7 && IntPair_second_get(intPairConstRef)==6); + + assert(product1(intPairConstRef) == 42); + assert(product2(intPairConstRef) == 42); + assert(product3(intPairConstRef) == 42); + } +} diff --git a/Lib/c/std_pair.i b/Lib/c/std_pair.i index 82ca45c1a..f6e1c7c81 100644 --- a/Lib/c/std_pair.i +++ b/Lib/c/std_pair.i @@ -1 +1,24 @@ -%include +%{ +#include +%} + +// Ideal, especially for the simple/primitive types, would be to represent +// pair as a C struct with the 2 fields, but for now we use the simplest +// possible implementation, with the accessor functions required to work with +// the fields. + +namespace std { + template struct pair { + typedef T first_type; + typedef U second_type; + + pair(); + pair(T first, U second); + pair(const pair& other); + + template pair(const pair &other); + + T first; + U second; + }; +}