Add interface for enumerating over sequences.

This commit is contained in:
kayomn 2023-03-02 19:57:24 +00:00
parent 7876efc4f5
commit 57d94ef8b9

View File

@ -495,6 +495,35 @@ export namespace coral {
*/
virtual expected<usize, io_error> write(slice<u8 const> const & data) = 0;
};
/**
* Sequence enumeration interface.
*/
template<typename type> struct enumerator {
virtual ~enumerator() {}
/**
* Returns the last-enumerated value.
*
* *Note*: calling this function before first having recieved a `true` value from [enumerate] will result in
* implementation-defined behaviour.
*/
virtual type value() = 0;
/**
* Attempts to retrieve the next file path in the file tree, returning true if another value was retrieved or
* `false` if there are no more values to be enumerated over.
*
* ```cpp
* while (sequence.enumerate()) {
* do_thing(sequence.value());
* }
* ```
*
* The enumerated value may be accessed through [value].
*/
virtual bool enumerate() = 0;
}
}
// Input/output operations.