conv text and pure

Jonathan M Davis jmdavisProg at gmx.com
Wed Oct 23 16:46:25 PDT 2013


On Thursday, October 24, 2013 00:12:48 Daniel Davidson wrote:
> On Wednesday, 23 October 2013 at 21:37:25 UTC, H. S. Teoh wrote:
> > On Wed, Oct 23, 2013 at 11:17:30PM +0200, Daniel Davidson wrote:
> >> On Wednesday, 23 October 2013 at 20:18:39 UTC, Andrej Mitrovic
> >> 
> >> wrote:
> >> >On 10/23/13, Daniel Davidson <nospam at spam.com> wrote:
> >> >>Great, thanks. What is the best way to get on that version
> >> >>for the
> >> >>Mac (pointer to instructions)?
> >> >
> >> >You can download the beta here:
> >> >http://forum.dlang.org/thread/52605C84.6010109@walterbright.com
> >> 
> >> Thanks for pointer. I am using it and the file conv.d has:
> >> 
> >> string text(T...)(T args) { return textImpl!string(args); }
> >> 
> >> 
> >> So, when you say it is pure, what are you referring to. I
> >> think pure
> >> could be specified as a block, but when I search up the next
> >> prior
> >> 
> >> pure occurrence is:
> >> @safe pure unittest
> > 
> > No, pure can't be specified as a block. You can only mark a
> > function as
> > pure.
> 
> I think that is not correct. Consider:
> 
> int x = 3;
> struct S {
> pure {
> void foo() {
> //x = 4;
> }
> }
> }
> 
> pure blocks seem to have the effect you would expect. In fact it
> seems like you can stream them together to make code more
> pleasant:
> 
> const pure ... { ... }

You can use pretty much any attribute with a block or a :, so you can use a 
pure block, but it's almost always a bad idea to put pure, nothrow, @safe, or 
@trusted on a templated function, because whether the attribute is valid or 
not almost always depends on the template arguments. So, if you use such an 
attribute no a templated function, you restrict the types that will work with 
that function. Rather, templated functions infer pure, nothrow, and @safe, so 
in most cases, using those attributes on templated functions should be 
unnecessary.

Now, the template inferrence needs a lot of work, so it doesn't generally work 
on the more complicated cases yet (e.g. a struct declared inside of a 
templated function doesn't end up getting inferrence for its member functions 
like it should), but that will be fixed. That combined with the fact that 
several lower level constructs in druntime and Phobos still need some work to 
make them properly pure, nothrow, and/or @trusted/@safe makes it so that a lot 
less of Phobos is pure, nothrow, or @safe than should be the case. Progress is 
being made on that however (as evidenced by the fact that format can now be 
pure in the beta for 2.064).

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list