CT BitArray

Steven Schveighoffer schveiguy at gmail.com
Thu Apr 2 12:41:28 UTC 2020


On 4/2/20 8:26 AM, Bastiaan Veelo wrote:
> On Thursday, 1 November 2018 at 08:50:38 UTC, Bastiaan Veelo wrote:
>> On Thursday, 1 November 2018 at 00:01:04 UTC, Stefan Koch wrote:
>>> On Wednesday, 31 October 2018 at 23:14:08 UTC, Bastiaan Veelo wrote:
>>>> Currently, BitArray is not usable at compile time, so you cannot do
>>>> ```
>>>> enum e = BitArray([1, 1, 1, 0]);
>>>> ```
>>>> This gives
>>>>> /dlang/dmd/linux/bin64/../../src/phobos/std/bitmanip.d(1190): 
>>>>> Error: `bts` cannot be interpreted at compile time, because it has 
>>>>> no available source code
> 
> [....]
> 
>> meanwhile use module level BitArrays like
>> ```
>> immutable BitArray e;
>> static this()
>> {
>>     e = BitArray([1, 1, 1, 0]);
>> }
>> ```
> 
> Note to self: when this occurs, the above error message does not offer a 
> trace to the place where this originates. To get that, temporarily 
> insert the following at the indicated line in bitmanip.d:
> ```
> if(__ctfe) assert(false, "trap");
> ```
> 

Hm... I thought there was precedent for providing fallback 
implementations for intrinsics. That is, you define the function, which 
is only used if the intrinsic is not available.

I can't remember where I saw this. But you could try this by simply 
implementing the bitops in core.bitop, and see if they are used outside 
ctfe.

-Steve


More information about the Digitalmars-d-learn mailing list