February 02, 2013
i've got something like an streaming/converter system
and parts of the specialised converters are stateless other statefull

is there any way to force pureness/stateless-ness through the base
class or an interface in D?
February 03, 2013
On 02/02/2013 02:23 AM, dennis luehring wrote:
> i've got something like an streaming/converter system
> and parts of the specialised converters are stateless other statefull
>
> is there any way to force pureness/stateless-ness through the base
> class or an interface in D?

That seems to be the case:

interface I
{
    int foo() const pure;
}

int g;

class C : I
{
    int foo() const
    {
        return g;    // ERROR: pure function 'deneme.C.foo' cannot access
                     //        mutable static data 'g'
    }
}

void main()
{
    auto o = new C;
    o.foo();
}

Note that there is no 'pure' on C.foo; it is inherited from I.foo.

Ali