forked from Mooophy/Cpp-Primer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
46 lines (39 loc) · 1.38 KB
/
main.cpp
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
/***************************************************************************
* @file main.cpp
* @author Alan.W
* @date 01 Feb 2014
* @remark This code is for the exercises from C++ Primer 5th Edition
* @note
***************************************************************************/
//
// Exercise 15.39:
// Implement the Query and Query_base classes. Test your application by
// evaluating and printing a query such as the one in Figure 15.3 (p. 638).
//
// Exercise 15.40:
// In the OrQuery eval function what would happen if its rhs member returned
// an empty set? What if its lhs member did so? What if both rhs and lhs
// returned empty sets?
// Nothing special will happen. The codes as following:
// std::shared_ptr<std::set<line_no>> ret_lines =
// std::make_shared<std::set<line_no>>(left.begin(), left.end());
// ^^^^^^^^^^^^^^^^
// Since std::make_shared will allocate dynamically a new std::set, nothing will
// be added into this std::set if any set is empty.The codes in main function
// proves this.
//
#include <iostream>
#include <string>
#include <vector>
#include <memory>
#include <fstream>
#include "textquery.h"
#include "query.h"
int main()
{
std::ifstream file("test.txt");
TextQuery tQuery(file);
Query q = Query("fieryzzz") | Query("wind");
std::cout << q.eval(tQuery);
return 0;
}