language: C++ 4.7.2 (gcc-4.7.2)
date: 837 days 20 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <map>
#include <string>
#include <cstdio>
 
using namespace std;
 
#define WITH_TEMPLATE 1
 
#ifdef WITH_TEMPLATE
template <class C>
struct MyClass : public map<string, C>
#else
struct MyClass : public map<string, int>
#endif
{
    bool haskey(const string &s)
    {
#ifdef WITH_TEMPLATE
        typename MyClass<C>::iterator it = this->find(s);
        return (it != this->end());
#else
        iterator it = find(s);
        return (it != end());
#endif
    }
};
 
int main()
{
#ifdef WITH_TEMPLATE
    MyClass<int> m;
#else
    MyClass m;
#endif
    m["test"] = 10;    
    printf("%d %d\n", m.haskey("test"), m.haskey("no"));
}