习题12-31
如果用vector会有重复的行号,用set比较好,不会重复显示;
习题12-32
替换一下就行
class TextQuery
{
public:
TextQuery(ifstream &in);
QueryResult query(const string &str) const;
private:
shared_ptr<strBlob> data;
map<string, shared_ptr<set<line_no>>> wm;
};
class QueryResult
{
friend ostream &print(ostream &, const QueryResult&);
public:
QueryResult(string s, shared_ptr<set<line_no>> p, shared_ptr<strBlob> f) :
sought(s), lines(p), file(f) { }
private:
string sought;
shared_ptr<set<line_no>> lines;
shared_ptr<strBlob> file;
};
习题12-33
using Iter = std::set<line_no>::iterator;
Iter begin() { return lines->begin(); }
Iter end() { return lines->end(); }
shared_ptr<vector<string>> get_file()
{
return make_shared<vector<string>>(file);
}