digitalmars.D.learn - How can I check a newly set ref value
- solidstate1991 (19/19) Oct 23 2021 Let's say I have something like this:
- Adam D Ruppe (4/7) Oct 23 2021 You can't with ref, you will need to do separate getter and
Let's say I have something like this: ``` struct Foo { int[] bar; this() { bar.length = 10; } ref int opIndex(size_t i) { return bar[i]; } } void main() { Foo f = Foo(); f[3] = 15; } ``` If I wanted to check whether the assigned value is within a range, and I want to throw a certain exception if outside of it, then how I can do that?
Oct 23 2021
On Saturday, 23 October 2021 at 20:14:25 UTC, solidstate1991 wrote:If I wanted to check whether the assigned value is within a range, and I want to throw a certain exception if outside of it, then how I can do that?You can't with ref, you will need to do separate getter and setter properties for that.
Oct 23 2021