Skip to content

Commit

Permalink
change internal comment mark to // for cpp files
Browse files Browse the repository at this point in the history
	modified:   uniform_comments_mark.rb
	modified:   ../ch06/ex6_54_55_56.cpp
	modified:   ../ch09/ex9_13.cpp
	modified:   ../ch09/ex9_26.cpp
	modified:   ../ch09/ex9_51.cpp
	modified:   ../ch10/ex10_01_02.cpp
	modified:   ../ch10/ex10_03_04.cpp
	modified:   ../ch10/ex10_12.cpp
	modified:   ../ch10/ex10_16.cpp
	modified:   ../ch10/ex10_18_19.cpp
	modified:   ../ch10/ex10_20_21.cpp
	modified:   ../ch10/ex10_34_35_36_37.cpp
	modified:   ../ch11/ex11_12_13.cpp
	modified:   ../ch11/ex11_18.cpp
	modified:   ../ch11/ex11_20.cpp
	modified:   ../ch11/ex11_24_25_26.cpp
	modified:   ../ch11/ex11_27_28_29_30.cpp
	modified:   ../ch11/ex11_3_4.cpp
	modified:   ../ch11/ex11_7.cpp
	modified:   ../ch11/ex11_9_10.cpp
	modified:   ../ch14/ex14_24.cpp
	modified:   ../ch14/ex14_49.cpp
	modified:   ../ch15/ex15.12.13.14/main.cpp
	modified:   ../ch15/ex15.23.cpp
	modified:   ../ch15/ex15.30/basket.cpp
	modified:   ../ch15/ex15.34.35.36.38/queryresult.cpp
	modified:   ../ch15/ex15.34.35.36.38/textquery.cpp
	modified:   ../ch15/ex15.39.40/andquery.cpp
	modified:   ../ch15/ex15.39.40/notquery.cpp
	modified:   ../ch15/ex15.39.40/orquery.cpp
	modified:   ../ch15/ex15.39.40/queryresult.cpp
	modified:   ../ch15/ex15.39.40/textquery.cpp
	modified:   ../ch15/ex15.4.5.6/main.cpp
	modified:   ../ch15/ex15.42_b/textquery.cpp
	modified:   ../ch15/ex15.42_c/textquery.cpp
	modified:   ../ch15/ex15.7/main.cpp
	modified:   ../ch16/ex16.1.2.3/main.cpp
	modified:   ../ch16/ex16.21.22/wy_queryresult.cpp
	modified:   ../ch16/ex16.21.22/wy_textquery.cpp
	modified:   ../ch16/ex16.37.38.39/main.cpp
	modified:   ../ch16/ex16.47/main.cpp
	modified:   ../ch16/ex16.56.57/main.cpp
	modified:   ../ch16/ex16.58.59/strvec.cpp
	modified:   ../ch16/ex16.62/main.cpp
	modified:   ../ch16/ex16.63.64/main.cpp
	modified:   ../ch16/ex16.7.8/main.cpp
	modified:   ../ch16/ex16.9.10.11/main.cpp
	modified:   ../ch17/ex17.3/textquery.cpp
	modified:   ../ch17/ex17_14_15_16.cpp
	modified:   ../ch17/ex17_19_20.cpp
	modified:   ../ch17/ex17_21.cpp
	modified:   ../ch17/ex17_4_5_6_7_8.cpp
	modified:   ../ch17/ex17_4_5_6_7_8_SalesData.cpp
	modified:   ../ch18/ex18.1.2.3.cpp
	modified:   ../ch18/ex18.12.13.14.cpp
	modified:   ../ch18/ex18.15.16.17.cpp
  • Loading branch information
Mooophy committed Aug 25, 2015
1 parent 41355c7 commit d0840da
Show file tree
Hide file tree
Showing 56 changed files with 271 additions and 273 deletions.
6 changes: 2 additions & 4 deletions .tools/uniform_comments_mark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@
paths.each do |path|
content = File.readlines path
content.each do |line|
if line[0..1] == "//" # to ignore lines with comments at end.
line.sub! "///", "//"
line.sub! "//!", "//"
end
line.sub! "///", "//"
line.sub! "//!", "//"
end
File.open(path, 'w+'){ |file| file.puts content }
end
8 changes: 4 additions & 4 deletions ch06/ex6_54_55_56.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ vector<fp*> v{ NumAdd, NumSub, NumMul, NumDiv };

int main()
{
//!
//! @brief Exercise 6.56
//! @note Call each element in the vector and print their result.
//!
//
// @brief Exercise 6.56
// @note Call each element in the vector and print their result.
//
for (auto it = v.cbegin(); it != v.cend(); ++it)
cout << (*it)(2, 2) << std::endl;

Expand Down
4 changes: 2 additions & 2 deletions ch09/ex9_13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ int main()
list<int> ilst(5, 4);
vector<int> ivc(5, 5);

//! from list<int> to vector<double>
// from list<int> to vector<double>
vector<double> dvc(ilst.begin(), ilst.end());
for (auto i : ilst) cout << i << " ";
cout << endl;
for (auto d : dvc) cout << d << " ";
cout << endl;

//! from vector<int> to vector<double>
// from vector<int> to vector<double>
vector<double> dvc2(ivc.begin(), ivc.end());
for (auto i : ivc) cout << i << " ";
cout << endl;
Expand Down
8 changes: 4 additions & 4 deletions ch09/ex9_26.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ int main()
{
int ia[] = { 0, 1, 1, 2, 3, 5, 8, 13, 21, 55, 89 };

//! init
// init
vector<int> vec(ia, end(ia));
list<int> lst(vec.begin(), vec.end());

//! remove odd value
// remove odd value
for(auto it = lst.begin(); it != lst.end(); )
if(*it & 0x1) it = lst.erase(it);
else ++it;

//! remove even value
// remove even value
for(auto it = vec.begin(); it != vec.end(); )
if(! (*it & 0x1)) it = vec.erase(it);
else ++it;

//! print
// print
cout << "list : ";
for(auto i : lst) cout << i << " ";
cout << "\nvector : ";
Expand Down
6 changes: 3 additions & 3 deletions ch09/ex9_51.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ class My_date{
unsigned format;
format = tag = 0;

//! 1/1/1900
// 1/1/1900
if(s.find_first_of("/")!= string :: npos)
{
format = 0x01;
}

//! January 1,1900 or Jan 1, 1900
// January 1,1900 or Jan 1, 1900
if((s.find_first_of(',') >= 4) && s.find_first_of(',')!= string :: npos){
format = 0x10;
}
else{ //! Jan 1 1900
else{ // Jan 1 1900
if(s.find_first_of(' ') >= 3
&& s.find_first_of(' ')!= string :: npos){
format = 0x10;
Expand Down
4 changes: 2 additions & 2 deletions ch10/ex10_01_02.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

int main()
{
//! 10.1
// 10.1
std::vector<int> v = { 1, 2, 3, 4, 5, 6, 6, 6, 2 };
std::cout << "ex 10.01: " << std::count(v.cbegin(), v.cend(), 6) << std::endl;

//! 10.2
// 10.2
std::list<std::string> l = { "aa", "aaa", "aa", "cc" };
std::cout << "ex 10.02: " << std::count(l.cbegin(), l.cend(), "aa") << std::endl;

Expand Down
20 changes: 10 additions & 10 deletions ch10/ex10_03_04.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@

int main()
{
//! Exercise 10.3
// Exercise 10.3
std::vector<int> v = { 1, 2, 3, 4 };
std::cout << "ex 10.03: " << std::accumulate(v.cbegin(), v.cend(), 0) << std::endl;

//! Exercise 10.4
// Exercise 10.4
std::vector<double> vd = { 1.1, 0.5, 3.3 };
std::cout << "ex 10.04: "
<< std::accumulate(vd.cbegin(), vd.cend(), 0)
<< std::endl; //! ^<-- note here.
//! @attention
//!
//! The ouput is 4 rather than 4.9 as expected.
//! The reason is std::accumulate is a template function. The third parameter is _Tp __init
//! When "0" , an integer, had been specified here, the compiler deduced _Tp as
//! interger.As a result ,when the following statments were being excuted :
<< std::endl; // ^<-- note here.
// @attention
//
// The ouput is 4 rather than 4.9 as expected.
// The reason is std::accumulate is a template function. The third parameter is _Tp __init
// When "0" , an integer, had been specified here, the compiler deduced _Tp as
// interger.As a result ,when the following statments were being excuted :
// for (; __first != __last; ++__first)
// __init = __init + *__first;
// return __init;
//! all calculation would be converted to integer.
// all calculation would be converted to integer.

return 0;
}
4 changes: 2 additions & 2 deletions ch10/ex10_12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ int main()
Sales_data d1("aa"), d2("aaaa"), d3("aaa"), d4("z"), d5("aaaaz");
std::vector<Sales_data> v{d1, d2, d3, d4, d5};

//! @note the elements the iterators pointing to
//! must match the parameters of the predicate.
// @note the elements the iterators pointing to
// must match the parameters of the predicate.
std::sort(v.begin(), v.end(), compareIsbn);

for(const auto &element : v)
Expand Down
8 changes: 4 additions & 4 deletions ch10/ex10_16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ void biggies(std::vector<std::string> &vs, std::size_t sz)

elimdups(vs);

//! sort by size, but maintain alphabetical order for same size.
// sort by size, but maintain alphabetical order for same size.
std::stable_sort(vs.begin(), vs.end(),[](string const& lhs, string const& rhs){
return lhs.size() < rhs.size();
});

//! get an iterator to the first one whose size() is >= sz
// get an iterator to the first one whose size() is >= sz
auto wc = std::find_if(vs.begin(), vs.end(),[sz](string const& s){
return s.size() >= sz;
});

//! print the biggies
// print the biggies
std::for_each(wc, vs.end(), [](const string &s){
std::cout << s << " ";
});
}

int main()
{
//! ex10.16
// ex10.16
std::vector<std::string> v
{
"1234","1234","1234","hi~", "alan", "alan", "cp"
Expand Down
4 changes: 2 additions & 2 deletions ch10/ex10_18_19.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void biggies_stable_partition(std::vector<std::string> &vs, std::size_t sz)

int main()
{
//! ex10.18
// ex10.18
std::vector<std::string> v{
"the", "quick", "red", "fox", "jumps", "over", "the", "slow", "red", "turtle"
};
Expand All @@ -66,7 +66,7 @@ int main()
biggies_partition(v1,4);
std::cout << std::endl;

//! ex10.19
// ex10.19
std::cout << "ex10.19: ";
std::vector<std::string> v2(v);
biggies_stable_partition(v2,4);
Expand Down
4 changes: 2 additions & 2 deletions ch10/ex10_20_21.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ std::size_t bigerThan6(vector<string> const& v)

int main()
{
//! ex10.20
// ex10.20
vector<string> v{
"alan","moophy","1234567","1234567","1234567","1234567"
};
std::cout << "ex10.20: " << bigerThan6(v) << std::endl;

//! ex10.21
// ex10.21
int i = 7;
auto check_and_decrement = [&i](){ return --i ? false : true; };
std::cout << "ex10.21: ";
Expand Down
14 changes: 7 additions & 7 deletions ch10/ex10_34_35_36_37.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ int main()
// 10.37
std::list<int> ret_lst;
std::copy(vec.crbegin() + 3, vec.crbegin() + 8, std::back_inserter(ret_lst));
//! 0,1,2,3,4,5,6,7,8,9
//! ^ ^
//! rend rbegin
//! @note: std::copy copies the range [first,last) into result.
//! hence, the arguments here denote:
//! [6 5 4 3 2 1)
//! ^ this one is specified but not included.
// 0,1,2,3,4,5,6,7,8,9
// ^ ^
// rend rbegin
// @note: std::copy copies the range [first,last) into result.
// hence, the arguments here denote:
// [6 5 4 3 2 1)
// ^ this one is specified but not included.
for (auto i : ret_lst) std::cout << i << " ";
std::cout << std::endl;
}
2 changes: 1 addition & 1 deletion ch11/ex11_12_13.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main()
vec.push_back(std::pair<std::string, int>(str, i));
//vec.push_back(std::make_pair(str, i));
//vec.push_back({str, i});
//vec.emplace_back(str, i); //!!! easiest way.
//vec.emplace_back(str, i); //!! easiest way.

for (const auto &p : vec)
std::cout << p.first << ":" << p.second << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion ch11/ex11_18.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ int main()
{
std::map<std::string, size_t> word_count;

//! the orignal codes:
// the orignal codes:
//auto map_it = word_count.cbegin();


Expand Down
2 changes: 1 addition & 1 deletion ch11/ex11_20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int main()
if(!ret.second) ++ret.first->second;
}

//! print the content of the map.
// print the content of the map.
for(const auto &w : word_count)
std::cout << w.first << " " << w.second
<< ((w.second > 1) ? " times" : " time") << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion ch11/ex11_24_25_26.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

int main()
{
//! ex11.26
// ex11.26
std::map<int, std::string> m = { { 1,"ss" },{ 2,"sz" } };
using KeyType = std::map<int, std::string>::key_type;

Expand Down
2 changes: 1 addition & 1 deletion ch11/ex11_27_28_29_30.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int main()
std::map<std::string, std::vector<int>> m;
m = {{"Alan",{1,2,3,4,5,}},{"John",{1,5,6,7,8}}};

//! ex11.28
// ex11.28
std::map<std::string, std::vector<int>>::iterator it;
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
// type used to define this iterator.
Expand Down
6 changes: 3 additions & 3 deletions ch11/ex11_3_4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ void word_count_pro(std::map<std::string, int> &m)
{
for(auto& ch : word)
ch = tolower(ch);
//! According to the erase-remove idiom.
//! For more information about the erase-remove idiom, please refer to
//! http://en.wikipedia.org/wiki/Erase-remove_idiom
// According to the erase-remove idiom.
// For more information about the erase-remove idiom, please refer to
// http://en.wikipedia.org/wiki/Erase-remove_idiom
word.erase(std::remove_if(word.begin(), word.end(), ispunct), word.end());
++m[word];
}
Expand Down
10 changes: 5 additions & 5 deletions ch11/ex11_7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ int main()

std::string lastName, chldName;

//! while(lambda)
//! go to the discussions on stack overfow for more.
// while(lambda)
// go to the discussions on stack overfow for more.
while([&]() -> bool
{
std::cout << "Please enter last name:\n";
Expand All @@ -38,17 +38,17 @@ int main()
std::cout << "PLZ Enter children's name:\n";
while(std::cin >> chldName && chldName != "@q")
{
//! add new items into the vector
// add new items into the vector
famls[lastName].push_back(chldName);
}
}

//! iterate through the map.
// iterate through the map.
for(auto e : famls)
{
std::cout << e.first << ":\n";

//! iterate through the vector.
// iterate through the vector.
for(auto c : e.second)
std::cout << c << " ";
std::cout << "\n";
Expand Down
10 changes: 5 additions & 5 deletions ch11/ex11_9_10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

int main()
{
//! ex 11.9
// ex 11.9
std::map<std::string, std::list<std::size_t>> m;

//! ex 11.10
//! can be declared.
// ex 11.10
// can be declared.
std::map<std::vector<int>::iterator, int> mv;
std::map<std::list<int>::iterator, int> ml;


std::vector<int> vi;
mv.insert(std::pair<std::vector<int>::iterator, int>(vi.begin(),0));

//! but when using this one the compiler complained that
//! error: no match for 'operator<' in '__x < __y'
// but when using this one the compiler complained that
// error: no match for 'operator<' in '__x < __y'
std::list<int> li;
ml.insert(std::pair<std::list<int>::iterator,int>(li.begin(),0));

Expand Down
Loading

0 comments on commit d0840da

Please sign in to comment.