[llvm-commits] [PATCH] YAML I/O for review

Sean Silva silvas at purdue.edu
Wed Dec 5 12:58:26 PST 2012


On Wed, Dec 5, 2012 at 3:31 PM, Nick Kledzik <kledzik at apple.com> wrote:
> 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.

If you use SFINAE you should be able to have the primary traits
template detect whether the class has a begin(), end(), push_back(),
iterator, and value_type member, and allow clients to specialize the
template if they need custom behavior.

Instead of relying on begin(), end(), push_back(), iterator, and
value_type on the class, what you could do instead is have the
sequence notion expressed in terms of iterators, so the traits class
has one method to get an output iterator from the class (it's easy to
adapt any type with push_back() to be an output iterator by just using
std::back_inserter), and one function in the traits class which gets
an input iterator. That seems a lot simpler and more idiomatic.

-- Sean Silva



More information about the llvm-commits mailing list