Possible bug when instantiating template function with nested struct

Basile B. b2.temp at gmx.com
Sun Nov 7 14:08:32 UTC 2021


On Sunday, 7 November 2021 at 12:02:49 UTC, Alexandru Ermicioi 
wrote:
> I've always wondered, whats the problem with representing an 
> array through a simple struct?
>
> I've seen multiple comments in the forum where people mentioned 
> that an array is basically a struct with one pointer and 
> length. So why not have entire array lower to smth like this:
>
> [...]
>
> Best regards,
> Alexandru.

- `.length` and `.ptr` becomes functions calls.
- things like `.length++` is not really supported, you have to 
make a `Length` struct for that
- implicit conversions, templates constraints, would lead to 
plenty of templates instances (things like `if (is(T == U[]))` 
would require to instantiate `U[]` right ?)
- dynamic arrays are part of the type system, being `TypeNext` 
derived they share common methods with pointers and static arrays.
- the internal type is still required (or plenty of special 
cases) so that for example errors message display the type 
representation correctly and not as lowered.
- CTFE must use the new struct template too ?
- apparently (recently read that elsewhere) control of the bound 
checks cannot be based on `version`

I think that those arrays, despite of small technic problem to 
implement them, would work but would slow compilation down (even 
without -O) and the code generated would be less efficient.


More information about the Digitalmars-d mailing list