-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Suppose we have a formatter for a compound type, and we implement it with two formatter member variables for the sub-types. We'd like to delegate to the formatter members for both parse and format.
This comment gets very close to what I want, but the parse implementation is only comments. The problem is that I'm finding it very tricky to actually implement what those comments say to do.
To be concrete, aurora-opensource/au#491 was my attempt (specifically, this file). This is extra tricky because I can't take a physical dependency on {fmt} in my zero-dependency library; I have to tell users to inherit their fmt::formatter<Quantity<U, R>> from au::QuantityFormatter<U, R>. But in some ways, that's beside the point, because this would actually work if we had a robust way to delegate the parse functions.
I tried constructing my own parse context object based on the start and end iterators. Abstractly, this feels like the right approach (at least, going based on start and end iterators and then delegating does). In practice, I find that the constructor for the context type varies too much over different versions. In fact, it even seems like it has changed significantly between 11.0.2 and 11.2.0!
What's the preferred, idiomatic way to actually do that parsing delegation? If we have an "overall" parse context, and a start and end iterator for the subset that applies to a member delegator, how can we provide that information to the member? (Bonus points for solutions that avoid needing to take a physical dependency on {fmt}, and that work across a wide range of versions as well as std::format.)