Add trivial but working std::pair typemaps implementation
The existing typemaps didn't work at all and making them work would require defining all the typemaps needed by the Unified Typemaps Library, which seems to be geared towards dynamic languages. Just implement completely straightforward (and not very convenient to use) typemaps instead. Enable the now passing unit tests and add a runme for one of them.
This commit is contained in:
parent
c6efb0b8e6
commit
fc1ebd7c18
3 changed files with 66 additions and 3 deletions
|
|
@ -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 \
|
||||
|
|
|
|||
42
Examples/test-suite/c/li_std_pair_runme.c
Normal file
42
Examples/test-suite/c/li_std_pair_runme.c
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include "li_std_pair/li_std_pair_wrap.h"
|
||||
#include <assert.h>
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
@ -1 +1,24 @@
|
|||
%include <std/std_pair.i>
|
||||
%{
|
||||
#include <utility>
|
||||
%}
|
||||
|
||||
// Ideal, especially for the simple/primitive types, would be to represent
|
||||
// pair<T,U> 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 <class T, class U> struct pair {
|
||||
typedef T first_type;
|
||||
typedef U second_type;
|
||||
|
||||
pair();
|
||||
pair(T first, U second);
|
||||
pair(const pair& other);
|
||||
|
||||
template <class T2, class U2> pair(const pair<T2, U2> &other);
|
||||
|
||||
T first;
|
||||
U second;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue