tcbrindle / flux

A C++20 library for sequence-orientated programming
https://tristanbrindle.com/flux/
Boost Software License 1.0
476 stars 29 forks source link

Add default_sequence_traits #207

Closed tcbrindle closed 3 weeks ago

tcbrindle commented 3 weeks ago

The sequence concept has several optional customisation points, for example read_at_unchecked() and for_each_while(), for which we can provide a reasonable default if the sequence implementation does not.

Previously this was handled by the wrapper functions (flux::read_at_unchecked etc) examining the sequence_traits<T> struct and using the customised function if it existed, otherwise falling back to their default implementation.

This PR changes the arrangement somewhat. Rather than being strictly optional, the sequence concept now requires that all customisation points are implemented. We can still provide default implementations, but this is now handled by having sequence_traits<T> inherit from a new base class default_sequence_traits. (In principle using this base class is not required by the sequence concept, but in practise everyone will want to use it.)

This has the advantage that user-defined customisations can now be concept-checked; that is, if a user provides an incompatible signature for e.g. for_each_while in their sequence_traits, it will hide the default implementation, and result in a compile error; previously, the incompatible signature would just have been ignored and the default impl would silently have been used.

For complicated sequence implementations (e.g. the zip and cartesian_product families), this means that we also need to be explicit about when we're using the default impls vs using customised versions. This is a good thing.

codecov[bot] commented 3 weeks ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.30%. Comparing base (bbdd46f) to head (4bb55a8). Report is 11 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #207 +/- ## ======================================= Coverage 98.30% 98.30% ======================================= Files 70 71 +1 Lines 2479 2485 +6 ======================================= + Hits 2437 2443 +6 Misses 42 42 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.