Skip to content

Commit 56a2a69

Browse files
committed
Minor changes
1 parent cb4c946 commit 56a2a69

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

10-templates-exceptions-lambdas-smart-pointers.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ public:
123123
}
124124
};
125125
126-
auto o1 = Opt{ 1.2 };
127-
auto o2 = Opt{ 3 };
128-
auto o3 = Opt{};
129-
auto o4 = Opt<size_t>{};
126+
auto o1 = Opt{ 1.2 }; // T = double, valid = true
127+
auto o2 = Opt{ 3 }; // T = int, valid = true
128+
auto o3 = Opt{}; // T = char, valid = false
129+
auto o4 = Opt<size_t>{}; // T = size_t, valid = false
130130
```
131131

132132
Some things to note about this program:
@@ -139,7 +139,7 @@ Some things to note about this program:
139139

140140
* Calling member function `hasValue()` is always safe, yielding a `bool`. Calling `get()` on an `Opt` with no value immediately terminates the program (the keyword `throw` is explained later in this Chapter).
141141

142-
Of course, this simple class is of limited practical use, if you need a type to be considered optionally valid without using a "special" value to indicate this, then make use of `std::optional<T>` from the Standard Library.
142+
Of course, this simple class is of limited practical use; if you need a type to be considered optionally valid without using a "special" value to indicate this, then making use of `std::optional<T>` from the Standard Library is recommended.
143143

144144
Member functions can be template functions, too. The following program defines a `Stringy` class with a `std::string` member, which can be initialized from another `std::string`, a `std::string_view` or a `const char *`:
145145

@@ -854,7 +854,7 @@ int main() {
854854
cout << "Name not recognized!\n";
855855
}
856856
}
857-
}
857+
}
858858
```
859859

860860
This is one of the larger programs we have seen, and covers much of the contents of this Chapter:
@@ -885,4 +885,4 @@ This is one of the larger programs we have seen, and covers much of the contents
885885

886886
* Change `Pupil` and `Class` to be `class`es instead of `struct`s, with `private:` data members. Hint: you will need to write some `public:` getters.
887887

888-
*All text and program code &copy;2019-2022 Richard Spencer, all rights reserved.*
888+
*All text and program code &copy;2019-2024 Richard Spencer, all rights reserved.*

0 commit comments

Comments
 (0)