hatcat / cg30_issues

The public issues repository for the book "Beautiful C++"
4 stars 1 forks source link

Page 241 has wrong definition and usage of `sort_concept` #37

Open Ukilele opened 2 years ago

Ukilele commented 2 years ago

On page 241 is following concept defined:

template <typename R, typename T , typename U>
concept sort_concept = std::equality_comparable<T, U>
and std::copy_constructible<T>
and std::incrementable<T>
and std::indirectly_readable<T>
and std::swappable<T>
and std::strict_weak_order<R, T, U>;

(Side note: The space in T , appears also in the book.)

Afterwards, following function is defined:

void sort(sort_concept auto begin, sort_concept auto end);
  1. Regarding sort_concept:
    • std::equality_comparable only has one template parameter. Did you intent to use std::equality_comparable_with<T, U> or maybe sentinel_for<T, U>?
    • Shouldn't you use std::indirect_strict_weak_order<R, T, U> instead of std::strict_weak_order<R, T, U>?
    • Why is it templated of both T and U? Wasn't there only one InIt on page 240 that we write this concept for?
  2. The use of sort_concept auto in the definition of void sort(...) wont compile. The concept takes three arguments, but we only (implicitly) provide one argument.

Label: 4.6: T.10