]> granicus.if.org Git - llvm/commitdiff
[ADT] Make SmallVector emplace_back return a reference
authorFangrui Song <maskray@google.com>
Sat, 16 Mar 2019 02:41:45 +0000 (02:41 +0000)
committerFangrui Song <maskray@google.com>
Sat, 16 Mar 2019 02:41:45 +0000 (02:41 +0000)
This follows the C++17 std::vector change and can simplify immediate
back() calls.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356312 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/SmallVector.h

index e3bfb90e1ba752f5424ed3ff097b45b993b1ff27..96a49cd955096e73d9c5db6784fe89a8757674eb 100644 (file)
@@ -318,6 +318,7 @@ class SmallVectorImpl : public SmallVectorTemplateBase<T> {
 public:
   using iterator = typename SuperClass::iterator;
   using const_iterator = typename SuperClass::const_iterator;
+  using reference = typename SuperClass::reference;
   using size_type = typename SuperClass::size_type;
 
 protected:
@@ -641,11 +642,12 @@ public:
     insert(I, IL.begin(), IL.end());
   }
 
-  template <typename... ArgTypes> void emplace_back(ArgTypes &&... Args) {
+  template <typename... ArgTypes> reference emplace_back(ArgTypes &&... Args) {
     if (LLVM_UNLIKELY(this->size() >= this->capacity()))
       this->grow();
     ::new ((void *)this->end()) T(std::forward<ArgTypes>(Args)...);
     this->set_size(this->size() + 1);
+    return this->back();
   }
 
   SmallVectorImpl &operator=(const SmallVectorImpl &RHS);