From 48aec46738bca191de9863f9ad5989a9b1429af0 Mon Sep 17 00:00:00 2001 From: Mooophy Date: Sun, 30 Aug 2015 12:33:55 +1200 Subject: [PATCH] format {foo} => { foo } modified: format.rb modified: ../ch03/README.md modified: ../ch04/README.md modified: ../ch05/README.md modified: ../ch05/ex5_14.cpp modified: ../ch05/ex5_17.cpp modified: ../ch06/README.md modified: ../ch06/ex6_23.cpp modified: ../ch07/README.md modified: ../ch07/ex7_11.h modified: ../ch07/ex7_12.h modified: ../ch07/ex7_15.h modified: ../ch07/ex7_21.h modified: ../ch07/ex7_22.h modified: ../ch07/ex7_23.h modified: ../ch07/ex7_24.h modified: ../ch07/ex7_26.h modified: ../ch07/ex7_27.h modified: ../ch07/ex7_32.h modified: ../ch07/ex7_50.h modified: ../ch09/README.md modified: ../ch09/ex9_41.cpp modified: ../ch09/ex9_47_1.cpp modified: ../ch09/ex9_47_2.cpp modified: ../ch09/ex9_52.cpp modified: ../ch10/README.md modified: ../ch10/ex10_05.cpp modified: ../ch10/ex10_12.cpp modified: ../ch10/ex10_17.cpp modified: ../ch10/ex10_22.cpp modified: ../ch10/ex10_27.cpp modified: ../ch10/ex10_28.cpp modified: ../ch10/ex10_32.cpp modified: ../ch11/README.md modified: ../ch11/ex11_12_13.cpp modified: ../ch11/ex11_20.cpp modified: ../ch11/ex11_27_28_29_30.cpp modified: ../ch11/ex11_31.cpp modified: ../ch11/ex11_32.cpp modified: ../ch11/ex11_8.cpp modified: ../ch12/README.md modified: ../ch12/ex12_02_TEST.cpp modified: ../ch12/ex12_06.cpp modified: ../ch12/ex12_15.cpp modified: ../ch12/ex12_17_18.cpp modified: ../ch12/ex12_19.h modified: ../ch12/ex12_22.h modified: ../ch12/ex12_23.cpp modified: ../ch12/ex12_24.cpp modified: ../ch12/ex12_27_30.cpp modified: ../ch12/ex12_27_30.h modified: ../ch12/ex12_28.cpp modified: ../ch12/ex12_32.cpp modified: ../ch12/ex12_32.h modified: ../ch12/ex12_33.cpp modified: ../ch12/ex12_33.h modified: ../ch13/README.md modified: ../ch13/ex13_13.cpp modified: ../ch13/ex13_26.h modified: ../ch13/ex13_28.h modified: ../ch13/ex13_34_36_37.h modified: ../ch13/ex13_39.h modified: ../ch13/ex13_40.h modified: ../ch13/ex13_42_StrVec.h modified: ../ch13/ex13_42_TextQuery.h modified: ../ch13/ex13_44_47.h modified: ../ch13/ex13_49_Message.h modified: ../ch13/ex13_49_StrVec.h modified: ../ch13/ex13_49_String.h modified: ../ch14/ex14_02.h modified: ../ch14/ex14_07.h modified: ../ch14/ex14_16_StrBlob.h modified: ../ch14/ex14_16_StrVec.h modified: ../ch14/ex14_16_String.h modified: ../ch14/ex14_18_StrBlob.h modified: ../ch14/ex14_18_StrVec.h modified: ../ch14/ex14_18_StrVecMain.cpp modified: ../ch14/ex14_18_String.h modified: ../ch14/ex14_22.h modified: ../ch14/ex14_23.h modified: ../ch14/ex14_24.cpp modified: ../ch14/ex14_24.h modified: ../ch14/ex14_26_StrBlob.h modified: ../ch14/ex14_26_StrVec.h modified: ../ch14/ex14_26_String.h modified: ../ch14/ex14_27_28_StrBlob.h modified: ../ch14/ex14_30_StrBlob.h modified: ../ch14/ex14_32.cpp modified: ../ch14/ex14_32.h modified: ../ch14/ex14_37.cpp modified: ../ch14/ex14_38_39.cpp modified: ../ch14/ex14_40.cpp modified: ../ch14/ex14_42.cpp modified: ../ch14/ex14_44.cpp modified: ../ch14/ex14_45.h modified: ../ch14/ex14_49.cpp modified: ../ch14/ex14_49.h modified: ../ch15/ex15.23.cpp modified: ../ch15/ex15.26/bulk_quote.h modified: ../ch15/ex15.27/bulk_quote.h modified: ../ch15/ex15.28.29/bulk_quote.h modified: ../ch15/ex15.30/basket.h modified: ../ch15/ex15.30/bulk_quote.h modified: ../ch15/ex15.30/quote.h modified: ../ch15/ex15.31.32.33.cpp modified: ../ch15/ex15.42_b/andquery.h modified: ../ch15/ex15.42_b/binaryquery.h modified: ../ch15/ex15.42_b/notquery.h modified: ../ch15/ex15.42_b/orquery.h modified: ../ch15/ex15.42_b/query.h modified: ../ch15/ex15.42_b/queryresult.h modified: ../ch15/ex15.42_b/wordquery.h modified: ../ch15/ex15.42_c/andquery.h modified: ../ch15/ex15.42_c/binaryquery.h modified: ../ch15/ex15.42_c/notquery.h modified: ../ch15/ex15.42_c/orquery.h modified: ../ch15/ex15.42_c/query.h modified: ../ch15/ex15.42_c/queryresult.h modified: ../ch15/ex15.42_c/wordquery.h modified: ../ch16/ex16.1.2.3/main.cpp modified: ../ch16/ex16.12.13/Blob.h modified: ../ch16/ex16.16/main.cpp modified: ../ch16/ex16.16/vec.h modified: ../ch16/ex16.24/Blob.h modified: ../ch16/ex16.24/main.cpp modified: ../ch16/ex16.28/shared_pointer.hpp modified: ../ch16/ex16.28/unique_pointer.h modified: ../ch16/ex16.29/Blob.h modified: ../ch16/ex16.29/shared_pointer.h modified: ../ch16/ex16.29/unique_pointer.h modified: ../ch16/ex16.40/main.cpp modified: ../ch16/ex16.58.59/strvec.h modified: ../ch16/ex16.58.59/vec.h modified: ../ch16/ex16.6/main.cpp modified: ../ch16/ex16.60.61/main.cpp modified: ../ch16/ex16.7.8/main.cpp modified: ../ch17/ex17_10.cpp modified: ../ch17/ex17_11_12_13.cpp modified: ../ch17/ex17_19_20.cpp modified: ../ch17/ex17_21.cpp modified: ../ch17/ex17_23.cpp modified: ../ch17/ex17_33.cpp modified: ../ch17/ex17_4_5_6_7_8.cpp modified: ../ch17/ex17_4_5_6_7_8_SalesData.h modified: ../ch18/ex18.1.2.3.cpp --- .tools/format.rb | 21 ++++++++++++++++++--- ch03/README.md | 12 ++++++------ ch04/README.md | 2 +- ch05/README.md | 4 ++-- ch05/ex5_14.cpp | 2 +- ch05/ex5_17.cpp | 4 ++-- ch06/README.md | 2 +- ch06/ex6_23.cpp | 2 +- ch07/README.md | 4 ++-- ch07/ex7_11.h | 4 ++-- ch07/ex7_12.h | 6 +++--- ch07/ex7_15.h | 4 ++-- ch07/ex7_21.h | 6 +++--- ch07/ex7_22.h | 4 ++-- ch07/ex7_23.h | 2 +- ch07/ex7_24.h | 4 ++-- ch07/ex7_26.h | 4 ++-- ch07/ex7_27.h | 4 ++-- ch07/ex7_32.h | 4 ++-- ch07/ex7_50.h | 4 ++-- ch09/README.md | 12 ++++++------ ch09/ex9_41.cpp | 2 +- ch09/ex9_47_1.cpp | 6 +++--- ch09/ex9_47_2.cpp | 6 +++--- ch09/ex9_52.cpp | 2 +- ch10/README.md | 4 ++-- ch10/ex10_05.cpp | 2 +- ch10/ex10_12.cpp | 2 +- ch10/ex10_17.cpp | 2 +- ch10/ex10_22.cpp | 2 +- ch10/ex10_27.cpp | 2 +- ch10/ex10_28.cpp | 2 +- ch10/ex10_32.cpp | 2 +- ch11/README.md | 8 ++++---- ch11/ex11_12_13.cpp | 2 +- ch11/ex11_20.cpp | 2 +- ch11/ex11_27_28_29_30.cpp | 2 +- ch11/ex11_31.cpp | 12 ++++++------ ch11/ex11_32.cpp | 12 ++++++------ ch11/ex11_8.cpp | 2 +- ch12/README.md | 2 +- ch12/ex12_02_TEST.cpp | 4 ++-- ch12/ex12_06.cpp | 2 +- ch12/ex12_15.cpp | 2 +- ch12/ex12_17_18.cpp | 4 ++-- ch12/ex12_19.h | 2 +- ch12/ex12_22.h | 2 +- ch12/ex12_23.cpp | 2 +- ch12/ex12_24.cpp | 2 +- ch12/ex12_27_30.cpp | 2 +- ch12/ex12_27_30.h | 2 +- ch12/ex12_28.cpp | 2 +- ch12/ex12_32.cpp | 2 +- ch12/ex12_32.h | 2 +- ch12/ex12_33.cpp | 2 +- ch12/ex12_33.h | 2 +- ch13/README.md | 4 ++-- ch13/ex13_13.cpp | 4 ++-- ch13/ex13_26.h | 4 ++-- ch13/ex13_28.h | 6 +++--- ch13/ex13_34_36_37.h | 2 +- ch13/ex13_39.h | 2 +- ch13/ex13_40.h | 2 +- ch13/ex13_42_StrVec.h | 2 +- ch13/ex13_42_TextQuery.h | 2 +- ch13/ex13_44_47.h | 2 +- ch13/ex13_49_Message.h | 8 ++++---- ch13/ex13_49_StrVec.h | 2 +- ch13/ex13_49_String.h | 2 +- ch14/ex14_02.h | 6 +++--- ch14/ex14_07.h | 2 +- ch14/ex14_16_StrBlob.h | 16 ++++++++-------- ch14/ex14_16_StrVec.h | 2 +- ch14/ex14_16_String.h | 2 +- ch14/ex14_18_StrBlob.h | 16 ++++++++-------- ch14/ex14_18_StrVec.h | 2 +- ch14/ex14_18_StrVecMain.cpp | 2 +- ch14/ex14_18_String.h | 2 +- ch14/ex14_22.h | 6 +++--- ch14/ex14_23.h | 2 +- ch14/ex14_24.cpp | 4 ++-- ch14/ex14_24.h | 4 ++-- ch14/ex14_26_StrBlob.h | 16 ++++++++-------- ch14/ex14_26_StrVec.h | 2 +- ch14/ex14_26_String.h | 2 +- ch14/ex14_27_28_StrBlob.h | 16 ++++++++-------- ch14/ex14_30_StrBlob.h | 16 ++++++++-------- ch14/ex14_32.cpp | 2 +- ch14/ex14_32.h | 2 +- ch14/ex14_37.cpp | 4 ++-- ch14/ex14_38_39.cpp | 2 +- ch14/ex14_40.cpp | 4 ++-- ch14/ex14_42.cpp | 4 ++-- ch14/ex14_44.cpp | 2 +- ch14/ex14_45.h | 6 +++--- ch14/ex14_49.cpp | 4 ++-- ch14/ex14_49.h | 4 ++-- ch15/ex15.23.cpp | 10 +++++----- ch15/ex15.26/bulk_quote.h | 2 +- ch15/ex15.27/bulk_quote.h | 2 +- ch15/ex15.28.29/bulk_quote.h | 2 +- ch15/ex15.30/basket.h | 2 +- ch15/ex15.30/bulk_quote.h | 6 +++--- ch15/ex15.30/quote.h | 4 ++-- ch15/ex15.31.32.33.cpp | 2 +- ch15/ex15.42_b/andquery.h | 2 +- ch15/ex15.42_b/binaryquery.h | 2 +- ch15/ex15.42_b/notquery.h | 2 +- ch15/ex15.42_b/orquery.h | 2 +- ch15/ex15.42_b/query.h | 4 ++-- ch15/ex15.42_b/queryresult.h | 2 +- ch15/ex15.42_b/wordquery.h | 2 +- ch15/ex15.42_c/andquery.h | 2 +- ch15/ex15.42_c/binaryquery.h | 2 +- ch15/ex15.42_c/notquery.h | 2 +- ch15/ex15.42_c/orquery.h | 2 +- ch15/ex15.42_c/query.h | 4 ++-- ch15/ex15.42_c/queryresult.h | 2 +- ch15/ex15.42_c/wordquery.h | 2 +- ch16/ex16.1.2.3/main.cpp | 4 ++-- ch16/ex16.12.13/Blob.h | 6 +++--- ch16/ex16.16/main.cpp | 2 +- ch16/ex16.16/vec.h | 4 ++-- ch16/ex16.24/Blob.h | 8 ++++---- ch16/ex16.24/main.cpp | 2 +- ch16/ex16.28/shared_pointer.hpp | 8 ++++---- ch16/ex16.28/unique_pointer.h | 4 ++-- ch16/ex16.29/Blob.h | 8 ++++---- ch16/ex16.29/shared_pointer.h | 6 +++--- ch16/ex16.29/unique_pointer.h | 4 ++-- ch16/ex16.40/main.cpp | 2 +- ch16/ex16.58.59/strvec.h | 2 +- ch16/ex16.58.59/vec.h | 4 ++-- ch16/ex16.6/main.cpp | 2 +- ch16/ex16.60.61/main.cpp | 2 +- ch16/ex16.7.8/main.cpp | 2 +- ch17/ex17_10.cpp | 2 +- ch17/ex17_11_12_13.cpp | 2 +- ch17/ex17_19_20.cpp | 2 +- ch17/ex17_21.cpp | 2 +- ch17/ex17_23.cpp | 2 +- ch17/ex17_33.cpp | 6 +++--- ch17/ex17_4_5_6_7_8.cpp | 2 +- ch17/ex17_4_5_6_7_8_SalesData.h | 8 ++++---- ch18/ex18.1.2.3.cpp | 4 ++-- 145 files changed, 296 insertions(+), 281 deletions(-) diff --git a/.tools/format.rb b/.tools/format.rb index 6d1cf5ef..faf98058 100644 --- a/.tools/format.rb +++ b/.tools/format.rb @@ -20,15 +20,30 @@ def for_commas end end end - + + def for_curly_brackets + count = 0 + each_line do |line| + begin + if line.match /{.*}/ + puts (count += 1).to_s; puts line + line.gsub! /{(\S)/, '{ \1' + line.gsub! /(\S)}/, '\1 }' + end + rescue Exception => e + puts e.message + ", ignored." + end + end + end + private def each_line @handlers.each do |h| h.on_each_line { |line| yield line } - end + end end end format = Format.new ARGV[0], [ "cpp", "h", "hpp", "md" ] format.for_commas - +format.for_curly_brackets diff --git a/ch03/README.md b/ch03/README.md index d4ba066e..da64b445 100644 --- a/ch03/README.md +++ b/ch03/README.md @@ -39,7 +39,7 @@ This code was dereferencing and printing the first item stored in `s`. Since `s` >Is the following range for legal? If so, what is the type of c? ```cpp const string s = "Keep out!"; -for (auto &c : s){/*... */} +for (auto &c : s){ /*... */ } ``` Depending on the code within for loop body. For example: @@ -66,10 +66,10 @@ vectors? What are the values of the elements? vector v1; // size:0, no values. vector v2(10); // size:10, value:0 vector v3(10, 42); // size:10, value:42 -vector v4{10}; // size:1, value:10 -vector v5{10, 42}; // size:2, value:10, 42 -vector v6{10}; // size:10, value:"" -vector v7{10, "hi"}; // size:10, value:"hi" +vector v4{ 10 }; // size:1, value:10 +vector v5{ 10, 42 }; // size:2, value:10, 42 +vector v6{ 10 }; // size:10, value:"" +vector v7{ 10, "hi" }; // size:10, value:"hi" ``` ##[Exercise 3.14](ex3_14.cpp) @@ -161,7 +161,7 @@ p1 += p2 - p1; ##Exercise 3.37 >What does the following program do? ```cpp -const char ca[] = {'h', 'e', 'l', 'l', 'o'}; +const char ca[] = { 'h', 'e', 'l', 'l', 'o' }; const char *cp = ca; while (*cp) { cout << *cp << endl; diff --git a/ch04/README.md b/ch04/README.md index 6f6daed5..29b31efb 100644 --- a/ch04/README.md +++ b/ch04/README.md @@ -294,7 +294,7 @@ reference: [Usage of the Built-in Comma Operator](http://stackoverflow.com/quest >Explain the following loop. ```cpp constexpr int size = 5; -int ia[size] = {1, 2, 3, 4, 5}; +int ia[size] = { 1, 2, 3, 4, 5 }; for (int *ptr = ia, ix = 0; ix != size && ptr != ia+size; ++ix, ++ptr) { /* ... */ } diff --git a/ch05/README.md b/ch05/README.md index c7f885b2..898a8446 100644 --- a/ch05/README.md +++ b/ch05/README.md @@ -61,8 +61,8 @@ while (iter != s.end()) { /* . . . */ } ```cpp //corrrected as: bool status; -while ((status = find(word))) {/* ... */} -if (!status) {/* ... */} +while ((status = find(word))) { /* ... */ } +if (!status) { /* ... */ } ``` ##[Exercise 5.5](ex5_5.cpp) diff --git a/ch05/ex5_14.cpp b/ch05/ex5_14.cpp index 18f901f6..efcc9f93 100644 --- a/ch05/ex5_14.cpp +++ b/ch05/ex5_14.cpp @@ -11,7 +11,7 @@ int main() { if (str == prestr) ++count; else count = 0; - if (count > max_duplicated.second) max_duplicated = {prestr, count}; + if (count > max_duplicated.second) max_duplicated = { prestr, count }; } if (max_duplicated.first.empty()) cout << "There's no duplicated string." << endl; diff --git a/ch05/ex5_17.cpp b/ch05/ex5_17.cpp index 73f037eb..bf9fb0fe 100644 --- a/ch05/ex5_17.cpp +++ b/ch05/ex5_17.cpp @@ -5,8 +5,8 @@ using std::cout; using std::endl; using std::vector; int main() { - vector vec1{0, 1, 1, 2}; - vector vec2{0, 1, 1, 2, 3, 5, 8}; + vector vec1{ 0, 1, 1, 2 }; + vector vec2{ 0, 1, 1, 2, 3, 5, 8 }; auto size = vec1.size() < vec2.size() ? vec1.size() : vec2.size(); for (decltype(vec1.size()) i = 0; i != size; ++i) { diff --git a/ch06/README.md b/ch06/README.md index 5040c485..52925627 100644 --- a/ch06/README.md +++ b/ch06/README.md @@ -410,7 +410,7 @@ int divide(int a, int b) { return b != 0 ? a / b : 0; } ## Exercise 6.56 ```cpp -std::vector vec{add, subtract, multiply, divide}; +std::vector vec{ add, subtract, multiply, divide }; for (auto f : vec) std::cout << f(2, 2) << std::endl; ``` diff --git a/ch06/ex6_23.cpp b/ch06/ex6_23.cpp index 5948abe5..35c62490 100644 --- a/ch06/ex6_23.cpp +++ b/ch06/ex6_23.cpp @@ -35,7 +35,7 @@ void print(int (&arr)[2]) int main() { - int i = 0, j[2] = {0, 1}; + int i = 0, j[2] = { 0, 1 }; char ch[5] = "pezy"; print(ch); diff --git a/ch07/README.md b/ch07/README.md index 57a7703c..a70c7f69 100644 --- a/ch07/README.md +++ b/ch07/README.md @@ -31,7 +31,7 @@ the condition of the `if` statement would read two Sales_data object at one time ## [Exercise 7.13](ex7_13.cpp) ## Exercise 7.14 ```cpp -Sales_data() : units_sold(0) , revenue(0){} +Sales_data() : units_sold(0) , revenue(0){ } ``` ## [Exercise 7.15](ex7_15.h) @@ -122,7 +122,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXX - less scope for misreading - can use the member function parameter which name is same as the member name. - void setAddr(const std::string &addr) {this->addr = addr;} + void setAddr(const std::string &addr) { this->addr = addr; } **Cons** diff --git a/ch07/ex7_11.h b/ch07/ex7_11.h index b749f022..ca5133c1 100644 --- a/ch07/ex7_11.h +++ b/ch07/ex7_11.h @@ -13,8 +13,8 @@ struct Sales_data { Sales_data() = default; - Sales_data(const std::string &s):bookNo(s) {} - Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){} + Sales_data(const std::string &s):bookNo(s) { } + Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){ } Sales_data(std::istream &is); std::string isbn() const { return bookNo; }; diff --git a/ch07/ex7_12.h b/ch07/ex7_12.h index 4ae1dca2..88717d4e 100644 --- a/ch07/ex7_12.h +++ b/ch07/ex7_12.h @@ -16,9 +16,9 @@ std::istream &read(std::istream&, Sales_data&); struct Sales_data { Sales_data() = default; - Sales_data(const std::string &s):bookNo(s) {} - Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){} - Sales_data(std::istream &is) { read(is, *this);} + Sales_data(const std::string &s):bookNo(s) { } + Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){ } + Sales_data(std::istream &is) { read(is, *this); } std::string isbn() const { return bookNo; }; Sales_data& combine(const Sales_data&); diff --git a/ch07/ex7_15.h b/ch07/ex7_15.h index ef5f2e28..f6b8c219 100644 --- a/ch07/ex7_15.h +++ b/ch07/ex7_15.h @@ -16,8 +16,8 @@ std::istream &read(std::istream&, Person&); struct Person { Person() = default; - Person(const std::string sname, const std::string saddr):name(sname), address(saddr){} - Person(std::istream &is){read(is, *this);} + Person(const std::string sname, const std::string saddr):name(sname), address(saddr){ } + Person(std::istream &is){ read(is, *this); } std::string getName() const { return name; } std::string getAddress() const { return address; } diff --git a/ch07/ex7_21.h b/ch07/ex7_21.h index fe011e74..1c27114f 100644 --- a/ch07/ex7_21.h +++ b/ch07/ex7_21.h @@ -18,9 +18,9 @@ class Sales_data { public: Sales_data() = default; - Sales_data(const std::string &s):bookNo(s) {} - Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){} - Sales_data(std::istream &is) { read(is, *this);} + Sales_data(const std::string &s):bookNo(s) { } + Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){ } + Sales_data(std::istream &is) { read(is, *this); } std::string isbn() const { return bookNo; }; Sales_data& combine(const Sales_data&); diff --git a/ch07/ex7_22.h b/ch07/ex7_22.h index f93d6d69..535e0824 100644 --- a/ch07/ex7_22.h +++ b/ch07/ex7_22.h @@ -17,8 +17,8 @@ struct Person { public: Person() = default; - Person(const std::string sname, const std::string saddr):name(sname), address(saddr){} - Person(std::istream &is){read(is, *this);} + Person(const std::string sname, const std::string saddr):name(sname), address(saddr){ } + Person(std::istream &is){ read(is, *this); } std::string getName() const { return name; } std::string getAddress() const { return address; } diff --git a/ch07/ex7_23.h b/ch07/ex7_23.h index c12db662..cc30396d 100644 --- a/ch07/ex7_23.h +++ b/ch07/ex7_23.h @@ -15,7 +15,7 @@ class Screen { using pos = std::string::size_type; Screen() = default; - Screen(pos ht, pos wd, char c):height(ht), width(wd), contents(ht*wd, c){} + Screen(pos ht, pos wd, char c):height(ht), width(wd), contents(ht*wd, c){ } char get() const { return contents[cursor]; } char get(pos r, pos c) const { return contents[r*width+c]; } diff --git a/ch07/ex7_24.h b/ch07/ex7_24.h index d598f92a..f57c9d94 100644 --- a/ch07/ex7_24.h +++ b/ch07/ex7_24.h @@ -15,8 +15,8 @@ class Screen { using pos = std::string::size_type; Screen() = default; // 1 - Screen(pos ht, pos wd):height(ht), width(wd), contents(ht*wd, ' '){} // 2 - Screen(pos ht, pos wd, char c):height(ht), width(wd), contents(ht*wd, c){} // 3 + Screen(pos ht, pos wd):height(ht), width(wd), contents(ht*wd, ' '){ } // 2 + Screen(pos ht, pos wd, char c):height(ht), width(wd), contents(ht*wd, c){ } // 3 char get() const { return contents[cursor]; } char get(pos r, pos c) const { return contents[r*width+c]; } diff --git a/ch07/ex7_26.h b/ch07/ex7_26.h index b4efb2e1..2f570e2a 100644 --- a/ch07/ex7_26.h +++ b/ch07/ex7_26.h @@ -20,8 +20,8 @@ class Sales_data { public: Sales_data() = default; - Sales_data(const std::string &s):bookNo(s) {} - Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){} + Sales_data(const std::string &s):bookNo(s) { } + Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){ } Sales_data(std::istream &is) { read(is, *this); } std::string isbn() const { return bookNo; }; diff --git a/ch07/ex7_27.h b/ch07/ex7_27.h index 3e623aad..f4e76c1b 100644 --- a/ch07/ex7_27.h +++ b/ch07/ex7_27.h @@ -16,8 +16,8 @@ class Screen { using pos = std::string::size_type; Screen() = default; // 1 - Screen(pos ht, pos wd):height(ht), width(wd), contents(ht*wd, ' '){} // 2 - Screen(pos ht, pos wd, char c):height(ht), width(wd), contents(ht*wd, c){} // 3 + Screen(pos ht, pos wd):height(ht), width(wd), contents(ht*wd, ' '){ } // 2 + Screen(pos ht, pos wd, char c):height(ht), width(wd), contents(ht*wd, c){ } // 3 char get() const { return contents[cursor]; } char get(pos r, pos c) const { return contents[r*width+c]; } diff --git a/ch07/ex7_32.h b/ch07/ex7_32.h index c6b4587e..7768c71f 100644 --- a/ch07/ex7_32.h +++ b/ch07/ex7_32.h @@ -29,8 +29,8 @@ class Screen { using pos = std::string::size_type; Screen() = default; // 1 - Screen(pos ht, pos wd):height(ht), width(wd), contents(ht*wd, ' '){} // 2 - Screen(pos ht, pos wd, char c):height(ht), width(wd), contents(ht*wd, c){} // 3 + Screen(pos ht, pos wd):height(ht), width(wd), contents(ht*wd, ' '){ } // 2 + Screen(pos ht, pos wd, char c):height(ht), width(wd), contents(ht*wd, c){ } // 3 char get() const { return contents[cursor]; } char get(pos r, pos c) const { return contents[r*width+c]; } diff --git a/ch07/ex7_50.h b/ch07/ex7_50.h index 1fa54fb0..573e1f48 100644 --- a/ch07/ex7_50.h +++ b/ch07/ex7_50.h @@ -19,8 +19,8 @@ struct Person { public: Person() = default; - Person(const std::string sname, const std::string saddr):name(sname), address(saddr){} - explicit Person(std::istream &is){read(is, *this);} + Person(const std::string sname, const std::string saddr):name(sname), address(saddr){ } + explicit Person(std::istream &is){ read(is, *this); } std::string getName() const { return name; } std::string getAddress() const { return address; } diff --git a/ch09/README.md b/ch09/README.md index ab19f74f..b7db145f 100644 --- a/ch09/README.md +++ b/ch09/README.md @@ -117,7 +117,7 @@ auto it2 = v2.begin(), it3 = v1.cbegin(), it4 = v2.cbegin(); vector vec; // 0 vector vec(10); // 0 vector vec(10, 1); // 1 -vector vec{1, 2, 3, 4, 5}; // 1, 2, 3, 4, 5 +vector vec{ 1, 2, 3, 4, 5 }; // 1, 2, 3, 4, 5 vector vec(other_vec); // same as other_vec vector vec(other_vec.begin(), other_vec.end()); // same as other_vec ``` @@ -127,7 +127,7 @@ vector vec(other_vec.begin(), other_vec.end()); // same as other_vec - The constructor that takes another container as an argument (excepting array) assumes the container type and element type of both containers are identical. It will also copy all the elements of the received container into the new one: ```cpp -list numbers = {1, 2, 3, 4, 5}; +list numbers = { 1, 2, 3, 4, 5 }; list numbers2(numbers); // ok, numbers2 has the same elements as numbers vector numbers3(numbers); // error: no matching function for call... list numbers4(numbers); // error: no matching function for call... @@ -135,11 +135,11 @@ list numbers4(numbers); // error: no matching function for call... - The constructor that takes two iterators as arguments does not require the container types to be identical. Moreover, the element types in the new and original containers can differ as long as it is possible to convert the elements we’re copying to the element type of the container we are initializing. It will also copy only the object delimited by the received iterators. ```cpp -list numbers = {1, 2, 3, 4, 5}; +list numbers = { 1, 2, 3, 4, 5 }; list numbers2(numbers.begin(), numbers.end); // ok, numbers2 has the same elements as numbers -vector numbers3(numbers.begin(), --numbers.end()); // ok, numbers3 is {1, 2, 3, 4} -list numbers4(++numbers.beg(), --numbers.end()); // ok, numbers4 is {2, 3, 4} -forward_list numbers5(numbers.begin(), numbers.end()); // ok, number5 is {1, 2, 3, 4, 5} +vector numbers3(numbers.begin(), --numbers.end()); // ok, numbers3 is { 1, 2, 3, 4 } +list numbers4(++numbers.beg(), --numbers.end()); // ok, numbers4 is { 2, 3, 4 } +forward_list numbers5(numbers.begin(), numbers.end()); // ok, number5 is { 1, 2, 3, 4, 5 } ``` diff --git a/ch09/ex9_41.cpp b/ch09/ex9_41.cpp index d9f334d6..2d687572 100644 --- a/ch09/ex9_41.cpp +++ b/ch09/ex9_41.cpp @@ -14,7 +14,7 @@ using std::vector; using std::cout; using std::endl; using std::string; int main() { - vector vec{'p', 'e', 'z', 'y'}; + vector vec{ 'p', 'e', 'z', 'y' }; string str(vec.begin(), vec.end()); cout << str << endl; diff --git a/ch09/ex9_47_1.cpp b/ch09/ex9_47_1.cpp index 7a1c12a5..b81c3456 100644 --- a/ch09/ex9_47_1.cpp +++ b/ch09/ex9_47_1.cpp @@ -17,9 +17,9 @@ using std::string; using std::cout; using std::endl; int main() { - string numbers{"123456789"}; - string alphabet{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}; - string str{"ab2c3d7R4E6"}; + string numbers{ "123456789" }; + string alphabet{ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" }; + string str{ "ab2c3d7R4E6" }; cout << "numeric characters: "; for (string::size_type pos = 0; (pos = str.find_first_of(numbers, pos)) != string::npos; ++pos) diff --git a/ch09/ex9_47_2.cpp b/ch09/ex9_47_2.cpp index b608c401..da5e0911 100644 --- a/ch09/ex9_47_2.cpp +++ b/ch09/ex9_47_2.cpp @@ -17,9 +17,9 @@ using std::string; using std::cout; using std::endl; int main() { - string numbers{"123456789"}; - string alphabet{"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"}; - string str{"ab2c3d7R4E6"}; + string numbers{ "123456789" }; + string alphabet{ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" }; + string str{ "ab2c3d7R4E6" }; cout << "numeric characters: "; for (string::size_type pos = 0; (pos = str.find_first_not_of(alphabet, pos)) != string::npos; ++pos) diff --git a/ch09/ex9_52.cpp b/ch09/ex9_52.cpp index 044d0295..53e23ddd 100644 --- a/ch09/ex9_52.cpp +++ b/ch09/ex9_52.cpp @@ -18,7 +18,7 @@ using std::string; using std::cout; using std::endl; using std::stack; int main() { - string expression{"This is (pezy)."}; + string expression{ "This is (pezy)." }; bool bSeen = false; stack stk; for (const auto &s : expression) diff --git a/ch10/README.md b/ch10/README.md index e95cfeb6..335c4a8c 100644 --- a/ch10/README.md +++ b/ch10/README.md @@ -32,7 +32,7 @@ Cause the library algorithms operate on **iterators**, **not containers**. Thus, >Write a lambda that takes two ints and returns their sum. ```cpp -auto add = [](int lhs, int rhs){return lhs + rhs;}; +auto add = [](int lhs, int rhs){ return lhs + rhs; }; ``` ## Exercise 10.15: @@ -41,7 +41,7 @@ The lambda should return the sum of the captured int and the int parameter. ```cpp int i = 42; -auto add = [i](int num){return i + num;}; +auto add = [i](int num){ return i + num; }; ``` ##[Exercise 10.16](ex10_16.cpp) diff --git a/ch10/ex10_05.cpp b/ch10/ex10_05.cpp index bf594d18..a2014916 100644 --- a/ch10/ex10_05.cpp +++ b/ch10/ex10_05.cpp @@ -11,5 +11,5 @@ // #include -int main(){} +int main(){ } diff --git a/ch10/ex10_12.cpp b/ch10/ex10_12.cpp index c0657d5e..6435f0ee 100644 --- a/ch10/ex10_12.cpp +++ b/ch10/ex10_12.cpp @@ -19,7 +19,7 @@ inline bool compareIsbn(const Sales_data &sd1, const Sales_data &sd2) int main() { Sales_data d1("aa"), d2("aaaa"), d3("aaa"), d4("z"), d5("aaaaz"); - std::vector v{d1, d2, d3, d4, d5}; + std::vector v{ d1, d2, d3, d4, d5 }; // @note the elements the iterators pointing to // must match the parameters of the predicate. diff --git a/ch10/ex10_17.cpp b/ch10/ex10_17.cpp index bac3bac2..2005041b 100644 --- a/ch10/ex10_17.cpp +++ b/ch10/ex10_17.cpp @@ -15,7 +15,7 @@ int main() { Sales_data d1("aa"), d2("aaaa"), d3("aaa"), d4("z"), d5("aaaaz"); - std::vector v{d1, d2, d3, d4, d5}; + std::vector v{ d1, d2, d3, d4, d5 }; std::sort(v.begin(), v.end(), [](const Sales_data &sd1, const Sales_data &sd2){ return sd1.isbn().size() < sd2.isbn().size(); diff --git a/ch10/ex10_22.cpp b/ch10/ex10_22.cpp index 93310846..e5e8982d 100644 --- a/ch10/ex10_22.cpp +++ b/ch10/ex10_22.cpp @@ -23,6 +23,6 @@ bool isBiggerThan6(const string &s, string::size_type sz) int main() { - std::vector authors{"Mooophy", "pezy", "Queequeg90", "shbling", "evan617"}; + std::vector authors{ "Mooophy", "pezy", "Queequeg90", "shbling", "evan617" }; std::cout << count_if(authors.cbegin(), authors.cend(), bind(isBiggerThan6, _1, 6)); } diff --git a/ch10/ex10_27.cpp b/ch10/ex10_27.cpp index d539fd64..10b4ebe7 100644 --- a/ch10/ex10_27.cpp +++ b/ch10/ex10_27.cpp @@ -16,7 +16,7 @@ int main() { - std::vector vec{1, 1, 3, 3, 5, 5, 7, 7, 9}; + std::vector vec{ 1, 1, 3, 3, 5, 5, 7, 7, 9 }; std::list lst; std::unique_copy(vec.begin(), vec.end(), back_inserter(lst)); diff --git a/ch10/ex10_28.cpp b/ch10/ex10_28.cpp index 7c278782..f0767970 100644 --- a/ch10/ex10_28.cpp +++ b/ch10/ex10_28.cpp @@ -27,7 +27,7 @@ void print(Sequence const& seq) int main() { - std::vector vec{1, 2, 3, 4, 5, 6, 7, 8, 9}; + std::vector vec{ 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // uses inserter list lst1; diff --git a/ch10/ex10_32.cpp b/ch10/ex10_32.cpp index 00eb9e49..67017533 100644 --- a/ch10/ex10_32.cpp +++ b/ch10/ex10_32.cpp @@ -25,7 +25,7 @@ int main() vec.push_back(*in_iter++); sort(vec.begin(), vec.end(), compareIsbn); for (auto beg = vec.cbegin(), end = beg; beg != vec.cend(); beg = end) { - end = find_if(beg, vec.cend(), [beg](const Sales_item &item){return item.isbn() != beg->isbn();}); + end = find_if(beg, vec.cend(), [beg](const Sales_item &item){ return item.isbn() != beg->isbn(); }); std::cout << std::accumulate(beg, end, Sales_item(beg->isbn())) << std::endl; } } diff --git a/ch11/README.md b/ch11/README.md index f0e72493..f646ae70 100644 --- a/ch11/README.md +++ b/ch11/README.md @@ -22,7 +22,7 @@ A `vector` is a collection of objects, and every object has an **associated inde >Explain the difference between a map and a set. When might you use one or the other? - `set` : the element type is the **key type**. -- `map` : we should use a key-value pair, such as `{key, value}` to indicate that the items together from one element in the map. +- `map` : we should use a key-value pair, such as `{ key, value }` to indicate that the items together from one element in the map. I use `set` when i just need to store the `key`, In other hand, I would like use `map` when i need to store a key-value pair. @@ -80,11 +80,11 @@ std::multiset::iterator c_it = bookstore.begin(); >Assuming word_count is a map from string to size_t and word is a string, explain the following loop: ```cpp while (cin >> word) - ++word_count.insert({word, 0}).first->second; + ++word_count.insert({ word, 0 }).first->second; ``` ```cpp -++ (word_count.insert({word, 0}).first->second) +++ (word_count.insert({ word, 0 }).first->second) ``` ## Exercise 11.22: >Given a map>, write the types used as an argument and as the return value for the version of insert that inserts one element. @@ -112,7 +112,7 @@ error: passing ‘const std::map, std::basic_stringIn buildMap, what effect, if any, would there be from rewriting `trans_map[key] = value.substr(1);` as `trans_map.insert({key, value.substr(1)})`? +>In buildMap, what effect, if any, would there be from rewriting `trans_map[key] = value.substr(1);` as `trans_map.insert({ key, value.substr(1) })`? - use subscript operator: if a word does appear multiple times, our loops will put the **last** corresponding phrase into trans_map - use `insert`: if a word does appear multiple times, our loops will put the **first** corresponding phrase into trans_map diff --git a/ch11/ex11_12_13.cpp b/ch11/ex11_12_13.cpp index 5d60ef6c..35fc2310 100644 --- a/ch11/ex11_12_13.cpp +++ b/ch11/ex11_12_13.cpp @@ -24,7 +24,7 @@ int main() while (std::cin >> str >> i) vec.push_back(std::pair(str, i)); //vec.push_back(std::make_pair(str, i)); - //vec.push_back({str, i}); + //vec.push_back({ str, i }); //vec.emplace_back(str, i); //!! easiest way. for (const auto &p : vec) diff --git a/ch11/ex11_20.cpp b/ch11/ex11_20.cpp index 851abd83..508ac0df 100644 --- a/ch11/ex11_20.cpp +++ b/ch11/ex11_20.cpp @@ -18,7 +18,7 @@ int main() string word; while(std::cin >> word) { - auto ret = word_count.insert({word, 1}); + auto ret = word_count.insert({ word, 1 }); if(!ret.second) ++ret.first->second; } diff --git a/ch11/ex11_27_28_29_30.cpp b/ch11/ex11_27_28_29_30.cpp index 612d7370..5173b633 100644 --- a/ch11/ex11_27_28_29_30.cpp +++ b/ch11/ex11_27_28_29_30.cpp @@ -40,7 +40,7 @@ int main() { std::map> m; - m = {{"Alan",{1,2,3,4,5,}},{"John",{1,5,6,7,8}}}; + m = { {"Alan",{ 1,2,3,4,5, }},{ "John",{ 1,5,6,7,8 }} }; // ex11.28 std::map>::iterator it; diff --git a/ch11/ex11_31.cpp b/ch11/ex11_31.cpp index b98c5527..678a86ce 100644 --- a/ch11/ex11_31.cpp +++ b/ch11/ex11_31.cpp @@ -17,12 +17,12 @@ using std::string; int main() { std::multimap authors{ - {"alan", "DMA"}, - {"pezy", "LeetCode"}, - {"alan", "CLRS"}, - {"wang", "FTP"}, - {"pezy", "CP5"}, - {"wang", "CPP-Concurrency"} + { "alan", "DMA" }, + { "pezy", "LeetCode" }, + { "alan", "CLRS" }, + { "wang", "FTP" }, + { "pezy", "CP5" }, + { "wang", "CPP-Concurrency" } }; // want to delete an element that author is [Alan], work is [112]. string author = "pezy"; diff --git a/ch11/ex11_32.cpp b/ch11/ex11_32.cpp index d6ddc757..3e0f2105 100644 --- a/ch11/ex11_32.cpp +++ b/ch11/ex11_32.cpp @@ -16,12 +16,12 @@ using std::string; int main() { std::multimap authors{ - {"alan", "DMA"}, - {"pezy", "LeetCode"}, - {"alan", "CLRS"}, - {"wang", "FTP"}, - {"pezy", "CP5"}, - {"wang", "CPP-Concurrency"} + { "alan", "DMA" }, + { "pezy", "LeetCode" }, + { "alan", "CLRS" }, + { "wang", "FTP" }, + { "pezy", "CP5" }, + { "wang", "CPP-Concurrency" } }; std::map> order_authors; for (const auto &author : authors) diff --git a/ch11/ex11_8.cpp b/ch11/ex11_8.cpp index 43349e73..e42d5828 100644 --- a/ch11/ex11_8.cpp +++ b/ch11/ex11_8.cpp @@ -32,7 +32,7 @@ int main() { - std::vector exclude = {"aa","bb","cc"}; + std::vector exclude = { "aa","bb","cc" }; std::string word; while([&]() { diff --git a/ch12/README.md b/ch12/README.md index add4f342..f98518a9 100644 --- a/ch12/README.md +++ b/ch12/README.md @@ -5,7 +5,7 @@ ```cpp StrBlob b1; { - StrBlob b2 = {"a", "an", "the"}; + StrBlob b2 = { "a", "an", "the" }; b1 = b2; b2.push_back("about"); } diff --git a/ch12/ex12_02_TEST.cpp b/ch12/ex12_02_TEST.cpp index 870654f3..5ff37e6c 100644 --- a/ch12/ex12_02_TEST.cpp +++ b/ch12/ex12_02_TEST.cpp @@ -3,8 +3,8 @@ int main() { - const StrBlob csb{"hello", "world", "pezy"}; - StrBlob sb{"hello", "world", "Mooophy"}; + const StrBlob csb{ "hello", "world", "pezy" }; + StrBlob sb{ "hello", "world", "Mooophy" }; std::cout << csb.front() << " " << csb.back() << std::endl; sb.back() = "pezy"; diff --git a/ch12/ex12_06.cpp b/ch12/ex12_06.cpp index 237a9a25..8901bf86 100644 --- a/ch12/ex12_06.cpp +++ b/ch12/ex12_06.cpp @@ -21,7 +21,7 @@ using Ptr = std::vector*; auto make_dynamically() -> Ptr { - return new std::vector < int > {}; + return new std::vector < int > { }; } auto populate(Ptr vec) -> Ptr diff --git a/ch12/ex12_15.cpp b/ch12/ex12_15.cpp index b5dc528c..0a2d3c22 100644 --- a/ch12/ex12_15.cpp +++ b/ch12/ex12_15.cpp @@ -36,7 +36,7 @@ void disconnect(connection pConn) void f(destination &d) { connection conn = connect(&d); - std::shared_ptr p(&conn, [](connection *p){disconnect(*p);}); + std::shared_ptr p(&conn, [](connection *p){ disconnect(*p); }); std::cout << "connecting now(" << p.use_count() << ")" << std::endl; } diff --git a/ch12/ex12_17_18.cpp b/ch12/ex12_17_18.cpp index 68918783..ab22e18a 100644 --- a/ch12/ex12_17_18.cpp +++ b/ch12/ex12_17_18.cpp @@ -31,7 +31,7 @@ int main() /** - * @brief error: invalid conversion from 'int' to 'std::unique_ptr::pointer {aka int*}' [-fpermissive] + * @brief error: invalid conversion from 'int' to 'std::unique_ptr::pointer { aka int* }' [-fpermissive] */ //IntP p0(ix); @@ -52,7 +52,7 @@ int main() * is pointing to. * @badcode */ - //{IntP p2(pi2);} + //{ IntP p2(pi2); } /** diff --git a/ch12/ex12_19.h b/ch12/ex12_19.h index f881eec3..f575eabe 100644 --- a/ch12/ex12_19.h +++ b/ch12/ex12_19.h @@ -73,7 +73,7 @@ class StrBlobPtr { public: StrBlobPtr():curr(0) { } StrBlobPtr(StrBlob &a, size_t sz = 0):wptr(a.data), curr(sz) { } - bool operator!=(const StrBlobPtr& p) {return p.curr != curr; } + bool operator!=(const StrBlobPtr& p) { return p.curr != curr; } string& deref() const { auto p = check(curr, "dereference past end"); return (*p)[curr]; diff --git a/ch12/ex12_22.h b/ch12/ex12_22.h index fb12b92a..e6ce7c84 100644 --- a/ch12/ex12_22.h +++ b/ch12/ex12_22.h @@ -75,7 +75,7 @@ class ConstStrBlobPtr { public: ConstStrBlobPtr():curr(0) { } ConstStrBlobPtr(const StrBlob &a, size_t sz = 0):wptr(a.data), curr(sz) { } // should add const - bool operator!=(ConstStrBlobPtr& p) {return p.curr != curr; } + bool operator!=(ConstStrBlobPtr& p) { return p.curr != curr; } const string& deref() const { // return value should add const auto p = check(curr, "dereference past end"); return (*p)[curr]; diff --git a/ch12/ex12_23.cpp b/ch12/ex12_23.cpp index f8e08e44..3841744d 100644 --- a/ch12/ex12_23.cpp +++ b/ch12/ex12_23.cpp @@ -21,6 +21,6 @@ int main() delete [] concatenate_string; // std::string - std::string str1{"hello "}, str2{"world"}; + std::string str1{ "hello " }, str2{ "world" }; std::cout << str1 + str2 << std::endl; } diff --git a/ch12/ex12_24.cpp b/ch12/ex12_24.cpp index 46043c25..38f1f51b 100644 --- a/ch12/ex12_24.cpp +++ b/ch12/ex12_24.cpp @@ -15,7 +15,7 @@ int main() { // need to tell the size. std::cout << "How long do you want the string? "; - int size{0}; + int size{ 0 }; std::cin >> size; char *input = new char[size+1](); std::cin.ignore(); diff --git a/ch12/ex12_27_30.cpp b/ch12/ex12_27_30.cpp index 4fd92e0c..14187409 100644 --- a/ch12/ex12_27_30.cpp +++ b/ch12/ex12_27_30.cpp @@ -13,7 +13,7 @@ TextQuery::TextQuery(std::ifstream &ifs) : input(new vector) { - LineNo lineNo{0}; + LineNo lineNo{ 0 }; for (string line; std::getline(ifs, line); ++lineNo) { input->push_back(line); std::istringstream line_stream(line); diff --git a/ch12/ex12_27_30.h b/ch12/ex12_27_30.h index 8eb44b22..b26e0bae 100644 --- a/ch12/ex12_27_30.h +++ b/ch12/ex12_27_30.h @@ -39,7 +39,7 @@ class QueryResult { public: friend std::ostream& print(std::ostream &, const QueryResult&); public: - QueryResult(const string &s, shared_ptr> set, shared_ptr> v) : word(s), nos(set), input(v) {} + QueryResult(const string &s, shared_ptr> set, shared_ptr> v) : word(s), nos(set), input(v) { } private: string word; shared_ptr> nos; diff --git a/ch12/ex12_28.cpp b/ch12/ex12_28.cpp index e23007c3..09cbb683 100644 --- a/ch12/ex12_28.cpp +++ b/ch12/ex12_28.cpp @@ -30,7 +30,7 @@ int main() std::ifstream file("../data/letter.txt"); vector input; std::map> dictionary; - decltype(input.size()) lineNo{0}; + decltype(input.size()) lineNo{ 0 }; for (string line; std::getline(file, line); ++lineNo) { input.push_back(line); diff --git a/ch12/ex12_32.cpp b/ch12/ex12_32.cpp index 164d017b..b441da09 100644 --- a/ch12/ex12_32.cpp +++ b/ch12/ex12_32.cpp @@ -13,7 +13,7 @@ TextQuery::TextQuery(std::ifstream &ifs) { - StrBlob::size_type lineNo{0}; + StrBlob::size_type lineNo{ 0 }; for (string line; std::getline(ifs, line); ++lineNo) { file.push_back(line); std::istringstream line_stream(line); diff --git a/ch12/ex12_32.h b/ch12/ex12_32.h index 7d25e21e..ae3d1461 100644 --- a/ch12/ex12_32.h +++ b/ch12/ex12_32.h @@ -32,7 +32,7 @@ class QueryResult { public: friend std::ostream& print(std::ostream &, const QueryResult&); public: - QueryResult(const string &s, shared_ptr> set, const StrBlob& f) : word(s), nos(set), file(f) {} + QueryResult(const string &s, shared_ptr> set, const StrBlob& f) : word(s), nos(set), file(f) { } private: string word; shared_ptr> nos; diff --git a/ch12/ex12_33.cpp b/ch12/ex12_33.cpp index d2b166d1..f7888c5c 100644 --- a/ch12/ex12_33.cpp +++ b/ch12/ex12_33.cpp @@ -13,7 +13,7 @@ TextQuery::TextQuery(std::ifstream &ifs) { - StrBlob::size_type lineNo{0}; + StrBlob::size_type lineNo{ 0 }; for (string line; std::getline(ifs, line); ++lineNo) { file.push_back(line); std::istringstream line_stream(line); diff --git a/ch12/ex12_33.h b/ch12/ex12_33.h index 8fc20016..32a74569 100644 --- a/ch12/ex12_33.h +++ b/ch12/ex12_33.h @@ -36,7 +36,7 @@ class QueryResult { using ResultIter = std::set::iterator; friend std::ostream& print(std::ostream &, const QueryResult&); public: - QueryResult(const string &s, shared_ptr> set, const StrBlob& f) : word(s), nos(set), file(f) {} + QueryResult(const string &s, shared_ptr> set, const StrBlob& f) : word(s), nos(set), file(f) { } ResultIter begin() const { return nos->begin(); } ResultIter end() const { return nos->end(); } shared_ptr get_file() const { return std::make_shared(file); } diff --git a/ch13/README.md b/ch13/README.md index 46635154..1bcc768c 100644 --- a/ch13/README.md +++ b/ch13/README.md @@ -31,7 +31,7 @@ long count() { } // test codes in main() -StrBlob str({"hello", "world"}); +StrBlob str({ "hello", "world" }); std::cout << "before: " << str.count() << std::endl; // 1 StrBlob str_cp(str); std::cout << "after: " << str.count() << std::endl; // 2 @@ -349,7 +349,7 @@ see more information at [this question && answer](http://stackoverflow.com/quest >What would happen if we defined a `HasPtr` move-assignment operator but did not change the copy-and-swap operator? Write code to test your answer. ```sh -error: ambiguous overload for 'operator=' (operand types are 'HasPtr' and 'std::remove_reference::type {aka HasPtr}') +error: ambiguous overload for 'operator=' (operand types are 'HasPtr' and 'std::remove_reference::type { aka HasPtr }') hp1 = std::move(*pH); ^ ``` diff --git a/ch13/ex13_13.cpp b/ch13/ex13_13.cpp index b09be150..dec1e125 100644 --- a/ch13/ex13_13.cpp +++ b/ch13/ex13_13.cpp @@ -6,8 +6,8 @@ // // A good way to understand copy-control members and constructors is to define a simple class with these members in which each member prints its name: // struct X { -// X() {std::cout << "X()" << std::endl;} -// X(const X&) {std::cout << "X(const X&)" << std::endl;} +// X() { std::cout << "X()" << std::endl; } +// X(const X&) { std::cout << "X(const X&)" << std::endl; } // }; // Add the copy-assignment operator and destructor to X and write a program using X objects in various ways: // Pass them as nonreference and reference parameters; diff --git a/ch13/ex13_26.h b/ch13/ex13_26.h index 80aa7b86..6bf2f7ab 100644 --- a/ch13/ex13_26.h +++ b/ch13/ex13_26.h @@ -33,7 +33,7 @@ class StrBlob { StrBlob(std::initializer_list il):data(std::make_shared>(il)) { } // copy constructor - StrBlob(const StrBlob& sb) : data(std::make_shared>(*sb.data)) {} + StrBlob(const StrBlob& sb) : data(std::make_shared>(*sb.data)) { } // copyassignment operators StrBlob& operator=(const StrBlob& sb); @@ -78,7 +78,7 @@ class ConstStrBlobPtr { public: ConstStrBlobPtr():curr(0) { } ConstStrBlobPtr(const StrBlob &a, size_t sz = 0):wptr(a.data), curr(sz) { } // should add const - bool operator!=(ConstStrBlobPtr& p) {return p.curr != curr; } + bool operator!=(ConstStrBlobPtr& p) { return p.curr != curr; } const string& deref() const { // return value should add const auto p = check(curr, "dereference past end"); return (*p)[curr]; diff --git a/ch13/ex13_28.h b/ch13/ex13_28.h index 08e58842..4030a59f 100644 --- a/ch13/ex13_28.h +++ b/ch13/ex13_28.h @@ -14,7 +14,7 @@ using std::string; class TreeNode { public: - TreeNode() : value(string()), count(new int(1)), left(nullptr), right(nullptr) {} + TreeNode() : value(string()), count(new int(1)), left(nullptr), right(nullptr) { } TreeNode(const TreeNode &rhs) : value(rhs.value), count(rhs.count), left(rhs.left), right(rhs.right) { ++*count; } TreeNode& operator=(const TreeNode &rhs); ~TreeNode() { @@ -41,8 +41,8 @@ class TreeNode { class BinStrTree { public: - BinStrTree() : root(new TreeNode()) {} - BinStrTree(const BinStrTree &bst) : root(new TreeNode(*bst.root)) {} + BinStrTree() : root(new TreeNode()) { } + BinStrTree(const BinStrTree &bst) : root(new TreeNode(*bst.root)) { } BinStrTree& operator=(const BinStrTree &bst); ~BinStrTree() { delete root; } diff --git a/ch13/ex13_34_36_37.h b/ch13/ex13_34_36_37.h index c033fc8a..efd664c9 100644 --- a/ch13/ex13_34_36_37.h +++ b/ch13/ex13_34_36_37.h @@ -24,7 +24,7 @@ class Message { friend void swap(Folder &, Folder &); friend class Folder; public: - explicit Message(const std::string &str = ""):contents(str) {} + explicit Message(const std::string &str = ""):contents(str) { } Message(const Message&); Message& operator=(const Message&); ~Message(); diff --git a/ch13/ex13_39.h b/ch13/ex13_39.h index c5ac5213..80478c48 100644 --- a/ch13/ex13_39.h +++ b/ch13/ex13_39.h @@ -17,7 +17,7 @@ class StrVec { public: - StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) {} + StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) { } StrVec(const StrVec&); StrVec& operator=(const StrVec&); ~StrVec(); diff --git a/ch13/ex13_40.h b/ch13/ex13_40.h index e75b4d22..f07c18e4 100644 --- a/ch13/ex13_40.h +++ b/ch13/ex13_40.h @@ -17,7 +17,7 @@ class StrVec { public: - StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) {} + StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) { } StrVec(const StrVec&); StrVec(std::initializer_list); StrVec& operator=(const StrVec&); diff --git a/ch13/ex13_42_StrVec.h b/ch13/ex13_42_StrVec.h index e17b4f6b..1a28fe95 100644 --- a/ch13/ex13_42_StrVec.h +++ b/ch13/ex13_42_StrVec.h @@ -8,7 +8,7 @@ class StrVec { public: - StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) {} + StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) { } StrVec(const StrVec&); StrVec(std::initializer_list); StrVec& operator=(const StrVec&); diff --git a/ch13/ex13_42_TextQuery.h b/ch13/ex13_42_TextQuery.h index 55ddffe6..9a2f575e 100644 --- a/ch13/ex13_42_TextQuery.h +++ b/ch13/ex13_42_TextQuery.h @@ -24,7 +24,7 @@ class QueryResult { public: friend std::ostream& print(std::ostream &, const QueryResult&); public: - QueryResult(const std::string &s, std::shared_ptr> set, std::shared_ptr v) : word(s), nos(set), input(v) {} + QueryResult(const std::string &s, std::shared_ptr> set, std::shared_ptr v) : word(s), nos(set), input(v) { } private: std::string word; std::shared_ptr> nos; diff --git a/ch13/ex13_44_47.h b/ch13/ex13_44_47.h index 9d17d6b6..e472509d 100644 --- a/ch13/ex13_44_47.h +++ b/ch13/ex13_44_47.h @@ -6,7 +6,7 @@ class String { public: - String() : String("") {} + String() : String("") { } String(const char *); String(const String&); String& operator=(const String&); diff --git a/ch13/ex13_49_Message.h b/ch13/ex13_49_Message.h index b5097a54..17ece00a 100644 --- a/ch13/ex13_49_Message.h +++ b/ch13/ex13_49_Message.h @@ -18,10 +18,10 @@ class Message friend void swap(Folder &, Folder &); friend class Folder; public: - explicit Message(const std::string &str = "") : contents(str) {} + explicit Message(const std::string &str = "") : contents(str) { } Message(const Message&); Message& operator=(const Message&); - Message(Message &&m) NOEXCEPT : contents(std::move(m.contents)), folders(std::move(m.folders)) {} + Message(Message &&m) NOEXCEPT : contents(std::move(m.contents)), folders(std::move(m.folders)) { } Message& operator=(Message&&)NOEXCEPT; ~Message(); @@ -50,10 +50,10 @@ class Folder { friend void swap(Folder &, Folder &); friend class Message; public: - explicit Folder(const std::string &str = "") :name(str) {} + explicit Folder(const std::string &str = "") :name(str) { } Folder(const Folder &); Folder& operator=(const Folder &); - Folder(Folder &&f) NOEXCEPT : name(std::move(f.name)), msgs(std::move(f.msgs)) {} + Folder(Folder &&f) NOEXCEPT : name(std::move(f.name)), msgs(std::move(f.msgs)) { } Folder& operator=(Folder &&)NOEXCEPT; ~Folder(); diff --git a/ch13/ex13_49_StrVec.h b/ch13/ex13_49_StrVec.h index 9e7f7256..64cebdd7 100644 --- a/ch13/ex13_49_StrVec.h +++ b/ch13/ex13_49_StrVec.h @@ -14,7 +14,7 @@ class StrVec { public: - StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) {} + StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) { } StrVec(std::initializer_list); StrVec(const StrVec&); StrVec& operator=(const StrVec&); diff --git a/ch13/ex13_49_String.h b/ch13/ex13_49_String.h index 1403b4fe..ffa8f786 100644 --- a/ch13/ex13_49_String.h +++ b/ch13/ex13_49_String.h @@ -12,7 +12,7 @@ class String { public: - String() : String("") {} + String() : String("") { } String(const char *); String(const String&); String& operator=(const String&); diff --git a/ch14/ex14_02.h b/ch14/ex14_02.h index 42cd34f2..33d91870 100644 --- a/ch14/ex14_02.h +++ b/ch14/ex14_02.h @@ -19,9 +19,9 @@ class Sales_data { friend Sales_data operator+(const Sales_data&, const Sales_data&); // addition public: - Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){} - Sales_data() : Sales_data("", 0, 0.0f){} - Sales_data(const std::string &s) : Sales_data(s, 0, 0.0f){} + Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){ } + Sales_data() : Sales_data("", 0, 0.0f){ } + Sales_data(const std::string &s) : Sales_data(s, 0, 0.0f){ } Sales_data(std::istream &is); Sales_data& operator+=(const Sales_data&); // compound-assignment diff --git a/ch14/ex14_07.h b/ch14/ex14_07.h index 613770c8..ccca4b0b 100644 --- a/ch14/ex14_07.h +++ b/ch14/ex14_07.h @@ -8,7 +8,7 @@ class String { friend std::ostream& operator<<(std::ostream&, const String&); public: - String() : String("") {} + String() : String("") { } String(const char *); String(const String&); String& operator=(const String&); diff --git a/ch14/ex14_16_StrBlob.h b/ch14/ex14_16_StrBlob.h index 8744eed6..42b94bb0 100644 --- a/ch14/ex14_16_StrBlob.h +++ b/ch14/ex14_16_StrBlob.h @@ -50,13 +50,13 @@ class StrBlob { friend bool operator!=(const StrBlob&, const StrBlob&); public: - StrBlob() : data(make_shared>()) {} - StrBlob(initializer_list il) : data(make_shared>(il)) {} + StrBlob() : data(make_shared>()) { } + StrBlob(initializer_list il) : data(make_shared>(il)) { } - StrBlob(const StrBlob &sb) : data(make_shared>(*sb.data)) {} + StrBlob(const StrBlob &sb) : data(make_shared>(*sb.data)) { } StrBlob& operator=(const StrBlob&); - StrBlob(StrBlob &&rhs) NOEXCEPT : data(std::move(rhs.data)) {} + StrBlob(StrBlob &&rhs) NOEXCEPT : data(std::move(rhs.data)) { } StrBlob& operator=(StrBlob &&)NOEXCEPT; StrBlobPtr begin(); @@ -131,8 +131,8 @@ class StrBlobPtr { friend bool operator==(const StrBlobPtr&, const StrBlobPtr&); friend bool operator!=(const StrBlobPtr&, const StrBlobPtr&); public: - StrBlobPtr() : curr(0) {} - StrBlobPtr(StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) {} + StrBlobPtr() : curr(0) { } + StrBlobPtr(StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) { } string& deref() const; StrBlobPtr& incr(); @@ -179,8 +179,8 @@ class ConstStrBlobPtr { friend bool operator!=(const ConstStrBlobPtr&, const ConstStrBlobPtr&); public: - ConstStrBlobPtr() : curr(0) {} - ConstStrBlobPtr(const StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) {} + ConstStrBlobPtr() : curr(0) { } + ConstStrBlobPtr(const StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) { } const string& deref() const; ConstStrBlobPtr& incr(); diff --git a/ch14/ex14_16_StrVec.h b/ch14/ex14_16_StrVec.h index 1f5ed7c1..edb7cfc6 100644 --- a/ch14/ex14_16_StrVec.h +++ b/ch14/ex14_16_StrVec.h @@ -17,7 +17,7 @@ class StrVec friend bool operator!=(const StrVec&, const StrVec&); public: - StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) {} + StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) { } StrVec(std::initializer_list); StrVec(const StrVec&); StrVec& operator=(const StrVec&); diff --git a/ch14/ex14_16_String.h b/ch14/ex14_16_String.h index 30f141d1..1deae133 100644 --- a/ch14/ex14_16_String.h +++ b/ch14/ex14_16_String.h @@ -18,7 +18,7 @@ class String friend bool operator!=(const String&, const String&); public: - String() : String("") {} + String() : String("") { } String(const char *); String(const String&); String& operator=(const String&); diff --git a/ch14/ex14_18_StrBlob.h b/ch14/ex14_18_StrBlob.h index 1eab5365..f669e367 100644 --- a/ch14/ex14_18_StrBlob.h +++ b/ch14/ex14_18_StrBlob.h @@ -54,13 +54,13 @@ class StrBlob { friend bool operator>=(const StrBlob&, const StrBlob&); public: - StrBlob() : data(make_shared>()) {} - StrBlob(initializer_list il) : data(make_shared>(il)) {} + StrBlob() : data(make_shared>()) { } + StrBlob(initializer_list il) : data(make_shared>(il)) { } - StrBlob(const StrBlob &sb) : data(make_shared>(*sb.data)) {} + StrBlob(const StrBlob &sb) : data(make_shared>(*sb.data)) { } StrBlob& operator=(const StrBlob&); - StrBlob(StrBlob &&rhs) NOEXCEPT : data(std::move(rhs.data)) {} + StrBlob(StrBlob &&rhs) NOEXCEPT : data(std::move(rhs.data)) { } StrBlob& operator=(StrBlob &&)NOEXCEPT; StrBlobPtr begin(); @@ -144,8 +144,8 @@ class StrBlobPtr { friend bool operator>=(const StrBlobPtr&, const StrBlobPtr&); public: - StrBlobPtr() : curr(0) {} - StrBlobPtr(StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) {} + StrBlobPtr() : curr(0) { } + StrBlobPtr(StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) { } string& deref() const; StrBlobPtr& incr(); @@ -200,8 +200,8 @@ class ConstStrBlobPtr { friend bool operator>=(const ConstStrBlobPtr&, const ConstStrBlobPtr&); public: - ConstStrBlobPtr() : curr(0) {} - ConstStrBlobPtr(const StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) {} + ConstStrBlobPtr() : curr(0) { } + ConstStrBlobPtr(const StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) { } const string& deref() const; ConstStrBlobPtr& incr(); diff --git a/ch14/ex14_18_StrVec.h b/ch14/ex14_18_StrVec.h index 52a39e9d..8a9a80f2 100644 --- a/ch14/ex14_18_StrVec.h +++ b/ch14/ex14_18_StrVec.h @@ -21,7 +21,7 @@ class StrVec friend bool operator>=(const StrVec&, const StrVec&); public: - StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) {} + StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) { } StrVec(std::initializer_list); StrVec(const StrVec&); StrVec& operator=(const StrVec&); diff --git a/ch14/ex14_18_StrVecMain.cpp b/ch14/ex14_18_StrVecMain.cpp index 52a39e9d..8a9a80f2 100644 --- a/ch14/ex14_18_StrVecMain.cpp +++ b/ch14/ex14_18_StrVecMain.cpp @@ -21,7 +21,7 @@ class StrVec friend bool operator>=(const StrVec&, const StrVec&); public: - StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) {} + StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) { } StrVec(std::initializer_list); StrVec(const StrVec&); StrVec& operator=(const StrVec&); diff --git a/ch14/ex14_18_String.h b/ch14/ex14_18_String.h index 38bf5722..240fafac 100644 --- a/ch14/ex14_18_String.h +++ b/ch14/ex14_18_String.h @@ -30,7 +30,7 @@ class String friend bool operator>=(const String&, const String&); public: - String() : String("") {} + String() : String("") { } String(const char *); String(const String&); String& operator=(const String&); diff --git a/ch14/ex14_22.h b/ch14/ex14_22.h index 487f4df3..2af564fd 100644 --- a/ch14/ex14_22.h +++ b/ch14/ex14_22.h @@ -22,9 +22,9 @@ class Sales_data { friend Sales_data operator+(const Sales_data&, const Sales_data&); public: - Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){} - Sales_data() : Sales_data("", 0, 0.0f){} - Sales_data(const std::string &s) : Sales_data(s, 0, 0.0f){} + Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){ } + Sales_data() : Sales_data("", 0, 0.0f){ } + Sales_data(const std::string &s) : Sales_data(s, 0, 0.0f){ } Sales_data(std::istream &is); Sales_data& operator=(const std::string&); diff --git a/ch14/ex14_23.h b/ch14/ex14_23.h index a2a9fb3b..102845f9 100644 --- a/ch14/ex14_23.h +++ b/ch14/ex14_23.h @@ -21,7 +21,7 @@ class StrVec friend bool operator>=(const StrVec&, const StrVec&); public: - StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) {} + StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) { } StrVec(std::initializer_list); StrVec(const StrVec&); StrVec& operator=(const StrVec&); diff --git a/ch14/ex14_24.cpp b/ch14/ex14_24.cpp index 875eb916..49a93c93 100644 --- a/ch14/ex14_24.cpp +++ b/ch14/ex14_24.cpp @@ -64,12 +64,12 @@ Date::Date(std::istream &is, std::ostream &os) // copy constructor Date::Date(const Date &d) : day(d.day), month(d.month), year(d.year) -{} +{ } // move constructor Date::Date(Date&& d) NOEXCEPT : day(d.day), month(d.month), year(d.year) -{ std::cout << "copy moving";} +{ std::cout << "copy moving"; } // copy operator= Date &Date::operator= (const Date &d) diff --git a/ch14/ex14_24.h b/ch14/ex14_24.h index a7b702f3..4f152eae 100644 --- a/ch14/ex14_24.h +++ b/ch14/ex14_24.h @@ -108,11 +108,11 @@ static const Date::Size YtoD_1 = 365; //365 // normal year static const std::vector monthsVec_n = -{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // leap year static const std::vector monthsVec_l = -{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // non-member operators: << >> - == != < <= > >= // diff --git a/ch14/ex14_26_StrBlob.h b/ch14/ex14_26_StrBlob.h index c6833ef7..650e1366 100644 --- a/ch14/ex14_26_StrBlob.h +++ b/ch14/ex14_26_StrBlob.h @@ -54,13 +54,13 @@ class StrBlob { friend bool operator>=(const StrBlob&, const StrBlob&); public: - StrBlob() : data(make_shared>()) {} - StrBlob(initializer_list il) : data(make_shared>(il)) {} + StrBlob() : data(make_shared>()) { } + StrBlob(initializer_list il) : data(make_shared>(il)) { } - StrBlob(const StrBlob &sb) : data(make_shared>(*sb.data)) {} + StrBlob(const StrBlob &sb) : data(make_shared>(*sb.data)) { } StrBlob& operator=(const StrBlob&); - StrBlob(StrBlob &&rhs) NOEXCEPT : data(std::move(rhs.data)) {} + StrBlob(StrBlob &&rhs) NOEXCEPT : data(std::move(rhs.data)) { } StrBlob& operator=(StrBlob &&)NOEXCEPT; StrBlobPtr begin(); @@ -159,8 +159,8 @@ class StrBlobPtr { friend bool operator>=(const StrBlobPtr&, const StrBlobPtr&); public: - StrBlobPtr() : curr(0) {} - StrBlobPtr(StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) {} + StrBlobPtr() : curr(0) { } + StrBlobPtr(StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) { } string& deref() const; StrBlobPtr& incr(); @@ -230,8 +230,8 @@ class ConstStrBlobPtr { friend bool operator>=(const ConstStrBlobPtr&, const ConstStrBlobPtr&); public: - ConstStrBlobPtr() : curr(0) {} - ConstStrBlobPtr(const StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) {} + ConstStrBlobPtr() : curr(0) { } + ConstStrBlobPtr(const StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) { } const string& deref() const; ConstStrBlobPtr& incr(); diff --git a/ch14/ex14_26_StrVec.h b/ch14/ex14_26_StrVec.h index 54b80038..6c8f2131 100644 --- a/ch14/ex14_26_StrVec.h +++ b/ch14/ex14_26_StrVec.h @@ -21,7 +21,7 @@ class StrVec friend bool operator>=(const StrVec&, const StrVec&); public: - StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) {} + StrVec() : elements(nullptr), first_free(nullptr), cap(nullptr) { } StrVec(std::initializer_list); StrVec(const StrVec&); StrVec& operator=(const StrVec&); diff --git a/ch14/ex14_26_String.h b/ch14/ex14_26_String.h index 49d867be..6af223fb 100644 --- a/ch14/ex14_26_String.h +++ b/ch14/ex14_26_String.h @@ -30,7 +30,7 @@ class String friend bool operator>=(const String&, const String&); public: - String() : String("") {} + String() : String("") { } String(const char *); String(const String&); String& operator=(const String&); diff --git a/ch14/ex14_27_28_StrBlob.h b/ch14/ex14_27_28_StrBlob.h index 8653ec29..0af18f2f 100644 --- a/ch14/ex14_27_28_StrBlob.h +++ b/ch14/ex14_27_28_StrBlob.h @@ -54,13 +54,13 @@ class StrBlob { friend bool operator>=(const StrBlob&, const StrBlob&); public: - StrBlob() : data(make_shared>()) {} - StrBlob(initializer_list il) : data(make_shared>(il)) {} + StrBlob() : data(make_shared>()) { } + StrBlob(initializer_list il) : data(make_shared>(il)) { } - StrBlob(const StrBlob &sb) : data(make_shared>(*sb.data)) {} + StrBlob(const StrBlob &sb) : data(make_shared>(*sb.data)) { } StrBlob& operator=(const StrBlob&); - StrBlob(StrBlob &&rhs) NOEXCEPT : data(std::move(rhs.data)) {} + StrBlob(StrBlob &&rhs) NOEXCEPT : data(std::move(rhs.data)) { } StrBlob& operator=(StrBlob &&)NOEXCEPT; StrBlobPtr begin(); @@ -159,8 +159,8 @@ class StrBlobPtr { friend bool operator>=(const StrBlobPtr&, const StrBlobPtr&); public: - StrBlobPtr() : curr(0) {} - StrBlobPtr(StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) {} + StrBlobPtr() : curr(0) { } + StrBlobPtr(StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) { } string& deref() const; StrBlobPtr& operator++(); @@ -286,8 +286,8 @@ class ConstStrBlobPtr { friend bool operator>=(const ConstStrBlobPtr&, const ConstStrBlobPtr&); public: - ConstStrBlobPtr() : curr(0) {} - ConstStrBlobPtr(const StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) {} + ConstStrBlobPtr() : curr(0) { } + ConstStrBlobPtr(const StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) { } const string& deref() const; ConstStrBlobPtr& operator++(); diff --git a/ch14/ex14_30_StrBlob.h b/ch14/ex14_30_StrBlob.h index 4f0bcbf4..396fef13 100644 --- a/ch14/ex14_30_StrBlob.h +++ b/ch14/ex14_30_StrBlob.h @@ -54,13 +54,13 @@ class StrBlob { friend bool operator>=(const StrBlob&, const StrBlob&); public: - StrBlob() : data(make_shared>()) {} - StrBlob(initializer_list il) : data(make_shared>(il)) {} + StrBlob() : data(make_shared>()) { } + StrBlob(initializer_list il) : data(make_shared>(il)) { } - StrBlob(const StrBlob &sb) : data(make_shared>(*sb.data)) {} + StrBlob(const StrBlob &sb) : data(make_shared>(*sb.data)) { } StrBlob& operator=(const StrBlob&); - StrBlob(StrBlob &&rhs) NOEXCEPT : data(std::move(rhs.data)) {} + StrBlob(StrBlob &&rhs) NOEXCEPT : data(std::move(rhs.data)) { } StrBlob& operator=(StrBlob &&)NOEXCEPT; StrBlobPtr begin(); @@ -159,8 +159,8 @@ class StrBlobPtr { friend bool operator>=(const StrBlobPtr&, const StrBlobPtr&); public: - StrBlobPtr() : curr(0) {} - StrBlobPtr(StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) {} + StrBlobPtr() : curr(0) { } + StrBlobPtr(StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) { } string& deref() const; StrBlobPtr& operator++(); @@ -286,8 +286,8 @@ class ConstStrBlobPtr { friend bool operator>=(const ConstStrBlobPtr&, const ConstStrBlobPtr&); public: - ConstStrBlobPtr() : curr(0) {} - ConstStrBlobPtr(const StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) {} + ConstStrBlobPtr() : curr(0) { } + ConstStrBlobPtr(const StrBlob &s, size_t sz = 0) : wptr(s.data), curr(sz) { } const string& operator*() const; const string* operator->() const; diff --git a/ch14/ex14_32.cpp b/ch14/ex14_32.cpp index 32f2d4eb..1d1d7db4 100644 --- a/ch14/ex14_32.cpp +++ b/ch14/ex14_32.cpp @@ -16,7 +16,7 @@ StrBlobPtr_pointer::operator ->() int main() { - StrBlob sb{"hello", "world"}; + StrBlob sb{ "hello", "world" }; StrBlobPtr iter = sb.begin(); StrBlobPtr_pointer p(&iter); std::cout << p->deref() << std::endl; diff --git a/ch14/ex14_32.h b/ch14/ex14_32.h index eda3aaac..d0931b67 100644 --- a/ch14/ex14_32.h +++ b/ch14/ex14_32.h @@ -17,7 +17,7 @@ class StrBlobPtr_pointer { public: StrBlobPtr_pointer() = default; - StrBlobPtr_pointer(StrBlobPtr* p) : pointer(p) {} + StrBlobPtr_pointer(StrBlobPtr* p) : pointer(p) { } StrBlobPtr& operator *(); StrBlobPtr* operator->(); diff --git a/ch14/ex14_37.cpp b/ch14/ex14_37.cpp index bcf4ef40..c1df35b5 100644 --- a/ch14/ex14_37.cpp +++ b/ch14/ex14_37.cpp @@ -5,7 +5,7 @@ class IsEqual { int value; public: - IsEqual(int v) : value(v) {} + IsEqual(int v) : value(v) { } bool operator()(int elem) { return elem == value; } @@ -13,7 +13,7 @@ class IsEqual { int main() { - std::vector vec = {3, 2, 1, 4, 3, 7, 8, 6}; + std::vector vec = { 3, 2, 1, 4, 3, 7, 8, 6 }; std::replace_if(vec.begin(), vec.end(), IsEqual(3), 5); for (int i : vec) std::cout << i << " "; std::cout << std::endl; diff --git a/ch14/ex14_38_39.cpp b/ch14/ex14_38_39.cpp index 0304b4e0..1a1f14c0 100644 --- a/ch14/ex14_38_39.cpp +++ b/ch14/ex14_38_39.cpp @@ -19,7 +19,7 @@ struct IsInRange { IsInRange(std::size_t lower, std::size_t upper) :_lower(lower), _upper(upper) - {} + { } bool operator()(std::string const& str) const { diff --git a/ch14/ex14_40.cpp b/ch14/ex14_40.cpp index e5b19fee..f94b2977 100644 --- a/ch14/ex14_40.cpp +++ b/ch14/ex14_40.cpp @@ -30,7 +30,7 @@ class ShorterString { class BiggerEqual { size_t sz_; public: - BiggerEqual(size_t sz) : sz_(sz) {} + BiggerEqual(size_t sz) : sz_(sz) { } bool operator()(string const& s) { return s.size() >= sz_; } }; @@ -62,6 +62,6 @@ void biggies( vector &words, vector::size_type sz ) { int main() { - vector vec{ "fox", "jumps", "over", "quick", "red", "red", "slow", "the", "turtle"}; + vector vec{ "fox", "jumps", "over", "quick", "red", "red", "slow", "the", "turtle" }; biggies(vec, 4); } diff --git a/ch14/ex14_42.cpp b/ch14/ex14_42.cpp index 12ccb592..027babf9 100644 --- a/ch14/ex14_42.cpp +++ b/ch14/ex14_42.cpp @@ -8,11 +8,11 @@ int main() { using std::placeholders::_1; - std::vector ivec {1, 111, 1111, 11111}; + std::vector ivec { 1, 111, 1111, 11111 }; int count = std::count_if (ivec.cbegin(), ivec.cend(), std::bind(std::greater(), _1, 1024)); std::cout << count << std::endl; - std::vector svec {"pooh", "pooh", "pezy", "pooh"}; + std::vector svec { "pooh", "pooh", "pezy", "pooh" }; auto found = std::find_if (svec.cbegin(), svec.cend(), std::bind(std::not_equal_to(), _1, "pooh")); std::cout << *found << std::endl; diff --git a/ch14/ex14_44.cpp b/ch14/ex14_44.cpp index ab6528ff..c88d463c 100644 --- a/ch14/ex14_44.cpp +++ b/ch14/ex14_44.cpp @@ -17,7 +17,7 @@ #include int add(int i, int j){ return i + j; } -auto mod = [](int i, int j){return i % j; }; +auto mod = [](int i, int j){ return i % j; }; struct Div{ int operator ()(int i, int j) const { return i / j; } }; auto binops = std::map> diff --git a/ch14/ex14_45.h b/ch14/ex14_45.h index 7a7a1b9f..fc0f3229 100644 --- a/ch14/ex14_45.h +++ b/ch14/ex14_45.h @@ -22,9 +22,9 @@ class Sales_data { friend Sales_data operator+(const Sales_data&, const Sales_data&); public: - Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){} - Sales_data() : Sales_data("", 0, 0.0f){} - Sales_data(const std::string &s) : Sales_data(s, 0, 0.0f){} + Sales_data(const std::string &s, unsigned n, double p):bookNo(s), units_sold(n), revenue(n*p){ } + Sales_data() : Sales_data("", 0, 0.0f){ } + Sales_data(const std::string &s) : Sales_data(s, 0, 0.0f){ } Sales_data(std::istream &is); Sales_data& operator=(const std::string&); diff --git a/ch14/ex14_49.cpp b/ch14/ex14_49.cpp index 8998ee79..9c4f1f84 100644 --- a/ch14/ex14_49.cpp +++ b/ch14/ex14_49.cpp @@ -64,12 +64,12 @@ Date::Date(std::istream &is, std::ostream &os) // copy constructor Date::Date(const Date &d) : day(d.day), month(d.month), year(d.year) -{} +{ } // move constructor Date::Date(Date&& d) noexcept : day(d.day), month(d.month), year(d.year) -{ std::cout << "copy moving";} +{ std::cout << "copy moving"; } // copy operator= Date &Date::operator= (const Date &d) diff --git a/ch14/ex14_49.h b/ch14/ex14_49.h index 48c4b40d..28012327 100644 --- a/ch14/ex14_49.h +++ b/ch14/ex14_49.h @@ -106,11 +106,11 @@ static const Date::Size YtoD_1 = 365; //365 // normal year static const std::vector monthsVec_n = -{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // leap year static const std::vector monthsVec_l = -{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; +{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // non-member operators: << >> - == != < <= > >= // diff --git a/ch15/ex15.23.cpp b/ch15/ex15.23.cpp index 5a27b97e..02c29579 100644 --- a/ch15/ex15.23.cpp +++ b/ch15/ex15.23.cpp @@ -26,23 +26,23 @@ class Base { public: - virtual int fcn(){std::cout << "Base::fcn()\n"; return 0;} + virtual int fcn(){ std::cout << "Base::fcn()\n"; return 0; } }; class D1 : public Base { public: - int fcn() override {std::cout << "D1::fcn()\n";return 0;} + int fcn() override { std::cout << "D1::fcn()\n";return 0; } // ^^^--fixed to override the inherited version - virtual void f2() {std::cout << "D1::f2()\n";} + virtual void f2() { std::cout << "D1::f2()\n"; } }; class D2 : public D1 { public: int fcn(int); - int fcn() override {std::cout << "D2::fcn()\n";return 0;} - void f2() override {std::cout << "D2::f2()\n";} + int fcn() override { std::cout << "D2::fcn()\n";return 0; } + void f2() override { std::cout << "D2::f2()\n"; } }; int main() diff --git a/ch15/ex15.26/bulk_quote.h b/ch15/ex15.26/bulk_quote.h index 594d1ca9..d3d2a0ce 100644 --- a/ch15/ex15.26/bulk_quote.h +++ b/ch15/ex15.26/bulk_quote.h @@ -6,7 +6,7 @@ class Bulk_quote : public Disc_quote { public: - Bulk_quote() {std::cout << "default constructing Bulk_quote\n"; } + Bulk_quote() { std::cout << "default constructing Bulk_quote\n"; } Bulk_quote(const std::string& b, double p, std::size_t q, double disc) : Disc_quote(b, p, q, disc) { std::cout << "Bulk_quote : constructor taking 4 parameters\n"; } diff --git a/ch15/ex15.27/bulk_quote.h b/ch15/ex15.27/bulk_quote.h index 9fa75b1a..814674f7 100644 --- a/ch15/ex15.27/bulk_quote.h +++ b/ch15/ex15.27/bulk_quote.h @@ -6,7 +6,7 @@ class Bulk_quote : public Disc_quote { public: - Bulk_quote() {std::cout << "default constructing Bulk_quote\n"; } + Bulk_quote() { std::cout << "default constructing Bulk_quote\n"; } // changed the below to the inherited constructor for ex15.27. // rules: 1. only inherit from the direct base class. diff --git a/ch15/ex15.28.29/bulk_quote.h b/ch15/ex15.28.29/bulk_quote.h index 9fa75b1a..814674f7 100644 --- a/ch15/ex15.28.29/bulk_quote.h +++ b/ch15/ex15.28.29/bulk_quote.h @@ -6,7 +6,7 @@ class Bulk_quote : public Disc_quote { public: - Bulk_quote() {std::cout << "default constructing Bulk_quote\n"; } + Bulk_quote() { std::cout << "default constructing Bulk_quote\n"; } // changed the below to the inherited constructor for ex15.27. // rules: 1. only inherit from the direct base class. diff --git a/ch15/ex15.30/basket.h b/ch15/ex15.30/basket.h index a3627d5c..752a0a00 100644 --- a/ch15/ex15.30/basket.h +++ b/ch15/ex15.30/basket.h @@ -28,7 +28,7 @@ class Basket // hold multiple quotes, ordered by the compare member std::multiset, decltype(compare)*> - items{compare}; + items{ compare }; }; #endif // BASKET_H diff --git a/ch15/ex15.30/bulk_quote.h b/ch15/ex15.30/bulk_quote.h index cd7b2d72..355b7799 100644 --- a/ch15/ex15.30/bulk_quote.h +++ b/ch15/ex15.30/bulk_quote.h @@ -6,7 +6,7 @@ class Bulk_quote : public Disc_quote { public: - Bulk_quote() {std::cout << "default constructing Bulk_quote\n"; } + Bulk_quote() { std::cout << "default constructing Bulk_quote\n"; } // changed the below to the inherited constructor for ex15.27. // rules: 1. only inherit from the direct base class. @@ -49,8 +49,8 @@ class Bulk_quote : public Disc_quote } // clone self - virtual Bulk_quote* clone() const & {return new Bulk_quote(*this);} - virtual Bulk_quote* clone() && {return new Bulk_quote(std::move(*this));} + virtual Bulk_quote* clone() const & { return new Bulk_quote(*this); } + virtual Bulk_quote* clone() && { return new Bulk_quote(std::move(*this)); } double net_price(std::size_t n) const override; void debug() const override; diff --git a/ch15/ex15.30/quote.h b/ch15/ex15.30/quote.h index 9f0ec3a5..495b735b 100644 --- a/ch15/ex15.30/quote.h +++ b/ch15/ex15.30/quote.h @@ -47,8 +47,8 @@ class Quote } // clone self - virtual Quote* clone() const & {return new Quote(*this);} - virtual Quote* clone() && {return new Quote(std::move(*this));} + virtual Quote* clone() const & { return new Quote(*this); } + virtual Quote* clone() && { return new Quote(std::move(*this)); } std::string isbn() const { return bookNo; } virtual double net_price(std::size_t n) const { return n * price; } diff --git a/ch15/ex15.31.32.33.cpp b/ch15/ex15.31.32.33.cpp index 4ceb6801..4da0dc18 100644 --- a/ch15/ex15.31.32.33.cpp +++ b/ch15/ex15.31.32.33.cpp @@ -74,7 +74,7 @@ class Foo }; int main() { - std::vector v = {"alan","alan","alan","alan","alan"}; + std::vector v = { "alan","alan","alan","alan","alan" }; Foo foo(v); diff --git a/ch15/ex15.42_b/andquery.h b/ch15/ex15.42_b/andquery.h index 04cfd68d..53207061 100644 --- a/ch15/ex15.42_b/andquery.h +++ b/ch15/ex15.42_b/andquery.h @@ -13,7 +13,7 @@ class TextQuery; class AndQuery :public BinaryQuery { friend Query operator&(const Query&, const Query&); - AndQuery(const Query &left, const Query &right) :BinaryQuery(left, right, "&"){} + AndQuery(const Query &left, const Query &right) :BinaryQuery(left, right, "&"){ } QueryResult eval(const TextQuery&) const; }; diff --git a/ch15/ex15.42_b/binaryquery.h b/ch15/ex15.42_b/binaryquery.h index 4389d42d..722e9aa5 100644 --- a/ch15/ex15.42_b/binaryquery.h +++ b/ch15/ex15.42_b/binaryquery.h @@ -11,7 +11,7 @@ using std::string; class BinaryQuery :public Query_base { protected: - BinaryQuery(const Query &l, const Query &r, string s) :lhs(l), rhs(r), opSym(s){} + BinaryQuery(const Query &l, const Query &r, string s) :lhs(l), rhs(r), opSym(s){ } string rep() const { return "(" + lhs.rep() + " " + opSym + " " + rhs.rep() + ")"; diff --git a/ch15/ex15.42_b/notquery.h b/ch15/ex15.42_b/notquery.h index 6c11f90c..a797fb9b 100644 --- a/ch15/ex15.42_b/notquery.h +++ b/ch15/ex15.42_b/notquery.h @@ -17,7 +17,7 @@ class NotQuery :public Query_base { friend Query operator~(const Query&); //call Query's default copy constructor. - NotQuery(const Query &q) :query(q){} + NotQuery(const Query &q) :query(q){ } string rep() const{ return "~(" + query.rep() + ")"; } QueryResult eval(const TextQuery&) const; diff --git a/ch15/ex15.42_b/orquery.h b/ch15/ex15.42_b/orquery.h index 95a4856d..3212fcd2 100644 --- a/ch15/ex15.42_b/orquery.h +++ b/ch15/ex15.42_b/orquery.h @@ -13,7 +13,7 @@ class TextQuery; class OrQuery :public BinaryQuery { friend Query operator|(const Query&, const Query&); - OrQuery(const Query &left, const Query &right) :BinaryQuery(left, right, "|"){} + OrQuery(const Query &left, const Query &right) :BinaryQuery(left, right, "|"){ } QueryResult eval(const TextQuery&) const; }; diff --git a/ch15/ex15.42_b/query.h b/ch15/ex15.42_b/query.h index 0c48989b..7e1992a5 100644 --- a/ch15/ex15.42_b/query.h +++ b/ch15/ex15.42_b/query.h @@ -28,12 +28,12 @@ class Query QueryResult eval(const TextQuery &t) const { return q->eval(t); } string rep() const { return q->rep(); } private: - Query(shared_ptr query) :q(query){} + Query(shared_ptr query) :q(query){ } shared_ptr q; }; ostream & operator<<(ostream &os, const Query &query); -inline Query::Query(const string &s) :q(new WordQuery(s)){} +inline Query::Query(const string &s) :q(new WordQuery(s)){ } #endif diff --git a/ch15/ex15.42_b/queryresult.h b/ch15/ex15.42_b/queryresult.h index f8c6a941..183a1ee6 100644 --- a/ch15/ex15.42_b/queryresult.h +++ b/ch15/ex15.42_b/queryresult.h @@ -27,7 +27,7 @@ class QueryResult QueryResult(string s, shared_ptr> l, shared_ptr> f) : - sought(s), lines(l), file(f){} + sought(s), lines(l), file(f){ } set::iterator begin(){ return lines->begin(); } set::iterator end(){ return lines->end(); } diff --git a/ch15/ex15.42_b/wordquery.h b/ch15/ex15.42_b/wordquery.h index 7410e41a..2c0bfe67 100644 --- a/ch15/ex15.42_b/wordquery.h +++ b/ch15/ex15.42_b/wordquery.h @@ -11,7 +11,7 @@ using std::string; class WordQuery:public Query_base { friend class Query; - WordQuery(const string &s) :query_word(s){} + WordQuery(const string &s) :query_word(s){ } QueryResult eval(const TextQuery &t) const{ return t.query(query_word); } string rep() const { return query_word; } diff --git a/ch15/ex15.42_c/andquery.h b/ch15/ex15.42_c/andquery.h index 04cfd68d..53207061 100644 --- a/ch15/ex15.42_c/andquery.h +++ b/ch15/ex15.42_c/andquery.h @@ -13,7 +13,7 @@ class TextQuery; class AndQuery :public BinaryQuery { friend Query operator&(const Query&, const Query&); - AndQuery(const Query &left, const Query &right) :BinaryQuery(left, right, "&"){} + AndQuery(const Query &left, const Query &right) :BinaryQuery(left, right, "&"){ } QueryResult eval(const TextQuery&) const; }; diff --git a/ch15/ex15.42_c/binaryquery.h b/ch15/ex15.42_c/binaryquery.h index 4389d42d..722e9aa5 100644 --- a/ch15/ex15.42_c/binaryquery.h +++ b/ch15/ex15.42_c/binaryquery.h @@ -11,7 +11,7 @@ using std::string; class BinaryQuery :public Query_base { protected: - BinaryQuery(const Query &l, const Query &r, string s) :lhs(l), rhs(r), opSym(s){} + BinaryQuery(const Query &l, const Query &r, string s) :lhs(l), rhs(r), opSym(s){ } string rep() const { return "(" + lhs.rep() + " " + opSym + " " + rhs.rep() + ")"; diff --git a/ch15/ex15.42_c/notquery.h b/ch15/ex15.42_c/notquery.h index 6c11f90c..a797fb9b 100644 --- a/ch15/ex15.42_c/notquery.h +++ b/ch15/ex15.42_c/notquery.h @@ -17,7 +17,7 @@ class NotQuery :public Query_base { friend Query operator~(const Query&); //call Query's default copy constructor. - NotQuery(const Query &q) :query(q){} + NotQuery(const Query &q) :query(q){ } string rep() const{ return "~(" + query.rep() + ")"; } QueryResult eval(const TextQuery&) const; diff --git a/ch15/ex15.42_c/orquery.h b/ch15/ex15.42_c/orquery.h index 95a4856d..3212fcd2 100644 --- a/ch15/ex15.42_c/orquery.h +++ b/ch15/ex15.42_c/orquery.h @@ -13,7 +13,7 @@ class TextQuery; class OrQuery :public BinaryQuery { friend Query operator|(const Query&, const Query&); - OrQuery(const Query &left, const Query &right) :BinaryQuery(left, right, "|"){} + OrQuery(const Query &left, const Query &right) :BinaryQuery(left, right, "|"){ } QueryResult eval(const TextQuery&) const; }; diff --git a/ch15/ex15.42_c/query.h b/ch15/ex15.42_c/query.h index 0c48989b..7e1992a5 100644 --- a/ch15/ex15.42_c/query.h +++ b/ch15/ex15.42_c/query.h @@ -28,12 +28,12 @@ class Query QueryResult eval(const TextQuery &t) const { return q->eval(t); } string rep() const { return q->rep(); } private: - Query(shared_ptr query) :q(query){} + Query(shared_ptr query) :q(query){ } shared_ptr q; }; ostream & operator<<(ostream &os, const Query &query); -inline Query::Query(const string &s) :q(new WordQuery(s)){} +inline Query::Query(const string &s) :q(new WordQuery(s)){ } #endif diff --git a/ch15/ex15.42_c/queryresult.h b/ch15/ex15.42_c/queryresult.h index 9022a6de..84c6d439 100644 --- a/ch15/ex15.42_c/queryresult.h +++ b/ch15/ex15.42_c/queryresult.h @@ -28,7 +28,7 @@ class QueryResult QueryResult(string s, shared_ptr> l, shared_ptr> f) : - sought(s), lines(l), file(f){} + sought(s), lines(l), file(f){ } set::iterator begin(){ return lines->begin(); } set::iterator end(){ return lines->end(); } diff --git a/ch15/ex15.42_c/wordquery.h b/ch15/ex15.42_c/wordquery.h index 7410e41a..2c0bfe67 100644 --- a/ch15/ex15.42_c/wordquery.h +++ b/ch15/ex15.42_c/wordquery.h @@ -11,7 +11,7 @@ using std::string; class WordQuery:public Query_base { friend class Query; - WordQuery(const string &s) :query_word(s){} + WordQuery(const string &s) :query_word(s){ } QueryResult eval(const TextQuery &t) const{ return t.query(query_word); } string rep() const { return query_word; } diff --git a/ch16/ex16.1.2.3/main.cpp b/ch16/ex16.1.2.3/main.cpp index 42c7c8d5..ebd39919 100644 --- a/ch16/ex16.1.2.3/main.cpp +++ b/ch16/ex16.1.2.3/main.cpp @@ -31,7 +31,7 @@ using std::endl; #include using std::vector; -class Sales_data{}; +class Sales_data{ }; template int compare(const T& lhs, const T& rhs) @@ -45,7 +45,7 @@ int main() { // Test compare function cout << compare(1, 0) << endl; - vector vec1{1, 2, 3}, vec2{4, 5, 6}; + vector vec1{ 1, 2, 3 }, vec2{ 4, 5, 6 }; cout << compare(vec1, vec2) << endl; return 0; diff --git a/ch16/ex16.12.13/Blob.h b/ch16/ex16.12.13/Blob.h index 571a9f3a..b42dee30 100644 --- a/ch16/ex16.12.13/Blob.h +++ b/ch16/ex16.12.13/Blob.h @@ -15,10 +15,10 @@ template class Blob // number of elements in the Blob size_type size() const { return data->size(); } - bool empty() const{ return data->empty();} + bool empty() const{ return data->empty(); } void push_back(const T& t) { data->push_back(t); } - void push_back(T&& t) { data->push_back(std::move(t));} + void push_back(T&& t) { data->push_back(std::move(t)); } void pop_back(); // element access @@ -37,7 +37,7 @@ template class Blob // constructors template Blob::Blob() : data(std::make_shared>()) -{} +{ } template Blob::Blob(std::initializer_list il): diff --git a/ch16/ex16.16/main.cpp b/ch16/ex16.16/main.cpp index 9cefd521..bf42bd11 100644 --- a/ch16/ex16.16/main.cpp +++ b/ch16/ex16.16/main.cpp @@ -16,7 +16,7 @@ int main() { - Vec v = {1, 2, 3, 4, 5}; + Vec v = { 1, 2, 3, 4, 5 }; Vec v2; diff --git a/ch16/ex16.16/vec.h b/ch16/ex16.16/vec.h index 91d018b3..61f6af69 100644 --- a/ch16/ex16.16/vec.h +++ b/ch16/ex16.16/vec.h @@ -49,7 +49,7 @@ class Vec // utillities void reallocate(); - void chk_n_alloc() { if(size()==capacity()) reallocate();} + void chk_n_alloc() { if(size()==capacity()) reallocate(); } void free(); void wy_alloc_n_move(std::size_t n); @@ -205,7 +205,7 @@ Vec::alloc_n_copy(T *b, T *e) { // calculate the size needed and allocate space accordingly T* data = alloc.allocate(e-b); - return { data, std::uninitialized_copy(b, e, data)}; + return { data, std::uninitialized_copy(b, e, data) }; // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // which copies the range[first, last) to the space to which // the starting address data is pointing. diff --git a/ch16/ex16.24/Blob.h b/ch16/ex16.24/Blob.h index ae5ff318..b25b563c 100644 --- a/ch16/ex16.24/Blob.h +++ b/ch16/ex16.24/Blob.h @@ -27,10 +27,10 @@ template class Blob // number of elements in the Blob size_type size() const { return data->size(); } - bool empty() const{ return data->empty();} + bool empty() const{ return data->empty(); } void push_back(const T& t) { data->push_back(t); } - void push_back(T&& t) { data->push_back(std::move(t));} + void push_back(T&& t) { data->push_back(std::move(t)); } void pop_back(); // element access @@ -49,7 +49,7 @@ template class Blob // default constructor template Blob::Blob() : data(std::make_shared>()) -{} +{ } // constructor taking initializer_list template @@ -61,7 +61,7 @@ template //for class template //for this member Blob::Blob(It b, It e) : data(std::make_shared>(b, e)) -{} +{ } template void Blob::check(size_type i, const std::string &msg) const diff --git a/ch16/ex16.24/main.cpp b/ch16/ex16.24/main.cpp index 5f946b07..20e84847 100644 --- a/ch16/ex16.24/main.cpp +++ b/ch16/ex16.24/main.cpp @@ -21,7 +21,7 @@ int main() { - std::vector v = {1, 2, 3, 4, 5}; + std::vector v = { 1, 2, 3, 4, 5 }; Blob b(v.begin(), v.end()); return 0; } diff --git a/ch16/ex16.28/shared_pointer.hpp b/ch16/ex16.28/shared_pointer.hpp index a6977b23..63fe7289 100644 --- a/ch16/ex16.28/shared_pointer.hpp +++ b/ch16/ex16.28/shared_pointer.hpp @@ -33,14 +33,14 @@ namespace cp5 // Default Ctor // SharedPointer() - : ptr{ nullptr }, ref_count{ new std::size_t(1) }, deleter{ cp5::Delete{} } - {} + : ptr{ nullptr }, ref_count{ new std::size_t(1) }, deleter{ cp5::Delete{ } } + { } // // Ctor that takes raw pointer // explicit SharedPointer(T* raw_ptr) - : ptr{ raw_ptr }, ref_count{ new std::size_t(1) }, deleter{ cp5::Delete{} } - {} + : ptr{ raw_ptr }, ref_count{ new std::size_t(1) }, deleter{ cp5::Delete{ } } + { } // // Copy Ctor // diff --git a/ch16/ex16.28/unique_pointer.h b/ch16/ex16.28/unique_pointer.h index edfbc2c2..850b8138 100644 --- a/ch16/ex16.28/unique_pointer.h +++ b/ch16/ex16.28/unique_pointer.h @@ -44,10 +44,10 @@ class unique_pointer operator bool() const { return ptr ? true : false; } // return the underlying pointer - T* get() const noexcept { return ptr;} + T* get() const noexcept { return ptr; } // swap member using swap friend - void swap(unique_pointer &rhs) {::swap(*this, rhs);} + void swap(unique_pointer &rhs) { ::swap(*this, rhs); } // free and make it point to nullptr or to p's pointee. void reset() noexcept { deleter(ptr); ptr = nullptr; } diff --git a/ch16/ex16.29/Blob.h b/ch16/ex16.29/Blob.h index ddd4876a..7d76629d 100644 --- a/ch16/ex16.29/Blob.h +++ b/ch16/ex16.29/Blob.h @@ -33,10 +33,10 @@ template class Blob // number of elements in the Blob size_type size() const { return data->size(); } - bool empty() const{ return data->empty();} + bool empty() const{ return data->empty(); } void push_back(const T& t) { data->push_back(t); } - void push_back(T&& t) { data->push_back(std::move(t));} + void push_back(T&& t) { data->push_back(std::move(t)); } void pop_back(); // element access @@ -61,7 +61,7 @@ template class Blob // default constructor template Blob::Blob() : data(std::make_shared>()) -{} +{ } // constructor taking initializer_list template @@ -73,7 +73,7 @@ template //for class template //for this member Blob::Blob(It b, It e) : data(std::make_shared>(b, e)) -{} +{ } template void Blob::check(size_type i, const std::string &msg) const diff --git a/ch16/ex16.29/shared_pointer.h b/ch16/ex16.29/shared_pointer.h index 737c46b4..86402c13 100644 --- a/ch16/ex16.29/shared_pointer.h +++ b/ch16/ex16.29/shared_pointer.h @@ -60,7 +60,7 @@ class shared_pointer // conversion operator - operator bool() const { return ptr ? true : false;} + operator bool() const { return ptr ? true : false; } // dereference * arrow -> T& operator* () const { return *ptr; } @@ -73,7 +73,7 @@ class shared_pointer T* get() const noexcept { return ptr; } // check if the unique user - bool unique() const noexcept { return *refCount == 1;} + bool unique() const noexcept { return *refCount == 1; } // swap member void swap( shared_pointer& rhs) { ::swap(*this, rhs); } @@ -100,7 +100,7 @@ class shared_pointer // any functor lambda or function pointer that matched this // signature can replace the default one at run time. - std::function deleter{DebugDelete()}; + std::function deleter{ DebugDelete() }; // ^~~~~~~~~~~~~~^ // here: = doesn't work, another way is initializing it in constructor. diff --git a/ch16/ex16.29/unique_pointer.h b/ch16/ex16.29/unique_pointer.h index edfbc2c2..850b8138 100644 --- a/ch16/ex16.29/unique_pointer.h +++ b/ch16/ex16.29/unique_pointer.h @@ -44,10 +44,10 @@ class unique_pointer operator bool() const { return ptr ? true : false; } // return the underlying pointer - T* get() const noexcept { return ptr;} + T* get() const noexcept { return ptr; } // swap member using swap friend - void swap(unique_pointer &rhs) {::swap(*this, rhs);} + void swap(unique_pointer &rhs) { ::swap(*this, rhs); } // free and make it point to nullptr or to p's pointee. void reset() noexcept { deleter(ptr); ptr = nullptr; } diff --git a/ch16/ex16.40/main.cpp b/ch16/ex16.40/main.cpp index 448f6c46..1a2715de 100644 --- a/ch16/ex16.40/main.cpp +++ b/ch16/ex16.40/main.cpp @@ -21,7 +21,7 @@ #include #include -class Bar{}; +class Bar{ }; Bar operator +(Bar lhs, int) { diff --git a/ch16/ex16.58.59/strvec.h b/ch16/ex16.58.59/strvec.h index 2de42d43..db58d48a 100644 --- a/ch16/ex16.58.59/strvec.h +++ b/ch16/ex16.58.59/strvec.h @@ -18,7 +18,7 @@ class StrVec // Big 3/5. StrVec(): element(nullptr), first_free(nullptr), cap(nullptr) - {} + { } StrVec(std::initializer_list l); diff --git a/ch16/ex16.58.59/vec.h b/ch16/ex16.58.59/vec.h index 1bc539a2..998af9a7 100644 --- a/ch16/ex16.58.59/vec.h +++ b/ch16/ex16.58.59/vec.h @@ -52,7 +52,7 @@ class Vec // utillities void reallocate(); - void chk_n_alloc() { if(size()==capacity()) reallocate();} + void chk_n_alloc() { if(size()==capacity()) reallocate(); } void free(); void wy_alloc_n_move(std::size_t n); @@ -217,7 +217,7 @@ Vec::alloc_n_copy(T *b, T *e) { // calculate the size needed and allocate space accordingly T* data = alloc.allocate(e-b); - return { data, std::uninitialized_copy(b, e, data)}; + return { data, std::uninitialized_copy(b, e, data) }; // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ // which copies the range[first, last) to the space to which // the starting address data is pointing. diff --git a/ch16/ex16.6/main.cpp b/ch16/ex16.6/main.cpp index 86badf49..31b1c94b 100644 --- a/ch16/ex16.6/main.cpp +++ b/ch16/ex16.6/main.cpp @@ -44,7 +44,7 @@ T* end_def(T (&arr)[size]) int main() { - std::string s[] = {"sssss","ss","ss","ssssszzzz"}; + std::string s[] = { "sssss","ss","ss","ssssszzzz" }; std::cout << *(begin_def(s)+1) << std::endl; std::cout << *(end_def(s) - 1) << std::endl; return 0; diff --git a/ch16/ex16.60.61/main.cpp b/ch16/ex16.60.61/main.cpp index d490efdf..c90695c5 100644 --- a/ch16/ex16.60.61/main.cpp +++ b/ch16/ex16.60.61/main.cpp @@ -33,7 +33,7 @@ namespace ch16 //to differ from std::make_shared struct Foo { - explicit Foo(int b) : bar(b){} + explicit Foo(int b) : bar(b){ } int bar; }; diff --git a/ch16/ex16.7.8/main.cpp b/ch16/ex16.7.8/main.cpp index e9206b68..b0476bf8 100644 --- a/ch16/ex16.7.8/main.cpp +++ b/ch16/ex16.7.8/main.cpp @@ -31,7 +31,7 @@ constexpr unsigned getSize(const T(&)[size]) int main() { - std::string s[] = {"sss"}; + std::string s[] = { "sss" }; std::cout << getSize(s) << std::endl; char c[] = "s"; diff --git a/ch17/ex17_10.cpp b/ch17/ex17_10.cpp index d1bfeb83..015f6e6c 100644 --- a/ch17/ex17_10.cpp +++ b/ch17/ex17_10.cpp @@ -21,7 +21,7 @@ int main() { - std::vector v = {1, 2, 3, 5, 8, 13, 21}; + std::vector v = { 1, 2, 3, 5, 8, 13, 21 }; std::bitset<32> bset; for (auto i : v) bset.set(i); diff --git a/ch17/ex17_11_12_13.cpp b/ch17/ex17_11_12_13.cpp index 403cc72f..0f1a6acd 100644 --- a/ch17/ex17_11_12_13.cpp +++ b/ch17/ex17_11_12_13.cpp @@ -37,7 +37,7 @@ class Quiz public: //constructors Quiz() = default; - Quiz(std::string& s) :bitquiz(s){} + Quiz(std::string& s) :bitquiz(s){ } //generate grade template diff --git a/ch17/ex17_19_20.cpp b/ch17/ex17_19_20.cpp index 1c4206fe..24b254f6 100644 --- a/ch17/ex17_19_20.cpp +++ b/ch17/ex17_19_20.cpp @@ -37,7 +37,7 @@ bool valid(const smatch& m); int main() { - string phone = "(\\()?(\\d{3})(\\))?([-. ])?(\\d{3})([-. ]?)(\\d{4})"; + string phone = "(\\()?(\\d{ 3 })(\\))?([-. ])?(\\d{ 3 })([-. ]?)(\\d{ 4 })"; regex r(phone); smatch m; string s; diff --git a/ch17/ex17_21.cpp b/ch17/ex17_21.cpp index 2e689746..f6085db8 100644 --- a/ch17/ex17_21.cpp +++ b/ch17/ex17_21.cpp @@ -109,7 +109,7 @@ bool read_record(istream& is, vector& people) void format_record(ostream& os, const vector& people) { - string phone = "(\\()?(\\d{3})(\\))?([-. ])?(\\d{3})([-. ]?)(\\d{4})"; + string phone = "(\\()?(\\d{ 3 })(\\))?([-. ])?(\\d{ 3 })([-. ]?)(\\d{ 4 })"; regex r(phone); smatch m; diff --git a/ch17/ex17_23.cpp b/ch17/ex17_23.cpp index f950fee9..5faa734e 100644 --- a/ch17/ex17_23.cpp +++ b/ch17/ex17_23.cpp @@ -39,7 +39,7 @@ using std::regex_error; int main() { try { - regex reg("(\\d{4})?([-])?(\\d{5})"); + regex reg("(\\d{ 4 })?([-])?(\\d{ 5 })"); string str; while (getline(cin, str)) { for (sregex_iterator b(str.cbegin(), str.cend(), reg), e; b != e; ++b) { diff --git a/ch17/ex17_33.cpp b/ch17/ex17_33.cpp index 085ad43d..e916c2b8 100644 --- a/ch17/ex17_33.cpp +++ b/ch17/ex17_33.cpp @@ -45,14 +45,14 @@ int main() { } i.close(); // sort words in vector - sort(dict.begin(), dict.end(), [](const ps &_ps1, const ps &_ps2){return _ps1.first < _ps2.first; }); + sort(dict.begin(), dict.end(), [](const ps &_ps1, const ps &_ps2){ return _ps1.first < _ps2.first; }); i.open("i.txt"); default_random_engine e(time(0)); // read words from text while (i >> str1) { // find word in dictionary vector::const_iterator it = find_if(dict.cbegin(), dict.cend(), - [&str1](const ps &_ps){return _ps.first == str1; }); + [&str1](const ps &_ps){ return _ps.first == str1; }); // if word doesn't exist in dictionary if (it == dict.cend()) { // write it itself @@ -61,7 +61,7 @@ int main() { else { // get random meaning of word uniform_int_distribution u (0, find_if(dict.cbegin(), dict.cend(), - [&str1](const ps &_ps){return _ps.first > str1; }) - it - 1); + [&str1](const ps &_ps){ return _ps.first > str1; }) - it - 1); // write random meaning cout << (it + u(e))->second << ' '; } diff --git a/ch17/ex17_4_5_6_7_8.cpp b/ch17/ex17_4_5_6_7_8.cpp index b83b7668..76b68d35 100644 --- a/ch17/ex17_4_5_6_7_8.cpp +++ b/ch17/ex17_4_5_6_7_8.cpp @@ -63,7 +63,7 @@ struct matches_struct std::vector::const_iterator last; matches_struct(std::vector::size_type s, std::vector::const_iterator f, - std::vector::const_iterator l) : st(s), first(f), last(l) {} + std::vector::const_iterator l) : st(s), first(f), last(l) { } } ; // for ex17.4 diff --git a/ch17/ex17_4_5_6_7_8_SalesData.h b/ch17/ex17_4_5_6_7_8_SalesData.h index 285f933f..cfec9505 100644 --- a/ch17/ex17_4_5_6_7_8_SalesData.h +++ b/ch17/ex17_4_5_6_7_8_SalesData.h @@ -60,13 +60,13 @@ class Sales_data bookNo(s), units_sold(n), revenue(p*n) { } Sales_data(const Sales_data &s ): bookNo(s.bookNo), units_sold(s.units_sold), revenue(s.revenue) - {} + { } Sales_data(Sales_data&& s): bookNo(s.bookNo), units_sold(s.units_sold), revenue(s.revenue) - {} + { } - ~Sales_data(){} + ~Sales_data(){ } Sales_data(std::istream &); std::string isbn() const { return bookNo; } @@ -79,7 +79,7 @@ class Sales_data // conversion explicit operator std::string () const { return bookNo; } - explicit operator double () const { return revenue;} + explicit operator double () const { return revenue; } double avg_price() const; private: diff --git a/ch18/ex18.1.2.3.cpp b/ch18/ex18.1.2.3.cpp index 1d3c1f77..e236e52b 100644 --- a/ch18/ex18.1.2.3.cpp +++ b/ch18/ex18.1.2.3.cpp @@ -45,9 +45,9 @@ void exercise(int *b, int *e) */ struct intArray { - intArray() : p(nullptr) {} + intArray() : p(nullptr) { } explicit intArray(std::size_t s): - p(new int[s]) {} + p(new int[s]) { } ~intArray()