Function attribute best practices

H. S. Teoh hsteoh at
Mon Sep 12 17:29:57 UTC 2022

On Mon, Sep 12, 2022 at 10:08:29AM -0700, Ali Çehreli via Digitalmars-d-learn wrote:
> What I meant was
> - if I put 'pure' etc. on my templatized code,
> - and then tested with a 'pure' unittest,
> I wouldn't know that the gratuitous use of my 'pure' on the member
> function was wrong. I would be fooling myself thinking that I smartly
> wrote a 'pure' member function and a 'pure' unittest and all worked.
> Wrong idea! :)

That's an easy one: write a unittest where you instantiate Foo with a
deliberately-impure type (e.g., .front references some local variable in
the unittest outside the aggregate).  If there was a gratuitous `pure`
in Foo, this will fail to compile.


"I'm running Windows '98." "Yes." "My computer isn't working now." "Yes, you already said that." -- User-Friendly

More information about the Digitalmars-d-learn mailing list