proxygen
folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC > Class Template Reference

#include <small_vector.h>

Inheritance diagram for folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >:

Classes

union  Data
 
struct  HeapPtr
 
struct  HeapPtrWithCapacity
 

Public Types

typedef std::size_t size_type
 
typedef Value value_type
 
typedef value_typereference
 
typedef value_type const & const_reference
 
typedef value_typeiterator
 
typedef value_typepointer
 
typedef value_type const * const_iterator
 
typedef value_type const * const_pointer
 
typedef std::ptrdiff_t difference_type
 
typedef std::reverse_iterator< iteratorreverse_iterator
 
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 

Public Member Functions

 small_vector ()=default
 
 small_vector (const std::allocator< Value > &)
 
 small_vector (small_vector const &o)
 
 small_vector (small_vector &&o) noexcept(std::is_nothrow_move_constructible< Value >::value)
 
 small_vector (std::initializer_list< value_type > il)
 
 small_vector (size_type n)
 
 small_vector (size_type n, value_type const &t)
 
template<class Arg >
 small_vector (Arg arg1, Arg arg2)
 
 ~small_vector ()
 
small_vectoroperator= (small_vector const &o)
 
small_vectoroperator= (small_vector &&o)
 
bool operator== (small_vector const &o) const
 
bool operator< (small_vector const &o) const
 
size_type size () const
 
bool empty () const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
reverse_iterator rbegin ()
 
reverse_iterator rend ()
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator rend () const
 
const_reverse_iterator crbegin () const
 
const_reverse_iterator crend () const
 
void swap (small_vector &o)
 
void resize (size_type sz)
 
void resize (size_type sz, value_type const &v)
 
value_typedata () noexcept
 
value_type const * data () const noexcept
 
template<class... Args>
iterator emplace (const_iterator p, Args &&...args)
 
void reserve (size_type sz)
 
size_type capacity () const
 
void shrink_to_fit ()
 
template<class... Args>
void emplace_back (Args &&...args)
 
void push_back (value_type &&t)
 
void push_back (value_type const &t)
 
void pop_back ()
 
iterator insert (const_iterator constp, value_type &&t)
 
iterator insert (const_iterator p, value_type const &t)
 
iterator insert (const_iterator pos, size_type n, value_type const &val)
 
template<class Arg >
iterator insert (const_iterator p, Arg arg1, Arg arg2)
 
iterator insert (const_iterator p, std::initializer_list< value_type > il)
 
iterator erase (const_iterator q)
 
iterator erase (const_iterator q1, const_iterator q2)
 
void clear ()
 
template<class Arg >
void assign (Arg first, Arg last)
 
void assign (std::initializer_list< value_type > il)
 
void assign (size_type n, const value_type &t)
 
reference front ()
 
reference back ()
 
const_reference front () const
 
const_reference back () const
 
reference operator[] (size_type i)
 
const_reference operator[] (size_type i) const
 
reference at (size_type i)
 
const_reference at (size_type i) const
 

Static Public Member Functions

static constexpr size_type max_size ()
 

Private Types

typedef detail::small_vector_base< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::type BaseType
 
typedef BaseType::InternalSizeType InternalSizeType
 
typedef std::aligned_storage< sizeof(value_type)*MaxInline, alignof(value_type)>::type InlineStorageDataType
 
typedef std::conditional< sizeof(value_type)*MaxInline!=0, InlineStorageDataType, void * >::type InlineStorageType
 
typedef std::conditional< kHasInlineCapacity, HeapPtrWithCapacity, HeapPtr >::type PointerType
 

Private Member Functions

template<class It >
iterator insertImpl (iterator pos, It first, It last, std::false_type)
 
iterator insertImpl (iterator pos, size_type n, const value_type &val, std::true_type)
 
template<class It >
void constructImpl (It first, It last, std::false_type)
 
template<typename InitFunc >
void doConstruct (size_type n, InitFunc &&func)
 
void constructImpl (size_type n, value_type const &val, std::true_type)
 
size_type computeNewSize () const
 
void makeSize (size_type newSize)
 
template<typename EmplaceFunc >
void makeSize (size_type newSize, EmplaceFunc &&emplaceFunc, size_type pos)
 
template<typename EmplaceFunc >
void makeSizeInternal (size_type newSize, bool insert, EmplaceFunc &&emplaceFunc, size_type pos)
 
void setCapacity (size_type newCapacity)
 

Static Private Member Functions

static iterator unconst (const_iterator it)
 

Private Attributes

union folly::small_vector::Data u
 

Static Private Attributes

static constexpr std::size_t MaxInline
 
static bool constexpr kHasInlineCapacity
 
static size_t constexpr kHeapifyCapacitySize
 
static size_t constexpr kHeapifyCapacityThreshold
 

Detailed Description

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
class folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >

Definition at line 92 of file small_vector.h.

Member Typedef Documentation

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef detail:: small_vector_base<Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC>:: type folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::BaseType
private

Definition at line 411 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef value_type const* folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::const_iterator

Definition at line 429 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef value_type const* folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::const_pointer

Definition at line 430 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef value_type const& folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::const_reference

Definition at line 426 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef std::reverse_iterator<const_iterator> folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::const_reverse_iterator

Definition at line 434 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef std::ptrdiff_t folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::difference_type

Definition at line 431 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef std::aligned_storage< sizeof(value_type) * MaxInline, alignof(value_type)>::type folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::InlineStorageDataType
private

Definition at line 1129 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef std::conditional< sizeof(value_type) * MaxInline != 0, InlineStorageDataType, void*>::type folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::InlineStorageType
private

Definition at line 1134 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef BaseType::InternalSizeType folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::InternalSizeType
private

Definition at line 412 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef value_type* folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::iterator

Definition at line 427 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef value_type* folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::pointer

Definition at line 428 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef std:: conditional<kHasInlineCapacity, HeapPtrWithCapacity, HeapPtr>::type folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::PointerType
private

Definition at line 1150 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef value_type& folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::reference

Definition at line 425 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef std::reverse_iterator<iterator> folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::reverse_iterator

Definition at line 433 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef std::size_t folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::size_type

Definition at line 423 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
typedef Value folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::value_type

Definition at line 424 of file small_vector.h.

Constructor & Destructor Documentation

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::small_vector ( )
default
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::small_vector ( const std::allocator< Value > &  )
inline

Definition at line 439 of file small_vector.h.

439 {}
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::small_vector ( small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC > const &  o)
inline

Definition at line 441 of file small_vector.h.

441  {
442  auto n = o.size();
443  makeSize(n);
444  try {
445  std::uninitialized_copy(o.begin(), o.end(), begin());
446  } catch (...) {
447  if (this->isExtern()) {
448  u.freeHeap();
449  }
450  throw;
451  }
452  this->setSize(n);
453  }
union folly::small_vector::Data u
void makeSize(size_type newSize)
Definition: small_vector.h:993
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::small_vector ( small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC > &&  o)
inlinenoexcept

Definition at line 455 of file small_vector.h.

456  {
457  if (o.isExtern()) {
458  swap(o);
459  } else {
460  std::uninitialized_copy(
461  std::make_move_iterator(o.begin()),
462  std::make_move_iterator(o.end()),
463  begin());
464  this->setSize(o.size());
465  }
466  }
void swap(small_vector &o)
Definition: small_vector.h:583
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::small_vector ( std::initializer_list< value_type il)
inline

Definition at line 468 of file small_vector.h.

468  {
469  constructImpl(il.begin(), il.end(), std::false_type());
470  }
void constructImpl(It first, It last, std::false_type)
Definition: small_vector.h:941
bool_constant< false > false_type
Definition: gtest-port.h:2209
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::small_vector ( size_type  n)
inlineexplicit

Definition at line 472 of file small_vector.h.

472  {
473  doConstruct(n, [&](void* p) { new (p) value_type(); });
474  }
void doConstruct(size_type n, InitFunc &&func)
Definition: small_vector.h:967
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::small_vector ( size_type  n,
value_type const &  t 
)
inline

Definition at line 476 of file small_vector.h.

476  {
477  doConstruct(n, [&](void* p) { new (p) value_type(t); });
478  }
void doConstruct(size_type n, InitFunc &&func)
Definition: small_vector.h:967
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
template<class Arg >
folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::small_vector ( Arg  arg1,
Arg  arg2 
)
inlineexplicit

Definition at line 481 of file small_vector.h.

481  {
482  // Forward using std::is_arithmetic to get to the proper
483  // implementation; this disambiguates between the iterators and
484  // (size_t, value_type) meaning for this constructor.
485  constructImpl(arg1, arg2, std::is_arithmetic<Arg>());
486  }
void constructImpl(It first, It last, std::false_type)
Definition: small_vector.h:941
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::~small_vector ( )
inline

Definition at line 488 of file small_vector.h.

488  {
489  for (auto& t : *this) {
490  (&t)->~value_type();
491  }
492  if (this->isExtern()) {
493  u.freeHeap();
494  }
495  }
union folly::small_vector::Data u

Member Function Documentation

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
template<class Arg >
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::assign ( Arg  first,
Arg  last 
)
inline

Definition at line 846 of file small_vector.h.

Referenced by TEST().

846  {
847  clear();
848  insert(end(), first, last);
849  }
iterator insert(const_iterator constp, value_type &&t)
Definition: small_vector.h:769
constexpr detail::First first
Definition: Base-inl.h:2553
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::assign ( std::initializer_list< value_type il)
inline

Definition at line 851 of file small_vector.h.

851  {
852  assign(il.begin(), il.end());
853  }
void assign(Arg first, Arg last)
Definition: small_vector.h:846
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::assign ( size_type  n,
const value_type t 
)
inline

Definition at line 855 of file small_vector.h.

855  {
856  clear();
857  insert(end(), n, t);
858  }
iterator insert(const_iterator constp, value_type &&t)
Definition: small_vector.h:769
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
reference folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::at ( size_type  i)
inline

Definition at line 887 of file small_vector.h.

887  {
888  if (i >= size()) {
889  throw_exception<std::out_of_range>("index out of range");
890  }
891  return (*this)[i];
892  }
size_type size() const
Definition: small_vector.h:527
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_reference folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::at ( size_type  i) const
inline

Definition at line 894 of file small_vector.h.

894  {
895  if (i >= size()) {
896  throw_exception<std::out_of_range>("index out of range");
897  }
898  return (*this)[i];
899  }
size_type size() const
Definition: small_vector.h:527
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
reference folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::back ( )
inline

Definition at line 864 of file small_vector.h.

Referenced by TEST().

864  {
865  assert(!empty());
866  return *(end() - 1);
867  }
bool empty() const
Definition: small_vector.h:530
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_reference folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::back ( ) const
inline

Definition at line 872 of file small_vector.h.

872  {
873  assert(!empty());
874  return *(end() - 1);
875  }
bool empty() const
Definition: small_vector.h:530
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::begin ( )
inline
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::begin ( ) const
inline

Definition at line 540 of file small_vector.h.

540  {
541  return data();
542  }
value_type * data() noexcept
Definition: small_vector.h:684
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
size_type folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::capacity ( ) const
inline

Definition at line 722 of file small_vector.h.

Referenced by folly::small_vector< Observer< T > *, InlineObservers >::swap(), and TEST().

722  {
723  if (this->isExtern()) {
724  if (u.hasCapacity()) {
725  return u.getCapacity();
726  }
727  return malloc_usable_size(u.pdata_.heap_) / sizeof(value_type);
728  }
729  return MaxInline;
730  }
union folly::small_vector::Data u
static constexpr std::size_t MaxInline
Definition: small_vector.h:419
InternalSizeType getCapacity() const
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::cbegin ( ) const
inline

Definition at line 546 of file small_vector.h.

546  {
547  return begin();
548  }
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::cend ( ) const
inline

Definition at line 549 of file small_vector.h.

549  {
550  return end();
551  }
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::clear ( )
inline

Definition at line 841 of file small_vector.h.

841  {
842  erase(begin(), end());
843  }
iterator erase(const_iterator q)
Definition: small_vector.h:822
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
size_type folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::computeNewSize ( ) const
inlineprivate

Definition at line 989 of file small_vector.h.

989  {
990  return std::min((3 * capacity()) / 2 + 1, max_size());
991  }
static constexpr size_type max_size()
Definition: small_vector.h:522
LogLevel min
Definition: LogLevel.cpp:30
size_type capacity() const
Definition: small_vector.h:722
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
template<class It >
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::constructImpl ( It  first,
It  last,
std::false_type   
)
inlineprivate

Definition at line 941 of file small_vector.h.

941  {
942  typedef typename std::iterator_traits<It>::iterator_category categ;
944  // With iterators that only allow a single pass, we can't really
945  // do anything sane here.
946  while (first != last) {
947  emplace_back(*first++);
948  }
949  return;
950  }
951 
952  auto distance = std::distance(first, last);
953  makeSize(distance);
954  this->setSize(distance);
955  try {
957  data(), distance, [&](void* p) { new (p) value_type(*first++); });
958  } catch (...) {
959  if (this->isExtern()) {
960  u.freeHeap();
961  }
962  throw;
963  }
964  }
void emplace_back(Args &&...args)
Definition: small_vector.h:742
union folly::small_vector::Data u
void populateMemForward(T *mem, std::size_t n, Function const &op)
Definition: small_vector.h:156
value_type * data() noexcept
Definition: small_vector.h:684
static const char *const value
Definition: Conv.cpp:50
void makeSize(size_type newSize)
Definition: small_vector.h:993
constexpr detail::First first
Definition: Base-inl.h:2553
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::constructImpl ( size_type  n,
value_type const &  val,
std::true_type   
)
inlineprivate

Definition at line 982 of file small_vector.h.

982  {
983  doConstruct(n, [&](void* p) { new (p) value_type(val); });
984  }
double val
Definition: String.cpp:273
void doConstruct(size_type n, InitFunc &&func)
Definition: small_vector.h:967
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_reverse_iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::crbegin ( ) const
inline

Definition at line 568 of file small_vector.h.

568  {
569  return rbegin();
570  }
reverse_iterator rbegin()
Definition: small_vector.h:553
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_reverse_iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::crend ( ) const
inline

Definition at line 571 of file small_vector.h.

571  {
572  return rend();
573  }
reverse_iterator rend()
Definition: small_vector.h:556
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
value_type* folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::data ( )
inlinenoexcept

Definition at line 684 of file small_vector.h.

684  {
685  return this->isExtern() ? u.heap() : u.buffer();
686  }
union folly::small_vector::Data u
value_type * buffer() noexcept
value_type * heap() noexcept
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
value_type const* folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::data ( ) const
inlinenoexcept

Definition at line 688 of file small_vector.h.

688  {
689  return this->isExtern() ? u.heap() : u.buffer();
690  }
union folly::small_vector::Data u
value_type * buffer() noexcept
value_type * heap() noexcept
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
template<typename InitFunc >
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::doConstruct ( size_type  n,
InitFunc &&  func 
)
inlineprivate

Definition at line 967 of file small_vector.h.

967  {
968  makeSize(n);
969  this->setSize(n);
970  try {
971  detail::populateMemForward(data(), n, std::forward<InitFunc>(func));
972  } catch (...) {
973  if (this->isExtern()) {
974  u.freeHeap();
975  }
976  throw;
977  }
978  }
union folly::small_vector::Data u
void populateMemForward(T *mem, std::size_t n, Function const &op)
Definition: small_vector.h:156
value_type * data() noexcept
Definition: small_vector.h:684
void makeSize(size_type newSize)
Definition: small_vector.h:993
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
template<class... Args>
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::emplace ( const_iterator  p,
Args &&...  args 
)
inline

Definition at line 693 of file small_vector.h.

Referenced by TEST().

693  {
694  if (p == cend()) {
695  emplace_back(std::forward<Args>(args)...);
696  return end() - 1;
697  }
698 
699  /*
700  * We implement emplace at places other than at the back with a
701  * temporary for exception safety reasons. It is possible to
702  * avoid having to do this, but it becomes hard to maintain the
703  * basic exception safety guarantee (unless you respond to a copy
704  * constructor throwing by clearing the whole vector).
705  *
706  * The reason for this is that otherwise you have to destruct an
707  * element before constructing this one in its place---if the
708  * constructor throws, you either need a nothrow default
709  * constructor or a nothrow copy/move to get something back in the
710  * "gap", and the vector requirements don't guarantee we have any
711  * of these. Clearing the whole vector is a legal response in
712  * this situation, but it seems like this implementation is easy
713  * enough and probably better.
714  */
715  return insert(p, value_type(std::forward<Args>(args)...));
716  }
void emplace_back(Args &&...args)
Definition: small_vector.h:742
iterator insert(const_iterator constp, value_type &&t)
Definition: small_vector.h:769
const_iterator cend() const
Definition: small_vector.h:549
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
template<class... Args>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::emplace_back ( Args &&...  args)
inline

Definition at line 742 of file small_vector.h.

Referenced by TEST().

742  {
743  if (capacity() == size()) {
744  // Any of args may be references into the vector.
745  // When we are reallocating, we have to be careful to construct the new
746  // element before modifying the data in the old buffer.
747  makeSize(
748  size() + 1,
749  [&](void* p) { new (p) value_type(std::forward<Args>(args)...); },
750  size());
751  } else {
752  new (end()) value_type(std::forward<Args>(args)...);
753  }
754  this->setSize(size() + 1);
755  }
size_type size() const
Definition: small_vector.h:527
void makeSize(size_type newSize)
Definition: small_vector.h:993
size_type capacity() const
Definition: small_vector.h:722
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
bool folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::empty ( ) const
inline

Definition at line 530 of file small_vector.h.

Referenced by TEST().

530  {
531  return !size();
532  }
size_type size() const
Definition: small_vector.h:527
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::end ( )
inline
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::end ( ) const
inline

Definition at line 543 of file small_vector.h.

543  {
544  return data() + size();
545  }
size_type size() const
Definition: small_vector.h:527
value_type * data() noexcept
Definition: small_vector.h:684
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::erase ( const_iterator  q)
inline

Definition at line 822 of file small_vector.h.

Referenced by TEST().

822  {
823  std::move(unconst(q) + 1, end(), unconst(q));
824  (data() + size() - 1)->~value_type();
825  this->setSize(size() - 1);
826  return unconst(q);
827  }
static iterator unconst(const_iterator it)
Definition: small_vector.h:902
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
size_type size() const
Definition: small_vector.h:527
value_type * data() noexcept
Definition: small_vector.h:684
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::erase ( const_iterator  q1,
const_iterator  q2 
)
inline

Definition at line 829 of file small_vector.h.

829  {
830  if (q1 == q2) {
831  return unconst(q1);
832  }
833  std::move(unconst(q2), end(), unconst(q1));
834  for (auto it = (end() - std::distance(q1, q2)); it != end(); ++it) {
835  it->~value_type();
836  }
837  this->setSize(size() - (q2 - q1));
838  return unconst(q1);
839  }
static iterator unconst(const_iterator it)
Definition: small_vector.h:902
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
size_type size() const
Definition: small_vector.h:527
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
reference folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::front ( )
inline

Definition at line 860 of file small_vector.h.

Referenced by TEST().

860  {
861  assert(!empty());
862  return *begin();
863  }
bool empty() const
Definition: small_vector.h:530
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_reference folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::front ( ) const
inline

Definition at line 868 of file small_vector.h.

868  {
869  assert(!empty());
870  return *begin();
871  }
bool empty() const
Definition: small_vector.h:530
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::insert ( const_iterator  constp,
value_type &&  t 
)
inline

Definition at line 769 of file small_vector.h.

Referenced by TEST().

769  {
770  iterator p = unconst(constp);
771 
772  if (p == end()) {
774  return end() - 1;
775  }
776 
777  auto offset = p - begin();
778 
779  if (capacity() == size()) {
780  makeSize(
781  size() + 1,
782  [&t](void* ptr) { new (ptr) value_type(std::move(t)); },
783  offset);
784  this->setSize(this->size() + 1);
785  } else {
787  data() + offset, data() + size(), data() + size() + 1);
788  this->setSize(size() + 1);
789  data()[offset] = std::move(t);
790  }
791  return begin() + offset;
792  }
void * ptr
static iterator unconst(const_iterator it)
Definition: small_vector.h:902
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
size_type size() const
Definition: small_vector.h:527
value_type * data() noexcept
Definition: small_vector.h:684
void push_back(value_type &&t)
Definition: small_vector.h:757
value_type * iterator
Definition: small_vector.h:427
void makeSize(size_type newSize)
Definition: small_vector.h:993
size_type capacity() const
Definition: small_vector.h:722
std::enable_if< std::is_default_constructible< T >::value &&!folly::is_trivially_copyable< T >::value >::type moveObjectsRight(T *first, T *lastConstructed, T *realLast)
Definition: small_vector.h:108
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::insert ( const_iterator  p,
value_type const &  t 
)
inline

Definition at line 794 of file small_vector.h.

794  {
795  // Make a copy and forward to the rvalue value_type&& overload
796  // above.
797  return insert(p, value_type(t));
798  }
iterator insert(const_iterator constp, value_type &&t)
Definition: small_vector.h:769
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::insert ( const_iterator  pos,
size_type  n,
value_type const &  val 
)
inline

Definition at line 800 of file small_vector.h.

800  {
801  auto offset = pos - begin();
802  makeSize(size() + n);
804  data() + offset, data() + size(), data() + size() + n);
805  this->setSize(size() + n);
806  std::generate_n(begin() + offset, n, [&] { return val; });
807  return begin() + offset;
808  }
double val
Definition: String.cpp:273
size_type size() const
Definition: small_vector.h:527
value_type * data() noexcept
Definition: small_vector.h:684
void makeSize(size_type newSize)
Definition: small_vector.h:993
std::enable_if< std::is_default_constructible< T >::value &&!folly::is_trivially_copyable< T >::value >::type moveObjectsRight(T *first, T *lastConstructed, T *realLast)
Definition: small_vector.h:108
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
template<class Arg >
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::insert ( const_iterator  p,
Arg  arg1,
Arg  arg2 
)
inline

Definition at line 811 of file small_vector.h.

811  {
812  // Forward using std::is_arithmetic to get to the proper
813  // implementation; this disambiguates between the iterators and
814  // (size_t, value_type) meaning for this function.
815  return insertImpl(unconst(p), arg1, arg2, std::is_arithmetic<Arg>());
816  }
iterator insertImpl(iterator pos, It first, It last, std::false_type)
Definition: small_vector.h:909
static iterator unconst(const_iterator it)
Definition: small_vector.h:902
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::insert ( const_iterator  p,
std::initializer_list< value_type il 
)
inline

Definition at line 818 of file small_vector.h.

818  {
819  return insert(p, il.begin(), il.end());
820  }
iterator insert(const_iterator constp, value_type &&t)
Definition: small_vector.h:769
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
template<class It >
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::insertImpl ( iterator  pos,
It  first,
It  last,
std::false_type   
)
inlineprivate

Definition at line 909 of file small_vector.h.

909  {
910  typedef typename std::iterator_traits<It>::iterator_category categ;
912  auto offset = pos - begin();
913  while (first != last) {
914  pos = insert(pos, *first++);
915  ++pos;
916  }
917  return begin() + offset;
918  }
919 
920  auto distance = std::distance(first, last);
921  auto offset = pos - begin();
922  makeSize(size() + distance);
924  data() + offset, data() + size(), data() + size() + distance);
925  this->setSize(size() + distance);
926  std::copy_n(first, distance, begin() + offset);
927  return begin() + offset;
928  }
size_type size() const
Definition: small_vector.h:527
value_type * data() noexcept
Definition: small_vector.h:684
iterator insert(const_iterator constp, value_type &&t)
Definition: small_vector.h:769
static const char *const value
Definition: Conv.cpp:50
void makeSize(size_type newSize)
Definition: small_vector.h:993
std::pair< InIt, OutIt > copy_n(InIt b, typename std::iterator_traits< InIt >::difference_type n, OutIt d)
Definition: FBString.h:130
constexpr detail::First first
Definition: Base-inl.h:2553
std::enable_if< std::is_default_constructible< T >::value &&!folly::is_trivially_copyable< T >::value >::type moveObjectsRight(T *first, T *lastConstructed, T *realLast)
Definition: small_vector.h:108
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::insertImpl ( iterator  pos,
size_type  n,
const value_type val,
std::true_type   
)
inlineprivate

Definition at line 931 of file small_vector.h.

931  {
932  // The true_type means this should call the size_t,value_type
933  // overload. (See insert().)
934  return insert(pos, n, val);
935  }
double val
Definition: String.cpp:273
iterator insert(const_iterator constp, value_type &&t)
Definition: small_vector.h:769
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::makeSize ( size_type  newSize)
inlineprivate

Definition at line 993 of file small_vector.h.

993  {
994  makeSizeInternal(newSize, false, [](void*) { assume_unreachable(); }, 0);
995  }
FOLLY_ALWAYS_INLINE void assume_unreachable()
Definition: Assume.h:59
void makeSizeInternal(size_type newSize, bool insert, EmplaceFunc &&emplaceFunc, size_type pos)
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
template<typename EmplaceFunc >
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::makeSize ( size_type  newSize,
EmplaceFunc &&  emplaceFunc,
size_type  pos 
)
inlineprivate

Definition at line 998 of file small_vector.h.

998  {
999  assert(size() == capacity());
1001  newSize, true, std::forward<EmplaceFunc>(emplaceFunc), pos);
1002  }
size_type size() const
Definition: small_vector.h:527
void makeSizeInternal(size_type newSize, bool insert, EmplaceFunc &&emplaceFunc, size_type pos)
size_type capacity() const
Definition: small_vector.h:722
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
template<typename EmplaceFunc >
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::makeSizeInternal ( size_type  newSize,
bool  insert,
EmplaceFunc &&  emplaceFunc,
size_type  pos 
)
inlineprivate

Definition at line 1015 of file small_vector.h.

1019  {
1020  if (newSize > max_size()) {
1021  throw std::length_error("max_size exceeded in small_vector");
1022  }
1023  if (newSize <= capacity()) {
1024  assert(!insert);
1025  return;
1026  }
1027 
1028  assert(this->kShouldUseHeap);
1029  // This branch isn't needed for correctness, but allows the optimizer to
1030  // skip generating code for the rest of this function in NoHeap
1031  // small_vectors.
1032  if (!this->kShouldUseHeap) {
1033  return;
1034  }
1035 
1036  newSize = std::max(newSize, computeNewSize());
1037 
1038  auto needBytes = newSize * sizeof(value_type);
1039  // If the capacity isn't explicitly stored inline, but the heap
1040  // allocation is grown to over some threshold, we should store
1041  // a capacity at the front of the heap allocation.
1042  bool heapifyCapacity =
1044  if (heapifyCapacity) {
1045  needBytes += kHeapifyCapacitySize;
1046  }
1047  auto const sizeBytes = goodMallocSize(needBytes);
1048  void* newh = checkedMalloc(sizeBytes);
1049  // We expect newh to be at least 2-aligned, because we want to
1050  // use its least significant bit as a flag.
1051  assert(!detail::pointerFlagGet(newh));
1052 
1053  value_type* newp = static_cast<value_type*>(
1054  heapifyCapacity ? detail::shiftPointer(newh, kHeapifyCapacitySize)
1055  : newh);
1056 
1057  try {
1058  if (insert) {
1059  // move and insert the new element
1060  this->moveToUninitializedEmplace(
1061  begin(), end(), newp, pos, std::forward<EmplaceFunc>(emplaceFunc));
1062  } else {
1063  // move without inserting new element
1064  this->moveToUninitialized(begin(), end(), newp);
1065  }
1066  } catch (...) {
1067  free(newh);
1068  throw;
1069  }
1070  for (auto& val : *this) {
1071  val.~value_type();
1072  }
1073 
1074  if (this->isExtern()) {
1075  u.freeHeap();
1076  }
1077  auto availableSizeBytes = sizeBytes;
1078  if (heapifyCapacity) {
1079  u.pdata_.heap_ = detail::pointerFlagSet(newh);
1080  availableSizeBytes -= kHeapifyCapacitySize;
1081  } else {
1082  u.pdata_.heap_ = newh;
1083  }
1084  this->setExtern(true);
1085  this->setCapacity(availableSizeBytes / sizeof(value_type));
1086  }
void * checkedMalloc(size_t size)
Definition: Malloc.h:227
T * pointerFlagSet(T *p)
Definition: small_vector.h:379
LogLevel max
Definition: LogLevel.cpp:31
union folly::small_vector::Data u
static bool constexpr kHasInlineCapacity
static constexpr size_type max_size()
Definition: small_vector.h:522
double val
Definition: String.cpp:273
static size_t constexpr kHeapifyCapacitySize
iterator insert(const_iterator constp, value_type &&t)
Definition: small_vector.h:769
size_type computeNewSize() const
Definition: small_vector.h:989
void * shiftPointer(void *p, size_t sizeBytes)
Definition: small_vector.h:390
void free()
static size_t constexpr kHeapifyCapacityThreshold
bool pointerFlagGet(T *p)
Definition: small_vector.h:383
void setCapacity(size_type newCapacity)
size_t goodMallocSize(size_t minSize) noexcept
Definition: Malloc.h:201
size_type capacity() const
Definition: small_vector.h:722
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
static constexpr size_type folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::max_size ( )
inlinestatic

Definition at line 522 of file small_vector.h.

Referenced by TEST().

522  {
523  return !BaseType::kShouldUseHeap ? static_cast<size_type>(MaxInline)
524  : BaseType::policyMaxSize();
525  }
std::size_t size_type
Definition: small_vector.h:423
static constexpr std::size_t MaxInline
Definition: small_vector.h:419
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
bool folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::operator< ( small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC > const &  o) const
inline

Definition at line 518 of file small_vector.h.

518  {
519  return std::lexicographical_compare(begin(), end(), o.begin(), o.end());
520  }
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
small_vector& folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::operator= ( small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC > const &  o)
inline

Definition at line 497 of file small_vector.h.

497  {
498  if (FOLLY_LIKELY(this != &o)) {
499  assign(o.begin(), o.end());
500  }
501  return *this;
502  }
void assign(Arg first, Arg last)
Definition: small_vector.h:846
#define FOLLY_LIKELY(x)
Definition: Likely.h:35
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
small_vector& folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::operator= ( small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC > &&  o)
inline

Definition at line 504 of file small_vector.h.

504  {
505  // TODO: optimization:
506  // if both are internal, use move assignment where possible
507  if (FOLLY_LIKELY(this != &o)) {
508  clear();
509  swap(o);
510  }
511  return *this;
512  }
void swap(small_vector &o)
Definition: small_vector.h:583
#define FOLLY_LIKELY(x)
Definition: Likely.h:35
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
bool folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::operator== ( small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC > const &  o) const
inline

Definition at line 514 of file small_vector.h.

514  {
515  return size() == o.size() && std::equal(begin(), end(), o.begin());
516  }
size_type size() const
Definition: small_vector.h:527
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
reference folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::operator[] ( size_type  i)
inline

Definition at line 877 of file small_vector.h.

877  {
878  assert(i < size());
879  return *(begin() + i);
880  }
size_type size() const
Definition: small_vector.h:527
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_reference folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::operator[] ( size_type  i) const
inline

Definition at line 882 of file small_vector.h.

882  {
883  assert(i < size());
884  return *(begin() + i);
885  }
size_type size() const
Definition: small_vector.h:527
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::pop_back ( )
inline

Definition at line 765 of file small_vector.h.

765  {
766  erase(end() - 1);
767  }
iterator erase(const_iterator q)
Definition: small_vector.h:822
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::push_back ( value_type &&  t)
inline

Definition at line 757 of file small_vector.h.

Referenced by wangle::Observable< T >::forEachObserver(), wangle::Observable< T >::observe(), and TEST().

757  {
758  return emplace_back(std::move(t));
759  }
void emplace_back(Args &&...args)
Definition: small_vector.h:742
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::push_back ( value_type const &  t)
inline

Definition at line 761 of file small_vector.h.

761  {
762  emplace_back(t);
763  }
void emplace_back(Args &&...args)
Definition: small_vector.h:742
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
reverse_iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::rbegin ( )
inline

Definition at line 553 of file small_vector.h.

553  {
554  return reverse_iterator(end());
555  }
std::reverse_iterator< iterator > reverse_iterator
Definition: small_vector.h:433
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_reverse_iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::rbegin ( ) const
inline

Definition at line 560 of file small_vector.h.

560  {
561  return const_reverse_iterator(end());
562  }
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: small_vector.h:434
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
reverse_iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::rend ( )
inline

Definition at line 556 of file small_vector.h.

556  {
557  return reverse_iterator(begin());
558  }
std::reverse_iterator< iterator > reverse_iterator
Definition: small_vector.h:433
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
const_reverse_iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::rend ( ) const
inline

Definition at line 564 of file small_vector.h.

564  {
565  return const_reverse_iterator(begin());
566  }
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition: small_vector.h:434
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::reserve ( size_type  sz)
inline

Definition at line 718 of file small_vector.h.

Referenced by TEST().

718  {
719  makeSize(sz);
720  }
void makeSize(size_type newSize)
Definition: small_vector.h:993
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::resize ( size_type  sz)
inline

Definition at line 662 of file small_vector.h.

Referenced by TEST().

662  {
663  if (sz < size()) {
664  erase(begin() + sz, end());
665  return;
666  }
667  makeSize(sz);
669  begin() + size(), sz - size(), [&](void* p) { new (p) value_type(); });
670  this->setSize(sz);
671  }
void populateMemForward(T *mem, std::size_t n, Function const &op)
Definition: small_vector.h:156
size_type size() const
Definition: small_vector.h:527
void makeSize(size_type newSize)
Definition: small_vector.h:993
iterator erase(const_iterator q)
Definition: small_vector.h:822
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::resize ( size_type  sz,
value_type const &  v 
)
inline

Definition at line 673 of file small_vector.h.

673  {
674  if (sz < size()) {
675  erase(begin() + sz, end());
676  return;
677  }
678  makeSize(sz);
680  begin() + size(), sz - size(), [&](void* p) { new (p) value_type(v); });
681  this->setSize(sz);
682  }
void populateMemForward(T *mem, std::size_t n, Function const &op)
Definition: small_vector.h:156
size_type size() const
Definition: small_vector.h:527
void makeSize(size_type newSize)
Definition: small_vector.h:993
iterator erase(const_iterator q)
Definition: small_vector.h:822
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::setCapacity ( size_type  newCapacity)
inlineprivate

Definition at line 1092 of file small_vector.h.

Referenced by folly::small_vector< Observer< T > *, InlineObservers >::swap().

1092  {
1093  assert(this->isExtern());
1094  if (u.hasCapacity()) {
1095  assert(newCapacity < std::numeric_limits<InternalSizeType>::max());
1096  u.setCapacity(newCapacity);
1097  }
1098  }
LogLevel max
Definition: LogLevel.cpp:31
union folly::small_vector::Data u
void setCapacity(InternalSizeType c)
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::shrink_to_fit ( )
inline

Definition at line 732 of file small_vector.h.

Referenced by TEST().

732  {
733  if (!this->isExtern()) {
734  return;
735  }
736 
737  small_vector tmp(begin(), end());
738  tmp.swap(*this);
739  }
small_vector()=default
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
size_type folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::size ( ) const
inline
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
void folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::swap ( small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC > &  o)
inline

Definition at line 583 of file small_vector.h.

Referenced by folly::small_vector< Observer< T > *, InlineObservers >::shrink_to_fit(), and folly::swap().

583  {
584  using std::swap; // Allow ADL on swap for our value_type.
585 
586  if (this->isExtern() && o.isExtern()) {
587  this->swapSizePolicy(o);
588 
589  auto thisCapacity = this->capacity();
590  auto oCapacity = o.capacity();
591 
592  auto* tmp = u.pdata_.heap_;
593  u.pdata_.heap_ = o.u.pdata_.heap_;
594  o.u.pdata_.heap_ = tmp;
595 
596  this->setCapacity(oCapacity);
597  o.setCapacity(thisCapacity);
598 
599  return;
600  }
601 
602  if (!this->isExtern() && !o.isExtern()) {
603  auto& oldSmall = size() < o.size() ? *this : o;
604  auto& oldLarge = size() < o.size() ? o : *this;
605 
606  for (size_type i = 0; i < oldSmall.size(); ++i) {
607  swap(oldSmall[i], oldLarge[i]);
608  }
609 
610  size_type i = oldSmall.size();
611  const size_type ci = i;
612  try {
613  for (; i < oldLarge.size(); ++i) {
614  auto addr = oldSmall.begin() + i;
615  new (addr) value_type(std::move(oldLarge[i]));
616  oldLarge[i].~value_type();
617  }
618  } catch (...) {
619  oldSmall.setSize(i);
620  for (; i < oldLarge.size(); ++i) {
621  oldLarge[i].~value_type();
622  }
623  oldLarge.setSize(ci);
624  throw;
625  }
626  oldSmall.setSize(i);
627  oldLarge.setSize(ci);
628  return;
629  }
630 
631  // isExtern != o.isExtern()
632  auto& oldExtern = o.isExtern() ? o : *this;
633  auto& oldIntern = o.isExtern() ? *this : o;
634 
635  auto oldExternCapacity = oldExtern.capacity();
636  auto oldExternHeap = oldExtern.u.pdata_.heap_;
637 
638  auto buff = oldExtern.u.buffer();
639  size_type i = 0;
640  try {
641  for (; i < oldIntern.size(); ++i) {
642  new (&buff[i]) value_type(std::move(oldIntern[i]));
643  oldIntern[i].~value_type();
644  }
645  } catch (...) {
646  for (size_type kill = 0; kill < i; ++kill) {
647  buff[kill].~value_type();
648  }
649  for (; i < oldIntern.size(); ++i) {
650  oldIntern[i].~value_type();
651  }
652  oldIntern.setSize(0);
653  oldExtern.u.pdata_.heap_ = oldExternHeap;
654  oldExtern.setCapacity(oldExternCapacity);
655  throw;
656  }
657  oldIntern.u.pdata_.heap_ = oldExternHeap;
658  this->swapSizePolicy(o);
659  oldIntern.setCapacity(oldExternCapacity);
660  }
std::size_t size_type
Definition: small_vector.h:423
void swap(small_vector< T, MaxInline, A, B, C > &a, small_vector< T, MaxInline, A, B, C > &b)
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
union folly::small_vector::Data u
size_type size() const
Definition: small_vector.h:527
void swap(small_vector &o)
Definition: small_vector.h:583
ThreadPoolListHook * addr
void setCapacity(size_type newCapacity)
size_type capacity() const
Definition: small_vector.h:722
template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
static iterator folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::unconst ( const_iterator  it)
inlinestaticprivate

Definition at line 902 of file small_vector.h.

902  {
903  return const_cast<iterator>(it);
904  }
value_type * iterator
Definition: small_vector.h:427

Member Data Documentation

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
bool constexpr folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::kHasInlineCapacity
staticprivate
Initial value:
=
sizeof(HeapPtrWithCapacity) < sizeof(InlineStorageType)

Definition at line 1136 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
size_t constexpr folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::kHeapifyCapacitySize
staticprivate
Initial value:

Definition at line 1140 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
size_t constexpr folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::kHeapifyCapacityThreshold
staticprivate
Initial value:

Definition at line 1145 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
constexpr std::size_t folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::MaxInline
staticprivate
Initial value:
{
constexpr_max(sizeof(Value*) / sizeof(Value), RequestedMaxInline)}

Definition at line 419 of file small_vector.h.

template<class Value, std::size_t RequestedMaxInline = 1, class PolicyA = void, class PolicyB = void, class PolicyC = void>
union folly::small_vector::Data folly::small_vector< Value, RequestedMaxInline, PolicyA, PolicyB, PolicyC >::u
private

The documentation for this class was generated from the following file: