[llvm] r223201 - ADT: Add SmallVector<>::emplace_back()

Duncan P. N. Exon Smith dexonsmith at apple.com
Tue Dec 2 21:54:38 PST 2014


> On 2014 Dec 2, at 21:49, David Blaikie <dblaikie at gmail.com> wrote:
> 
> 
> 
> On Tue, Dec 2, 2014 at 9:36 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
> 
> > On 2014 Dec 2, at 21:00, David Blaikie <dblaikie at gmail.com> wrote:
> >
> >
> >
> > On Tue, Dec 2, 2014 at 8:45 PM, Duncan P. N. Exon Smith <dexonsmith at apple.com> wrote:
> > Author: dexonsmith
> > Date: Tue Dec  2 22:45:09 2014
> > New Revision: 223201
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=223201&view=rev
> > Log:
> > ADT: Add SmallVector<>::emplace_back()
> >
> > Modified:
> >     llvm/trunk/include/llvm/ADT/SmallVector.h
> >     llvm/trunk/unittests/ADT/SmallVectorTest.cpp
> >
> > Modified: llvm/trunk/include/llvm/ADT/SmallVector.h
> > URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallVector.h?rev=223201&r1=223200&r2=223201&view=diff
> > ==============================================================================
> > --- llvm/trunk/include/llvm/ADT/SmallVector.h (original)
> > +++ llvm/trunk/include/llvm/ADT/SmallVector.h Tue Dec  2 22:45:09 2014
> > @@ -236,6 +236,51 @@ public:
> >      this->setEnd(this->end()-1);
> >      this->end()->~T();
> >    }
> > +
> > +#if LLVM_HAS_VARIADIC_TEMPLATES
> > +  template <typename... ArgTypes> void emplace_back(ArgTypes &&... Args) {
> > +    if (LLVM_UNLIKELY(this->EndX >= this->CapacityX))
> > +      this->grow();
> > +    ::new ((void *)this->end()) T(std::forward<ArgTypes>(Args)...);
> > +    this->setEnd(this->end() + 1);
> > +  }
> > +#else
> > +private:
> > +  template <typename Constructor> emplace_back_impl(Constructor emplace) {
> >
> > wow, calling that functor 'emplace' confused me for quite a while (I was wondering why we had an emplace function that took a void* and didn't update the end function) - at some point we might grow SmallVector::emplace to match std::vector::emplace (emplace at a specified location, rather than the back) - so it might be best not to use that name in this context.
> 
> Heh, good point.  Totally missed that.  How do you feel about `construct`?
> 
> Works for me
>  

r223212



More information about the llvm-commits mailing list