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.
- Registered by Nickolay Bukreyev
- 1.0.0 released 10 months ago
- SirNickolas/readonly_range.d
- MIT
- Copyright © 2024, Nickolay Bukreyev
- Authors:
- Dependencies:
- none
- Versions:
-
1.0.0 2024-Feb-13 ~master 2024-Feb-13 - Download Stats:
-
-
0 downloads today
-
0 downloads this week
-
0 downloads this month
-
1 downloads total
-
- Score:
- 0.5
- Short URL:
- readonly_range.dub.pm