digitalmars.D.learn - isAllocator
- Tofu Ninja (2/2) Nov 30 2015 Is there something like isInputRange for allocators, I tried
- Tofu Ninja (2/5) Nov 30 2015 Aka, some way to check that type T is an allocator.
- Rikki Cattermole (6/10) Nov 30 2015 Doesn't look like it.
- BBaz (3/16) Dec 01 2015 I think that `is(CAllocatorImpl!Alloc)` should work too then.
- Tofu Ninja (11/12) Dec 01 2015 According to the 'is' version, int is an allocator. No idea why
- BBaz (6/10) Dec 01 2015 Me neither, actually, and to be honnest, I didn't test, but from
Is there something like isInputRange for allocators, I tried looking for something but couldn't find anything? If not, why not?
Nov 30 2015
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
On 01/12/15 3:23 AM, Tofu Ninja wrote:On Monday, 30 November 2015 at 14:21:49 UTC, Tofu Ninja wrote:Doesn't look like it. bool isAllocator(Alloc)() pure { return __traits(compiles, {IAllocator alloc = new CAllocatorImpl!Alloc;}); } That should work however.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
On Tuesday, 1 December 2015 at 03:05:34 UTC, Rikki Cattermole wrote:On 01/12/15 3:23 AM, Tofu Ninja wrote:I think that `is(CAllocatorImpl!Alloc)` should work too then.On Monday, 30 November 2015 at 14:21:49 UTC, Tofu Ninja wrote:Doesn't look like it. bool isAllocator(Alloc)() pure { return __traits(compiles, {IAllocator alloc = new CAllocatorImpl!Alloc;}); } That should work however.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.
Dec 01 2015
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
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: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.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...
Dec 01 2015