folly::padded::Adaptor

Adaptor around a STL sequence container.

Synopsis

Declared in <folly/Padded.h>

template<class Container>
class Adaptor;

Description

Converts a sequence of Node into a sequence of its underlying elements (with enough functionality to make it useful, although it's not fully compatible with the STL container requirements, see below).

Provides iterators (of the same category as those of the underlying container), size(), front(), back(), push_back(), pop_back(), and const / non-const versions of operator[]the underlying container supports them). Does not provide push_front() / pop_front() or arbitrary insert / emplace / erase. Also provides reserve() / capacity() if supported by the underlying container.

Yes, it's called Adaptor, not Adapter, as that's the name used by the STL and by boost. Deal with it.

Internally, we hold a container of Node and the number of elements in the last block. We don't keep empty blocks, so the number of elements in the last block is always between 1 and Node::kElementCount (inclusive). (this is true if the container is empty as well to make push_back() simpler, see the implementation of the size() method for details).

Type Aliases

NameDescription
Node The underlying node type.
const_iterator Const element iterator.
const_reference Const reference to an element.
difference_type Signed difference type between iterators.
iterator Mutable element iterator.
reference Reference to an element.
size_type Unsigned size type.
value_type The underlying element type.

Member Functions

NameDescription
Adaptor [constructor]Constructors
operator= Assignment operators
back back overloads
begin begin overloads
capacity Returns the current element capacity.
cbegin Returns a const iterator to the first element.
cend Returns a const iterator past the last element.
clear Removes all elements.
emplace_back Constructs a new element in place at the end.
empty Reports whether the adaptor holds no elements.
end end overloads
front front overloads
max_size Returns the maximum number of elements the adaptor can hold.
move Return the underlying container and number of elements in the last block, and clear *this. Useful when you want to process the data as Nodes (again) and want to avoid copies.
operator[] Accesses the element at the given index.
padToFullNode Pads the last node up to a full node with a fill value.
peek Return a const reference to the underlying container and the current number of elements in the last block.
pop_back Removes the last element.
push_back Appends an element at the end.
reserve Reserves capacity for at least n elements.
size Returns the number of elements.
swap Swaps the contents of this adaptor with another.

Static Data Members

NameDescription
kElementsPerNode The number of elements stored per node.