On Friday, 25 October 2013 at 16:03:24 UTC, Gary Willoughby wrote:
Just noticed something interesting in the std.allocator source, right at the very bottom. An EOF and some code? Does the compiler stop at the EOF? If so why add code beyond that? Also version(none), eh?

https://github.com/andralex/phobos/blob/allocator/std/allocator.d#L4071

What's going on there?

...
__EOF__

version(none) struct TemplateAllocator
{
    enum alignment = platformAlignment;
    static size_t goodAllocSize(size_t s)
    {
    }
    void[] allocate(size_t)
    {
    }
    bool owns(void[])
    {
    }
    bool expand(ref void[] b, size_t)
    {
    }
    bool reallocate(ref void[] b, size_t)
    {
    }
    void deallocate(void[] b)
    {
    }
    void deallocateAll()
    {
    }
    void[] allocateAll()
    {
    }
    static shared TemplateAllocator it;
}

Yeah, it sets the lexer to the end of file so it stops. See Special Tokens section: http://dlang.org/lex.html

Andrei is using it to include a pattern of the general structure you'd need to write your own allocator that the compiler doesn't even bother looking at. He could have commented it out too. The version(none) also accomplishes this. __EOF__ just makes it so the compiler doesn't even bother looking at it (you can shave a few microseconds off your build time!)

Reply via email to