View mode: basic / threaded / horizontal-split · Log in · Help
September 05, 2010
std.typecons.Rebindable with arrays
Currently (dmd 2.048) this is the signature of Rebindable:

template Rebindable(T) if (is(T == class) || is(T == interface) || isArray!(T))

Is it meangful to "rebind" immutable static arrays? In D2 they now are values, so the rebinding means overwriting all its items, so them being constant is useless.

So this looks better:
template Rebindable(T) if (is(T == class) || is(T == interface) || isDynamicArray!T)

Is it meangful to rebind a dynamic array? There is already a syntax to perform what rebindable does:
const(int)[] arr;

Rebinding a dynamic array may be a bit useful for generic code.

I have tried Rebindable with a dynamic array:

import std.typecons: Rebindable;
void main() {
   const int[] a1 = [1, 2, 3];
   const int[] a2 = [2, 3, 4];
   auto r = Rebindable!(typeof(a1))(a1);
   r = a2;

But it seems there are some problems.

Top | Discussion index | About this forum | D home