[PATCH] D24162: [yaml] Add the ability to pass in context at the map level

Zachary Turner via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 2 09:26:44 PDT 2016

zturner updated this revision to Diff 70175.
zturner added a comment.

It occurred to me that a limitation of my original patch is that it would have been impossible to define a mapping function that accepts a context if a specialization of `MappingTraits` had already been defined for `T` out of your control, since they all reused the same exact `MappingTraits<T>` specialization.  To fix this mapping with context now requires an entirely different class.  Instead of reusing `MappingTraits<T>::mapping()` it relies on `MappingContextTraits<T, Context>::mapping()`.  Now one can have both a `MappingContextTraits<T, Context>` as well as a `MappingTraits<T>`, and if the non-context mapping functionality is identical, one could even define the context mapping traits like this:

  struct MappingContextTraits<MyClass, MyContext> : public MappingTraits<MyClass> {
    static void mapping(IO &io, MyClass &Obj, MyContext &Context) {
      MappingTraits<MyClass>::mapping(io, Obj);
      // Do something with the context.



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24162.70175.patch
Type: text/x-patch
Size: 21545 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160902/9f6804a9/attachment.bin>

More information about the llvm-commits mailing list