Skip to content

Commit 360d04e

Browse files
author
tiberius
committed
added MapToFirst implementation
1 parent a2dadb1 commit 360d04e

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

cpp4j/cpp4j.pro

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ HEADERS += \
1616
rationalnumberarray.h \
1717
pair.h \
1818
less.h \
19-
greater.h
19+
greater.h \
20+
maptofirst.h
2021

cpp4j/maptofirst.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef MAPTOFIRST_H
2+
#define MAPTOFIRST_H
3+
4+
#include "pair.h"
5+
6+
// int string less
7+
template <class T1, class T2, template<typename> class Order > class MapToFirst {
8+
9+
public:
10+
11+
//int,string
12+
bool operator ()(const Pair<T1,T2> &left, const Pair<T1,T2> &right){
13+
Order<T1> functor; // less<int>
14+
return functor(left.first(),right.first());
15+
}
16+
17+
18+
};
19+
20+
#endif // MAPTOFIRST_H

cpp4j/testTemplates.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ using namespace std;
1616
#include "pair.h"
1717
#include "less.h"
1818
#include "greater.h"
19+
#include "maptofirst.h"
1920
//#include "order.h"
2021
//#include "tree.h"
2122
//#include "map.h"
@@ -88,14 +89,13 @@ int testTemplates(void)
8889

8990
Greater<string> greaterString;
9091
cout << "Hallo > Welt == " << greaterString("Hallo","Welt") << endl;
92+
assert(!greaterString("Hallo","Welt"));
9193

9294
/////////////////////////////////////////
9395
// TEST PAIR ORDER
9496
MapToFirst< int, float, Less > lessPair;
9597
cout << i_f << " < " << i_f2 << " == " << lessPair(i_f, i_f2) << endl;
96-
97-
#if 0 // move this line down while your implementation proceeds...
98-
98+
assert(lessPair(i_f, i_f2));
9999

100100
/////////////////////////////////////////
101101
// TEST TREE
@@ -105,6 +105,8 @@ int testTemplates(void)
105105
cout << "empty tree: ";
106106
assert(printAndCount(t) == 0);
107107

108+
#if 0 // move this line down while your implementation proceeds...
109+
108110
// insert elements in a certain order
109111
t.insert(4);
110112
t.insert(3);

0 commit comments

Comments
 (0)