An unsigned integer represents nonnegative values, but it does not make negative input safe. In the triangle example, unsigned arithmetic provides a larger range, yet wraps to 0 after 4,294,967,295, making overflow harder to notice. Assigning -2 to an unsigned value compiles and produces a large positive number, removing the simple nonnegative check available with signed integers. section 2.3.4
Generating rows of a number triangle
A triangle generator works through 34 rows with signed int values, but the next row doubles 1,166,803,110 and exceeds the signed range. Signed overflow is undefined; unsigned arithmetic wraps instead. The practical lesson is to test the known safe limit rather than switching to unsigned merely to avoid negative values. section 2.3.4
Listing 2.14 Making sure there are no negative numbers by using a view
auto negative = [](int x) { return x < 0; }; #1
auto negatives = row | std::views::filter(negative); #2
assert(negatives.empty()); #3
Inspect a view-based check for negative values before choosing an integer representation; it demonstrates filtering and asserting that a row contains no negatives. section 2.3.4








