www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Just noticed something interesting in the std.allocator source...

reply "Gary Willoughby" <dev nomad.so> writes:
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;
}
Oct 25 2013
next sibling parent "Brad Anderson" <eco gnuk.net> writes:
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!)
Oct 25 2013
prev sibling parent "evilrat" <evilrat666 gmail.com> writes:
as replied, version(none) allows removing some code from build 
but it still parses and spew errors in it, there is also 
version(all) to re-enable code.
Oct 26 2013