Fix `With{Equal,Compare}` in C++17 for corner cases:

1. Heterogeneous secondary comparisons (`!=`, `<`, `>`, `<=`, and `>=`)
   are not defined if the other type is also implemented using `WithEqual`
   or `WithCompare`.

2. Heterogeneous primary comparisons with swapped parameters (`==` and
   `RIEGELI_COMPARE`) are added only for types explicitly specified by
   additional template parameters of `WithEqual` and `WithCompare`.

This avoids ambiguous overloads and cyclic template instantiations:

1. If both parameter types consider swapping the parameters, but the types are
   not comparable, then each definition is rewritten from the other one, and
   their SFINAE constraints depend on each other.

   This does not happen only if the code tries to compare incomparable values.
   Due to how ADL works, a call to an unqualified function name with an argument
   of type `A<T>` brings not only functions related to `A`, but also functions
   related to `T`. The argument of type `A<T>` will not match the parameter
   of type `T`, but the function template is instantiated earlier, trying to
   compare `T` against `A<T>`.

2. Automatic parameter swapping could only generate a constrained template
   rather than overloads with concrete parameter types.

   That converts parameters in the callee rather than in the caller, which leads
   to different overload resolution.

   That would create ambiguities in cases like `CompactString == Chain`.
   The parameters are not swapped because both types use `WithEqual`.
   Intended `Chain == absl::string_view` is not found because it requires
   parameter swapping after all, since the converted parameter does not use
   `WithEqual`.

PiperOrigin-RevId: 900626664
14 files changed
tree: 8788a0a8289fc682b17b878704afaa1b3f3a7190
  1. doc/
  2. python/
  3. riegeli/
  4. tf_dependency/
  5. .bazelrc
  6. configure
  7. CONTRIBUTING.md
  8. LICENSE
  9. MANIFEST.in
  10. MODULE.bazel
  11. README.md
README.md

Riegeli

Riegeli/records is a file format for storing a sequence of string records, typically serialized protocol buffers. It supports dense compression, fast decoding, seeking, detection and optional skipping of data corruption, filtering of proto message fields for even faster decoding, and parallel encoding.

See documentation.

Status

Riegeli file format will only change in a backward compatible way (i.e. future readers will understand current files, but current readers might not understand files using future features).

Riegeli C++ API might change in incompatible ways.