Index: llvm/trunk/include/llvm/Support/YAMLTraits.h =================================================================== --- llvm/trunk/include/llvm/Support/YAMLTraits.h +++ llvm/trunk/include/llvm/Support/YAMLTraits.h @@ -1359,66 +1359,63 @@ return yout; } +template struct SequenceTraitsImpl { + typedef typename T::value_type _type; + static size_t size(IO &io, T &seq) { return seq.size(); } + static _type &element(IO &io, T &seq, size_t index) { + if (index >= seq.size()) + seq.resize(index + 1); + return seq[index]; + } +}; + } // namespace yaml } // namespace llvm /// Utility for declaring that a std::vector of a particular type /// should be considered a YAML sequence. -#define LLVM_YAML_IS_SEQUENCE_VECTOR(_type) \ - namespace llvm { \ - namespace yaml { \ - template<> \ - struct SequenceTraits< std::vector<_type> > { \ - static size_t size(IO &io, std::vector<_type> &seq) { \ - return seq.size(); \ - } \ - static _type& element(IO &io, std::vector<_type> &seq, size_t index) {\ - if ( index >= seq.size() ) \ - seq.resize(index+1); \ - return seq[index]; \ - } \ - }; \ - } \ +#define LLVM_YAML_IS_SEQUENCE_VECTOR(_type) \ + namespace llvm { \ + namespace yaml { \ + template <> \ + struct SequenceTraits> \ + : public SequenceTraitsImpl> {}; \ + template \ + struct SequenceTraits> \ + : public SequenceTraitsImpl> {}; \ + } \ } /// Utility for declaring that a std::vector of a particular type /// should be considered a YAML flow sequence. -#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(_type) \ - namespace llvm { \ - namespace yaml { \ - template<> \ - struct SequenceTraits< std::vector<_type> > { \ - static size_t size(IO &io, std::vector<_type> &seq) { \ - return seq.size(); \ - } \ - static _type& element(IO &io, std::vector<_type> &seq, size_t index) {\ - (void)flow; /* Remove this workaround after PR17897 is fixed */ \ - if ( index >= seq.size() ) \ - seq.resize(index+1); \ - return seq[index]; \ - } \ - static const bool flow = true; \ - }; \ - } \ +#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(_type) \ + namespace llvm { \ + namespace yaml { \ + template \ + struct SequenceTraits> \ + : public SequenceTraitsImpl> { \ + static const bool flow = true; \ + }; \ + template <> \ + struct SequenceTraits> \ + : public SequenceTraitsImpl> { \ + static const bool flow = true; \ + }; \ + } \ } /// Utility for declaring that a std::vector of a particular type /// should be considered a YAML document list. -#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \ - namespace llvm { \ - namespace yaml { \ - template<> \ - struct DocumentListTraits< std::vector<_type> > { \ - static size_t size(IO &io, std::vector<_type> &seq) { \ - return seq.size(); \ - } \ - static _type& element(IO &io, std::vector<_type> &seq, size_t index) {\ - if ( index >= seq.size() ) \ - seq.resize(index+1); \ - return seq[index]; \ - } \ - }; \ - } \ +#define LLVM_YAML_IS_DOCUMENT_LIST_VECTOR(_type) \ + namespace llvm { \ + namespace yaml { \ + template \ + struct DocumentListTraits> \ + : public SequenceTraitsImpl> {}; \ + template <> \ + struct DocumentListTraits> \ + : public SequenceTraitsImpl> {}; \ + } \ } #endif // LLVM_SUPPORT_YAMLTRAITS_H