readonly_range 1.0.0
A head-const (aka read-only, aka final) adapter for ranges.
To use this package, run the following command in your project's root directory:
Manual usage
Put the following dependency into your project's dependences section:
readonly_range
This library provides a simple wrapper that makes the passed range head-const: it prevents reassigning the elements but otherwise does not affect their constness. This is essentially the opposite of Rebindable.
import readonly_range;
struct S {
int field;
}
auto data = [new S(1), new S(2), new S(3)];
auto view = data.readonlyRange;
// view[0] = null; // Forbidden.
view[0].field = 13; // Allowed.
assert(data[0].field == 13);
const(S*)[ ] constView = view; // Implicit conversion.
It works by making front, back, and opIndex return the element by value—keep that in mind
and avoid using it for types that are expensive to copy. Note that in the example above, data is
S*[ ] so view[0] copies just the pointer, not the pointed-to object.
- 1.0.0 released a year ago
- SirNickolas/readonly_range.d
- MIT
- Copyright © 2024, Nickolay Bukreyev
- Authors:
- Dependencies:
- none
- Versions:
-
Show all 2 versions1.0.0 2024-Feb-13 ~master 2024-Feb-13 - Download Stats:
-
-
0 downloads today
-
3 downloads this week
-
3 downloads this month
-
7 downloads total
-
- Score:
- 0.4
- Short URL:
- readonly_range.dub.pm