[llvm-commits] [PATCH] YAML I/O for review
Nick Kledzik
kledzik at apple.com
Wed Dec 5 12:31:59 PST 2012
On Dec 5, 2012, at 12:16 PM, Sean Silva wrote:
> On Wed, Dec 5, 2012 at 2:58 PM, Michael Spencer <bigcheesegs at gmail.com> wrote:
>> + struct IntVector : public std::vector<int> {
>> + // The existence of this member causes YAML I/O to use a flow sequence
>> + static const bool flow = true;
>> + };
>>
>> Deriving types like this breaks the constructors for vector. There
>> needs to be a different way to do this that doesn't require flow to be
>> a member.
>
> traits++
>
> You can just have a template (e.g. FlowFormattingTraits<>) which you
> specialize to indicate that a class should be flow formatted. The
> primary template can conveniently use the presence (using SFINAE) and
> value of the class member (`flow` in Nick's original patch, although I
> think a longer and more unique name would be better) to select flow
> formatting if there is no explicit specialization for the type.
It did seem a little odd that you needed a class wrapper to make flow sequence.
So I do like the FlowFormattingTraits<> idea. But that brings up the issue
that sequences in general are not trait based like the other parts of YAML I/O
are. Your existing data has to have begin(), end(), push_back(), iterator,
and type_value to work as a sequence. It would be better if you could specify
a trait on your native type that tells YAML I/O how to iterate through it and
how to append to it. Hopefully, I could then have a built in trait specialized on
any std::vector<>. Thus if your native type is a vector, it would automatically
convert to a YAML sequence. But if you have some other form of container
you can write a trait which allows YAML I/O to use your type as a sequence.
-Nick
More information about the llvm-commits
mailing list