The tailconst problem (and suggestions for solution)

Don Clugston dac at nospam.com.au
Fri Dec 7 06:14:48 PST 2007


Janice Caron wrote:
> On Dec 7, 2007 11:00 AM, Walter Bright <newshound1 at digitalmars.com> wrote:
>> That doesn't work because of the need to have a consistent system for
>> use with generic code.
> 
> I think I got misunderstood. But no matter - it's unimportant. It just
> goes to show how hard it is to have a conversation about this stuff at
> all! :-)
> 
> 
>> If it can be done with a template, then I'd prefer the template solution
> 
> I believe it can be done with a template, yes.
> 
> However, that template needs to be written by someone who really
> understands what goes on under the hood, because (if it works like I
> think it will have to work) that template is going to need to do
> something which the manual says is undefined: it will have to cast
> away const (in at least one place). That's not a problem in a
> standard-library-provided template, of course. It's probably better
> done there than in user code.
> 
> That said, Andrei is much smarter than I, so maybe he can do it
> without even needed that cast.

Don't you just need to wrap it in a struct ??

struct A
{
   const B b;
}

A a;
Then you can't change a.b, but you can replace a.
Or did I miss something?



More information about the Digitalmars-d mailing list