diff --git a/ch03/ex3_14.cpp b/ch03/ex3_14.cpp index 0b0a3302..cd18d29e 100644 --- a/ch03/ex3_14.cpp +++ b/ch03/ex3_14.cpp @@ -1,10 +1,10 @@ -/// -///@Author @PEZY @Yue Wang -///@Date Aug. 2014 Jun.2015 -///@Brief -/// read a sequence of ints from cin and -/// store those values in a vector. -/// +// +//@Author @PEZY @Yue Wang +//@Date Aug. 2014 Jun.2015 +//@Brief +// read a sequence of ints from cin and +// store those values in a vector. +// #include #include diff --git a/ch03/ex3_15.cpp b/ch03/ex3_15.cpp index f7270859..f4c935d4 100644 --- a/ch03/ex3_15.cpp +++ b/ch03/ex3_15.cpp @@ -1,10 +1,10 @@ -/// -///@Author @PEZY @Yue Wang -///@Date Aug. 2014, Jun 2015 -///@Brief -/// read a sequence of strings from cin and -/// store those values in a vector. -/// +// +//@Author @PEZY @Yue Wang +//@Date Aug. 2014, Jun 2015 +//@Brief +// read a sequence of strings from cin and +// store those values in a vector. +// #include #include diff --git a/ch03/ex3_16.cpp b/ch03/ex3_16.cpp index f9a0d440..00869603 100644 --- a/ch03/ex3_16.cpp +++ b/ch03/ex3_16.cpp @@ -1,11 +1,11 @@ -/// -///@Author PEZY -///@Date Aug. 2014 -///@Brief -/// print the size and contents of the vectors from exercise 3.13. -/// Check whether your answers to that exercise were correct. -/// If not, restudy § 3.3.1 (p. 97) until you understand why you were wrong. -/// +// +//@Author PEZY +//@Date Aug. 2014 +//@Brief +// print the size and contents of the vectors from exercise 3.13. +// Check whether your answers to that exercise were correct. +// If not, restudy § 3.3.1 (p. 97) until you understand why you were wrong. +// #include #include diff --git a/ch03/ex3_17.cpp b/ch03/ex3_17.cpp index 22501038..c4631cf2 100644 --- a/ch03/ex3_17.cpp +++ b/ch03/ex3_17.cpp @@ -1,11 +1,11 @@ -/// -///@Author @PEZY @Yue Wang -///@Date Aug. 2014 Jun.2015 -///@Brief -/// Read a sequence of words from cin and store the values a vector. -/// After you've read all the words, process the vector and change each word to uppercase. -/// Print the transformed elements, eight words to a line. -/// +// +//@Author @PEZY @Yue Wang +//@Date Aug. 2014 Jun.2015 +//@Brief +// Read a sequence of words from cin and store the values a vector. +// After you've read all the words, process the vector and change each word to uppercase. +// Print the transformed elements, eight words to a line. +// #include #include diff --git a/ch03/ex3_19.cpp b/ch03/ex3_19.cpp index 04890959..a8e097ab 100644 --- a/ch03/ex3_19.cpp +++ b/ch03/ex3_19.cpp @@ -1,10 +1,10 @@ -/// -///@Author @PEZY @Yue Wang -///@Date Aug. 2014 Jun. 2015 -///@Brief -/// List three ways to define a vector and give it ten elements, -/// each with the value 42. -/// Indicate whether there is a preferred way to do so and why. +// +//@Author @PEZY @Yue Wang +//@Date Aug. 2014 Jun. 2015 +//@Brief +// List three ways to define a vector and give it ten elements, +// each with the value 42. +// Indicate whether there is a preferred way to do so and why. #include #include diff --git a/ch03/ex3_21.cpp b/ch03/ex3_21.cpp index 533ae66f..76a5314f 100644 --- a/ch03/ex3_21.cpp +++ b/ch03/ex3_21.cpp @@ -1,6 +1,6 @@ -/// -///Redo the first exercise from § 3.3.3 (p. 105) using iterators. -/// +// +//Redo the first exercise from § 3.3.3 (p. 105) using iterators. +// #include #include diff --git a/ch03/ex3_22.cpp b/ch03/ex3_22.cpp index 10cb50d2..ce289a73 100644 --- a/ch03/ex3_22.cpp +++ b/ch03/ex3_22.cpp @@ -1,9 +1,9 @@ -/// -///Revise the loop that printed the first paragraph in text -///to instead change the elements in text that correspond -///to the first paragraph to all uppercase. -///After you’ve updated text, print its contents. -/// +// +//Revise the loop that printed the first paragraph in text +//to instead change the elements in text that correspond +//to the first paragraph to all uppercase. +//After you’ve updated text, print its contents. +// #include #include diff --git a/ch03/ex3_23.cpp b/ch03/ex3_23.cpp index 9f1d02b5..a5a9f10d 100644 --- a/ch03/ex3_23.cpp +++ b/ch03/ex3_23.cpp @@ -1,8 +1,8 @@ -/// -///Write a program to create a vector with ten int elements. -///Using an iterator, assign each element a value that is twice its current value. -/// Test your program by printing the vector. -/// +// +//Write a program to create a vector with ten int elements. +//Using an iterator, assign each element a value that is twice its current value. +// Test your program by printing the vector. +// #include #include diff --git a/ch06/ex6_10.cpp b/ch06/ex6_10.cpp index 73a25d31..d18b71bb 100644 --- a/ch06/ex6_10.cpp +++ b/ch06/ex6_10.cpp @@ -1,9 +1,9 @@ -//!@Yue wang -//! -//! Exercise 6.10: -//! Using pointers, write a function to swap the values of two ints. -//! Test the function by calling it and printing the swapped values. -//! +//@Yue wang +// +// Exercise 6.10: +// Using pointers, write a function to swap the values of two ints. +// Test the function by calling it and printing the swapped values. +// #include #include #include diff --git a/ch06/ex6_12.cpp b/ch06/ex6_12.cpp index 47343663..655d3883 100644 --- a/ch06/ex6_12.cpp +++ b/ch06/ex6_12.cpp @@ -1,11 +1,11 @@ -//!@Yue Wang -//! -//! Exercise 6.12: -//! Rewrite the program from exercise 6.10 in § 6.2.1 (p. 210) to use -//! references instead of pointers to swap the value of two ints. Which -//! version do you think would be easier to use and why? +//@Yue Wang +// +// Exercise 6.12: +// Rewrite the program from exercise 6.10 in § 6.2.1 (p. 210) to use +// references instead of pointers to swap the value of two ints. Which +// version do you think would be easier to use and why? // The version using reference is easier. -//! +// #include #include diff --git a/ch06/ex6_21.cpp b/ch06/ex6_21.cpp index af4dd16b..3a779fd5 100644 --- a/ch06/ex6_21.cpp +++ b/ch06/ex6_21.cpp @@ -1,10 +1,10 @@ -//! @Yue Wang -//! -//! Exercise 6.21: -//! Write a function that takes an int and a pointer to an int and -//! returns the larger of the int value or the value to which the -//! pointer points. What type should you use for the pointer? -//! +// @Yue Wang +// +// Exercise 6.21: +// Write a function that takes an int and a pointer to an int and +// returns the larger of the int value or the value to which the +// pointer points. What type should you use for the pointer? +// #include using std::cout; diff --git a/ch06/ex6_22.cpp b/ch06/ex6_22.cpp index 2c338519..bff89139 100644 --- a/ch06/ex6_22.cpp +++ b/ch06/ex6_22.cpp @@ -1,8 +1,8 @@ -//! @Yue Wang -//! -//! Exercise 6.22: -//! Write a function to swap two int pointers. -//! +// @Yue Wang +// +// Exercise 6.22: +// Write a function to swap two int pointers. +// #include #include diff --git a/ch06/ex6_25_26.cpp b/ch06/ex6_25_26.cpp index a7d0bf86..b7830335 100644 --- a/ch06/ex6_25_26.cpp +++ b/ch06/ex6_25_26.cpp @@ -1,11 +1,11 @@ -//! @Yue Wang -//! -//! Exercise 6.25: Write a main function that takes two arguments. -//! Concatenate the supplied arguments and print the resulting string. -//! -//! Exercise 6.26: Write a program that accepts the options presented -//! in this section. Print the values of the arguments passed to main. -//! +// @Yue Wang +// +// Exercise 6.25: Write a main function that takes two arguments. +// Concatenate the supplied arguments and print the resulting string. +// +// Exercise 6.26: Write a program that accepts the options presented +// in this section. Print the values of the arguments passed to main. +// #include #include diff --git a/ch06/ex6_42.cpp b/ch06/ex6_42.cpp index 50f8c6ba..88461fa2 100644 --- a/ch06/ex6_42.cpp +++ b/ch06/ex6_42.cpp @@ -1,13 +1,13 @@ -//! @creator by Wang Yue -//! @refactor by pezy -//! -//! @date 27, July. 2015 -//! -//! @question -//! Give the second parameter of make_plural (§ 6.3.2, p. 224) a default -//! argument of 's'. Test your program by printing singular and plural versions -//! of the words success and failure. -//! +// @creator by Wang Yue +// @refactor by pezy +// +// @date 27, July. 2015 +// +// @question +// Give the second parameter of make_plural (§ 6.3.2, p. 224) a default +// argument of 's'. Test your program by printing singular and plural versions +// of the words success and failure. +// #include #include diff --git a/ch06/ex6_44.cpp b/ch06/ex6_44.cpp index c5d712b3..f5594895 100644 --- a/ch06/ex6_44.cpp +++ b/ch06/ex6_44.cpp @@ -1,7 +1,7 @@ -//! @Yue Wang -//! -//! Exercise 6.44: Rewrite the isShorter function from § 6.2.2 (p. 211) to be inline. -//! +// @Yue Wang +// +// Exercise 6.44: Rewrite the isShorter function from § 6.2.2 (p. 211) to be inline. +// #include #include using std::string; using std::cout; using std::endl; diff --git a/ch06/ex6_54_55_56.cpp b/ch06/ex6_54_55_56.cpp index df1f3133..3757c329 100644 --- a/ch06/ex6_54_55_56.cpp +++ b/ch06/ex6_54_55_56.cpp @@ -1,35 +1,35 @@ -//! @Yue Wang -//! -//! Exercise 6.54: -//! Write a declaration for a function that takes two int -//! parameters and returns an int, and declare a vector whose -//! elements have this function pointer type. -//! -//! Exercise 6.55: -//! Write four functions that add, subtract, multiply, and divide -//! two int values. Store pointers to these functions in your -//! vector from the previous exercise. -//! -//! Exercise 6.56: -//! Call each element in the vector and print their result. -//! +// @Yue Wang +// +// Exercise 6.54: +// Write a declaration for a function that takes two int +// parameters and returns an int, and declare a vector whose +// elements have this function pointer type. +// +// Exercise 6.55: +// Write four functions that add, subtract, multiply, and divide +// two int values. Store pointers to these functions in your +// vector from the previous exercise. +// +// Exercise 6.56: +// Call each element in the vector and print their result. +// #include #include #include using std::vector; using std::cout; -//! -//! @brief Exercise 6.54 -//! @note define the function type fp -//! +// +// @brief Exercise 6.54 +// @note define the function type fp +// inline int f(const int, const int); typedef decltype(f) fp;//fp is just a function type not a function pointer -//! -//! @brief Exercise 6.55 -//! @note Store pointers to these functions in the vector -//! +// +// @brief Exercise 6.55 +// @note Store pointers to these functions in the vector +// inline int NumAdd(const int n1, const int n2) { return n1 + n2; } inline int NumSub(const int n1, const int n2) { return n1 - n2; } inline int NumMul(const int n1, const int n2) { return n1 * n2; } diff --git a/ch09/ex9_13.cpp b/ch09/ex9_13.cpp index 6c1f0cb2..a9ff7721 100644 --- a/ch09/ex9_13.cpp +++ b/ch09/ex9_13.cpp @@ -1,10 +1,10 @@ -//! @author @shbling @Yue Wang -//! -//! Exercise 9.13: -//! How would you initialize a vector from a list? -//! From a vector? -//! Write code to check your answers. -//! +// @author @shbling @Yue Wang +// +// Exercise 9.13: +// How would you initialize a vector from a list? +// From a vector? +// Write code to check your answers. +// #include #include #include diff --git a/ch09/ex9_14.cpp b/ch09/ex9_14.cpp index 52aa5423..663606b9 100644 --- a/ch09/ex9_14.cpp +++ b/ch09/ex9_14.cpp @@ -1,11 +1,11 @@ -//! @Yue Wang @pezy -//! -//! Exercise 9.14: -//! Write a program to assign the elements from a list of char* pointers -//! to C-style character strings -//! -//! @Notice C-style character strings should use const char*, otherwise warning. -//! +// @Yue Wang @pezy +// +// Exercise 9.14: +// Write a program to assign the elements from a list of char* pointers +// to C-style character strings +// +// @Notice C-style character strings should use const char*, otherwise warning. +// #include #include diff --git a/ch09/ex9_24.cpp b/ch09/ex9_24.cpp index dd7696b3..62a67823 100644 --- a/ch09/ex9_24.cpp +++ b/ch09/ex9_24.cpp @@ -1,9 +1,9 @@ -//! @Yue Wang @pezy -//! -//! Exercise 9.24: -//! Write a program that fetches the first element in a vector using at, -//! the subscript operator, front, and begin. Test your program on an empty vector. -//! +// @Yue Wang @pezy +// +// Exercise 9.24: +// Write a program that fetches the first element in a vector using at, +// the subscript operator, front, and begin. Test your program on an empty vector. +// #include #include diff --git a/ch09/ex9_26.cpp b/ch09/ex9_26.cpp index 63e8e852..0b343bc6 100644 --- a/ch09/ex9_26.cpp +++ b/ch09/ex9_26.cpp @@ -1,12 +1,12 @@ -//! -//! @author @huangjuncmj @Yue Wang -//! @date 19.11.2014 -//! -//! Exercise 9.26: -//! Using the following definition of ia, copy ia into a vector and into a list. -//! Use the single-iterator form of erase to remove the elements with odd values from your -//! list and the even values from your vector. -//! +// +// @author @huangjuncmj @Yue Wang +// @date 19.11.2014 +// +// Exercise 9.26: +// Using the following definition of ia, copy ia into a vector and into a list. +// Use the single-iterator form of erase to remove the elements with odd values from your +// list and the even values from your vector. +// #include #include #include diff --git a/ch09/ex9_38.cpp b/ch09/ex9_38.cpp index 9cb2805f..a5950a7b 100644 --- a/ch09/ex9_38.cpp +++ b/ch09/ex9_38.cpp @@ -1,8 +1,8 @@ -//! @Yue Wang -//! -//! Exercise 9.38: -//! Write a program to explore how vectors grow in the library you use. -//! +// @Yue Wang +// +// Exercise 9.38: +// Write a program to explore how vectors grow in the library you use. +// #include #include diff --git a/ch09/ex9_45.cpp b/ch09/ex9_45.cpp index 1bb4acd7..67e5c89a 100644 --- a/ch09/ex9_45.cpp +++ b/ch09/ex9_45.cpp @@ -1,18 +1,18 @@ -//! @author @TungWah @Yue Wang -//! @date 4 Oct,2014. -//! -//! Exercise 9.45: -//! Write a funtion that takes a string representing a name and two other -//! strings representing a prefix, such as “Mr.” or “Ms.” and a suffix, -//! such as “Jr.” or “III”. Using iterators and the insert and append functions, -//! generate and return a new string with the suffix and prefix added to the -//! given name. -//! +// @author @TungWah @Yue Wang +// @date 4 Oct,2014. +// +// Exercise 9.45: +// Write a funtion that takes a string representing a name and two other +// strings representing a prefix, such as “Mr.” or “Ms.” and a suffix, +// such as “Jr.” or “III”. Using iterators and the insert and append functions, +// generate and return a new string with the suffix and prefix added to the +// given name. +// #include #include -//! Exercise 9.45 +// Exercise 9.45 std::string pre_suffix(const std::string &name, const std::string &pre, const std::string &su); diff --git a/ch09/ex9_50.cpp b/ch09/ex9_50.cpp index 784605e5..d89bb802 100644 --- a/ch09/ex9_50.cpp +++ b/ch09/ex9_50.cpp @@ -1,10 +1,10 @@ -//! @Yue Wang -//! -//! Exercise 9.50: -//! Write a program to process a vectors whose elements represent integral values. -//! Produce the sum of all the elements in that vector. -//! Change the program so that it sums of strings that represent floating-point values. -//! +// @Yue Wang +// +// Exercise 9.50: +// Write a program to process a vectors whose elements represent integral values. +// Produce the sum of all the elements in that vector. +// Change the program so that it sums of strings that represent floating-point values. +// #include #include diff --git a/ch09/ex9_51.cpp b/ch09/ex9_51.cpp index fbd187c1..d417cbc6 100644 --- a/ch09/ex9_51.cpp +++ b/ch09/ex9_51.cpp @@ -1,11 +1,11 @@ -//! @Soyn -//! -//! Exercise 9.51: -//! Write a class that has three unsigned members representing year, -//! month, and day. Write a constructor that takes a string representing -//! a date. Your constructor should handle a variety of date formats, -//! such as January 1, 1900, 1/1/1900, Jan 1, 1900, and so on. -//! +// @Soyn +// +// Exercise 9.51: +// Write a class that has three unsigned members representing year, +// month, and day. Write a constructor that takes a string representing +// a date. Your constructor should handle a variety of date formats, +// such as January 1, 1900, 1/1/1900, Jan 1, 1900, and so on. +// #include #include diff --git a/ch10/ex10_01_02.cpp b/ch10/ex10_01_02.cpp index 600f7320..d06a01b9 100644 --- a/ch10/ex10_01_02.cpp +++ b/ch10/ex10_01_02.cpp @@ -1,17 +1,17 @@ -//! -//! @author Yue Wang -//! @date 01.12.2014 -//! -//! Exercise 10.1: -//! The algorithm header defines a function named count that, like find, -//! takes a pair of iterators and a value.count returns a count of how -//! often that value appears. -//! Read a sequence of ints into a vector and print the count of how many -//! elements have a given value. -//! -//! Exercise 10.2: -//! Repeat the previous program, but read values into a list of strings. -//! +// +// @author Yue Wang +// @date 01.12.2014 +// +// Exercise 10.1: +// The algorithm header defines a function named count that, like find, +// takes a pair of iterators and a value.count returns a count of how +// often that value appears. +// Read a sequence of ints into a vector and print the count of how many +// elements have a given value. +// +// Exercise 10.2: +// Repeat the previous program, but read values into a list of strings. +// #include diff --git a/ch10/ex10_03_04.cpp b/ch10/ex10_03_04.cpp index 48751a11..2d7697ac 100644 --- a/ch10/ex10_03_04.cpp +++ b/ch10/ex10_03_04.cpp @@ -1,15 +1,15 @@ -//! -//! @author Yue Wang -//! @date 01.12.2014 -//! -//! Exercise 10.3: -//! Use accumulate to sum the elements in a vector. -//! -//! Exercise 10.4: -//! Assuming v is a vector, what, if anything, -//! is wrong with calling accumulate(v.cbegin(), v.cend(), 0)? +// +// @author Yue Wang +// @date 01.12.2014 +// +// Exercise 10.3: +// Use accumulate to sum the elements in a vector. +// +// Exercise 10.4: +// Assuming v is a vector, what, if anything, +// is wrong with calling accumulate(v.cbegin(), v.cend(), 0)? // Check below. -//! +// #include #include diff --git a/ch10/ex10_09.cpp b/ch10/ex10_09.cpp index be2ba30b..ee31bd2a 100644 --- a/ch10/ex10_09.cpp +++ b/ch10/ex10_09.cpp @@ -1,12 +1,12 @@ -//! -//! @author @Yue Wang @shbling @pezy @zzzkl @Yue Wang -//! @date 01.12.2014 Jun 2015 -//! -//! Exercise 10.9: -//! Implement your own version of elimDups. Test your program by printing -//! the vector after you read the input, after the call to unique, and after -//! the call to erase. -//! +// +// @author @Yue Wang @shbling @pezy @zzzkl @Yue Wang +// @date 01.12.2014 Jun 2015 +// +// Exercise 10.9: +// Implement your own version of elimDups. Test your program by printing +// the vector after you read the input, after the call to unique, and after +// the call to erase. +// #include #include diff --git a/ch10/ex10_11.cpp b/ch10/ex10_11.cpp index abeda8d7..77f984ca 100644 --- a/ch10/ex10_11.cpp +++ b/ch10/ex10_11.cpp @@ -1,9 +1,9 @@ -//! @Alan -//! Exercise 10.11: -//! Write a program that uses stable_sort and isShorter to sort a vector passed -//! to your version of elimDups. -//! Print the vector to verify that your program is correct. -//! +// @Alan +// Exercise 10.11: +// Write a program that uses stable_sort and isShorter to sort a vector passed +// to your version of elimDups. +// Print the vector to verify that your program is correct. +// #include #include @@ -12,7 +12,7 @@ #include #include -//! print a container like vector,deque, list,etc. +// print a container like vector,deque, list,etc. template inline std::ostream& println(Sequence const& seq) { diff --git a/ch10/ex10_12.cpp b/ch10/ex10_12.cpp index 0695a00a..b27b2db6 100644 --- a/ch10/ex10_12.cpp +++ b/ch10/ex10_12.cpp @@ -1,8 +1,8 @@ -//! @Yue Wang -//! Exercise 10.12: -//! Write a function named compareIsbn that compares the isbn() members of two Sales_data objects. -//! Use that function to sort a vector that holds Sales_data objects. -//! +// @Yue Wang +// Exercise 10.12: +// Write a function named compareIsbn that compares the isbn() members of two Sales_data objects. +// Use that function to sort a vector that holds Sales_data objects. +// #include #include diff --git a/ch10/ex10_13.cpp b/ch10/ex10_13.cpp index 062d5b59..639c9b70 100644 --- a/ch10/ex10_13.cpp +++ b/ch10/ex10_13.cpp @@ -1,15 +1,15 @@ -//! @Yue Wang -//! -//! Exercise 10.13: -//! The library defines an algorithm named partition that takes a predicate -//! and partitions the container so that values for which the predicate is -//! true appear in the first part and those for which the predicate is false -//! appear in the second part. The algorithm returns an iterator just past -//! the last element for which the predicate returned true. Write a function -//! that takes a string and returns a bool indicating whether the string has -//! five characters or more. Use that function to partition words. Print the -//! elements that have five or more characters. -//! +// @Yue Wang +// +// Exercise 10.13: +// The library defines an algorithm named partition that takes a predicate +// and partitions the container so that values for which the predicate is +// true appear in the first part and those for which the predicate is false +// appear in the second part. The algorithm returns an iterator just past +// the last element for which the predicate returned true. Write a function +// that takes a string and returns a bool indicating whether the string has +// five characters or more. Use that function to partition words. Print the +// elements that have five or more characters. +// #include #include diff --git a/ch10/ex10_16.cpp b/ch10/ex10_16.cpp index d5204125..e435d592 100644 --- a/ch10/ex10_16.cpp +++ b/ch10/ex10_16.cpp @@ -1,17 +1,17 @@ -//! -//! @author @Yue Wang @pezy -//! @date 02.12.2014 -//! -//! Exercise 10.16: -//! Write your own version of the biggies function using lambdas. -//! +// +// @author @Yue Wang @pezy +// @date 02.12.2014 +// +// Exercise 10.16: +// Write your own version of the biggies function using lambdas. +// #include #include #include #include -//! from ex 10.9 +// from ex 10.9 void elimdups(std::vector &vs) { std::sort(vs.begin(), vs.end()); diff --git a/ch10/ex10_17.cpp b/ch10/ex10_17.cpp index 696453f0..bac3bac2 100644 --- a/ch10/ex10_17.cpp +++ b/ch10/ex10_17.cpp @@ -1,10 +1,10 @@ -//! @pezy -//! -//! Exercise 10.17 -//! Rewrite exercise 10.12 from 10.3.1 (p. 387) -//! to use a lambda in the call to sort instead of the compareIsbn function. -//! -//! @See 7.26, 10.12 +// @pezy +// +// Exercise 10.17 +// Rewrite exercise 10.12 from 10.3.1 (p. 387) +// to use a lambda in the call to sort instead of the compareIsbn function. +// +// @See 7.26, 10.12 #include #include diff --git a/ch10/ex10_18_19.cpp b/ch10/ex10_18_19.cpp index e2a40b48..bfa63788 100644 --- a/ch10/ex10_18_19.cpp +++ b/ch10/ex10_18_19.cpp @@ -1,15 +1,15 @@ -//! -//! @author @Yue Wang @pezy -//! @date 12.10.2014 -//! -//! Exercise 10.18: -//! Rewrite biggies to use partition instead of find_if. -//! -//! Exercise 10.19: -//! Rewrite the previous exercise to use stable_partition, which like -//! stable_sort maintains the original element order in the paritioned -//! sequence. -//! +// +// @author @Yue Wang @pezy +// @date 12.10.2014 +// +// Exercise 10.18: +// Rewrite biggies to use partition instead of find_if. +// +// Exercise 10.19: +// Rewrite the previous exercise to use stable_partition, which like +// stable_sort maintains the original element order in the paritioned +// sequence. +// #include @@ -17,7 +17,7 @@ #include #include -//! from ex 10.9 +// from ex 10.9 void elimdups(std::vector &vs) { std::sort(vs.begin(), vs.end()); @@ -26,7 +26,7 @@ void elimdups(std::vector &vs) } -//! ex10.18 +// ex10.18 void biggies_partition(std::vector &vs, std::size_t sz) { elimdups(vs); @@ -40,7 +40,7 @@ void biggies_partition(std::vector &vs, std::size_t sz) } -//! ex10.19 +// ex10.19 void biggies_stable_partition(std::vector &vs, std::size_t sz) { elimdups(vs); diff --git a/ch10/ex10_20_21.cpp b/ch10/ex10_20_21.cpp index 3e9d4fb7..a76527da 100644 --- a/ch10/ex10_20_21.cpp +++ b/ch10/ex10_20_21.cpp @@ -1,19 +1,19 @@ -//! -//! @author @Yue Wang @shbling @pezy @zzzkl -//! @date 02.12.2014 -//! -//! Exercise 10.20: -//! The library defines an algorithm named count_if. Like find_if, this function takes -//! a pair of iterators denoting an input range and a predicate that it applies to each -//! element in the given range. count_if returns a count of how often the predicate is -//! true. Use count_if to rewrite the portion of our program that counted how many words -//! are greater than length 6. -//! -//! Exercise 10.21: -//! Write a lambda that captures a local int variable and decrements that variable until -//! it reaches 0. Once the variable is 0 additional calls should no longer decrement the -//! variable. The lambda should return a bool that indicates whether the captured variable is 0. -//! +// +// @author @Yue Wang @shbling @pezy @zzzkl +// @date 02.12.2014 +// +// Exercise 10.20: +// The library defines an algorithm named count_if. Like find_if, this function takes +// a pair of iterators denoting an input range and a predicate that it applies to each +// element in the given range. count_if returns a count of how often the predicate is +// true. Use count_if to rewrite the portion of our program that counted how many words +// are greater than length 6. +// +// Exercise 10.21: +// Write a lambda that captures a local int variable and decrements that variable until +// it reaches 0. Once the variable is 0 additional calls should no longer decrement the +// variable. The lambda should return a bool that indicates whether the captured variable is 0. +// #include #include @@ -26,7 +26,7 @@ using std::count_if; using std::string; -//! Exercise 10.20 +// Exercise 10.20 std::size_t bigerThan6(vector const& v) { return count_if(v.cbegin(), v.cend(), [](string const& s){ diff --git a/ch10/ex10_24.cpp b/ch10/ex10_24.cpp index 60ba2eb4..9d39e442 100644 --- a/ch10/ex10_24.cpp +++ b/ch10/ex10_24.cpp @@ -1,13 +1,13 @@ -//! -//! @author @Yue Wang @shbling @Soyn @Yue Wang -//! -//! Exercise 10.24: -//! Use bind and check_size to find the first element in a vector of ints that has a value greater -//! than the length of a specified string value. -//! +// +// @author @Yue Wang @shbling @Soyn @Yue Wang +// +// Exercise 10.24: +// Use bind and check_size to find the first element in a vector of ints that has a value greater +// than the length of a specified string value. +// // Discussion over this exercise on StackOverflow // http://stackoverflow.com/questions/20539406/what-type-does-stdfind-if-not-return -//! +// #include #include diff --git a/ch10/ex10_34_35_36_37.cpp b/ch10/ex10_34_35_36_37.cpp index 26ba923b..189487db 100644 --- a/ch10/ex10_34_35_36_37.cpp +++ b/ch10/ex10_34_35_36_37.cpp @@ -1,18 +1,18 @@ -//! @Alan @pezy -//! -//! Exercise 10.34: -//! Use reverse_iterators to print a vector in reverse order. -//! -//! Exercise 10.35: -//! Now print the elements in reverse order using ordinary iterators. -//! -//! Exercise 10.36: -//! Use find to find the last element in a list of ints with value 0. -//! -//! Exercise 10.37: -//! Given a vector that has ten elements, copy the elements from positions -//! 3 through 7 in reverse order to a list. -//! +// @Alan @pezy +// +// Exercise 10.34: +// Use reverse_iterators to print a vector in reverse order. +// +// Exercise 10.35: +// Now print the elements in reverse order using ordinary iterators. +// +// Exercise 10.36: +// Use find to find the last element in a list of ints with value 0. +// +// Exercise 10.37: +// Given a vector that has ten elements, copy the elements from positions +// 3 through 7 in reverse order to a list. +// #include #include diff --git a/ch10/ex10_42.cpp b/ch10/ex10_42.cpp index f02b199a..566e97bf 100644 --- a/ch10/ex10_42.cpp +++ b/ch10/ex10_42.cpp @@ -1,9 +1,9 @@ -//! @Alan @pezy -//! -//! Exercise 10.42: -//! Reimplement the program that eliminated duplicate words that -//! we wrote in § 10.2.3 (p. 383) to use a list instead of a vector. -//! +// @Alan @pezy +// +// Exercise 10.42: +// Reimplement the program that eliminated duplicate words that +// we wrote in § 10.2.3 (p. 383) to use a list instead of a vector. +// #include #include diff --git a/ch11/ex11_14.cpp b/ch11/ex11_14.cpp index 1768d2e1..ddda3322 100644 --- a/ch11/ex11_14.cpp +++ b/ch11/ex11_14.cpp @@ -1,14 +1,14 @@ -//! @Yue Wang -//! Exercise 11.14: -//! Extend the map of children to their family name that you wrote for the -//! exercises in § 11.2.1 (p. 424) by having the vector store a pair that -//! holds a child’s name and birthday. -//! -//! Exercise 11.7: -//! Define a map for which the key is the family’s last name and -//! the value is a vector of the children’s names. Write code to -//! add new families and to add new children to an existing family. -//! +// @Yue Wang +// Exercise 11.14: +// Extend the map of children to their family name that you wrote for the +// exercises in § 11.2.1 (p. 424) by having the vector store a pair that +// holds a child’s name and birthday. +// +// Exercise 11.7: +// Define a map for which the key is the family’s last name and +// the value is a vector of the children’s names. Write code to +// add new families and to add new children to an existing family. +// #include #include diff --git a/ch11/ex11_18.cpp b/ch11/ex11_18.cpp index b414c5ce..d98ba0fd 100644 --- a/ch11/ex11_18.cpp +++ b/ch11/ex11_18.cpp @@ -1,8 +1,8 @@ -//! @Alan -//! -//! Exercise 11.18: -//! Write the type of map_it from the loop on page 430 without using auto or decltype. -//! +// @Alan +// +// Exercise 11.18: +// Write the type of map_it from the loop on page 430 without using auto or decltype. +// #include #include @@ -17,8 +17,8 @@ int main() std::map::const_iterator map_it = word_count.cbegin(); -//! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -//! the type ex11.18 required. +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// the type ex11.18 required. // compare the current iterator to the off-the-end iterator while (map_it != word_count.cend()) diff --git a/ch11/ex11_20.cpp b/ch11/ex11_20.cpp index c888d602..9811429d 100644 --- a/ch11/ex11_20.cpp +++ b/ch11/ex11_20.cpp @@ -1,10 +1,10 @@ -//! @Alan @pezy -//! -//! Exercise 11.20: -//! Rewrite the word-counting program from § 11.1 (p. 421) to use insert instead -//! of subscripting. Which program do you think is easier to write and read? -//! Explain your reasoning. -//! +// @Alan @pezy +// +// Exercise 11.20: +// Rewrite the word-counting program from § 11.1 (p. 421) to use insert instead +// of subscripting. Which program do you think is easier to write and read? +// Explain your reasoning. +// #include #include diff --git a/ch11/ex11_24_25_26.cpp b/ch11/ex11_24_25_26.cpp index 4617a10a..1e506c07 100644 --- a/ch11/ex11_24_25_26.cpp +++ b/ch11/ex11_24_25_26.cpp @@ -1,23 +1,23 @@ -//! @Yue Wang -//! -//! Exercise 11.24: -//! What does the following program do? -//! map m; -//! m[0] = 1; +// @Yue Wang +// +// Exercise 11.24: +// What does the following program do? +// map m; +// m[0] = 1; // add a key-value pair { 0, 1 } into the map. -//! -//! Exercise 11.25: -//! Contrast the following program with the one in the previous exercise -//! vector v; -//! v[0] = 1; +// +// Exercise 11.25: +// Contrast the following program with the one in the previous exercise +// vector v; +// v[0] = 1; // UB, since it's trying to dereference an item out of range. -//! -//! Exercise 11.26: -//! What type can be used to subscript a map? What type does the subscript -//! operator return? Give a concrete example—that is, define a map and then -//! write the types that can be used to subscript the map and the type that -//! would be returned from the subscript operator. -//! +// +// Exercise 11.26: +// What type can be used to subscript a map? What type does the subscript +// operator return? Give a concrete example—that is, define a map and then +// write the types that can be used to subscript the map and the type that +// would be returned from the subscript operator. +// #include #include diff --git a/ch11/ex11_27_28_29_30.cpp b/ch11/ex11_27_28_29_30.cpp index cd9c4e69..a959578e 100644 --- a/ch11/ex11_27_28_29_30.cpp +++ b/ch11/ex11_27_28_29_30.cpp @@ -1,18 +1,18 @@ -//! @Alan -//! -//! Exercise 11.27: -//! What kinds of problems would you use count to solve? -//! When might you use find instead? +// @Alan +// +// Exercise 11.27: +// What kinds of problems would you use count to solve? +// When might you use find instead? // I would use count to deal with multimap or multi multiset. // As for the associative container that have unique key, I would use find instead of count. -//! -//! Exercise 11.28: -//! Define and initialize a variable to hold the result of -//! calling find on a map from string to vector of int. -//! -//! Exercise 11.29: -//! What do upper_bound, lower_bound, and equal_range return -//! when you pass them a key that is not in the container? +// +// Exercise 11.28: +// Define and initialize a variable to hold the result of +// calling find on a map from string to vector of int. +// +// Exercise 11.29: +// What do upper_bound, lower_bound, and equal_range return +// when you pass them a key that is not in the container? // If the element is not in the multimap, then lower_bound // and upper_bound will return equal iterators; both will // refer to the point at which the key can be inserted without @@ -21,11 +21,11 @@ // If no matching element is found, then both the first and // second iterators refer to the position where this key can // be inserted. -//! -//! Exercise 11.30: -//! Explain the meaning of the operand pos.first->second used -//! in the output expression of the final program in this section. -//! cout << pos.first->second << endl; +// +// Exercise 11.30: +// Explain the meaning of the operand pos.first->second used +// in the output expression of the final program in this section. +// cout << pos.first->second << endl; // ^^^^^^^^^^^^^^^^^ // pos a pair // pos.first the iterator refering to the first element with the matching key @@ -44,8 +44,8 @@ int main() //! ex11.28 std::map>::iterator it; -//! ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -//! type used to define this iterator. +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +// type used to define this iterator. it = m.find("Alan"); diff --git a/ch11/ex11_3_4.cpp b/ch11/ex11_3_4.cpp index da1f5559..3843607b 100644 --- a/ch11/ex11_3_4.cpp +++ b/ch11/ex11_3_4.cpp @@ -1,13 +1,13 @@ -//! @Alan -//! -//! Exercise 11.3: -//! Write your own version of the word-counting program. -//! -//! Exercise 11.4: -//! Extend your program to ignore case and punctuation. -//! For example, “example.” “example,” and “Example” should -//! all increment the same counter. -//! +// @Alan +// +// Exercise 11.3: +// Write your own version of the word-counting program. +// +// Exercise 11.4: +// Extend your program to ignore case and punctuation. +// For example, “example.” “example,” and “Example” should +// all increment the same counter. +// #include #include @@ -15,7 +15,7 @@ #include #include -//! Exercise 11.4 +// Exercise 11.4 void word_count_pro(std::map &m) { std::string word; @@ -33,7 +33,7 @@ void word_count_pro(std::map &m) std::cout << e.first << " : " << e.second <<"\n"; } -//! Exercise 11.3 +// Exercise 11.3 void ex11_3() { std::map word_count; diff --git a/ch11/ex11_7.cpp b/ch11/ex11_7.cpp index 83a02752..3a67273e 100644 --- a/ch11/ex11_7.cpp +++ b/ch11/ex11_7.cpp @@ -1,12 +1,12 @@ -//! @Alan -//! -//! Exercise 11.7: -//! Define a map for which the key is the family’s last name and -//! the value is a vector of the children’s names. Write code to -//! add new families and to add new children to an existing family. +// @Alan +// +// Exercise 11.7: +// Define a map for which the key is the family’s last name and +// the value is a vector of the children’s names. Write code to +// add new families and to add new children to an existing family. // Discussion on Stack Overflow: // http://stackoverflow.com/questions/20608365/is-it-possible-to-code-this-waywhilelambda -//! +// #include #include @@ -30,9 +30,9 @@ int main() return std::cin>>lastName && lastName != "@q"; }()) -//! ^^ -//! the () used here is to call the lambda ,otherwise it does not work -//! go to the post on stack overflow for more detail. +// ^^ +// the () used here is to call the lambda ,otherwise it does not work +// go to the post on stack overflow for more detail. { std::cout << "PLZ Enter children's name:\n"; diff --git a/ch11/ex11_8.cpp b/ch11/ex11_8.cpp index 18b9fb18..50d9d956 100644 --- a/ch11/ex11_8.cpp +++ b/ch11/ex11_8.cpp @@ -1,8 +1,8 @@ -//! @Alan -//! -//! Exercise 11.8: -//! Write a program that stores the excluded words in a vector -//! instead of in a set. What are the advantages to using a set? +// @Alan +// +// Exercise 11.8: +// Write a program that stores the excluded words in a vector +// instead of in a set. What are the advantages to using a set? // copied from the post on stack overflow: // 1.No matter what elements you add or remove (unless you add // a duplicate, which is not allowed in a set), it will always @@ -21,7 +21,7 @@ // The same goes for removal. // // http://stackoverflow.com/questions/8686725/what-is-the-difference-between-stdset-and-stdvector -//! +// #include #include #include diff --git a/ch11/ex11_9_10.cpp b/ch11/ex11_9_10.cpp index a6b11702..b25c6bc3 100644 --- a/ch11/ex11_9_10.cpp +++ b/ch11/ex11_9_10.cpp @@ -1,13 +1,13 @@ -//! @Alan -//! -//! Exercise 11.9: -//! Define a map that associates words with a list of -//! line numbers on which the word might occur. -//! -//! Exercise 11.10: -//! Could we define a map from vector::iterator -//! to int? What about from list::iterator to int? -//! In each case, if not, why not? +// @Alan +// +// Exercise 11.9: +// Define a map that associates words with a list of +// line numbers on which the word might occur. +// +// Exercise 11.10: +// Could we define a map from vector::iterator +// to int? What about from list::iterator to int? +// In each case, if not, why not? // vector::iterator to int is ok ,because < is defined // list::iterator to int is not ok,as no < is defined. #include diff --git a/ch12/ex12_06.cpp b/ch12/ex12_06.cpp index 5e0c5854..237a9a25 100644 --- a/ch12/ex12_06.cpp +++ b/ch12/ex12_06.cpp @@ -5,14 +5,14 @@ * Jun 2015 * @remark ***************************************************************************/ -//! -//! Exercise 12.6: -//! Write a function that returns a dynamically allocated vector of ints. -//! Pass that vector to another function that reads the standard input to -//! give values to the elements. Pass the vector to another function to print -//! the values that were read. -//! Remember to delete the vector at the appropriate time. -//! +// +// Exercise 12.6: +// Write a function that returns a dynamically allocated vector of ints. +// Pass that vector to another function that reads the standard input to +// give values to the elements. Pass the vector to another function to print +// the values that were read. +// Remember to delete the vector at the appropriate time. +// #include #include diff --git a/ch12/ex12_07.cpp b/ch12/ex12_07.cpp index f7d31229..1e6b28fe 100644 --- a/ch12/ex12_07.cpp +++ b/ch12/ex12_07.cpp @@ -4,17 +4,17 @@ * @date 22 DEC 2013 * @remark ***************************************************************************/ -//! -//! Exercise 12.6: -//! Write a function that returns a dynamically allocated vector of ints. -//! Pass that vector to another function that reads the standard input to -//! give values to the elements. Pass the vector to another function to print -//! the values that were read. -//! Remember to delete the vector at the appropriate time. -//! -//! Exercise 12.7: -//! Redo the previous exercise, this time using shared_ptr. -//! +// +// Exercise 12.6: +// Write a function that returns a dynamically allocated vector of ints. +// Pass that vector to another function that reads the standard input to +// give values to the elements. Pass the vector to another function to print +// the values that were read. +// Remember to delete the vector at the appropriate time. +// +// Exercise 12.7: +// Redo the previous exercise, this time using shared_ptr. +// #include #include diff --git a/ch12/ex12_10.cpp b/ch12/ex12_10.cpp index e1676f8e..bda72570 100644 --- a/ch12/ex12_10.cpp +++ b/ch12/ex12_10.cpp @@ -4,10 +4,10 @@ * @date 23 DEC 2013 * @remark ***************************************************************************/ -//! -//! Exercise 12.10: -//! Explain whether the following call to the process function defined on page -//! 464 is correct. If not, how would you correct the call? +// +// Exercise 12.10: +// Explain whether the following call to the process function defined on page +// 464 is correct. If not, how would you correct the call? // correct. #include diff --git a/ch12/ex12_11.cpp b/ch12/ex12_11.cpp index 7bbedcd1..022f21f1 100644 --- a/ch12/ex12_11.cpp +++ b/ch12/ex12_11.cpp @@ -4,9 +4,9 @@ * @date 23 DEC 2013 * @remark ***************************************************************************/ -//! -//! Exercise 12.11: -//! What would happen if we called process as follows? +// +// Exercise 12.11: +// What would happen if we called process as follows? // An error was generated at run time : double free or corruption. // See the comments below. diff --git a/ch12/ex12_12.cpp b/ch12/ex12_12.cpp index ad4a9075..9076f6d9 100644 --- a/ch12/ex12_12.cpp +++ b/ch12/ex12_12.cpp @@ -4,13 +4,13 @@ * @date 23 DEC 2013 * @remark ***************************************************************************/ -//! -//! Exercise 12.12: -//! Using the declarations of p and sp explain each of the following calls to -//! process. If the call is legal, explain what it does. If the call is illegal, -//! explain why: +// +// Exercise 12.12: +// Using the declarations of p and sp explain each of the following calls to +// process. If the call is legal, explain what it does. If the call is illegal, +// explain why: // See comments below. -//! +// #include diff --git a/ch12/ex12_13.cpp b/ch12/ex12_13.cpp index ce4a7fb5..5eb3b040 100644 --- a/ch12/ex12_13.cpp +++ b/ch12/ex12_13.cpp @@ -1,9 +1,9 @@ -//! @Yue Wang -//! -//! ex12.13 What happens if we excute the following code? -//! +// @Yue Wang +// +// ex12.13 What happens if we excute the following code? +// // generate a runtime error : double free -//! +// #include #include diff --git a/ch12/ex12_17_18.cpp b/ch12/ex12_17_18.cpp index 0ba40223..68918783 100644 --- a/ch12/ex12_17_18.cpp +++ b/ch12/ex12_17_18.cpp @@ -4,14 +4,14 @@ * @date 24 DEC 2013 * @remark ***************************************************************************/ -//! -//! Exercise 12.17: -//! Which of the following unique_ptr declarations are illegal or likely to -//! result in subsequent program error? Explain what the problem is with each -//! one. -//! -//! Exercise 12.18: -//! Why doesn’t shared_ptr have a release member? +// +// Exercise 12.17: +// Which of the following unique_ptr declarations are illegal or likely to +// result in subsequent program error? Explain what the problem is with each +// one. +// +// Exercise 12.18: +// Why doesn’t shared_ptr have a release member? // Because other shared_ptr that points the same object can still delete this // object.Thus, it's meaningless to provide this member // more detail can be found a thread on Stack Overflow: diff --git a/ch14/ex14_24.cpp b/ch14/ex14_24.cpp index 8dd46961..fd525753 100644 --- a/ch14/ex14_24.cpp +++ b/ch14/ex14_24.cpp @@ -1,8 +1,8 @@ #include "ex14_24.h" #include -//! constructor taking Size as days -//! the argument must be within (0, 2^32) +// constructor taking Size as days +// the argument must be within (0, 2^32) Date::Date(Size days) { //! calculate the year @@ -39,7 +39,7 @@ Date::Date(Size days) }); } -//! construcotr taking iostream +// construcotr taking iostream Date::Date(std::istream &is, std::ostream &os) { is >> day >> month >> year; @@ -61,17 +61,17 @@ Date::Date(std::istream &is, std::ostream &os) } -//! copy constructor +// copy constructor Date::Date(const Date &d) : day(d.day), month(d.month), year(d.year) {} -//! move constructor +// move constructor Date::Date(Date&& d) NOEXCEPT : day(d.day), month(d.month), year(d.year) { std::cout << "copy moving";} -//! copy operator= +// copy operator= Date &Date::operator= (const Date &d) { this->day = d.day; @@ -81,7 +81,7 @@ Date &Date::operator= (const Date &d) return *this; } -//! move operator= +// move operator= Date &Date::operator =(Date&& rhs) NOEXCEPT { if(this != &rhs) @@ -95,7 +95,7 @@ Date &Date::operator =(Date&& rhs) NOEXCEPT return *this; } -//! conver to days +// conver to days Date::Size Date::toDays() const { Size result = this->day; @@ -117,7 +117,7 @@ Date::Size Date::toDays() const return result; } -//! member operators: += -= +// member operators: += -= Date &Date::operator +=(Date::Size offset) { @@ -135,7 +135,7 @@ Date &Date::operator -=(Date::Size offset) return *this; } -//! non-member operators: << >> - == != < <= > >= +// non-member operators: << >> - == != < <= > >= std::ostream& operator <<(std::ostream& os, const Date& d) diff --git a/ch14/ex14_24.h b/ch14/ex14_24.h index c8443e3e..2c25a7b2 100644 --- a/ch14/ex14_24.h +++ b/ch14/ex14_24.h @@ -4,47 +4,47 @@ * @date 15-17 JAN 2014 * @remark ***************************************************************************/ -//! -//! Exercise 7.40: -//! Choose one of the following abstractions (or an abstraction of your own choosing). -//! Determine what data are needed in the class. Provide an appropriate set of constructors. -//! Explain your decisions. -//! -//! Exercise 14.5: -//! In exercise 7.40 from § 7.5.1 (p. 291) you wrote a sketch of one of the -//! following classes. Decide what, if any, overloaded operators your class -//! should provide. +// +// Exercise 7.40: +// Choose one of the following abstractions (or an abstraction of your own choosing). +// Determine what data are needed in the class. Provide an appropriate set of constructors. +// Explain your decisions. +// +// Exercise 14.5: +// In exercise 7.40 from § 7.5.1 (p. 291) you wrote a sketch of one of the +// following classes. Decide what, if any, overloaded operators your class +// should provide. // - = < > <= >= ++ -- << >> == != += -= -//! Exercise 14.8: -//! Define an output operator for the class you chose in exercise 7.40 from -//! § 7.5.1 (p. 291). -//! -//! Exercise 14.12: -//! Define an input operator for the class you used in exercise 7.40 from -//! § 7.5.1 (p. 291). Be sure the operator handles input errors. -//! -//! Exercise 14.15: -//! Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) -//! define any of the arithmetic operators? If so, implement them. -//! If not, explain why not. -//! +// Exercise 14.8: +// Define an output operator for the class you chose in exercise 7.40 from +// § 7.5.1 (p. 291). +// +// Exercise 14.12: +// Define an input operator for the class you used in exercise 7.40 from +// § 7.5.1 (p. 291). Be sure the operator handles input errors. +// +// Exercise 14.15: +// Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) +// define any of the arithmetic operators? If so, implement them. +// If not, explain why not. +// // arithmetic operators : all non-members // + : Date + Size // - : Date - Size // - : Date - Date -//! -//! Exercise 14.17: -//! Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) define -//! the equality operators? If so, implement them. If not, explain why not. -//! -//! Exercise 14.19: -//! Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) define -//! the relational operators? If so, implement them. If not, explain why not. -//! -//! Exercise 14.25: -//! Implement any other assignment operators your class should define. -//! Explain which types should be used as operands and why. -//! +// +// Exercise 14.17: +// Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) define +// the equality operators? If so, implement them. If not, explain why not. +// +// Exercise 14.19: +// Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) define +// the relational operators? If so, implement them. If not, explain why not. +// +// Exercise 14.25: +// Implement any other assignment operators your class should define. +// Explain which types should be used as operands and why. +// #ifndef DATE_H #define DATE_H @@ -106,16 +106,16 @@ static const Date::Size YtoD_100 = 36524; //365*100 + 100/4 -1 == 36524 static const Date::Size YtoD_4 = 1461; //365*4 + 1 == 1461 static const Date::Size YtoD_1 = 365; //365 -//! normal year +// normal year static const std::vector monthsVec_n = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -//! leap year +// leap year static const std::vector monthsVec_l = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -//! non-member operators: << >> - == != < <= > >= -//! +// non-member operators: << >> - == != < <= > >= +// std::ostream& operator <<(std::ostream& os, const Date& d); std::istream& @@ -141,7 +141,7 @@ operator +(const Date& lhs, Date::Size rhs); -//! utillities: +// utillities: bool check(const Date &d); inline bool isLeapYear(Date::Size y); @@ -149,7 +149,7 @@ isLeapYear(Date::Size y); -//! check if the date object passed in is valid +// check if the date object passed in is valid inline bool check(const Date &d) { diff --git a/ch14/ex14_24_TEST.cpp b/ch14/ex14_24_TEST.cpp index b29841ca..5ed3f93a 100644 --- a/ch14/ex14_24_TEST.cpp +++ b/ch14/ex14_24_TEST.cpp @@ -5,22 +5,22 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 14.20: -//! Define the addition and compound-assignment operators for your Sales_data class. -//! -//! Exercise 14.22: -//! Define a version of the assignment operator that can assign a string representing -//! an ISBN to a Sales_data. -//! -//! Exercise 14.23: -//! Define an initializer_list assignment operator for your version of the StrVec -//! class. -//! -//! Exercise 14.24: -//! Decide whether the class you used in exercise 7.40 from § 7.5.1 (p. 291) needs a -//! copy- and move-assignment operator. If so, define those operators. -//! +// +// Exercise 14.20: +// Define the addition and compound-assignment operators for your Sales_data class. +// +// Exercise 14.22: +// Define a version of the assignment operator that can assign a string representing +// an ISBN to a Sales_data. +// +// Exercise 14.23: +// Define an initializer_list assignment operator for your version of the StrVec +// class. +// +// Exercise 14.24: +// Decide whether the class you used in exercise 7.40 from § 7.5.1 (p. 291) needs a +// copy- and move-assignment operator. If so, define those operators. +// #include "ex14_24.h" #include diff --git a/ch14/ex14_38_39.cpp b/ch14/ex14_38_39.cpp index 45304045..0304b4e0 100644 --- a/ch14/ex14_38_39.cpp +++ b/ch14/ex14_38_39.cpp @@ -1,13 +1,13 @@ -//! -//! Exercise 14.38: -//! Write a class that tests whether the length of a given string matches a -//! given bound. Use that object to write a program to report how many words -//! in an input file are of sizes 1 through 10 inclusive. -//! -//! Exercise 14.39: -//! Revise the previous program to report the count of words that are sizes -//! 1 through 9 and 10 or more. -//! +// +// Exercise 14.38: +// Write a class that tests whether the length of a given string matches a +// given bound. Use that object to write a program to report how many words +// in an input file are of sizes 1 through 10 inclusive. +// +// Exercise 14.39: +// Revise the previous program to report the count of words that are sizes +// 1 through 9 and 10 or more. +// #include #include diff --git a/ch14/ex14_43.cpp b/ch14/ex14_43.cpp index 426c3ed3..37441dca 100644 --- a/ch14/ex14_43.cpp +++ b/ch14/ex14_43.cpp @@ -5,11 +5,11 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 14.43: -//! Using library function objects, determine whether a given int value is -//! divisible by any element in a container of ints. -//! +// +// Exercise 14.43: +// Using library function objects, determine whether a given int value is +// divisible by any element in a container of ints. +// #include #include diff --git a/ch14/ex14_44.cpp b/ch14/ex14_44.cpp index 8ee8a509..ab6528ff 100644 --- a/ch14/ex14_44.cpp +++ b/ch14/ex14_44.cpp @@ -6,10 +6,10 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 14.44: -//! Write your own version of a simple desk calculator that can handle binary operations. -//! +// +// Exercise 14.44: +// Write your own version of a simple desk calculator that can handle binary operations. +// #include #include diff --git a/ch14/ex14_49.cpp b/ch14/ex14_49.cpp index c585b0a3..19f7ae7d 100644 --- a/ch14/ex14_49.cpp +++ b/ch14/ex14_49.cpp @@ -1,8 +1,8 @@ #include "ex14_49.h" #include -//! constructor taking Size as days -//! the argument must be within (0, 2^32) +// constructor taking Size as days +// the argument must be within (0, 2^32) Date::Date(Size days) { //! calculate the year @@ -39,7 +39,7 @@ Date::Date(Size days) }); } -//! construcotr taking iostream +// construcotr taking iostream Date::Date(std::istream &is, std::ostream &os) { is >> day >> month >> year; @@ -61,17 +61,17 @@ Date::Date(std::istream &is, std::ostream &os) } -//! copy constructor +// copy constructor Date::Date(const Date &d) : day(d.day), month(d.month), year(d.year) {} -//! move constructor +// move constructor Date::Date(Date&& d) noexcept : day(d.day), month(d.month), year(d.year) { std::cout << "copy moving";} -//! copy operator= +// copy operator= Date &Date::operator= (const Date &d) { this->day = d.day; @@ -81,7 +81,7 @@ Date &Date::operator= (const Date &d) return *this; } -//! move operator= +// move operator= Date &Date::operator =(Date&& rhs) noexcept { if(this != &rhs) @@ -95,7 +95,7 @@ Date &Date::operator =(Date&& rhs) noexcept return *this; } -//! conver to days +// conver to days Date::Size Date::toDays() const { Size result = this->day; @@ -117,7 +117,7 @@ Date::Size Date::toDays() const return result; } -//! member operators: += -= +// member operators: += -= Date &Date::operator +=(Date::Size offset) { @@ -135,7 +135,7 @@ Date &Date::operator -=(Date::Size offset) return *this; } -//! non-member operators: << >> - == != < <= > >= +// non-member operators: << >> - == != < <= > >= std::ostream& operator <<(std::ostream& os, const Date& d) diff --git a/ch14/ex14_49.h b/ch14/ex14_49.h index 9be38d4f..e78c4a95 100644 --- a/ch14/ex14_49.h +++ b/ch14/ex14_49.h @@ -4,51 +4,51 @@ * @date 15-17 JAN 2014 * @remark ***************************************************************************/ -//! -//! Exercise 7.40: -//! Choose one of the following abstractions (or an abstraction of your own choosing). -//! Determine what data are needed in the class. Provide an appropriate set of constructors. -//! Explain your decisions. -//! -//! Exercise 14.5: -//! In exercise 7.40 from § 7.5.1 (p. 291) you wrote a sketch of one of the -//! following classes. Decide what, if any, overloaded operators your class -//! should provide. +// +// Exercise 7.40: +// Choose one of the following abstractions (or an abstraction of your own choosing). +// Determine what data are needed in the class. Provide an appropriate set of constructors. +// Explain your decisions. +// +// Exercise 14.5: +// In exercise 7.40 from § 7.5.1 (p. 291) you wrote a sketch of one of the +// following classes. Decide what, if any, overloaded operators your class +// should provide. // - = < > <= >= ++ -- << >> == != += -= -//! Exercise 14.8: -//! Define an output operator for the class you chose in exercise 7.40 from -//! § 7.5.1 (p. 291). -//! -//! Exercise 14.12: -//! Define an input operator for the class you used in exercise 7.40 from -//! § 7.5.1 (p. 291). Be sure the operator handles input errors. -//! -//! Exercise 14.15: -//! Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) -//! define any of the arithmetic operators? If so, implement them. -//! If not, explain why not. -//! +// Exercise 14.8: +// Define an output operator for the class you chose in exercise 7.40 from +// § 7.5.1 (p. 291). +// +// Exercise 14.12: +// Define an input operator for the class you used in exercise 7.40 from +// § 7.5.1 (p. 291). Be sure the operator handles input errors. +// +// Exercise 14.15: +// Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) +// define any of the arithmetic operators? If so, implement them. +// If not, explain why not. +// // arithmetic operators : all non-members // + : Date + Size // - : Date - Size // - : Date - Date -//! -//! Exercise 14.17: -//! Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) define -//! the equality operators? If so, implement them. If not, explain why not. -//! -//! Exercise 14.19: -//! Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) define -//! the relational operators? If so, implement them. If not, explain why not. -//! -//! Exercise 14.25: -//! Implement any other assignment operators your class should define. -//! Explain which types should be used as operands and why. -//! -//! Exercise 14.49: -//! Regardless of whether it is a good idea to do so, define a conversion to bool -//! for the class from the previous exercise. -//! +// +// Exercise 14.17: +// Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) define +// the equality operators? If so, implement them. If not, explain why not. +// +// Exercise 14.19: +// Should the class you chose for exercise 7.40 from § 7.5.1 (p. 291) define +// the relational operators? If so, implement them. If not, explain why not. +// +// Exercise 14.25: +// Implement any other assignment operators your class should define. +// Explain which types should be used as operands and why. +// +// Exercise 14.49: +// Regardless of whether it is a good idea to do so, define a conversion to bool +// for the class from the previous exercise. +// #ifndef DATE_H #define DATE_H @@ -104,16 +104,16 @@ static const Date::Size YtoD_100 = 36524; //365*100 + 100/4 -1 == 36524 static const Date::Size YtoD_4 = 1461; //365*4 + 1 == 1461 static const Date::Size YtoD_1 = 365; //365 -//! normal year +// normal year static const std::vector monthsVec_n = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -//! leap year +// leap year static const std::vector monthsVec_l = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; -//! non-member operators: << >> - == != < <= > >= -//! +// non-member operators: << >> - == != < <= > >= +// std::ostream& operator <<(std::ostream& os, const Date& d); std::istream& @@ -139,7 +139,7 @@ operator +(const Date& lhs, Date::Size rhs); -//! utillities: +// utillities: bool check(const Date &d); inline bool isLeapYear(Date::Size y); @@ -147,7 +147,7 @@ isLeapYear(Date::Size y); -//! check if the date object passed in is valid +// check if the date object passed in is valid inline bool check(const Date &d) { diff --git a/ch15/ex15.1.2.3/main.cpp b/ch15/ex15.1.2.3/main.cpp index 3fc1a689..44523979 100644 --- a/ch15/ex15.1.2.3/main.cpp +++ b/ch15/ex15.1.2.3/main.cpp @@ -5,21 +5,21 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.1: -//! What is a virtual member? +// +// Exercise 15.1: +// What is a virtual member? // A virtual member in a base class expects its derived class define its own version. // In particular base classes ordinarily should define a virtual destructor, even if // it does no work. -//! -//! Exercise 15.2: -//! How does the protected access specifier differ from private? +// +// Exercise 15.2: +// How does the protected access specifier differ from private? // private members : base class itself and friend can access // protected members : base class itself, friend and derived classes can access -//! Exercise 15.3: -//! Define your own versions of the Quote class and the print_total function. -//! -//! +// Exercise 15.3: +// Define your own versions of the Quote class and the print_total function. +// +// #include #include #include diff --git a/ch15/ex15.11/main.cpp b/ch15/ex15.11/main.cpp index 3ac2f2c4..f5fd0956 100644 --- a/ch15/ex15.11/main.cpp +++ b/ch15/ex15.11/main.cpp @@ -5,11 +5,11 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.11: -//! Add a virtual debug function to your Quote class hierarchy that displays -//! the data members of the respective classes. -//! +// +// Exercise 15.11: +// Add a virtual debug function to your Quote class hierarchy that displays +// the data members of the respective classes. +// #include #include diff --git a/ch15/ex15.12.13.14/main.cpp b/ch15/ex15.12.13.14/main.cpp index abe7957d..33af37c4 100644 --- a/ch15/ex15.12.13.14/main.cpp +++ b/ch15/ex15.12.13.14/main.cpp @@ -5,22 +5,22 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.12: -//! Is it ever useful to declare a member function as both override and final? -//! Why or why not? +// +// Exercise 15.12: +// Is it ever useful to declare a member function as both override and final? +// Why or why not? // Sure. override means overriding the same name virtual function in base class. // final means preventing any overriding this virtual function by any derived classes // that are more lower at the hierachy . -//! -//! Exercise 15.13: -//! Given the following classes, explain each print function: -//! If there is a problem in this code, how would you fix it? -//! -//! Exercise 15.14: -//! Given the classes from the previous exercise and the following objects, -//! determine which function is called at run time: -//! +// +// Exercise 15.13: +// Given the following classes, explain each print function: +// If there is a problem in this code, how would you fix it? +// +// Exercise 15.14: +// Given the classes from the previous exercise and the following objects, +// determine which function is called at run time: +// #include diff --git a/ch15/ex15.15.16.17/main.cpp b/ch15/ex15.15.16.17/main.cpp index 981399ba..38f19d0c 100644 --- a/ch15/ex15.15.16.17/main.cpp +++ b/ch15/ex15.15.16.17/main.cpp @@ -5,26 +5,26 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.15: -//! Define your own versions of Disc_quote and Bulk_quote. -//! -//! Exercise 15.16: -//! Rewrite the class representing a limited discount strategy, which you wrote -//! for the exercises in § 15.2.2 (p. 601), to inherit from Disc_quote. -//! -//! Exercise 15.17: -//! Try to define an object of type Disc_quote and see what errors you get from -//! the compiler. +// +// Exercise 15.15: +// Define your own versions of Disc_quote and Bulk_quote. +// +// Exercise 15.16: +// Rewrite the class representing a limited discount strategy, which you wrote +// for the exercises in § 15.2.2 (p. 601), to inherit from Disc_quote. +// +// Exercise 15.17: +// Try to define an object of type Disc_quote and see what errors you get from +// the compiler. // error: cannot declare variable 'd' to be of abstract type 'Disc_quote' -//! Disc_quote d; -//! ^ +// Disc_quote d; +// ^ // note: because the following virtual functions are pure within 'Disc_quote': -//! class Disc_quote : public Quote -//! ^ +// class Disc_quote : public Quote +// ^ // note: virtual double Disc_quote::net_price(std::size_t) const -//! virtual double net_price(std::size_t n) const override = 0; -//! ^ +// virtual double net_price(std::size_t n) const override = 0; +// ^ #include diff --git a/ch15/ex15.18.19.20/main.cpp b/ch15/ex15.18.19.20/main.cpp index 7118f542..9a58b3bf 100644 --- a/ch15/ex15.18.19.20/main.cpp +++ b/ch15/ex15.18.19.20/main.cpp @@ -5,32 +5,32 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.18: -//! Given the classes from page 612 and page 613, and assuming each object -//! has the type specified in the comments, determine which of these assignments -//! are legal. Explain why those that are illegal aren’t allowed: -//! -//! Base *p = &d1; // d1 has type Pub_Derv -- legal --right -//! p = &d2; // d2 has type Priv_Derv -- illegal --right -//! p = &d3; // d3 has type Prot_Derv -- illegal --right -//! -//! p = &dd1; // dd1 has type Derived_from_Public -- legal --right -//! p = &dd2; // dd2 has type Derived_from_Private -- illegal --right -//! p = &dd3; // dd3 has type Derived_from_Protected -- illegal --right -//! +// +// Exercise 15.18: +// Given the classes from page 612 and page 613, and assuming each object +// has the type specified in the comments, determine which of these assignments +// are legal. Explain why those that are illegal aren’t allowed: +// +// Base *p = &d1; // d1 has type Pub_Derv -- legal --right +// p = &d2; // d2 has type Priv_Derv -- illegal --right +// p = &d3; // d3 has type Prot_Derv -- illegal --right +// +// p = &dd1; // dd1 has type Derived_from_Public -- legal --right +// p = &dd2; // dd2 has type Derived_from_Private -- illegal --right +// p = &dd3; // dd3 has type Derived_from_Protected -- illegal --right +// // User code may use the derived-to-base conversion only if D inherits // publicly from B. User code may not use the conversion if D inherits // from B using either protected or private. -//! -//! Exercise 15.19: -//! Assume that each of the classes from page 612 and page 613 has a member -//! function of the form: -//! +// +// Exercise 15.19: +// Assume that each of the classes from page 612 and page 613 has a member +// function of the form: +// // void memfcn(Base &b) { b = *this; } -//! -//! For each class, determine whether this function would be legal. -//! +// +// For each class, determine whether this function would be legal. +// // Member functions and friends of D can use the conversion to B regardless // of how D inherits from B. The derived-to-base conversion to a direct base // class is always accessible to members and friends of a derived class. @@ -47,10 +47,10 @@ // Derived_from_Public -- legal --right // Derived_from_Private -- illegal --right // Derived_from_Protected -- legal --right -//! -//! Exercise 15.20: -//! Write code to test your answers to the previous two exercises. -//! +// +// Exercise 15.20: +// Write code to test your answers to the previous two exercises. +// #include #include diff --git a/ch15/ex15.21.22/main.cpp b/ch15/ex15.21.22/main.cpp index dceebe8d..6aa5cde9 100644 --- a/ch15/ex15.21.22/main.cpp +++ b/ch15/ex15.21.22/main.cpp @@ -5,19 +5,19 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.21: -//! Choose one of the following general abstractions containing a family of -//! types (or choose one of your own). Organize the types into an inheritance -//! hierarchy: -//! (a) Graphical file formats (such as gif, tiff, jpeg, bmp) -//! (b) Geometric primitives (such as box, circle, sphere, cone) -//! (c) C++ language types (such as class, function, member function) -//! -//! Exercise 15.22: -//! For the class you chose in the previous exercise, identify some of the -//! likely virtual functions as well as public and protected members. -//! +// +// Exercise 15.21: +// Choose one of the following general abstractions containing a family of +// types (or choose one of your own). Organize the types into an inheritance +// hierarchy: +// (a) Graphical file formats (such as gif, tiff, jpeg, bmp) +// (b) Geometric primitives (such as box, circle, sphere, cone) +// (c) C++ language types (such as class, function, member function) +// +// Exercise 15.22: +// For the class you chose in the previous exercise, identify some of the +// likely virtual functions as well as public and protected members. +// #include #include @@ -27,7 +27,7 @@ #include "limit_quote.h" #include "disc_quote.h" -//! just for 2D shape +// just for 2D shape class Shape { public: diff --git a/ch15/ex15.23.cpp b/ch15/ex15.23.cpp index 049cb591..137b0a72 100644 --- a/ch15/ex15.23.cpp +++ b/ch15/ex15.23.cpp @@ -5,12 +5,12 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.23: -//! Assuming class D1 on page 620 had intended to override its inherited fcn -//! function, how would you fix that class? Assuming you fixed the class so -//! that fcn matched the definition in Base, how would the calls in that section -//! be resolved? +// +// Exercise 15.23: +// Assuming class D1 on page 620 had intended to override its inherited fcn +// function, how would you fix that class? Assuming you fixed the class so +// that fcn matched the definition in Base, how would the calls in that section +// be resolved? // remove the parameter int. // Disscussion on SO : // http://stackoverflow.com/questions/21320779/trying-to-understand-dynamic-binding-and-virtual-functions diff --git a/ch15/ex15.24.25.cpp b/ch15/ex15.24.25.cpp index 2b93bef3..155d8cd3 100644 --- a/ch15/ex15.24.25.cpp +++ b/ch15/ex15.24.25.cpp @@ -5,29 +5,29 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.24: -//! What kinds of classes need a virtual destructor? What operations must a -//! virtual destructor perform? +// +// Exercise 15.24: +// What kinds of classes need a virtual destructor? What operations must a +// virtual destructor perform? // Generally, a base class should define a virtual destructor. // The destructor needs to be virtual to allow objects in the inheritance // hierarchy to be dynamically allocated and destroyed. -//! -//! Exercise 15.25: -//! Why did we define a default constructor for Disc_quote? What effect, if -//! any, would removing that constructor have on the behavior of Bulk_quote? -//! +// +// Exercise 15.25: +// Why did we define a default constructor for Disc_quote? What effect, if +// any, would removing that constructor have on the behavior of Bulk_quote? +// // Without it, when building the statement below, the compiler would conplain // that: -//! -//! note: 'Bulk_quote::Bulk_quote()' is implicitly deleted because the default -//! definition would be ill-formed. -//! +// +// note: 'Bulk_quote::Bulk_quote()' is implicitly deleted because the default +// definition would be ill-formed. +// // The reason is that a constructor taking 4 parameters has been defined, which // prevented the compiler generate synthesized version default constructor. As a // result, the default constructor of any class derived from it has been defined // as deleted. Thus the default constructor must be defined explicitly so that // the derived classes can call it when executing its default constructor. -//! +// int main(){ return 0; } diff --git a/ch15/ex15.26/main.cpp b/ch15/ex15.26/main.cpp index 54b8faa7..6e42feb8 100644 --- a/ch15/ex15.26/main.cpp +++ b/ch15/ex15.26/main.cpp @@ -5,15 +5,15 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.26: -//! Define the Quote and Bulk_quote copy-control members to do the same job -//! as the synthesized versions. Give them and the other constructors print -//! statements that identify which function is running. Write programs using -//! these classes and predict what objects will be created and destroyed. -//! Compare your predictions with the output and continue experimenting -//! until your predictions are reliably correct. -//! +// +// Exercise 15.26: +// Define the Quote and Bulk_quote copy-control members to do the same job +// as the synthesized versions. Give them and the other constructors print +// statements that identify which function is running. Write programs using +// these classes and predict what objects will be created and destroyed. +// Compare your predictions with the output and continue experimenting +// until your predictions are reliably correct. +// #include diff --git a/ch15/ex15.27/main.cpp b/ch15/ex15.27/main.cpp index 21bdcb5d..8c668d2b 100644 --- a/ch15/ex15.27/main.cpp +++ b/ch15/ex15.27/main.cpp @@ -5,14 +5,14 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.27: -//! Redefine your Bulk_quote class to inherit its constructors. +// +// Exercise 15.27: +// Redefine your Bulk_quote class to inherit its constructors. // rules: 1. only inherit from the direct base class. // 2. default,copy and move constructors can not inherit. // 3. any data members of its own are default initialized. // 4. the rest details are in the section section 15.7.4. -//! +// #include diff --git a/ch15/ex15.28.29/main.cpp b/ch15/ex15.28.29/main.cpp index f91f5b53..c75483ef 100644 --- a/ch15/ex15.28.29/main.cpp +++ b/ch15/ex15.28.29/main.cpp @@ -5,15 +5,15 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! Exercise 15.28: -//! Define a vector to hold Quote objects but put Bulk_quote objects into that -//! vector. Compute the total net_price of all the elements in the vector. -//! -//! Exercise 15.29: -//! Repeat your program, but this time store shared_ptrs to objects of type -//! Quote. Explain any discrepancy in the sum generated by the this version and -//! the previous program. -//! +// Exercise 15.28: +// Define a vector to hold Quote objects but put Bulk_quote objects into that +// vector. Compute the total net_price of all the elements in the vector. +// +// Exercise 15.29: +// Repeat your program, but this time store shared_ptrs to objects of type +// Quote. Explain any discrepancy in the sum generated by the this version and +// the previous program. +// // Since the vector from the previous exercise holds objects, there's no polymorphism // happened while calling the virtual function net_price. Essentially, the obejcts // held in it are the Quote subjects of the Bulk_quote objects being pushed back, @@ -25,9 +25,9 @@ // are Bulk_quote::net_price that ensure discount is applied.Thus, the outcome is 6363. // It can be found that 30% dicount has been applied to the price calculation. // -//! -//! If there is no discrepancy, explain why there isn’t one. -//! +// +// If there is no discrepancy, explain why there isn’t one. +// #include diff --git a/ch15/ex15.30/basket.h b/ch15/ex15.30/basket.h index 20eac99c..9034c225 100644 --- a/ch15/ex15.30/basket.h +++ b/ch15/ex15.30/basket.h @@ -6,7 +6,7 @@ #include -//! a basket of objects from Quote hierachy, using smart pointers. +// a basket of objects from Quote hierachy, using smart pointers. class Basket { public: diff --git a/ch15/ex15.30/main.cpp b/ch15/ex15.30/main.cpp index daf0ef7a..4541cd16 100644 --- a/ch15/ex15.30/main.cpp +++ b/ch15/ex15.30/main.cpp @@ -5,11 +5,11 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.30: -//! Write your own version of the Basket class and use it to compute prices -//! for the same transactions as you used in the previous exercises. -//! +// +// Exercise 15.30: +// Write your own version of the Basket class and use it to compute prices +// for the same transactions as you used in the previous exercises. +// #include diff --git a/ch15/ex15.30/quote.cpp b/ch15/ex15.30/quote.cpp index e9990efa..4bbf7251 100644 --- a/ch15/ex15.30/quote.cpp +++ b/ch15/ex15.30/quote.cpp @@ -7,7 +7,7 @@ void Quote::debug() const << "price= " <price<< " \n"; } -//! non-member +// non-member double print_total(std::ostream &os,const Quote &item, size_t n) { // depending on the type of the object bound to the item parameter diff --git a/ch15/ex15.30/quote.h b/ch15/ex15.30/quote.h index f9f21b09..ac8e09d6 100644 --- a/ch15/ex15.30/quote.h +++ b/ch15/ex15.30/quote.h @@ -74,7 +74,7 @@ operator !=(const Quote& lhs, const Quote& rhs) lhs.price != rhs.price; } -//! non-member +// non-member double print_total(std::ostream &os,const Quote &item, size_t n); #endif // QUOTE_H diff --git a/ch15/ex15.31.32.33.cpp b/ch15/ex15.31.32.33.cpp index b5952ac2..4ceb6801 100644 --- a/ch15/ex15.31.32.33.cpp +++ b/ch15/ex15.31.32.33.cpp @@ -5,17 +5,17 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.31: -//! Given that s1, s2, s3, and s4 are all strings, determine what objects are created in the following expressions: -//! (a) Query(s1) | Query(s2) & ~ Query(s3); +// +// Exercise 15.31: +// Given that s1, s2, s3, and s4 are all strings, determine what objects are created in the following expressions: +// (a) Query(s1) | Query(s2) & ~ Query(s3); // OrQuery, AndQuery, NotQuery, WordQuery -//! (b) Query(s1) | (Query(s2) & ~ Query(s3)); +// (b) Query(s1) | (Query(s2) & ~ Query(s3)); // the same as the previous one -//! (c) (Query(s1) & (Query(s2)) | (Query(s3) & Query(s4))); -//! OrQuery, AndQuery, WordQuery -//! Exercise 15.32: -//! What happens when an object of type Query is copied, moved, assigned, and destroyed? +// (c) (Query(s1) & (Query(s2)) | (Query(s3) & Query(s4))); +// OrQuery, AndQuery, WordQuery +// Exercise 15.32: +// What happens when an object of type Query is copied, moved, assigned, and destroyed? // copy: // While being copied, the synthesized copy constructor is called. It copies the data member // into the new object. Since in this case, the data member is a shared pointer, while @@ -42,11 +42,11 @@ // shared_ptr which decrements the use count. If the count becomes zero, the destructor // from shared_ptr will delete the resources it point to. // -//! Exercise 15.33: -//! What about objects of type Query_base? +// Exercise 15.33: +// What about objects of type Query_base? // Managed by the synthesized version. Since Query_base a abstract class, the object of // this type is essentially a subobject of its derived class. -//! +// #include @@ -61,7 +61,7 @@ #include "query.h" -//! this class is a simulation for class Query used to answer ex15.32 +// this class is a simulation for class Query used to answer ex15.32 class Foo { public: diff --git a/ch15/ex15.34.35.36.38/main.cpp b/ch15/ex15.34.35.36.38/main.cpp index abeda5ce..a7b4ea91 100644 --- a/ch15/ex15.34.35.36.38/main.cpp +++ b/ch15/ex15.34.35.36.38/main.cpp @@ -5,9 +5,9 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.34: For the expression built in Figure 15.3 (p. 638): -//! (a) List the constructors executed in processing that expression. +// +// Exercise 15.34: For the expression built in Figure 15.3 (p. 638): +// (a) List the constructors executed in processing that expression. // Query q = Query("fiery") & Query("bird") | Query("wind"); // 1: Query::Query(const std::string& s) where s == "fiery","bird" and "wind" // 2: WordQuery::WordQuery(const std::string& s) where s == "fiery","bird" and "wind" @@ -18,7 +18,7 @@ // 7: BinaryQuery(const Query&l, const Query& r, std::string s); // 8: Query::Query(std::shared_ptr query) 2times // -//! (b) List the calls to rep that are made from cout << q. +// (b) List the calls to rep that are made from cout << q. // query.rep() inside the operator <<() // q->rep() insede the member function rep() // OrQuery::rep() which is inherited from BinaryQuery @@ -30,68 +30,68 @@ // BinaryQuer::rep() // for rhs: WordQuery::rep() where query_word("fiery") is retuerned // for lhs: WordQuery::rep() where query_word("bird" ) is retuerned -//! -//! (c) List the calls to eval made from q.eval(). +// +// (c) List the calls to eval made from q.eval(). // q.eval() // q->rep() where q is a pointer to OrQuary // QueryResult eval(const TextQuery& )const override -- is called but this one has not been defined yet. -//! -//! Exercise 15.35: -//! Implement the Query and Query_base classes, including a definition of -//! rep but omitting the definition of eval. -//! -//! Exercise 15.36: -//! Put print statements in the constructors and rep members and run your code -//! to check your answers to (a) and (b) from the first exercise. -//! +// +// Exercise 15.35: +// Implement the Query and Query_base classes, including a definition of +// rep but omitting the definition of eval. +// +// Exercise 15.36: +// Put print statements in the constructors and rep members and run your code +// to check your answers to (a) and (b) from the first exercise. +// // Query q = Query("fiery") & Query("bird") | Query("wind"); -//! -//! WordQuery::WordQuery(wind) -//! Query::Query(const std::string& s) where s=wind -//! WordQuery::WordQuery(bird) -//! Query::Query(const std::string& s) where s=bird -//! WordQuery::WordQuery(fiery) -//! Query::Query(const std::string& s) where s=fiery -//! BinaryQuery::BinaryQuery() where s=& -//! AndQuery::AndQuery() -//! Query::Query(std::shared_ptr query) -//! BinaryQuery::BinaryQuery() where s=| -//! OrQuery::OrQuery -//! Query::Query(std::shared_ptr query) -//! Press to close this window... -//! -//! -//! +// +// WordQuery::WordQuery(wind) +// Query::Query(const std::string& s) where s=wind +// WordQuery::WordQuery(bird) +// Query::Query(const std::string& s) where s=bird +// WordQuery::WordQuery(fiery) +// Query::Query(const std::string& s) where s=fiery +// BinaryQuery::BinaryQuery() where s=& +// AndQuery::AndQuery() +// Query::Query(std::shared_ptr query) +// BinaryQuery::BinaryQuery() where s=| +// OrQuery::OrQuery +// Query::Query(std::shared_ptr query) +// Press to close this window... +// +// +// // std::cout << q < to close this window... -//! -//! Exercise 15.37: -//! What changes would your classes need if the derived classes had -//! members of type shared_ptr rather than of type Query? +// +// Query::rep() +// BinaryQuery::rep() +// Query::rep() +// WodQuery::rep() +// Query::rep() +// BinaryQuery::rep() +// Query::rep() +// WodQuery::rep() +// Query::rep() +// WodQuery::rep() +// ((fiery & bird) | wind) +// Press to close this window... +// +// Exercise 15.37: +// What changes would your classes need if the derived classes had +// members of type shared_ptr rather than of type Query? // not done -//! -//! Exercise 15.38: -//! Are the following declarations legal? -//! If not, why not? If so, explain what the declarations mean. -//! BinaryQuery a = Query("fiery") & Query("bird"); +// +// Exercise 15.38: +// Are the following declarations legal? +// If not, why not? If so, explain what the declarations mean. +// BinaryQuery a = Query("fiery") & Query("bird"); // Illegal. Because BinaryQuery is an abstract class. -//! AndQuery b = Query("fiery") & Query("bird"); +// AndQuery b = Query("fiery") & Query("bird"); // Illegal. Because operator & returns a Query which can not conver to an AndQuery object. -//! OrQuery c = Query("fiery") & Query("bird"); +// OrQuery c = Query("fiery") & Query("bird"); // Illegal. Because operator & returns a Query which can not conver to an OrQuery object. -//! +// #include diff --git a/ch15/ex15.34.35.36.38/queryresult.h b/ch15/ex15.34.35.36.38/queryresult.h index 6134c1b2..62627518 100644 --- a/ch15/ex15.34.35.36.38/queryresult.h +++ b/ch15/ex15.34.35.36.38/queryresult.h @@ -5,16 +5,16 @@ * @remark using class StrBlob ***************************************************************************/ -//! -//! Exercise 12.33: -//! In Chapter 15 we’ll extend our query system and will need some additional -//! members in the QueryResult class. -//! -//! Add members named begin and end that -//! return iterators into the set of line numbers returned by a given query, -//! and a member named get_file that returns a shared_ptr to the file in the -//! QueryResult object. -//! +// +// Exercise 12.33: +// In Chapter 15 we’ll extend our query system and will need some additional +// members in the QueryResult class. +// +// Add members named begin and end that +// return iterators into the set of line numbers returned by a given query, +// and a member named get_file that returns a shared_ptr to the file in the +// QueryResult object. +// #ifndef QUERYRESULT_H #define QUERYRESULT_H diff --git a/ch15/ex15.34.35.36.38/textquery.cpp b/ch15/ex15.34.35.36.38/textquery.cpp index 30de5ebe..fe46e669 100644 --- a/ch15/ex15.34.35.36.38/textquery.cpp +++ b/ch15/ex15.34.35.36.38/textquery.cpp @@ -5,13 +5,13 @@ * @remark The TextQuery class using StrBlob ***************************************************************************/ -//! -//! Exercise 12.32: -//! Rewrite the TextQuery and QueryResult classes to use a StrBlob instead of a -//! vector to hold the input file. +// +// Exercise 12.32: +// Rewrite the TextQuery and QueryResult classes to use a StrBlob instead of a +// vector to hold the input file. // Relevant post on Stack Overflow: // http://stackoverflow.com/questions/20823225/what-will-happen-if-a-user-defined-constructor-omits-ininitialization-for-data-m -//! +// #include "textquery.h" #include "queryresult.h" diff --git a/ch15/ex15.34.35.36.38/textquery.h b/ch15/ex15.34.35.36.38/textquery.h index 38176709..7832b093 100644 --- a/ch15/ex15.34.35.36.38/textquery.h +++ b/ch15/ex15.34.35.36.38/textquery.h @@ -5,13 +5,13 @@ * @remark The TextQuery class using StrBlob ***************************************************************************/ -//! -//! Exercise 12.32: -//! Rewrite the TextQuery and QueryResult classes to use a StrBlob instead of a -//! vector to hold the input file. +// +// Exercise 12.32: +// Rewrite the TextQuery and QueryResult classes to use a StrBlob instead of a +// vector to hold the input file. // Relevant post on Stack Overflow: // http://stackoverflow.com/questions/20823225/what-will-happen-if-a-user-defined-constructor-omits-ininitialization-for-data-m -//! +// #ifndef TEXTQUERY_H diff --git a/ch15/ex15.39.40/main.cpp b/ch15/ex15.39.40/main.cpp index 764e1abc..8fa5b3c4 100644 --- a/ch15/ex15.39.40/main.cpp +++ b/ch15/ex15.39.40/main.cpp @@ -5,23 +5,23 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.39: -//! Implement the Query and Query_base classes. Test your application by -//! evaluating and printing a query such as the one in Figure 15.3 (p. 638). -//! -//! Exercise 15.40: -//! In the OrQuery eval function what would happen if its rhs member returned -//! an empty set? What if its lhs member did so? What if both rhs and lhs -//! returned empty sets? +// +// Exercise 15.39: +// Implement the Query and Query_base classes. Test your application by +// evaluating and printing a query such as the one in Figure 15.3 (p. 638). +// +// Exercise 15.40: +// In the OrQuery eval function what would happen if its rhs member returned +// an empty set? What if its lhs member did so? What if both rhs and lhs +// returned empty sets? // Nothing special will happen. The codes as following: // std::shared_ptr> ret_lines = // std::make_shared>(left.begin(), left.end()); -//! ^^^^^^^^^^^^^^^^ +// ^^^^^^^^^^^^^^^^ // Since std::make_shared will allocate dynamically a new std::set, nothing will // be added into this std::set if any set is empty.The codes in main function // proves this. -//! +// #include #include diff --git a/ch15/ex15.39.40/queryresult.h b/ch15/ex15.39.40/queryresult.h index 67fa6d45..9bc33e68 100644 --- a/ch15/ex15.39.40/queryresult.h +++ b/ch15/ex15.39.40/queryresult.h @@ -5,16 +5,16 @@ * @remark using class StrBlob ***************************************************************************/ -//! -//! Exercise 12.33: -//! In Chapter 15 we’ll extend our query system and will need some additional -//! members in the QueryResult class. -//! -//! Add members named begin and end that -//! return iterators into the set of line numbers returned by a given query, -//! and a member named get_file that returns a shared_ptr to the file in the -//! QueryResult object. -//! +// +// Exercise 12.33: +// In Chapter 15 we’ll extend our query system and will need some additional +// members in the QueryResult class. +// +// Add members named begin and end that +// return iterators into the set of line numbers returned by a given query, +// and a member named get_file that returns a shared_ptr to the file in the +// QueryResult object. +// #ifndef QUERYRESULT_H #define QUERYRESULT_H diff --git a/ch15/ex15.39.40/textquery.cpp b/ch15/ex15.39.40/textquery.cpp index 30de5ebe..fe46e669 100644 --- a/ch15/ex15.39.40/textquery.cpp +++ b/ch15/ex15.39.40/textquery.cpp @@ -5,13 +5,13 @@ * @remark The TextQuery class using StrBlob ***************************************************************************/ -//! -//! Exercise 12.32: -//! Rewrite the TextQuery and QueryResult classes to use a StrBlob instead of a -//! vector to hold the input file. +// +// Exercise 12.32: +// Rewrite the TextQuery and QueryResult classes to use a StrBlob instead of a +// vector to hold the input file. // Relevant post on Stack Overflow: // http://stackoverflow.com/questions/20823225/what-will-happen-if-a-user-defined-constructor-omits-ininitialization-for-data-m -//! +// #include "textquery.h" #include "queryresult.h" diff --git a/ch15/ex15.39.40/textquery.h b/ch15/ex15.39.40/textquery.h index 38176709..7832b093 100644 --- a/ch15/ex15.39.40/textquery.h +++ b/ch15/ex15.39.40/textquery.h @@ -5,13 +5,13 @@ * @remark The TextQuery class using StrBlob ***************************************************************************/ -//! -//! Exercise 12.32: -//! Rewrite the TextQuery and QueryResult classes to use a StrBlob instead of a -//! vector to hold the input file. +// +// Exercise 12.32: +// Rewrite the TextQuery and QueryResult classes to use a StrBlob instead of a +// vector to hold the input file. // Relevant post on Stack Overflow: // http://stackoverflow.com/questions/20823225/what-will-happen-if-a-user-defined-constructor-omits-ininitialization-for-data-m -//! +// #ifndef TEXTQUERY_H diff --git a/ch15/ex15.4.5.6/main.cpp b/ch15/ex15.4.5.6/main.cpp index b756bd06..bf92c39f 100644 --- a/ch15/ex15.4.5.6/main.cpp +++ b/ch15/ex15.4.5.6/main.cpp @@ -5,22 +5,22 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.4: -//! Which of the following declarations, if any, are incorrect? Explain why. +// +// Exercise 15.4: +// Which of the following declarations, if any, are incorrect? Explain why. // class Base { ... }; // (a) class Derived : public Derived { ... }; //incorrect, deirve from itself // (b) class Derived : private Base { ... }; //incorrect, this is a definition not a declaration // (c) class Derived : public Base; //incorrect, A derived class is declared like any other class. The declaration //contains the class name but does not include its derivation list. //@ reported by lafener, check #154 for detail. -//! Exercise 15.5: -//! Define your own version of the Bulk_quote class. -//! -//! Exercise 15.6: -//! Test your print_total function from the exercises in § 15.2.1 (p. 595) -//! by passing both Quote and Bulk_quote objects o that function. -//! +// Exercise 15.5: +// Define your own version of the Bulk_quote class. +// +// Exercise 15.6: +// Test your print_total function from the exercises in § 15.2.1 (p. 595) +// by passing both Quote and Bulk_quote objects o that function. +// #include #include diff --git a/ch15/ex15.7/main.cpp b/ch15/ex15.7/main.cpp index e671f4a2..8ae89cfc 100644 --- a/ch15/ex15.7/main.cpp +++ b/ch15/ex15.7/main.cpp @@ -5,13 +5,13 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.7: -//! Define a class that implements a limited discount strategy, which applies -//! a discount to books purchased up to a given limit. If the number of copies -//! exceeds that limit, the normal price applies to those purchased beyond the -//! limit. -//! +// +// Exercise 15.7: +// Define a class that implements a limited discount strategy, which applies +// a discount to books purchased up to a given limit. If the number of copies +// exceeds that limit, the normal price applies to those purchased beyond the +// limit. +// #include #include diff --git a/ch15/ex15.8.9.10/ex15.8.9.10.cpp b/ch15/ex15.8.9.10/ex15.8.9.10.cpp index 2d00559f..bc7fe6a1 100644 --- a/ch15/ex15.8.9.10/ex15.8.9.10.cpp +++ b/ch15/ex15.8.9.10/ex15.8.9.10.cpp @@ -5,25 +5,25 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 15.8: -//! Define static type and dynamic type. +// +// Exercise 15.8: +// Define static type and dynamic type. // The static type of an expression is always known at compile time. // The dynamic type is the type of the object in memory that the variable or // expression reprensents. The dynamic type may not be known until run time. -//! -//! Exercise 15.9: -//! When is it possible for an expression’s static type to differ from its -//! dynamic type? Give three examples in which the static and dynamic type differ. +// +// Exercise 15.9: +// When is it possible for an expression’s static type to differ from its +// dynamic type? Give three examples in which the static and dynamic type differ. // The static type of a pointer or reference to a base class may differ from // its dynamic type. Anying like this can be an example -//! -//! Exercise 15.10: -//! Recalling the discussion from §8.1 (p. 311), explain how the program on -//! page 317 that passed an ifstream to the Sales_data read function works. +// +// Exercise 15.10: +// Recalling the discussion from §8.1 (p. 311), explain how the program on +// page 317 that passed an ifstream to the Sales_data read function works. // the function takes a std::istream from which std::ifstream is derived. // Hence the ifstream object "is a" istream ,which is why it works. -//! +// #include #include diff --git a/ch16/ex16.1.2.3/main.cpp b/ch16/ex16.1.2.3/main.cpp index c4272fcd..3d3ade25 100644 --- a/ch16/ex16.1.2.3/main.cpp +++ b/ch16/ex16.1.2.3/main.cpp @@ -5,24 +5,24 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.1: -//! Define instantiation. +// +// Exercise 16.1: +// Define instantiation. // When the compiler instantiates a template, it creates a new “instance” of // the template using the actual template argument(s) in place of the // corresponding template parameter(s). -//! -//! Exercise 16.2: -//! Write and test your own versions of the compare functions. -//! -//! Exercise 16.3: -//! Call your compare function on two Sales_data objects to see how your compiler -//! handles errors during instantiation. +// +// Exercise 16.2: +// Write and test your own versions of the compare functions. +// +// Exercise 16.3: +// Call your compare function on two Sales_data objects to see how your compiler +// handles errors during instantiation. // error: no match for 'operator<' (operand types are 'const Sales_data' and // 'const Sales_data') -//! -//! -//! +// +// +// #include using std::cout; diff --git a/ch16/ex16.12.13/Blob.h b/ch16/ex16.12.13/Blob.h index 1a3e8239..db3f15c0 100644 --- a/ch16/ex16.12.13/Blob.h +++ b/ch16/ex16.12.13/Blob.h @@ -34,7 +34,7 @@ template class Blob void check(size_type i, const std::string &msg) const; }; -//! constructors +// constructors template Blob::Blob() : data(std::make_shared>()) {} diff --git a/ch16/ex16.12.13/blobptr.h b/ch16/ex16.12.13/blobptr.h index c92273d1..30a1ff9d 100644 --- a/ch16/ex16.12.13/blobptr.h +++ b/ch16/ex16.12.13/blobptr.h @@ -51,7 +51,7 @@ template class BlobPtr }; -//! prefix ++ +// prefix ++ template BlobPtr& BlobPtr::operator ++() { @@ -61,7 +61,7 @@ BlobPtr& BlobPtr::operator ++() return *this; } -//! prefix -- +// prefix -- template BlobPtr& BlobPtr::operator --() { @@ -72,7 +72,7 @@ BlobPtr& BlobPtr::operator --() } -//! postfix ++ +// postfix ++ template BlobPtr BlobPtr::operator ++(int) { @@ -82,7 +82,7 @@ BlobPtr BlobPtr::operator ++(int) return ret; } -//! postfix -- +// postfix -- template BlobPtr BlobPtr::operator --(int) { diff --git a/ch16/ex16.12.13/main.cpp b/ch16/ex16.12.13/main.cpp index aed93196..29fd0f31 100644 --- a/ch16/ex16.12.13/main.cpp +++ b/ch16/ex16.12.13/main.cpp @@ -5,16 +5,16 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.12: -//! Write your own version of the Blob and BlobPtr templates. including the -//! various const members that were not shown in the text. -//! -//! Exercise 16.13: -//! Explain which kind of friendship you chose for the equality and relational -//! operators for BlobPtr. +// +// Exercise 16.12: +// Write your own version of the Blob and BlobPtr templates. including the +// various const members that were not shown in the text. +// +// Exercise 16.13: +// Explain which kind of friendship you chose for the equality and relational +// operators for BlobPtr. // As shown in the class body. -//! +// #include diff --git a/ch16/ex16.14.15/Screen.h b/ch16/ex16.14.15/Screen.h index 33a5b51c..74de14c8 100644 --- a/ch16/ex16.14.15/Screen.h +++ b/ch16/ex16.14.15/Screen.h @@ -1,8 +1,8 @@ -//! -//! Exercise 16.14: -//! Write a Screen class template that uses nontype parameters to define the -//! height and width of the Screen. -//! +// +// Exercise 16.14: +// Write a Screen class template that uses nontype parameters to define the +// height and width of the Screen. +// #ifndef SCREEN_H #define SCREEN_H diff --git a/ch16/ex16.14.15/main.cpp b/ch16/ex16.14.15/main.cpp index 47725ddd..3e2cc87f 100644 --- a/ch16/ex16.14.15/main.cpp +++ b/ch16/ex16.14.15/main.cpp @@ -5,16 +5,16 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.14: -//! Write a Screen class template that uses nontype parameters to define the -//! height and width of the Screen. -//! -//! Exercise 16.15: -//! Implement input and output operators for your Screen template. -//! Which, if any, friends are necessary in class Screen to make the input and -//! output operators work? Explain why each friend declaration, if any, was -//! needed. +// +// Exercise 16.14: +// Write a Screen class template that uses nontype parameters to define the +// height and width of the Screen. +// +// Exercise 16.15: +// Implement input and output operators for your Screen template. +// Which, if any, friends are necessary in class Screen to make the input and +// output operators work? Explain why each friend declaration, if any, was +// needed. // According to the chapter of 14.2.1,the class of << and << should be a friend of this class. // diff --git a/ch16/ex16.16/main.cpp b/ch16/ex16.16/main.cpp index 2d4d01b5..ba7e5cce 100644 --- a/ch16/ex16.16/main.cpp +++ b/ch16/ex16.16/main.cpp @@ -5,10 +5,10 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.16: -//! Rewrite the StrVec class (§ 13.5, p. 526) as a template named Vec. -//! +// +// Exercise 16.16: +// Rewrite the StrVec class (§ 13.5, p. 526) as a template named Vec. +// #include "vec.h" #include diff --git a/ch16/ex16.16/vec.h b/ch16/ex16.16/vec.h index d9631f5b..69b834d7 100644 --- a/ch16/ex16.16/vec.h +++ b/ch16/ex16.16/vec.h @@ -58,7 +58,7 @@ class Vec }; -//! copy constructor +// copy constructor template Vec::Vec(const Vec &v) { @@ -73,7 +73,7 @@ Vec::Vec(const Vec &v) } -//! constructor that takes initializer_list +// constructor that takes initializer_list template Vec::Vec(std::initializer_list l) { @@ -91,7 +91,7 @@ Vec::Vec(std::initializer_list l) } -//! operator = +// operator = template Vec& Vec::operator =(const Vec& rhs) { @@ -109,7 +109,7 @@ Vec& Vec::operator =(const Vec& rhs) } -//! destructor +// destructor template Vec::~Vec() { diff --git a/ch16/ex16.17.18/main.cpp b/ch16/ex16.17.18/main.cpp index 1f62ecea..2becad7e 100644 --- a/ch16/ex16.17.18/main.cpp +++ b/ch16/ex16.17.18/main.cpp @@ -5,11 +5,11 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.17: -//! What, if any, are the differences between a type parameter that is declared -//! as a typename and one that is declared as a class? When must typename be used? -//! +// +// Exercise 16.17: +// What, if any, are the differences between a type parameter that is declared +// as a typename and one that is declared as a class? When must typename be used? +// // There is no difference. typename and class are interchangeable in the // declaration of a type template parameter. // You do, however, have to use class (and not typename) when declaring a @@ -17,27 +17,27 @@ // // When we want to inform the compiler that a name represents a type, we must use // the keyword typename, not class -//! -//! Exercise 16.18: -//! Explain each of the following function template declarations and identify -//! whether any are illegal. Correct each error that you find. -//! +// +// Exercise 16.18: +// Explain each of the following function template declarations and identify +// whether any are illegal. Correct each error that you find. +// template void f1(T, U, V); -//! ^^^^^^^^ added to fix the error +// ^^^^^^^^ added to fix the error template T f2(T&); -//! ^^ +// ^^ template inline T foo(T, unsigned int*); -//! ^^^^^^ inline must be after template +// ^^^^^^ inline must be after template template T f4(T, T); -//! ^ -- return type must be provided +// ^ -- return type must be provided typedef char Ctype; -//! ^^^^^ -//!the template declatation below hides this typedef +// ^^^^^ +//the template declatation below hides this typedef template Ctype f5(Ctype a); int main() diff --git a/ch16/ex16.19.20/main.cpp b/ch16/ex16.19.20/main.cpp index e5087b4e..11966902 100644 --- a/ch16/ex16.19.20/main.cpp +++ b/ch16/ex16.19.20/main.cpp @@ -6,22 +6,22 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.19: -//! Write a function that takes a reference to a container and prints the -//! elements in that container. Use the container’s size_type and size members -//! to control the loop that prints the elements. -//! -//! Exercise 16.20: -//! Rewrite the function from the previous exercise to use iterators returned -//! from begin and end to control the loop. -//! +// +// Exercise 16.19: +// Write a function that takes a reference to a container and prints the +// elements in that container. Use the container’s size_type and size members +// to control the loop that prints the elements. +// +// Exercise 16.20: +// Rewrite the function from the previous exercise to use iterators returned +// from begin and end to control the loop. +// #include #include #include -//! ex16.19 +// ex16.19 template std::ostream& print(Container const& container, std::ostream& os) { @@ -30,7 +30,7 @@ std::ostream& print(Container const& container, std::ostream& os) return os; } -//! ex16.20 +// ex16.20 template std::ostream& print2(Container const& container, std::ostream &os) { diff --git a/ch16/ex16.21.22/main.cpp b/ch16/ex16.21.22/main.cpp index def8eddf..22e33a57 100644 --- a/ch16/ex16.21.22/main.cpp +++ b/ch16/ex16.21.22/main.cpp @@ -5,14 +5,14 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.21: -//! Write your own version of DebugDelete. -//! -//! Exercise 16.22: -//! Revise your TextQuery programs from § 12.3 (p. 484) so that the shared_ptr -//! members use a DebugDelete as their deleter (§ 12.1.4, p. 468). -//! +// +// Exercise 16.21: +// Write your own version of DebugDelete. +// +// Exercise 16.22: +// Revise your TextQuery programs from § 12.3 (p. 484) so that the shared_ptr +// members use a DebugDelete as their deleter (§ 12.1.4, p. 468). +// #include #include diff --git a/ch16/ex16.21.22/wy_queryresult.cpp b/ch16/ex16.21.22/wy_queryresult.cpp index 720cc8e8..138cf903 100644 --- a/ch16/ex16.21.22/wy_queryresult.cpp +++ b/ch16/ex16.21.22/wy_queryresult.cpp @@ -4,24 +4,24 @@ * @date 27 DEC 2013 * @remark ***************************************************************************/ -//! -//! Exercise 12.27: -//! The TextQuery and QueryResult classes use only capabilities that we have -//! already covered. Without looking ahead, write your own versions of these -//! classes. -//! +// +// Exercise 12.27: +// The TextQuery and QueryResult classes use only capabilities that we have +// already covered. Without looking ahead, write your own versions of these +// classes. +// #include "wy_queryresult.h" -//! copy constructor +// copy constructor inline wy_queryResult::wy_queryResult(const wy_queryResult &qr): counter(qr.getCounter()), queryWord(qr.getQueryWord()), sp_file(qr.getSp_file()), sp_Qmap(qr.getSp_Qmap()) { } -//! constructor +// constructor wy_queryResult::wy_queryResult(std::size_t c, const std::string &str, const wy_textQuery::sp_file_Tp &sp_f, const wy_textQuery::sp_Qmap_Tp &sp_m) : @@ -29,7 +29,7 @@ wy_queryResult::wy_queryResult(std::size_t c, const std::string &str, { } -//! a non-member function printing the result of a query. +// a non-member function printing the result of a query. void print(std::ostream &os, const wy_queryResult &qr) { //! fetch the word being queried. diff --git a/ch16/ex16.21.22/wy_queryresult.h b/ch16/ex16.21.22/wy_queryresult.h index ef08e542..f6b38fcd 100644 --- a/ch16/ex16.21.22/wy_queryresult.h +++ b/ch16/ex16.21.22/wy_queryresult.h @@ -5,12 +5,12 @@ * @remark ***************************************************************************/ -//! -//! Exercise 12.27: -//! The TextQuery and QueryResult classes use only capabilities that we have -//! already covered. Without looking ahead, write your own versions of these -//! classes. -//! +// +// Exercise 12.27: +// The TextQuery and QueryResult classes use only capabilities that we have +// already covered. Without looking ahead, write your own versions of these +// classes. +// #ifndef WY_QUERYRESULT_H @@ -57,7 +57,7 @@ class wy_queryResult wy_textQuery::sp_Qmap_Tp sp_Qmap = nullptr; }; -//! print the result of searching +// print the result of searching void print(std::ostream &os, const wy_queryResult &qr); #endif // WY_QUERYRESULT_H diff --git a/ch16/ex16.21.22/wy_textquery.cpp b/ch16/ex16.21.22/wy_textquery.cpp index f0fcb715..d0598987 100644 --- a/ch16/ex16.21.22/wy_textquery.cpp +++ b/ch16/ex16.21.22/wy_textquery.cpp @@ -5,12 +5,12 @@ * @remark 03 FEB 2014 deleter added ***************************************************************************/ -//! -//! Exercise 12.27: -//! The TextQuery and QueryResult classes use only capabilities that we have -//! already covered. Without looking ahead, write your own versions of these -//! classes. -//! +// +// Exercise 12.27: +// The TextQuery and QueryResult classes use only capabilities that we have +// already covered. Without looking ahead, write your own versions of these +// classes. +// #include "wy_textquery.h" #include "wy_queryresult.h" diff --git a/ch16/ex16.21.22/wy_textquery.h b/ch16/ex16.21.22/wy_textquery.h index 4a7967f3..bd80dae5 100644 --- a/ch16/ex16.21.22/wy_textquery.h +++ b/ch16/ex16.21.22/wy_textquery.h @@ -5,12 +5,12 @@ * @remark ***************************************************************************/ -//! -//! Exercise 12.27: -//! The TextQuery and QueryResult classes use only capabilities that we have -//! already covered. Without looking ahead, write your own versions of these -//! classes. -//! +// +// Exercise 12.27: +// The TextQuery and QueryResult classes use only capabilities that we have +// already covered. Without looking ahead, write your own versions of these +// classes. +// #ifndef WY_TEXTQUERY_H #define WY_TEXTQUERY_H diff --git a/ch16/ex16.24/Blob.h b/ch16/ex16.24/Blob.h index c9781f5e..fe205ff1 100644 --- a/ch16/ex16.24/Blob.h +++ b/ch16/ex16.24/Blob.h @@ -46,17 +46,17 @@ template class Blob void check(size_type i, const std::string &msg) const; }; -//! default constructor +// default constructor template Blob::Blob() : data(std::make_shared>()) {} -//! constructor taking initializer_list +// constructor taking initializer_list template Blob::Blob(std::initializer_list il): data(std::make_shared>(il)){ } -//! constructor taking two iterators +// constructor taking two iterators template //for class template //for this member Blob::Blob(It b, It e) : diff --git a/ch16/ex16.24/blobptr.h b/ch16/ex16.24/blobptr.h index 6d3fd272..dba7bd83 100644 --- a/ch16/ex16.24/blobptr.h +++ b/ch16/ex16.24/blobptr.h @@ -51,7 +51,7 @@ template class BlobPtr }; -//! prefix ++ +// prefix ++ template BlobPtr& BlobPtr::operator ++() { @@ -61,7 +61,7 @@ BlobPtr& BlobPtr::operator ++() return *this; } -//! prefix -- +// prefix -- template BlobPtr& BlobPtr::operator --() { @@ -72,7 +72,7 @@ BlobPtr& BlobPtr::operator --() } -//! postfix ++ +// postfix ++ template BlobPtr BlobPtr::operator ++(int) { @@ -82,7 +82,7 @@ BlobPtr BlobPtr::operator ++(int) return ret; } -//! postfix -- +// postfix -- template BlobPtr BlobPtr::operator --(int) { diff --git a/ch16/ex16.24/main.cpp b/ch16/ex16.24/main.cpp index 4a89e205..c961a35d 100644 --- a/ch16/ex16.24/main.cpp +++ b/ch16/ex16.24/main.cpp @@ -5,10 +5,10 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.24: -//! Add a constructor that takes two iterators to your Blob template. -//! +// +// Exercise 16.24: +// Add a constructor that takes two iterators to your Blob template. +// #include #include diff --git a/ch16/ex16.25.26/main.cpp b/ch16/ex16.25.26/main.cpp index 984ad865..1e339b45 100644 --- a/ch16/ex16.25.26/main.cpp +++ b/ch16/ex16.25.26/main.cpp @@ -5,10 +5,10 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.25: -//! Explain the meaning of these declarations: -//! +// +// Exercise 16.25: +// Explain the meaning of these declarations: +// /** * @brief instantiation declaration. The definition of it is somewhere else @@ -20,11 +20,11 @@ */ //template class vector; -//! Exercise 16.26: -//! Assuming NoDefault is a class that does not have a default constructor, -//! can we explicitly instantiate vector? If not, why not? +// Exercise 16.26: +// Assuming NoDefault is a class that does not have a default constructor, +// can we explicitly instantiate vector? If not, why not? // http://stackoverflow.com/questions/21525169/while-explicitly-instantiating-vectorsometype-what-is-the-sometype-default-co -//! +// int main() { diff --git a/ch16/ex16.28/main.cpp b/ch16/ex16.28/main.cpp index dbe9a206..2c52e6f8 100644 --- a/ch16/ex16.28/main.cpp +++ b/ch16/ex16.28/main.cpp @@ -6,9 +6,9 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.28 Write your own versions of shared_ptr and unique_ptr -//! +// +// Exercise 16.28 Write your own versions of shared_ptr and unique_ptr +// #include #include diff --git a/ch16/ex16.28/unique_pointer.h b/ch16/ex16.28/unique_pointer.h index 8a49e2c7..d59f6f26 100644 --- a/ch16/ex16.28/unique_pointer.h +++ b/ch16/ex16.28/unique_pointer.h @@ -3,7 +3,7 @@ #include -//! forward declarations for friendship +// forward declarations for friendship template class unique_pointer; template void @@ -67,7 +67,7 @@ class unique_pointer }; -//! swap +// swap template inline void swap(unique_pointer& lhs, unique_pointer& rhs) @@ -77,7 +77,7 @@ swap(unique_pointer& lhs, unique_pointer& rhs) swap(lhs.deleter, rhs.deleter); } -//! move assignment +// move assignment template inline unique_pointer& unique_pointer::operator =(unique_pointer&& rhs) noexcept @@ -93,7 +93,7 @@ unique_pointer::operator =(unique_pointer&& rhs) noexcept } -//! std::nullptr_t assignment +// std::nullptr_t assignment template inline unique_pointer& unique_pointer::operator =(std::nullptr_t n) noexcept diff --git a/ch16/ex16.29/Blob.h b/ch16/ex16.29/Blob.h index 867a16d3..01d97f8f 100644 --- a/ch16/ex16.29/Blob.h +++ b/ch16/ex16.29/Blob.h @@ -58,17 +58,17 @@ template class Blob void check(size_type i, const std::string &msg) const; }; -//! default constructor +// default constructor template Blob::Blob() : data(std::make_shared>()) {} -//! constructor taking initializer_list +// constructor taking initializer_list template Blob::Blob(std::initializer_list il): data(std::make_shared>(il)){ } -//! constructor taking two iterators +// constructor taking two iterators template //for class template //for this member Blob::Blob(It b, It e) : diff --git a/ch16/ex16.29/main.cpp b/ch16/ex16.29/main.cpp index b8acdf57..f5078f64 100644 --- a/ch16/ex16.29/main.cpp +++ b/ch16/ex16.29/main.cpp @@ -5,11 +5,11 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.29: -//! Revise your Blob class to use your version of shared_ptr rather than the -//! library version. -//! +// +// Exercise 16.29: +// Revise your Blob class to use your version of shared_ptr rather than the +// library version. +// #include diff --git a/ch16/ex16.29/shared_pointer.h b/ch16/ex16.29/shared_pointer.h index d694ead4..c7249a62 100644 --- a/ch16/ex16.29/shared_pointer.h +++ b/ch16/ex16.29/shared_pointer.h @@ -12,7 +12,7 @@ #include #include -//! forward declarations needed for friendship +// forward declarations needed for friendship template class shared_pointer; template void swap(shared_pointer& lhs, shared_pointer& rhs); @@ -142,7 +142,7 @@ shared_pointer::shared_pointer(std::shared_ptr&& sp, } -//! move constructor +// move constructor template inline shared_pointer::shared_pointer(shared_pointer&& sp) noexcept: @@ -153,7 +153,7 @@ shared_pointer::shared_pointer(shared_pointer&& sp) noexcept: } -//! copy assignment +// copy assignment template inline shared_pointer& shared_pointer::operator =(const shared_pointer& rhs) @@ -173,7 +173,7 @@ shared_pointer::operator =(const shared_pointer& rhs) } -//! move assignment +// move assignment template inline shared_pointer& shared_pointer::operator =(shared_pointer&& rhs) noexcept @@ -190,7 +190,7 @@ shared_pointer::operator =(shared_pointer&& rhs) noexcept } -//! make prt point where p pointing and create a new coount for it +// make prt point where p pointing and create a new coount for it template inline void shared_pointer::reset(T* p) @@ -217,7 +217,7 @@ operator <<(std::ostream& os, shared_pointer p) } -//! utilities for decrement and delete using deleter. +// utilities for decrement and delete using deleter. template inline void shared_pointer::decrement_n_destroy() diff --git a/ch16/ex16.29/unique_pointer.h b/ch16/ex16.29/unique_pointer.h index 8a49e2c7..d59f6f26 100644 --- a/ch16/ex16.29/unique_pointer.h +++ b/ch16/ex16.29/unique_pointer.h @@ -3,7 +3,7 @@ #include -//! forward declarations for friendship +// forward declarations for friendship template class unique_pointer; template void @@ -67,7 +67,7 @@ class unique_pointer }; -//! swap +// swap template inline void swap(unique_pointer& lhs, unique_pointer& rhs) @@ -77,7 +77,7 @@ swap(unique_pointer& lhs, unique_pointer& rhs) swap(lhs.deleter, rhs.deleter); } -//! move assignment +// move assignment template inline unique_pointer& unique_pointer::operator =(unique_pointer&& rhs) noexcept @@ -93,7 +93,7 @@ unique_pointer::operator =(unique_pointer&& rhs) noexcept } -//! std::nullptr_t assignment +// std::nullptr_t assignment template inline unique_pointer& unique_pointer::operator =(std::nullptr_t n) noexcept diff --git a/ch16/ex16.32.33.34.35.36/main.cpp b/ch16/ex16.32.33.34.35.36/main.cpp index 95b77083..581543e9 100644 --- a/ch16/ex16.32.33.34.35.36/main.cpp +++ b/ch16/ex16.32.33.34.35.36/main.cpp @@ -5,18 +5,18 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.32: -//! What happens during template argument deduction? +// +// Exercise 16.32: +// What happens during template argument deduction? // The process of determining the template arguments from the function arguments // is known as template argument deduction. During template argument deduction, // the compiler uses types of the arguments in the call to find the template // arguments that generate a version of the function that best matches the given // call. -//! -//! Exercise 16.33: -//! Name two type conversions allowed on function arguments involved in template -//! argument deduction. +// +// Exercise 16.33: +// Name two type conversions allowed on function arguments involved in template +// argument deduction. // • const conversions: A function parameter that is a reference (or pointer) // to a const can be passed a reference (or pointer) to a nonconst object // (§ 4.11.2, p. 162). @@ -26,40 +26,40 @@ // to arguments of array or function type. An array argument will be converted // to a pointer to its first element. Similarly, a function argument will be // converted to a pointer to the function’s type (§ 4.11.2, p. 161). -//! -//! Exercise 16.34: -//! Given only the following code, explain whether each of these calls is legal. -//! If so, what is the type of T? If not, why not? -//! template int compare(const T&, const T&); -//! compare("hi", "world"); +// +// Exercise 16.34: +// Given only the following code, explain whether each of these calls is legal. +// If so, what is the type of T? If not, why not? +// template int compare(const T&, const T&); +// compare("hi", "world"); // It didn't complie, as two types are different, the first type being char[3] ,second char[6] -//! compare("bye", "dad"); +// compare("bye", "dad"); // the type should be pointer to char i.e. char* -//! -//! Exercise 16.35: -//! Which, if any, of the following calls are errors? If the call is legal, what -//! is the type of T? If the call is not legal, what is the problem? -//! template T calc(T, int); -//! template T fcn(T, T); -//! double d; float f; char c; -//! (a) calc(c, 'c'); -- legal,T is a char -//! (b) calc(d, f); -- legal,T is a double -//! (c) fcn(c, 'c'); -- legal,T is a char -//! (d) fcn(d, f); -- illegal, arguments d and f are double and float repectively -//! -//! Exercise 16.36: -//! What happens in the following calls: -//! template f1(T, T); -//! template T calc(T, int); +// template T fcn(T, T); +// double d; float f; char c; +// (a) calc(c, 'c'); -- legal,T is a char +// (b) calc(d, f); -- legal,T is a double +// (c) fcn(c, 'c'); -- legal,T is a char +// (d) fcn(d, f); -- illegal, arguments d and f are double and float repectively +// +// Exercise 16.36: +// What happens in the following calls: +// template f1(T, T); +// template template diff --git a/ch16/ex16.37.38.39/main.cpp b/ch16/ex16.37.38.39/main.cpp index 08b83c3b..e92fea4f 100644 --- a/ch16/ex16.37.38.39/main.cpp +++ b/ch16/ex16.37.38.39/main.cpp @@ -5,30 +5,30 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.37: -//! The library max function has two function parameters and returns the -//! larger of its arguments. This function has one template type parameter. -//! Could you call max passing it an int and a double? If so, how? If not, -//! why not? +// +// Exercise 16.37: +// The library max function has two function parameters and returns the +// larger of its arguments. This function has one template type parameter. +// Could you call max passing it an int and a double? If so, how? If not, +// why not? // If so, it doesn't compile, because the two argument must be the same type or // convertible. // -//! Exercise 16.38: -//! When we call make_shared (§ 12.1.1, p. 451), we have to provide an -//! explicit template argument. Explain why that argument is needed and -//! how it is used. -//! +// Exercise 16.38: +// When we call make_shared (§ 12.1.1, p. 451), we have to provide an +// explicit template argument. Explain why that argument is needed and +// how it is used. +// // without specified type given, make_shared has no possibility to // to determine how big the size it should allocate, which is the reason. // // Depending on the type specified, make_shared allocates proper size of memory // space and returns a proper type of shared_ptr pointing to it. -//! -//! Exercise 16.39: -//! Use an explicit template argument to make it sensible to pass two string -//! literals to the original version of compare from § 16.1.1 (p. 652). -//! +// +// Exercise 16.39: +// Use an explicit template argument to make it sensible to pass two string +// literals to the original version of compare from § 16.1.1 (p. 652). +// #include diff --git a/ch16/ex16.4/main.cpp b/ch16/ex16.4/main.cpp index 774e776e..260b9fd6 100644 --- a/ch16/ex16.4/main.cpp +++ b/ch16/ex16.4/main.cpp @@ -6,13 +6,13 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.4: -//! Write a template that acts like the library find algorithm. The function -//! will need two template type parameters, one to represent the function’s -//! iterator parameters and the other for the type of the value. Use your -//! function to find a given value in a vector and in a list. -//! +// +// Exercise 16.4: +// Write a template that acts like the library find algorithm. The function +// will need two template type parameters, one to represent the function’s +// iterator parameters and the other for the type of the value. Use your +// function to find a given value in a vector and in a list. +// #include #include diff --git a/ch16/ex16.40/main.cpp b/ch16/ex16.40/main.cpp index c3124d9c..448f6c46 100644 --- a/ch16/ex16.40/main.cpp +++ b/ch16/ex16.40/main.cpp @@ -5,16 +5,16 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.40: -//! Is the following function legal? If not, why not? If it is legal, what, -//! if any, are the restrictions on the argument type(s) that can be passed, -//! and what is the return type? -//! legal. -//! As shown below, only type that support this + 0 operation can be passed. -//! the return type depends on the what type the operator + returns. In the case -//! below, the return type is Bar. -//! +// +// Exercise 16.40: +// Is the following function legal? If not, why not? If it is legal, what, +// if any, are the restrictions on the argument type(s) that can be passed, +// and what is the return type? +// legal. +// As shown below, only type that support this + 0 operation can be passed. +// the return type depends on the what type the operator + returns. In the case +// below, the return type is Bar. +// #include diff --git a/ch16/ex16.41/main.cpp b/ch16/ex16.41/main.cpp index 2b6a0732..02000f6e 100644 --- a/ch16/ex16.41/main.cpp +++ b/ch16/ex16.41/main.cpp @@ -5,11 +5,11 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.41: -//! Write a version of sum with a return type that is guaranteed to be large -//! enough to hold the result of the addition. -//! +// +// Exercise 16.41: +// Write a version of sum with a return type that is guaranteed to be large +// enough to hold the result of the addition. +// #include diff --git a/ch16/ex16.42.43.44.45.46/main.cpp b/ch16/ex16.42.43.44.45.46/main.cpp index fd6e07be..6b867f85 100644 --- a/ch16/ex16.42.43.44.45.46/main.cpp +++ b/ch16/ex16.42.43.44.45.46/main.cpp @@ -5,71 +5,71 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.42: -//! Determine the type of T and of val in each of the following calls: -//! template void g(T&& val); -//! int i = 0; const int ci = i; -//! (a) g(i); +// +// Exercise 16.42: +// Determine the type of T and of val in each of the following calls: +// template void g(T&& val); +// int i = 0; const int ci = i; +// (a) g(i); // since i is lvalue, T is deduced as int&, val is int& && collapsing to int& -//! (b) g(ci); +// (b) g(ci); // since ci is lvaue, T is deduced as const int&, val is const int& && collapsing to const int& -//! (c) g(i * ci); +// (c) g(i * ci); // since i * ci is rvalue, T is deduced as int&&, val is int&& && colapsing to int&& -//! -//! Exercise 16.43: -//! Using the function defined in the previous exercise, what would the template -//! parameter of g be if we called g(i = ci)? +// +// Exercise 16.43: +// Using the function defined in the previous exercise, what would the template +// parameter of g be if we called g(i = ci)? // (i = ci) returns lvalue refering to the object i. // Hence T is deduced as int& val is int& && . // any change on val changes the object i. -//! -//! Exercise 16.44: -//! Using the same three calls as in the first exercise, determine the types for T -//! if g’s function parameter is declared as T (not T&&). +// +// Exercise 16.44: +// Using the same three calls as in the first exercise, determine the types for T +// if g’s function parameter is declared as T (not T&&). // ^ // g(i); -- T is deduced as int // g(ci); -- T is deduced as int, const is ignored. // g(i * ci); -- T is deduced as int, (i * ci) returns rvalue which is copied to // T -//! What if g’s function parameter is const T&? +// What if g’s function parameter is const T&? // ^^^^^^^^ // g(i) -- T is deduced as int , val : const int& // g(ci) -- T is deduced as int , val : const int& // g(i * ci) -- T is deduced as int&&, val : const int&& & collapse to const int& -//! -//! Exercise 16.45: -//! Given the following template, explain what happens if we call g on a literal value -//! such as 42. What if we call g on a variable of type int? -//! template void g(T&& val) { vector v; } -//! -//! Discussion on SO: +// +// Exercise 16.45: +// Given the following template, explain what happens if we call g on a literal value +// such as 42. What if we call g on a variable of type int? +// template void g(T&& val) { vector v; } +// +// Discussion on SO: // http://stackoverflow.com/questions/21624016/when-a-lvalue-is-passed-to-t-what-will-happen -//! -//! relevant section from textbook: -//! When we pass an lvalue (e.g., i) to a function parameter that is an rvalue reference to a -//! template type parameter (e.g, T&&), the compiler deduces the template type parameter as the -//! argument’s lvalue reference type. So, when we call f3(i), the compiler deduces the type of -//! T as int&, not int. -//! -- P.688 -//! -//! In this case, when calling on a literal value,say 42. int&& && will collapse to int&&. At last -//! T is deduced as int. Hence std::vector is instantiated as std::vector which is legal. -//! -//! When calling on a variable int. T will be deduced as int&. int & && will collapse to int&. -//! std::vector is not legal. The reason why int& can't be element of a vector can be found at: +// +// relevant section from textbook: +// When we pass an lvalue (e.g., i) to a function parameter that is an rvalue reference to a +// template type parameter (e.g, T&&), the compiler deduces the template type parameter as the +// argument’s lvalue reference type. So, when we call f3(i), the compiler deduces the type of +// T as int&, not int. +// -- P.688 +// +// In this case, when calling on a literal value,say 42. int&& && will collapse to int&&. At last +// T is deduced as int. Hence std::vector is instantiated as std::vector which is legal. +// +// When calling on a variable int. T will be deduced as int&. int & && will collapse to int&. +// std::vector is not legal. The reason why int& can't be element of a vector can be found at: // http://stackoverflow.com/questions/922360/why-cant-i-make-a-vector-of-references -//! -//! Exercise 16.46: -//! Explain this loop from StrVec::reallocate in § 13.5 (p. 530): -//! -//! for (size_t i = 0; i != size(); ++i) -//! alloc.construct(dest++, std::move(*elem++)); -//! -//! In each iteration, the dereference operator * returns a lvalue which is changed to rvalue by -//! std::move ,becasue the member function construct takes rvalue reference rather than lvalue -//! reference. -//! +// +// Exercise 16.46: +// Explain this loop from StrVec::reallocate in § 13.5 (p. 530): +// +// for (size_t i = 0; i != size(); ++i) +// alloc.construct(dest++, std::move(*elem++)); +// +// In each iteration, the dereference operator * returns a lvalue which is changed to rvalue by +// std::move ,becasue the member function construct takes rvalue reference rather than lvalue +// reference. +// diff --git a/ch16/ex16.47/main.cpp b/ch16/ex16.47/main.cpp index 926c87ce..287bc7e9 100644 --- a/ch16/ex16.47/main.cpp +++ b/ch16/ex16.47/main.cpp @@ -5,11 +5,11 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.47: -//! Write your own version of the flip function -//! and test it by calling functions that have lvalue and rvalue reference parameters. -//! +// +// Exercise 16.47: +// Write your own version of the flip function +// and test it by calling functions that have lvalue and rvalue reference parameters. +// #include #include diff --git a/ch16/ex16.48/main.cpp b/ch16/ex16.48/main.cpp index 396a907a..1caa698e 100644 --- a/ch16/ex16.48/main.cpp +++ b/ch16/ex16.48/main.cpp @@ -5,17 +5,17 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.48: -//! Write your own versions of the debug_rep functions. -//! +// +// Exercise 16.48: +// Write your own versions of the debug_rep functions. +// #include #include #include -//! always declare first: +// always declare first: template std::string debug_rep(const T& t); template std::string debug_rep(T* p); @@ -27,7 +27,7 @@ std::string debug_rep(const char *p); -//! print any type we don't otherwise. +// print any type we don't otherwise. template std::string debug_rep(const T& t) { std::ostringstream ret; @@ -35,7 +35,7 @@ template std::string debug_rep(const T& t) return ret.str(); } -//! print pointers as their pointer value, followed by the object to which the pointer points +// print pointers as their pointer value, followed by the object to which the pointer points template std::string debug_rep(T* p) { std::ostringstream ret; @@ -49,13 +49,13 @@ template std::string debug_rep(T* p) return ret.str(); } -//! non-template version +// non-template version std::string debug_rep(const std::string &s) { return '"' + s + '"'; } -//! convert the character pointers to string and call the string version of debug_rep +// convert the character pointers to string and call the string version of debug_rep std::string debug_rep(char *p) { return debug_rep(std::string(p)); diff --git a/ch16/ex16.49.50/main.cpp b/ch16/ex16.49.50/main.cpp index 86f3a466..51ad3ce5 100644 --- a/ch16/ex16.49.50/main.cpp +++ b/ch16/ex16.49.50/main.cpp @@ -5,15 +5,15 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.49: -//! Explain what happens in each of the following calls: -//! -//! Exercise 16.50: -//! Define the functions from the previous exercise so that they print an -//! identifying message. Run the code from that exercise. If the calls behave -//! differently from what you expected, make sure you understand why. -//! +// +// Exercise 16.49: +// Explain what happens in each of the following calls: +// +// Exercise 16.50: +// Define the functions from the previous exercise so that they print an +// identifying message. Run the code from that exercise. If the calls behave +// differently from what you expected, make sure you understand why. +// #include #include diff --git a/ch16/ex16.5/main.cpp b/ch16/ex16.5/main.cpp index 17f01a53..c111f13d 100644 --- a/ch16/ex16.5/main.cpp +++ b/ch16/ex16.5/main.cpp @@ -6,12 +6,12 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.5: -//! Write a template version of the print function from § 6.2.4 (p. 217) that -//! takes a reference to an array and can handle arrays of any size and any -//! element type. -//! +// +// Exercise 16.5: +// Write a template version of the print function from § 6.2.4 (p. 217) that +// takes a reference to an array and can handle arrays of any size and any +// element type. +// #include #include diff --git a/ch16/ex16.51.52/main.cpp b/ch16/ex16.51.52/main.cpp index bc8d790c..f932af99 100644 --- a/ch16/ex16.51.52/main.cpp +++ b/ch16/ex16.51.52/main.cpp @@ -5,13 +5,13 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.51: -//! Determine what sizeof...(Args) and sizeof...(rest) return for each call to foo in this section. -//! -//! Exercise 16.52: -//! Write a program to check your answer to the previous question. -//! +// +// Exercise 16.51: +// Determine what sizeof...(Args) and sizeof...(rest) return for each call to foo in this section. +// +// Exercise 16.52: +// Write a program to check your answer to the previous question. +// #include diff --git a/ch16/ex16.53.54.55/main.cpp b/ch16/ex16.53.54.55/main.cpp index 50378fa6..d2e8c716 100644 --- a/ch16/ex16.53.54.55/main.cpp +++ b/ch16/ex16.53.54.55/main.cpp @@ -6,21 +6,21 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.53: -//! Write your own version of the print functions and test them by printing -//! one, two, and five arguments, each of which should have different types. -//! -//! Exercise 16.54: -//! What happens if we call print on a type that doesn’t have an << operator? +// +// Exercise 16.53: +// Write your own version of the print functions and test them by printing +// one, two, and five arguments, each of which should have different types. +// +// Exercise 16.54: +// What happens if we call print on a type that doesn’t have an << operator? // It didn't compile. -//! -//! Exercise 16.55: -//! Explain how the variadic version of print would execute if we declared -//! the nonvariadic version of print after the definition of the variadic -//! version. +// +// Exercise 16.55: +// Explain how the variadic version of print would execute if we declared +// the nonvariadic version of print after the definition of the variadic +// version. // error: no matching function for call to 'print(std::ostream&)' -//! +// #include diff --git a/ch16/ex16.56.57/main.cpp b/ch16/ex16.56.57/main.cpp index 5a6ec976..49ece42f 100644 --- a/ch16/ex16.56.57/main.cpp +++ b/ch16/ex16.56.57/main.cpp @@ -5,24 +5,24 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.56: -//! Write and test a variadic version of errorMsg. -//! -//! Exercise 16.57: -//! Compare your variadic version of errorMsg to the error_msg function in -//! § 6.2.6 (p. 220). What are the advantages and disadvantages of each -//! approach? +// +// Exercise 16.56: +// Write and test a variadic version of errorMsg. +// +// Exercise 16.57: +// Compare your variadic version of errorMsg to the error_msg function in +// § 6.2.6 (p. 220). What are the advantages and disadvantages of each +// approach? // The error_msg takes initializer_list as the argument. So only the elements // stored in it must be the same or at least convertible. In contrast, the variadic // version provides better flexibility. -//! +// #include #include #include -//! always declare first: +// always declare first: template std::string debug_rep(const T& t); template @@ -32,7 +32,7 @@ std::string debug_rep(const std::string &s); std::string debug_rep(char* p); std::string debug_rep(const char *p); -//! print any type we don't otherwise. +// print any type we don't otherwise. template std::string debug_rep(const T& t) { @@ -41,7 +41,7 @@ std::string debug_rep(const T& t) return ret.str(); } -//! print pointers as their pointer value, followed by the object to which the pointer points +// print pointers as their pointer value, followed by the object to which the pointer points template std::string debug_rep(T* p) { @@ -56,13 +56,13 @@ std::string debug_rep(T* p) return ret.str(); } -//! non-template version +// non-template version std::string debug_rep(const std::string &s) { return '"' + s + '"'; } -//! convert the character pointers to string and call the string version of debug_rep +// convert the character pointers to string and call the string version of debug_rep std::string debug_rep(char *p) { return debug_rep(std::string(p)); @@ -73,9 +73,9 @@ std::string debug_rep(const char *p) return debug_rep(std::string(p)); } -//! function to end the recursion and print the last element -//! this function must be declared before the variadic version of -//! print is defined +// function to end the recursion and print the last element +// this function must be declared before the variadic version of +// print is defined template std::ostream& print(std::ostream& os, const T& t) { @@ -84,7 +84,7 @@ std::ostream& print(std::ostream& os, const T& t) //! note: no seperator after the last element in the pack } -//! this version of print will be called for all but the last element in the pack +// this version of print will be called for all but the last element in the pack template std::ostream& print(std::ostream &os, const T &t, const Args&... rest) { @@ -95,7 +95,7 @@ std::ostream& print(std::ostream &os, const T &t, const Args&... rest) return print(os, rest...); } -//! call debug_rep on each argument in the call to print +// call debug_rep on each argument in the call to print template std::ostream& errorMsg(std::ostream& os, const Args... rest) { diff --git a/ch16/ex16.58.59/strvec.cpp b/ch16/ex16.58.59/strvec.cpp index 5fbeb8f7..3a698044 100644 --- a/ch16/ex16.58.59/strvec.cpp +++ b/ch16/ex16.58.59/strvec.cpp @@ -9,7 +9,7 @@ #include -//! copy constructor +// copy constructor StrVec::StrVec(const StrVec &s) { /** @@ -45,7 +45,7 @@ StrVec::StrVec(std::initializer_list l) } -//! operator = +// operator = StrVec& StrVec::operator =(const StrVec& rhs) { @@ -62,7 +62,7 @@ StrVec::operator =(const StrVec& rhs) return *this; } -//! destructor +// destructor StrVec::~StrVec() { free(); diff --git a/ch16/ex16.58.59/strvec.h b/ch16/ex16.58.59/strvec.h index 9716d1b1..6315175e 100644 --- a/ch16/ex16.58.59/strvec.h +++ b/ch16/ex16.58.59/strvec.h @@ -78,8 +78,8 @@ class StrVec -//! call the constructors of the type to construct this element -//! and push it back. +// call the constructors of the type to construct this element +// and push it back. template inline void StrVec::emplace_back(Args&&... args) diff --git a/ch16/ex16.58.59/vec.h b/ch16/ex16.58.59/vec.h index 90416b07..a419bf0d 100644 --- a/ch16/ex16.58.59/vec.h +++ b/ch16/ex16.58.59/vec.h @@ -61,7 +61,7 @@ class Vec }; -//! copy constructor +// copy constructor template Vec::Vec(const Vec &v) { @@ -76,7 +76,7 @@ Vec::Vec(const Vec &v) } -//! constructor that takes initializer_list +// constructor that takes initializer_list template Vec::Vec(std::initializer_list l) { @@ -94,7 +94,7 @@ Vec::Vec(std::initializer_list l) } -//! operator = +// operator = template Vec& Vec::operator =(const Vec& rhs) { @@ -112,7 +112,7 @@ Vec& Vec::operator =(const Vec& rhs) } -//! destructor +// destructor template Vec::~Vec() { diff --git a/ch16/ex16.6/main.cpp b/ch16/ex16.6/main.cpp index 054c9bc2..86badf49 100644 --- a/ch16/ex16.6/main.cpp +++ b/ch16/ex16.6/main.cpp @@ -5,10 +5,10 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.6: -//! How do you think the library begin and end functions that take an array -//! argument work? +// +// Exercise 16.6: +// How do you think the library begin and end functions that take an array +// argument work? // std::begin is a template function that takes a reference to an array.It // returns this reference as the iterator pointing to the first element in // this array. @@ -17,15 +17,15 @@ // capture the size. It return this reference plus the size as the iterator pointing // to one past last element // -//! Define your own versions of these functions. -//! +// Define your own versions of these functions. +// #include #include #include #include -//! the same as std::begin +// the same as std::begin template T* begin_def(T(&arr)[size]) { @@ -33,7 +33,7 @@ T* begin_def(T(&arr)[size]) } -//! the same as std::end +// the same as std::end template T* end_def(T (&arr)[size]) ^^//We usually don't use a function name which is the same as the function of standard libary diff --git a/ch16/ex16.60.61/main.cpp b/ch16/ex16.60.61/main.cpp index 579df921..d490efdf 100644 --- a/ch16/ex16.60.61/main.cpp +++ b/ch16/ex16.60.61/main.cpp @@ -6,17 +6,17 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.60: -//! Explain how make_shared (§ 12.1.1, p. 451) works. -//! +// +// Exercise 16.60: +// Explain how make_shared (§ 12.1.1, p. 451) works. +// // make_shared shoudl be a variadic template function that forwards all arguments to // underlying constructors that allocate and initializes an object in dynamic memory and // , at last, build a shared_ptr by wrapping the raw pointer. -//! -//! Exercise 16.61: -//! Define your own version of make_shared. -//! +// +// Exercise 16.61: +// Define your own version of make_shared. +// #include #include diff --git a/ch16/ex16.62/Sales_data.h b/ch16/ex16.62/Sales_data.h index f401644e..259446e5 100644 --- a/ch16/ex16.62/Sales_data.h +++ b/ch16/ex16.62/Sales_data.h @@ -33,7 +33,7 @@ -//! unchanged from ch14 except for added friend declaration for hash. +// unchanged from ch14 except for added friend declaration for hash. class Sales_data { friend std::hash; friend std::ostream &operator<< @@ -90,8 +90,8 @@ std::ostream &operator<<(std::ostream&, const Sales_data&); std::istream &operator>>(std::istream&, Sales_data&); -//! specialize std::hash -//! note : template specialization should be put in the header! +// specialize std::hash +// note : template specialization should be put in the header! namespace std { template<> struct hash diff --git a/ch16/ex16.62/main.cpp b/ch16/ex16.62/main.cpp index 67f6f49c..2c72a6ad 100644 --- a/ch16/ex16.62/main.cpp +++ b/ch16/ex16.62/main.cpp @@ -5,13 +5,13 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.62: -//! Define your own version of hash and define an unordered_multiset of Sales_data -//! objects. Put several transactions into the container and print its contents. -//! +// +// Exercise 16.62: +// Define your own version of hash and define an unordered_multiset of Sales_data +// objects. Put several transactions into the container and print its contents. +// // keep all template codes in the header. -//! +// #include #include diff --git a/ch16/ex16.63.64/main.cpp b/ch16/ex16.63.64/main.cpp index c28fab63..25a52627 100644 --- a/ch16/ex16.63.64/main.cpp +++ b/ch16/ex16.63.64/main.cpp @@ -6,23 +6,23 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.63: -//! Define a function template to count the number of occurrences of a given -//! value in a vector. -//! Test your program by passing it a vector of doubles, a vector of ints, -//! and a vector of strings. -//! -//! Exercise 16.64: -//! Write a specialized version of the template from the previous exercise to -//! handle vector and a program that uses this specialization. -//! +// +// Exercise 16.63: +// Define a function template to count the number of occurrences of a given +// value in a vector. +// Test your program by passing it a vector of doubles, a vector of ints, +// and a vector of strings. +// +// Exercise 16.64: +// Write a specialized version of the template from the previous exercise to +// handle vector and a program that uses this specialization. +// #include #include #include -//! template +// template template std::size_t count(std::vector const& vec, T value) { @@ -32,7 +32,7 @@ std::size_t count(std::vector const& vec, T value) return count; } -//! template specialization +// template specialization template<> std::size_t count (std::vector const& vec, const char* value) { diff --git a/ch16/ex16.65.66.67/main.cpp b/ch16/ex16.65.66.67/main.cpp index 2d1515e1..edd8b410 100644 --- a/ch16/ex16.65.66.67/main.cpp +++ b/ch16/ex16.65.66.67/main.cpp @@ -5,37 +5,37 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.65: -//! In § 16.3 (p. 698) we defined overloaded two versions of debug_rep one -//! had a const char* and the other a char* parameter. Rewrite these functions -//! as specializations. -//! -//! Exercise 16.66: -//! What are the advantages and disadvantages of overloading -//! these debug_rep functions as compared to defining specializations? -//! +// +// Exercise 16.65: +// In § 16.3 (p. 698) we defined overloaded two versions of debug_rep one +// had a const char* and the other a char* parameter. Rewrite these functions +// as specializations. +// +// Exercise 16.66: +// What are the advantages and disadvantages of overloading +// these debug_rep functions as compared to defining specializations? +// // Overloading changes the function match. -//! -//! Exercise 16.67: -//! Would defining these specializations affect function matching for debug_rep? -//! If so, how? If not, why not? -//! +// +// Exercise 16.67: +// Would defining these specializations affect function matching for debug_rep? +// If so, how? If not, why not? +// // Won't change. // Specializations instantiate a template; they do not overload it. As a result, // specializations do not affect function matching. -//! +// #include #include #include #include -//! template +// template template std::string debug_rep(T* t); -//! template specialization T=const char* , char* respectively. +// template specialization T=const char* , char* respectively. template<> std::string debug_rep(const char* str); template<> @@ -57,8 +57,8 @@ std::string debug_rep(T* t) return ret.str(); } -//! template specialization -//! T = const char* +// template specialization +// T = const char* template<> std::string debug_rep(const char* str) { @@ -66,8 +66,8 @@ std::string debug_rep(const char* str) return str; } -//! template specialization -//! T = char* +// template specialization +// T = char* template<> std::string debug_rep( char *str) { diff --git a/ch16/ex16.7.8/main.cpp b/ch16/ex16.7.8/main.cpp index eaf74590..784a1096 100644 --- a/ch16/ex16.7.8/main.cpp +++ b/ch16/ex16.7.8/main.cpp @@ -5,18 +5,18 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.7: -//! Write a constexpr template that returns the size of a given array. -//! -//! Exercise 16.8: -//! In the “Key Concept” box on page 108, we noted that as a matter of habit -//! C++ programmers prefer using != to using <. Explain the rationale for -//! this habit. -//! +// +// Exercise 16.7: +// Write a constexpr template that returns the size of a given array. +// +// Exercise 16.8: +// In the “Key Concept” box on page 108, we noted that as a matter of habit +// C++ programmers prefer using != to using <. Explain the rationale for +// this habit. +// // The reason is that more class defines "!=" rather than "<". Doing so can // reduce the number of requirement of the class used with a template class. -//! +// #include #include diff --git a/ch16/ex16.9.10.11/main.cpp b/ch16/ex16.9.10.11/main.cpp index 55bdf243..a57939de 100644 --- a/ch16/ex16.9.10.11/main.cpp +++ b/ch16/ex16.9.10.11/main.cpp @@ -5,27 +5,27 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 16.9: -//! What is a function template? What is a class template? +// +// Exercise 16.9: +// What is a function template? What is a class template? // A function template is a formula from which we can generate type-specific // versions of that function. -//! +// // A class template is a blueprint for generating classes. Class templates // differ from function templates in that the compiler cannot deduce the // template parameter type(s) for a class template. Instead, as we’ve seen // many times, to use a class template we must supply additional information // inside angle brackets following the template’s name (§ 3.3, p. 97). -//! -//! Exercise 16.10: -//! What happens when a class template is instantiated? +// +// Exercise 16.10: +// What happens when a class template is instantiated? // The compiler uses these template arguments to instantiate a specific // class from the template. -//! -//! Exercise 16.11: -//! The following definition of List is incorrect. How would you fix it? +// +// Exercise 16.11: +// The following definition of List is incorrect. How would you fix it? // as commented below. -//! +// template class ListItem; template class List diff --git a/ch17/ex17.3/main.cpp b/ch17/ex17.3/main.cpp index 71f2f82b..da3cfbe2 100644 --- a/ch17/ex17.3/main.cpp +++ b/ch17/ex17.3/main.cpp @@ -5,14 +5,14 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 17.3: -//! Rewrite the TextQuery programs from § 12.3 (p. 484) to use a tuple instead -//! of the QueryResult class. Explain which design you think is better and why. -//! +// +// Exercise 17.3: +// Rewrite the TextQuery programs from § 12.3 (p. 484) to use a tuple instead +// of the QueryResult class. Explain which design you think is better and why. +// // The orignal way is more formal.The second way is quick to implement ,but hard to // refactor.So the second way is better for testing. -//! +// #include #include "textquery.h" diff --git a/ch17/ex17.3/textquery.cpp b/ch17/ex17.3/textquery.cpp index 2cb005d2..92779b72 100644 --- a/ch17/ex17.3/textquery.cpp +++ b/ch17/ex17.3/textquery.cpp @@ -11,7 +11,7 @@ #include #include -//! Constructor +// Constructor TextQuery::TextQuery(std::ifstream & is) : file(new std::vector) { //! each line diff --git a/ch17/ex17_10.cpp b/ch17/ex17_10.cpp index 30c8853e..7e5cca37 100644 --- a/ch17/ex17_10.cpp +++ b/ch17/ex17_10.cpp @@ -5,13 +5,13 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 17.10: -//! Using the sequence 1, 2, 3, 5, 8, 13, 21, initialize a bitset that has a -//! 1 bit in each position corresponding to a number in this sequence. Default -//! initialize another bitset and write a small program to turn on each of the -//! appropriate bits. -//! +// +// Exercise 17.10: +// Using the sequence 1, 2, 3, 5, 8, 13, 21, initialize a bitset that has a +// 1 bit in each position corresponding to a number in this sequence. Default +// initialize another bitset and write a small program to turn on each of the +// appropriate bits. +// diff --git a/ch17/ex17_11_12_13.cpp b/ch17/ex17_11_12_13.cpp index 4e09cfad..403cc72f 100644 --- a/ch17/ex17_11_12_13.cpp +++ b/ch17/ex17_11_12_13.cpp @@ -5,22 +5,22 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 17.11: -//! Define a data structure that contains an integral object to track responses -//! to a true/false quiz containing 10 questions. What changes, if any, would -//! you need to make in your data structure if the quiz had 100 questions? -//! -//! Exercise 17.12: -//! Using the data structure from the previous question, write a function that -//! takes a question number and a value to indicate a true/false answer and -//! updates the quiz results accordingly. -//! -//! Exercise 17.13: -//! Write an integral object that contains the correct answers for the -//! true/false quiz. Use it to generate grades on the quiz for the data -//! structure from the previous two exercises. -//! +// +// Exercise 17.11: +// Define a data structure that contains an integral object to track responses +// to a true/false quiz containing 10 questions. What changes, if any, would +// you need to make in your data structure if the quiz had 100 questions? +// +// Exercise 17.12: +// Using the data structure from the previous question, write a function that +// takes a question number and a value to indicate a true/false answer and +// updates the quiz results accordingly. +// +// Exercise 17.13: +// Write an integral object that contains the correct answers for the +// true/false quiz. Use it to generate grades on the quiz for the data +// structure from the previous two exercises. +// #ifndef QUIZ #define QUIZ diff --git a/ch17/ex17_14_15_16.cpp b/ch17/ex17_14_15_16.cpp index ebc80d94..9b37efe6 100644 --- a/ch17/ex17_14_15_16.cpp +++ b/ch17/ex17_14_15_16.cpp @@ -7,21 +7,21 @@ * to handle regular expression.To compile this program, please * turn to other compilers such as msvs2013 and clang. ***************************************************************************/ -//! -//! Exercise 17.14 -//! Write several regular expressions designed to trigger various errors. -//! Run your program to see what output your compiler generates for each error. +// +// Exercise 17.14 +// Write several regular expressions designed to trigger various errors. +// Run your program to see what output your compiler generates for each error. -//! Exercise 17.15 -//! Write a program using the pattern that finds word that violate the -//! "i before e except after c" rule. Have your program prompt the user to -//! supply a word and indicate whether the word is okay or not. Test your -//! program with words that do and do not violate the rule. +// Exercise 17.15 +// Write a program using the pattern that finds word that violate the +// "i before e except after c" rule. Have your program prompt the user to +// supply a word and indicate whether the word is okay or not. Test your +// program with words that do and do not violate the rule. -//! Exercise 17.16 -//! What would happen if your regex object in the previous program were -//! initialized with "[^c]ei"? Test your program using that pattern to see -//! whether your expectations were correct. +// Exercise 17.16 +// What would happen if your regex object in the previous program were +// initialized with "[^c]ei"? Test your program using that pattern to see +// whether your expectations were correct. #include diff --git a/ch17/ex17_17_18.cpp b/ch17/ex17_17_18.cpp index a7514521..d91fb272 100644 --- a/ch17/ex17_17_18.cpp +++ b/ch17/ex17_17_18.cpp @@ -7,15 +7,15 @@ * to handle regular expression.To compile this program, please * turn to other compilers such as msvs2013 and clang. ***************************************************************************/ -//! -//! Exercise 17.17 -//! Update your program so that it finds all the words in an input sequence -//! that violiate the "ei" grammar rule. +// +// Exercise 17.17 +// Update your program so that it finds all the words in an input sequence +// that violiate the "ei" grammar rule. -//! -//! Exercise 17.18 -//! Revise your program to ignore words that contain "ei" but are not -//! misspellings, such as "albeit" and "neighbor." +// +// Exercise 17.18 +// Revise your program to ignore words that contain "ei" but are not +// misspellings, such as "albeit" and "neighbor." #include using std::cout; diff --git a/ch17/ex17_19_20.cpp b/ch17/ex17_19_20.cpp index df9a8424..c4011d11 100644 --- a/ch17/ex17_19_20.cpp +++ b/ch17/ex17_19_20.cpp @@ -7,18 +7,18 @@ * to handle regular expression.To compile this program, please * turn to other compilers such as msvs2013 and clang. ***************************************************************************/ -//! -//! Exercise 17.19 -//! Why is it okay to call m[4].str() without first checking whether m[4] -//! was matched? -//! We expect that the two delimiters in m[4] and m[6] are the same. -//! If m[4](or m[6]) is mismatched, m[4].str()(or m[6].str() respectively) -//! returns an empty string which can also be compared with the other -//! delimiter. +// +// Exercise 17.19 +// Why is it okay to call m[4].str() without first checking whether m[4] +// was matched? +// We expect that the two delimiters in m[4] and m[6] are the same. +// If m[4](or m[6]) is mismatched, m[4].str()(or m[6].str() respectively) +// returns an empty string which can also be compared with the other +// delimiter. -//! -//! Exercise 17.20 -//! Write your own version of the program to validate phone numbers. +// +// Exercise 17.20 +// Write your own version of the program to validate phone numbers. #include using std::cout; diff --git a/ch17/ex17_1_2.cpp b/ch17/ex17_1_2.cpp index 7115d90f..f7bf9737 100644 --- a/ch17/ex17_1_2.cpp +++ b/ch17/ex17_1_2.cpp @@ -6,13 +6,13 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 17.1: -//! Define a tuple that holds three int values and initialize the members to 10, 20, and 30. -//! -//! Exercise 17.2: -//! Define a tuple that holds a string, a vector, and a pair. -//! +// +// Exercise 17.1: +// Define a tuple that holds three int values and initialize the members to 10, 20, and 30. +// +// Exercise 17.2: +// Define a tuple that holds a string, a vector, and a pair. +// #include #include diff --git a/ch17/ex17_21.cpp b/ch17/ex17_21.cpp index c533c18c..49c5fa8d 100644 --- a/ch17/ex17_21.cpp +++ b/ch17/ex17_21.cpp @@ -5,10 +5,10 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 17.21 -//! Rewrite your phone number program from 8.3.2 (p. 323) to use the -//! valid function defined in this section. +// +// Exercise 17.21 +// Rewrite your phone number program from 8.3.2 (p. 323) to use the +// valid function defined in this section. #include using std::cerr; @@ -47,7 +47,7 @@ bool valid(const smatch& m); bool read_record(istream& is, vector& people); void format_record(ostream& os, const vector& people); -//! fake function that makes the program compile +// fake function that makes the program compile string format(const string &num) { return num; } int main() diff --git a/ch17/ex17_23.cpp b/ch17/ex17_23.cpp index e15f07e9..24e21c2b 100644 --- a/ch17/ex17_23.cpp +++ b/ch17/ex17_23.cpp @@ -5,10 +5,10 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 17.21 -//! Rewrite your phone number program from 8.3.2 (p. 323) to use the -//! valid function defined in this section. +// +// Exercise 17.21 +// Rewrite your phone number program from 8.3.2 (p. 323) to use the +// valid function defined in this section. #include using std::cerr; diff --git a/ch17/ex17_28_29_30.cpp b/ch17/ex17_28_29_30.cpp index 504a791e..160c08f3 100644 --- a/ch17/ex17_28_29_30.cpp +++ b/ch17/ex17_28_29_30.cpp @@ -5,28 +5,28 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 17.28: -//! Write a function that generates and returns a uniformly distributed random -//! unsigned int each time it is called. -//! -//! Exercise 17.29: -//! Allow the user to supply a seed as an optional argument to the function you -//! wrote in the previous exercise. -//! -//! Exercise 17.30: -//! Revise your function again this time to take a minimum and maximum value for -//! the numbers that the function should return. -//! +// +// Exercise 17.28: +// Write a function that generates and returns a uniformly distributed random +// unsigned int each time it is called. +// +// Exercise 17.29: +// Allow the user to supply a seed as an optional argument to the function you +// wrote in the previous exercise. +// +// Exercise 17.30: +// Revise your function again this time to take a minimum and maximum value for +// the numbers that the function should return. +// #include #include -//! default version +// default version unsigned random_gen(); -//! with seed spicified +// with seed spicified unsigned random_gen(unsigned seed); -//! with seed and range spicified +// with seed and range spicified unsigned random_gen(unsigned seed, unsigned min, unsigned max); int main() { diff --git a/ch17/ex17_4_5_6_7_8.cpp b/ch17/ex17_4_5_6_7_8.cpp index 8ba77e4e..40b202a2 100644 --- a/ch17/ex17_4_5_6_7_8.cpp +++ b/ch17/ex17_4_5_6_7_8.cpp @@ -5,27 +5,27 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 17.4: -//! Write and test your own version of the findBook function. -//! -//! Exercise 17.5: -//! Rewrite findBook to return a pair that holds an index and a pair of iterators. -//! -//! Exercise 17.6: -//! Rewrite findBook so that it does not use tuple or pair. -//! -//! Exercise 17.7: -//! Explain which version of findBook you prefer and why. -//! +// +// Exercise 17.4: +// Write and test your own version of the findBook function. +// +// Exercise 17.5: +// Rewrite findBook to return a pair that holds an index and a pair of iterators. +// +// Exercise 17.6: +// Rewrite findBook so that it does not use tuple or pair. +// +// Exercise 17.7: +// Explain which version of findBook you prefer and why. +// // The version using tuple is prefered.It's more flexible, campared to other versions. -//! -//! Exercise 17.8: -//! What would happen if we passed Sales_data() as the third parameter to accumulate -//! in the last code example in this section? -//! +// +// Exercise 17.8: +// What would happen if we passed Sales_data() as the third parameter to accumulate +// in the last code example in this section? +// // If so, the output should be 0, as the Sales_data is default constructed. -//! +// @@ -39,23 +39,23 @@ #include "ex17_4_5_6_7_8_SalesData.h" -//! for ex17.4 -//! maches has 3 members: -//! an index of a store and iterators into that store's vector +// for ex17.4 +// maches has 3 members: +// an index of a store and iterators into that store's vector typedef std::tuple::size_type, std::vector::const_iterator, std::vector::const_iterator> matches; -//! for ex17.5 -//! return a pair that holds an index and a pair of iterators. +// for ex17.5 +// return a pair that holds an index and a pair of iterators. typedef std::pair::size_type, std::pair::const_iterator, std::vector::const_iterator>> matches_pair; -//! for ex17.6 -//! return a struct that holds an index of a store and iterators into that store's vector +// for ex17.6 +// return a struct that holds an index of a store and iterators into that store's vector struct matches_struct { std::vector::size_type st; @@ -66,24 +66,24 @@ struct matches_struct std::vector::const_iterator l) : st(s), first(f), last(l) {} } ; -//! for ex17.4 -//! return a vector with an entry for each store that sold the given book. +// for ex17.4 +// return a vector with an entry for each store that sold the given book. std::vector findBook(const std::vector>& files, const std::string& book); -//! print the result using the given iostream +// print the result using the given iostream void reportResults(std::istream& in, std::ostream os, const std::vector>& files); -//! for ex17.5 -//! return a vector with an entry for each store that sold the given book. +// for ex17.5 +// return a vector with an entry for each store that sold the given book. std::vector findBook_pair(const std::vector > &files, const std::string &book); -//! for ex17.6 -//! return a vector with an entry for each store that sold the given book. +// for ex17.6 +// return a vector with an entry for each store that sold the given book. std::vector findBook_struct(const std::vector > &files, const std::string &book); @@ -93,8 +93,8 @@ int main() return 0; } -//! for ex17.4 -//! return a vector with an entry for each store that sold the given book. +// for ex17.4 +// return a vector with an entry for each store that sold the given book. std::vector findBook(const std::vector>& files, const std::string& book) @@ -113,8 +113,8 @@ findBook(const std::vector>& files, return ret; } -//! for ex17.4 -//! print the result using the given iostream +// for ex17.4 +// print the result using the given iostream void reportResults(std::istream& in, std::ostream os, const std::vector>& files) { @@ -135,8 +135,8 @@ void reportResults(std::istream& in, std::ostream os, } } -//! for ex17.5 -//! return a vector with an entry for each store that sold the given book +// for ex17.5 +// return a vector with an entry for each store that sold the given book std::vector findBook_pair(const std::vector > &files, const std::string &book) @@ -152,8 +152,8 @@ findBook_pair(const std::vector > &files, return ret; } -//! for ex17.6 -//! return a vector with an entry for each store that sold the given book. +// for ex17.6 +// return a vector with an entry for each store that sold the given book. std::vector findBook_struct(const std::vector > &files, const std::string &book) diff --git a/ch17/ex17_4_5_6_7_8_SalesData.cpp b/ch17/ex17_4_5_6_7_8_SalesData.cpp index f175fbf4..5b409480 100644 --- a/ch17/ex17_4_5_6_7_8_SalesData.cpp +++ b/ch17/ex17_4_5_6_7_8_SalesData.cpp @@ -53,7 +53,7 @@ Sales_data::combine(const Sales_data &rhs) revenue += rhs.revenue; // the members of ``this'' object return *this; // return the object on which the function was called } -//! = Sales_data +// = Sales_data Sales_data &Sales_data::operator =(const Sales_data &rhs) { this->bookNo = rhs.bookNo; @@ -63,14 +63,14 @@ Sales_data &Sales_data::operator =(const Sales_data &rhs) return *this; } -//! =string +// =string Sales_data &Sales_data::operator =(const std::string &rhs) { *this= Sales_data(rhs); return *this; } -//! += +// += Sales_data &Sales_data::operator +=(const Sales_data &rhs) { this->revenue += rhs.revenue; @@ -105,7 +105,7 @@ print(ostream &os, const Sales_data &item) return os; } -//! added 10.Jan 2014 +// added 10.Jan 2014 std::ostream & operator <<(std::ostream &os, const Sales_data &item) { @@ -115,7 +115,7 @@ operator <<(std::ostream &os, const Sales_data &item) return os; } -//! added 12.Jan 2014 +// added 12.Jan 2014 std::istream& operator >>(std::istream &is, Sales_data &s) { diff --git a/ch17/ex17_4_5_6_7_8_SalesData.h b/ch17/ex17_4_5_6_7_8_SalesData.h index d31f9f57..0555c67e 100644 --- a/ch17/ex17_4_5_6_7_8_SalesData.h +++ b/ch17/ex17_4_5_6_7_8_SalesData.h @@ -25,11 +25,11 @@ * Fax: (201) 236-3290 */ -//! -//! Exercise 14.45: -//! Write conversion operators to convert a Sales_data to string and to double. -//! What values do you think these operators should return? -//! +// +// Exercise 14.45: +// Write conversion operators to convert a Sales_data to string and to double. +// What values do you think these operators should return? +// #ifndef SALES_DATA_H #define SALES_DATA_H @@ -89,7 +89,7 @@ class Sales_data }; -//! overloaded operators added 10.Jan.2014 for ex14.2 +// overloaded operators added 10.Jan.2014 for ex14.2 inline Sales_data operator+(const Sales_data& lhs, const Sales_data& rhs) { diff --git a/ch17/ex17_9.cpp b/ch17/ex17_9.cpp index 9aa662f6..a2c895b0 100644 --- a/ch17/ex17_9.cpp +++ b/ch17/ex17_9.cpp @@ -5,17 +5,17 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 17.9: Explain the bit pattern each of the following bitset objects contains: -//! (a) bitset<64> bitvec(32); +// +// Exercise 17.9: Explain the bit pattern each of the following bitset objects contains: +// (a) bitset<64> bitvec(32); // 0000000000000000000000000000000000000000000000000000000000100000 -// //! ^ -//! (b) bitset<32> bv(1010101); +// // ^ +// (b) bitset<32> bv(1010101); // 00000000000011110110100110110101 -// //! note that the argument here is decemal -//! (c) string bstr; cin >> bstr; bitset<8>bv(bstr); +// // note that the argument here is decemal +// (c) string bstr; cin >> bstr; bitset<8>bv(bstr); // depends on what has been input. -//! +// diff --git a/ch18/ex18.1.2.3.cpp b/ch18/ex18.1.2.3.cpp index 8c8caf4f..01d51459 100644 --- a/ch18/ex18.1.2.3.cpp +++ b/ch18/ex18.1.2.3.cpp @@ -5,20 +5,20 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 18.1: -//! What is the type of the exception object in the following throws? -//! (a) range_error r("error"); -//! throw r; -//! (b) exception *p = &r; -//! throw *p; +// +// Exercise 18.1: +// What is the type of the exception object in the following throws? +// (a) range_error r("error"); +// throw r; +// (b) exception *p = &r; +// throw *p; // the static, compile-time type of that expression determines the type of // the exception object. // so the object thrown the second time is std::exception type not std::range_error. -//! What would happen if the throw in (b) were written as throw p? +// What would happen if the throw in (b) were written as throw p? // terminate called after throwing an instance of 'std::exception*' -//! -//! Exercise 18.2: Explain what happens if an exception occurs at the indicated point: +// +// Exercise 18.2: Explain what happens if an exception occurs at the indicated point: /* void exercise(int *b, int *e) { @@ -28,11 +28,11 @@ void exercise(int *b, int *e) // exception occurs here } */ -//! Exercise 18.3: -//! There are two ways to make the previous code work correctly -//! if an exception is thrown. Describe them and implement them. +// Exercise 18.3: +// There are two ways to make the previous code work correctly +// if an exception is thrown. Describe them and implement them. // The first approach is to mange it using a class. The second one is using smart pointer. -//! +// #include #include diff --git a/ch18/ex18.12.13.14.cpp b/ch18/ex18.12.13.14.cpp index 15a9f520..376c322f 100644 --- a/ch18/ex18.12.13.14.cpp +++ b/ch18/ex18.12.13.14.cpp @@ -6,26 +6,26 @@ * @note ***************************************************************************/ //! -//! Exercise 18.12 -//! Organize the programs you have written to answer the questions in each -//! chapter into their own namespaces. That is, namespace chapter15 would -//! contain code for the Query programs and chapter10 would contain the -//! TextQuery code. Using this structure, compile the Query code examples. +// Exercise 18.12 +// Organize the programs you have written to answer the questions in each +// chapter into their own namespaces. That is, namespace chapter15 would +// contain code for the Query programs and chapter10 would contain the +// TextQuery code. Using this structure, compile the Query code examples. -//! Exercise 18.13 -//! When might you see use an unnamed namespace? -//! http://stackoverflow.com/questions/154469/unnamed-anonymous-namespaces-vs-static-functions -//! http://stackoverflow.com/questions/5312213/uses-of-unnamed-namespace-in-c +// Exercise 18.13 +// When might you see use an unnamed namespace? +// http://stackoverflow.com/questions/154469/unnamed-anonymous-namespaces-vs-static-functions +// http://stackoverflow.com/questions/5312213/uses-of-unnamed-namespace-in-c -//! Exercise 18.14 -//! Suppose we have the following declaration of the operator* that is a -//! a member of the nested namespace mathLib::MatrixLib. -//! How would you declare this operator in global scope? +// Exercise 18.14 +// Suppose we have the following declaration of the operator* that is a +// a member of the nested namespace mathLib::MatrixLib. +// How would you declare this operator in global scope? // mathLib::MatrixLib::matrix mathLib::MatrixLib::operator* // (const mathLib::MatrixLib::matrix&, const mathLib::MatrixLib::matrix&); -//! or :(provided by @lafener in #173) +// or :(provided by @lafener in #173) //mathLib::MatrixLib::matrix mathLib::MatrixLib::operator* (const matrix&, const matrix&); diff --git a/ch18/ex18.15.16.17.cpp b/ch18/ex18.15.16.17.cpp index dcf8fb7b..eee7336d 100644 --- a/ch18/ex18.15.16.17.cpp +++ b/ch18/ex18.15.16.17.cpp @@ -5,34 +5,34 @@ * @remark This code is for the exercises from C++ Primer 5th Edition * @note ***************************************************************************/ -//! -//! Exercise 18.15 -//! Explain the differences between using declarations and directives. -//! This difference in scope between a using declaration and a using directive -//! stems directly from how these two facilities work. In the case of a using -//! declaration, we are simply making name directly accessible in the local -//! scope. In contrast, a using directive makes the entire contents of a -//! namespace available In general, a namespace might include definitions that -//! cannot appear in a local scope. As a consequence, a using directive is -//! treated as if it appeared in the nearest enclosing namespace scope. - -//! Exercise 18.16 -//! Explain the following code assuming using declarations for all the -//! members of namespace Exercise are located at the location labeled -//! position 1. What if they appear at position 2 instead? Now answer the -//! same question but replace the using declarations with a using directive -//! for namespace Exercise. - -//! Exercise 18.17 -//! Write code to test your answers to the previous question. +// +// Exercise 18.15 +// Explain the differences between using declarations and directives. +// This difference in scope between a using declaration and a using directive +// stems directly from how these two facilities work. In the case of a using +// declaration, we are simply making name directly accessible in the local +// scope. In contrast, a using directive makes the entire contents of a +// namespace available In general, a namespace might include definitions that +// cannot appear in a local scope. As a consequence, a using directive is +// treated as if it appeared in the nearest enclosing namespace scope. + +// Exercise 18.16 +// Explain the following code assuming using declarations for all the +// members of namespace Exercise are located at the location labeled +// position 1. What if they appear at position 2 instead? Now answer the +// same question but replace the using declarations with a using directive +// for namespace Exercise. + +// Exercise 18.17 +// Write code to test your answers to the previous question. #include using std::cout; using std::endl; -//! using declarations for all the members of namespace Exercise -//! are located at the location labeled position 1. +// using declarations for all the members of namespace Exercise +// are located at the location labeled position 1. namespace Test0 { namespace Exercise @@ -76,8 +76,8 @@ namespace Test0 } -//! using declarations for all the members of namespace Exercise -//! are located at the location labeled position 2. +// using declarations for all the members of namespace Exercise +// are located at the location labeled position 2. namespace Test1 { namespace Exercise @@ -120,8 +120,8 @@ namespace Test1 } } -//! using directive for namespace Exercise is located at the -//! location labeled position 1. +// using directive for namespace Exercise is located at the +// location labeled position 1. namespace Test2 { namespace Exercise @@ -162,8 +162,8 @@ namespace Test2 } } -//! using directive for namespace Exercise is located at the -//! location labeled position 2. +// using directive for namespace Exercise is located at the +// location labeled position 2. namespace Test3 { namespace Exercise