www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - isAllocator

reply Tofu Ninja <emmons0 purdue.edu> writes:
Is there something like isInputRange for allocators, I tried 
looking for something but couldn't find anything? If not, why not?
Nov 30 2015
parent reply Tofu Ninja <emmons0 purdue.edu> writes:
On Monday, 30 November 2015 at 14:21:49 UTC, Tofu Ninja wrote:
 Is there something like isInputRange for allocators, I tried 
 looking for something but couldn't find anything? If not, why 
 not?
Aka, some way to check that type T is an allocator.
Nov 30 2015
parent reply Rikki Cattermole <alphaglosined gmail.com> writes:
On 01/12/15 3:23 AM, Tofu Ninja wrote:
 On Monday, 30 November 2015 at 14:21:49 UTC, Tofu Ninja wrote:
 Is there something like isInputRange for allocators, I tried looking
 for something but couldn't find anything? If not, why not?
Aka, some way to check that type T is an allocator.
Doesn't look like it. bool isAllocator(Alloc)() pure { return __traits(compiles, {IAllocator alloc = new CAllocatorImpl!Alloc;}); } That should work however.
Nov 30 2015
parent reply BBaz <2b.temp gmx.com> writes:
On Tuesday, 1 December 2015 at 03:05:34 UTC, Rikki Cattermole 
wrote:
 On 01/12/15 3:23 AM, Tofu Ninja wrote:
 On Monday, 30 November 2015 at 14:21:49 UTC, Tofu Ninja wrote:
 Is there something like isInputRange for allocators, I tried 
 looking
 for something but couldn't find anything? If not, why not?
Aka, some way to check that type T is an allocator.
Doesn't look like it. bool isAllocator(Alloc)() pure { return __traits(compiles, {IAllocator alloc = new CAllocatorImpl!Alloc;}); } That should work however.
I think that `is(CAllocatorImpl!Alloc)` should work too then.
Dec 01 2015
parent reply Tofu Ninja <emmons0 purdue.edu> writes:
On Tuesday, 1 December 2015 at 08:58:56 UTC, BBaz wrote:
 I think that `is(CAllocatorImpl!Alloc)` should work too then.
According to the 'is' version, int is an allocator. No idea why it thinks this works... enum isAllocator(Alloc) = is(CAllocatorImpl!Alloc); static assert(isAllocator!int); This seems to work well though... enum isAllocator(Alloc) = __traits(compiles, {IAllocator alloc = new CAllocatorImpl!Alloc;}); static assert(isAllocator!Mallocator); static assert(isAllocator!GCAllocator); static assert(!isAllocator!int);
Dec 01 2015
parent BBaz <2b.temp gmx.com> writes:
On Tuesday, 1 December 2015 at 12:37:12 UTC, Tofu Ninja wrote:
 On Tuesday, 1 December 2015 at 08:58:56 UTC, BBaz wrote:
 I think that `is(CAllocatorImpl!Alloc)` should work too then.
According to the 'is' version, int is an allocator. No idea why it thinks this works...
Me neither, actually, and to be honnest, I didn't test, but from the version that uses the "compiles" traits, I thought that testing if the type generated from a template instantiation is valid then it would be equivalent...Apologies, I didn't meant to lead anybody in the wrong direction.
Dec 01 2015