On 12/4/10 12:23 PM, Simen kjaeraas wrote:
Simen kjaeraas <[email protected]> wrote:
What might be appropriate is a function tailconst( T )( T t ) that
returns a tail const version of the passed type. That is, given a
T[], const(T[]), const(T)[], immutable(T[]), or immutable(T)[], it
returns a const(T)[]. For a MyRange!R, const(MyRange!R), or
immutable(MyRange!R), it returns a MyRange!(R).tailconst_t. See bottom
of post for a (naïve) implementation.
To expound further on this, I have created the attached module.
Critique wanted.
Looks promising. A few comments.
* For TailXxx you need to handle built-in simple types (int, float...)
to return themselves. Also, structs for which hasIndirections returns
false also return themselves.
* tailconst_t does not obey Phobos' naming convention. I think it's fine
to use TailConst in spite of the apparent ambiguity.
* You may want to add more stringent checks for tailconst_t (well
TailConst etc) to make sure it's not bogus - has the same size,
compatible members etc.
Andrei