C++ pattern matching is coming

rikki cattermole rikki at cattermole.co.nz
Mon Oct 24 21:13:33 UTC 2022


On 25/10/2022 9:38 AM, Walter Bright wrote:
> It seems you're suggesting attaching this behavior to the pointer, 
> rather than the function. That means multiple pointer types.
> 
> Multiple pointer types have been tried many times. They are attractive 
> in theory, but work out poorly in practice. For example, take:

That's not what I'm suggesting, and I'm familiar with that issue (sadly 
far too well). I have something like 700LOC just for replace in my 
Unicode string builder. For all the different string types. Can't use 
templates at that level due to shared libraries and wanting to guarantee 
everything is initialized + tested in it.

I have suggested this before, but scope as a type qualifier.

A type qualifier (especially if its scope!) adds the extra checks for a 
specific object, without invading the entire function call graph.

Consider:

```d
struct Nullable(T) {
	T value;

	ref borrow(T) get() {
		return value;
	}

	alias get this;
}

void func1() {
	Nullable!U n;
	func2(n);
}

void func2(scope U input) {

}
```

We have this sort of behavior in the language already i.e. shared. Why 
is lifetime tracking any different?


More information about the Digitalmars-d mailing list