| 
46 | 46 | #ifndef LLVM_SUPPORT_TRAILINGOBJECTS_H  | 
47 | 47 | #define LLVM_SUPPORT_TRAILINGOBJECTS_H  | 
48 | 48 | 
 
  | 
 | 49 | +#include "llvm/ADT/ArrayRef.h"  | 
49 | 50 | #include "llvm/Support/Alignment.h"  | 
50 | 51 | #include "llvm/Support/Compiler.h"  | 
51 | 52 | #include "llvm/Support/MathExtras.h"  | 
@@ -301,6 +302,41 @@ class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl<  | 
301 | 302 |         static_cast<BaseTy *>(this), TrailingObjectsBase::OverloadToken<T>());  | 
302 | 303 |   }  | 
303 | 304 | 
 
  | 
 | 305 | +  // getTrailingObjects() specialization for a single trailing type.  | 
 | 306 | +  using FirstTrailingType =  | 
 | 307 | +      typename std::tuple_element_t<0, std::tuple<TrailingTys...>>;  | 
 | 308 | + | 
 | 309 | +  const FirstTrailingType *getTrailingObjects() const {  | 
 | 310 | +    static_assert(sizeof...(TrailingTys) == 1,  | 
 | 311 | +                  "Can use non-templated getTrailingObjects() only when there "  | 
 | 312 | +                  "is a single trailing type");  | 
 | 313 | +    return getTrailingObjects<FirstTrailingType>();  | 
 | 314 | +  }  | 
 | 315 | + | 
 | 316 | +  FirstTrailingType *getTrailingObjects() {  | 
 | 317 | +    static_assert(sizeof...(TrailingTys) == 1,  | 
 | 318 | +                  "Can use non-templated getTrailingObjects() only when there "  | 
 | 319 | +                  "is a single trailing type");  | 
 | 320 | +    return getTrailingObjects<FirstTrailingType>();  | 
 | 321 | +  }  | 
 | 322 | + | 
 | 323 | +  // Functions that return the trailing objects as ArrayRefs.  | 
 | 324 | +  template <typename T> MutableArrayRef<T> getTrailingObjects(size_t N) {  | 
 | 325 | +    return MutableArrayRef(getTrailingObjects<T>(), N);  | 
 | 326 | +  }  | 
 | 327 | + | 
 | 328 | +  template <typename T> ArrayRef<T> getTrailingObjects(size_t N) const {  | 
 | 329 | +    return ArrayRef(getTrailingObjects<T>(), N);  | 
 | 330 | +  }  | 
 | 331 | + | 
 | 332 | +  MutableArrayRef<FirstTrailingType> getTrailingObjects(size_t N) {  | 
 | 333 | +    return MutableArrayRef(getTrailingObjects(), N);  | 
 | 334 | +  }  | 
 | 335 | + | 
 | 336 | +  ArrayRef<FirstTrailingType> getTrailingObjects(size_t N) const {  | 
 | 337 | +    return ArrayRef(getTrailingObjects(), N);  | 
 | 338 | +  }  | 
 | 339 | + | 
304 | 340 |   /// Returns the size of the trailing data, if an object were  | 
305 | 341 |   /// allocated with the given counts (The counts are in the same order  | 
306 | 342 |   /// as the template arguments). This does not include the size of the  | 
 | 
0 commit comments