Generically call a function on Variant's payload?

Nick Sabalausky (Abscissa) SeeWebsiteToContactMe at semitwist.com
Tue Aug 21 19:11:15 UTC 2018


On 08/21/2018 03:03 AM, Nicholas Wilson wrote:
> On Monday, 20 August 2018 at 00:27:04 UTC, Nick Sabalausky (Abscissa) 
> wrote:
>> Suppose I've wrapped a Variant in a struct/class which ensures the 
>> Variant *only* ever contains types which satisfy a particular 
>> constraint (for example: isInputRange, or hasLength, etc...).
>>
>> Is there a way to call a function (ex: popFront) on the Variant, 
>> *without* knowing ahead of time all the possible static types it might 
>> might contain?
> 
> I assume you mean at compile time AoT of development of your library?
> 
> Yes, don't use Variant; use https://github.com/s-ludwig/taggedalgebraic
> 

TaggedAlgebraic requires a finite list of every type it can contain. 
That's the deal-breaker for what I had in mind. I need something less 
like Algebraic and more like Variant, which *doesn't* require a finite, 
canonical list of every type it can contain.

The more I think about it though, the more I'm not so sure that the 
extensibility is important enough to warrant all of this, or...more 
importantly...that all of this is even necessary anyway for users to 
accomplish the use-cases I had in mind. I think I may go with an 
entirely different approach.


More information about the Digitalmars-d-learn mailing list