OSDN Git Service

SmallVector: support resize(N) with move-only types
authorDavid Blaikie <dblaikie@gmail.com>
Mon, 9 Jun 2014 22:26:20 +0000 (22:26 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Mon, 9 Jun 2014 22:26:20 +0000 (22:26 +0000)
commit78b4fd3a4b55d7f8b95fb56b5b4f76c83e369ae1
tree01789910a929f80da6375b3dda1560e59982ff3c
parent8e38e862667e89ac928b8f5e7ce0a91c84fae4bc
SmallVector: support resize(N) with move-only types

Unfortunately there's no way to elegantly do this with pre-canned
algorithms. Using a generating iterator doesn't work because you default
construct for each element, then move construct into the actual slot
(bad for copy but non-movable types, and a little unneeded overhead even
in the move-only case), so just write it out manually.

This solution isn't exception safe (if one of the element's ctors calls
we don't fall back, destroy the constructed elements, and throw on -
which std::uninitialized_fill does do) but SmallVector (and LLVM) isn't
exception safe anyway.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@210495 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/ADT/SmallVector.h
unittests/ADT/SmallVectorTest.cpp