#include #include #include #include /* // SF: // template // class Dictionary; // // template // Dictionary // subset(Key const &key, Dictionary const &dict); //FUNCTION template class Dictionary { friend Dictionary subset(Key const &key, Dictionary const &dict); std::map d_dict; public: Dictionary(); }; template Dictionary subset(Key const &key, Dictionary const &dict) { Dictionary 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)); return ret; } //= */ //CLASS1 template class Iterator; template class Dictionary { friend class Iterator; //= std::map d_dict; public: Dictionary(); // uses the friend's constructor template Iterator begin(); template Iterator // uses a member function subset(Key const &key); }; //CLASS2 template template Iterator Dictionary::begin() { return Iterator(*this); } template template Iterator Dictionary::subset(Key const &key) { return Iterator(*this).subset(key); } //= /* //CLASS3 template class Iterator { std::map &d_dict; public: Iterator(Dictionary &dict) : d_dict(dict.d_dict) {} //= */ //CLASS3a template class Iterator { friend Dictionary::Dictionary(); std::map &d_dict; Iterator(Dictionary &dict); public: //= typename std::map::iterator begin(); typename std::map::iterator subset(Key const &key); }; //CLASS4 template typename std::map::iterator Iterator::begin() { return d_dict.begin(); } //= template Iterator::Iterator(Dictionary &dict) : d_dict(dict.d_dict) {} template typename std::map::iterator Iterator::subset(Key const &key) { return d_dict.begin(); }