Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
November 30, 2015 isAllocator | ||||
---|---|---|---|---|
| ||||
Is there something like isInputRange for allocators, I tried looking for something but couldn't find anything? If not, why not? |
November 30, 2015 Re: isAllocator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | 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 Re: isAllocator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | 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 Re: isAllocator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rikki Cattermole | 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 Re: isAllocator | ||||
---|---|---|---|---|
| ||||
Posted in reply to BBaz | 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 Re: isAllocator | ||||
---|---|---|---|---|
| ||||
Posted in reply to Tofu Ninja | 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.
|
Copyright © 1999-2021 by the D Language Foundation