overiding mutable methods in immutable classes

Eric via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Nov 22 06:59:58 PST 2014


On Saturday, 22 November 2014 at 09:57:55 UTC, anonymous wrote:
> On Saturday, 22 November 2014 at 02:37:21 UTC, Eric wrote:
>> I know I can make a class immutable, but the problem is I want
>> to constrain a template parameter to only immutable types,
>> and I want to use class types.
>
> template Foo(T : immutable Object)
>
> Accepts immutable(Object) and other immutable class types.
> Rejects non-immutable class types like Object and const(Object),
> and non-class types.

Yes, but if I don't declare the class T as immutable, I don't
think this constraint will work.

-Eric


More information about the Digitalmars-d-learn mailing list