inout template parameter, or a solution to the templated container issue

deadalnix deadalnix at gmail.com
Wed Jun 12 19:54:19 PDT 2013


On Wednesday, 12 June 2013 at 19:00:28 UTC, Steven Schveighoffer 
wrote:
> To avoid escaping pointers to your elements.  This is 
> especially important if you have total control over allocation 
> of your elements.
>

Yes, that is definitively a point.

> The use case:
>
> class Container(T)
> {
>
>    struct range
>    {
>       size_t length;
>       T* ptr;
>    }
> }
>
> Which I use for all dcollections containers.
>
> Yes, I could introduce it like this:
>
> struct range(inout U) if(is(U == T))
> {
>    size_t length;
>    U *ptr;
> }
>
> but it feels unnecessary.  I also find the usage for this 
> solution clumsy.
>

Why would you need to do it ? Why not simply do :

class Container(T) {
     struct range {
         size_t length;
         T* ptr;
     }
}


More information about the Digitalmars-d mailing list