Exploring C++ 11: Problems and Solutions Handbook

Exploring C++ 20 is now available.

Almost all the code listings for Exploring C++ 11 are here, grouped by chapters. Some of the listings have been fleshed out from what appears in the book. For example, most "omitted for brevity" and similar statements are replaced by the relevant code.

The code has been compiled and checked with clang 3.3 and g++ 4.8.

Download all the files in a single ZIP.

Microsoft Visual Studio 2013 lacks several key features, such as constexpr, noexcept, inheriting constructors, and defaulted move functions, all features that are used heavily in these examples. Although one can work around some of these limitations, that work is left as an exercise for the reader. Working around the lack of constexpr is a big job because it means rewriting functions as template metafunctions.

Perhaps the next release of Visual Studio will support the entire C++ 11 standard.

Some projects require sample text files, especially when exploring international locales. See the data directory for files. The file name indicates the character set. Samples were excerpted from Wikipedia. See data/sample-utf8.txt for links to the source for each excerpt.

  1. Honing Your Tools
  2. Reading C++ Code
  3. Integer Expressions
  4. Strings
  5. Simple Input
  6. Error Messages
  7. For Loops
  8. Formatted Output
  9. Arrays and Vectors
  10. Algorithms and Iterators
  11. Increment and Decrement
  12. Conditions and Logic
  13. Compound Statements
  14. Introduction to File I/O
  15. The Map Data Structure
  16. Type Synonyms
  17. Characters
  18. Character Categories
  19. Case-Folding
  20. Writing Functions
  21. Function Arguments
  22. Using Algorithms
  23. Unnamed Functions
  24. Overloading Function Names
  25. Big and Little Numbers
  26. Very Big and Very Little Numbers
  27. Documentation
  28. Project 1: Body-Mass Index
  29. Custom Types
  30. Overloading Operators
  31. Custom I/O Operators
  32. Assignment and Initialization
  33. Writing Classes
  34. More About Member Functions
  35. Access Levels
  36. Introduction to Object-Oriented Programming
  37. Inheritance
  38. Virtual Functions
  39. Classes and Types
  40. Declarations and Definitions
  41. Using Multiple Source Files
  42. Function Objects
  43. Useful Algorithms
  44. Iterators
  45. Exceptions
  46. More Operators
  47. Project 2: Fixed-Point Numbers
  48. Function Templates
  49. Class Templates
  50. Template Specialization
  51. Partial Specialization
  52. Names and Namespaces
  53. Containers
  54. Locales and Facets
  55. International Characters
  56. Text I/O
  57. Project 3: Currency Type
  58. Pointers
  59. Dynamic Memory
  60. Moving With Rvalue References
  61. Exception-Safety
  62. Old-Fashioned Arrays
  63. Smart Pointers
  64. Working with Bits
  65. Enumerations
  66. Multiple Inheritance
  67. Traits and Policies
  68. Names and Templates
  69. Overloaded Functions
  70. Metaprogramming
  71. Project 4: Calculator