Containers
vit
vit at vit.vit
Wed Sep 1 16:34:35 UTC 2021
On Tuesday, 31 August 2021 at 17:21:02 UTC, deadalnix wrote:
> ...
> For instance, if we have a Vector!T, then we want it to convert
> to a Vector!(const T) and we want const(Vector!T) ==
> const(Vector!(const T)), all of it implicitly. Same goes for
> other qualifiers.
>
> To put it bluntly, I have no idea how to achieve this. And I
> don't think we'll have a good set of collection before this is
> sorted out.
> ...
Try `this` template parameter:
```d
import std.traits : CopyConstness, isMutable;
void main(){
{
Vector!int a;
Vector!(const int) b = a;
const Vector!int c = b;
}
{
Vector!int a;
Vector!(const int) b;
b = a;
}
}
struct Vector(T){
alias ElementType = T;
this(U, this This)(ref Vector!U rhs)
if(!is(U == T) && isCopyable!(This, typeof(rhs))){
//impl
}
this(U, this This)(Vector!U rhs)
if(isCopyable!(typeof(rhs), This)){
//impl
}
///TODO copy ctors...
void opAssign(U, this This)(auto ref Vector!U rhs)
if(isCopyable!(typeof(rhs), This) && isMutable!This){
//impl
}
}
private enum bool isCopyable(From, To) = is(
CopyConstness!(From, From.ElementType[]) : CopyConstness!(To,
To.ElementType[])
);
```
More information about the Digitalmars-d
mailing list