[PATCH] D129206: [ADT] Use Empty Base Optimization for Allocators

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 7 11:34:11 PDT 2022


dblaikie added inline comments.


================
Comment at: llvm/include/llvm/Support/AllocatorBase.h:102-136
+namespace detail {
+
+template <typename T>
+class ReferenceAllocator : public AllocatorBase<ReferenceAllocator<T>> {
+  static_assert(!std::is_const<T>::value, "Cannot have a const type here");
+  T &Underlying;
+
----------------
Could this be a bit simpler if it were an explicit allocator holder, rather than a wrapper (that still ends up needing the conversion operators anyway)?
```
template<typename Alloc> class AllocatorHolder: Alloc {
public:
  AllocatorHolder(const Alloc &A) : Alloc(A) { }
  Alloc &getAllocator() { return *this; }
  const Alloc &getAllocator() { return *this; }
};
template<typename Alloc> class AllocatorHolder<Alloc&> {
  Alloc &A;
public:
  AllocatorHolder(const Alloc &A) : A(A) { }
  Alloc &getAllocator() { return *this; }
  const Alloc &getAllocator() { return *this; }
};
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D129206/new/

https://reviews.llvm.org/D129206



More information about the llvm-commits mailing list