Thread overview
isAllocator
Nov 30, 2015
Tofu Ninja
Nov 30, 2015
Tofu Ninja
Dec 01, 2015
Rikki Cattermole
Dec 01, 2015
BBaz
Dec 01, 2015
Tofu Ninja
Dec 01, 2015
BBaz
November 30, 2015
Is there something like isInputRange for allocators, I tried looking for something but couldn't find anything? If not, why not?
November 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.
December 01, 2015
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.
December 01, 2015
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.
December 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);
December 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:
>> 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.