Last active
July 12, 2017 12:46
-
-
Save uucidl/c9a6103b0be76717f607055350866f51 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Passing container explicitely to all its functions, and using typed cursors (i.e. indices) | |
// rather than all-knowing iterators (i.e. pointers) allows to use the same return type for | |
// iteration, look-up etc.. regardless of what's going to happen next. | |
// | |
// Downsides: | |
// A cursor requires an indirection when looking at the data in the debugger. | |
// I.e. a `char*` member shows you directly what you should be looking at, | |
// whereas if you have the pos, you need the container and to use debugger expressions | |
// to see the content. | |
// | |
// In visual studio's debugger for instance you'd do: `buffer_start,<pos>` to see the content | |
// however <pos> has to be a litteral.. So again, indirection | |
struct Array_Cursor | |
{ | |
size_t pos; | |
}; | |
template <typename Container, Cursor> | |
requires(CursorType(Container) == Cursor) | |
Cursor find(Container const c, Cursor f, Cursor l, ValueType(Container) x) { | |
while (!equal(f, l)) { | |
auto const& y = valueAt(c, f); | |
if (equal(y, x)) { | |
return f; | |
} | |
f = next(f); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment