File: boundfriends.cc

package info (click to toggle)
c%2B%2B-annotations 13.02.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,576 kB
  • sloc: cpp: 25,297; makefile: 1,523; ansic: 165; sh: 126; perl: 90; fortran: 27
file content (126 lines) | stat: -rw-r--r-- 3,280 bytes parent folder | download | duplicates (9)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
    #include <map>
    #include <algorithm>
    #include <functional>
    #include <iterator>

/*
//  SF:
//    template <typename Key, typename Value>
//    class Dictionary;
//
//    template <typename Key, typename Value>
//    Dictionary<Key, Value>
//               subset(Key const &key, Dictionary<Key, Value> const &dict);

//FUNCTION
    template <typename Key, typename Value>
    class Dictionary
    {
        friend Dictionary<Key, Value>
            subset<Key, Value>(Key const &key,
                               Dictionary<Key, Value> const &dict);

        std::map<Key, Value> d_dict;
        public:
            Dictionary();
    };

    template <typename Key, typename Value>
    Dictionary<Key, Value>
               subset(Key const &key, Dictionary<Key, Value> const &dict)
    {
        Dictionary<Key, Value> ret;

        std::remove_copy_if(dict.d_dict.begin(), dict.d_dict.end(),
                            std::inserter(ret.d_dict, ret.d_dict.begin()),
                            std::bind2nd(std::equal_to<Key>(), key));
        return ret;
    }
//=
*/
//CLASS1
    template <typename Key, typename Value>
    class Iterator;

    template <typename Key, typename Value>
    class Dictionary
    {
        friend class Iterator<Key, Value>;
//=
        std::map<Key, Value> d_dict;

        public:
            Dictionary();

                                    // uses the friend's constructor
        template <typename Key2, typename Value2>
        Iterator<Key2, Value2> begin();


        template <typename Key2, typename Value2>
        Iterator<Key2, Value2>        // uses a member function
                    subset(Key const &key);
    };

//CLASS2
    template <typename Key, typename Value>
    template <typename Key2, typename Value2>
    Iterator<Key2, Value2> Dictionary<Key, Value>::begin()
    {
        return Iterator<Key, Value>(*this);
    }
    template <typename Key, typename Value>
    template <typename Key2, typename Value2>
    Iterator<Key2, Value2> Dictionary<Key, Value>::subset(Key const &key)
    {
        return Iterator<Key, Value>(*this).subset(key);
    }
//=

/*
//CLASS3
    template <typename Key, typename Value>
    class Iterator
    {
        std::map<Key, Value> &d_dict;

        public:
            Iterator(Dictionary<Key, Value> &dict)
            :
                d_dict(dict.d_dict)
            {}
//=
*/
//CLASS3a
    template <typename Key, typename Value>
    class Iterator
    {
        friend Dictionary<Key, Value>::Dictionary();
        std::map<Key, Value> &d_dict;
        Iterator(Dictionary<Key, Value> &dict);
        public:
//=
        typename std::map<Key, Value>::iterator begin();
        typename std::map<Key, Value>::iterator subset(Key const &key);
    };

//CLASS4
    template <typename Key, typename Value>
    typename std::map<Key, Value>::iterator Iterator<Key, Value>::begin()
    {
        return d_dict.begin();
    }
//=

    template <typename Key, typename Value>
    Iterator<Key, Value>::Iterator(Dictionary<Key, Value> &dict)
    :
        d_dict(dict.d_dict)
    {}

    template <typename Key, typename Value>
    typename std::map<Key, Value>::iterator
    Iterator<Key, Value>::subset(Key const &key)
    {
        return d_dict.begin();
    }