Failure due to memcpy being called at compile time
JG
someone at somewhere.com
Mon Jun 13 20:56:12 UTC 2022
On Monday, 13 June 2022 at 20:25:00 UTC, Steven Schveighoffer
wrote:
> On 6/13/22 4:09 PM, JG wrote:
>> Thanks. It seems to be something to do with the variadic
>> template since this
>> works:
>>
>> ```d
>> import std;
>>
>> struct ParseError { string msg; }
>>
>> alias ParseErrorOr(T) = SumType!(ParseError,T);
>> auto parseErrorOr(T)(T x) { return ParseErrorOr!T(x); }
>>
>> auto parserOr(I,alias f, alias g)(I i) {
>> auto cur = f(i);
>> if(cur.match!((ParseError e)=>false,_=>true)) { return cur;
>> }
>> return g(i);
>> }
>>
>> auto parseNothing(I)(I i) {
>> return parseErrorOr(tuple(i[0..0],i));
>> }
>>
>> void main()
>> {
>> enum a =
>> parserOr!(string,parseNothing!string,parseNothing!string)("hello");
>> }
>> ```
>
> Given that it's inside `moveEmplace`, I'd suspect something
> deep in `SumType`.
>
> -Steve
Really strange. I can also work around it like this:
```d
auto parserOr(I,fs...)(I i) if(fs.length>=2) {
auto cur = fs[0](i);
if(cur.match!((ParseError e)=>false,_=>true)) { return cur;
}
static if(fs.length==2) { return fs[1](i); }
else { return parserOr!(I,fs[1..$])(i); }
}
```
More information about the Digitalmars-d-learn
mailing list