X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FPadded.h;h=f30e22265bb9dd9dd91edc72beaaebf2b2aae0b4;hb=6e7e5a64d39ea0f2ed11660f46c4ba4d926ff419;hp=0a772a2d56fceb458d4e9a95b4775960d799bfdc;hpb=ed8c80a0e0988e4ce687f51ca832a00e4a6b7930;p=folly.git diff --git a/folly/Padded.h b/folly/Padded.h index 0a772a2d..f30e2226 100644 --- a/folly/Padded.h +++ b/folly/Padded.h @@ -28,7 +28,7 @@ #include #include -#include +#include /** * Code that aids in storing data aligned on block (possibly cache-line) @@ -67,7 +67,7 @@ struct NodeValid::type> { typedef void type; }; -} // namespace detail +} // namespace detail template class Node::type> { @@ -145,6 +145,33 @@ template class Iterator; namespace detail { +template +struct padded_emplace_back_or_push_back_ { + static decltype(auto) go(Container& container, Args&&... args) { + using Value = typename Container::value_type; + return container.push_back(Value(std::forward(args)...)); + } +}; + +template +struct padded_emplace_back_or_push_back_< + void_t().emplace_back(std::declval()...))>, + Container, + Args...> { + static decltype(auto) go(Container& container, Args&&... args) { + return container.emplace_back(std::forward(args)...); + } +}; + +template +decltype(auto) padded_emplace_back_or_push_back( + Container& container, + Args&&... args) { + using impl = padded_emplace_back_or_push_back_; + return impl::go(container, std::forward(args)...); +} + // Helper class to transfer the constness from From (a lvalue reference) // and create a lvalue reference to To. // @@ -190,7 +217,7 @@ struct IteratorBase { > type; }; -} // namespace detail +} // namespace detail /** * Wrapper around iterators to Node to return iterators to the underlying @@ -385,7 +412,7 @@ class Adaptor { iterator end() { auto it = iterator(c_.end()); if (lastCount_ != Node::kElementCount) { - it -= (Node::kElementCount - lastCount_); + it -= difference_type(Node::kElementCount - lastCount_); } return it; } @@ -495,7 +522,7 @@ class Adaptor { private: value_type* allocate_back() { if (lastCount_ == Node::kElementCount) { - container_emplace_back_or_push_back(c_); + detail::padded_emplace_back_or_push_back(c_); lastCount_ = 0; } return &c_.back().data()[lastCount_++]; @@ -510,5 +537,5 @@ class Adaptor { size_t lastCount_; // number of elements in last Node }; -} // namespace padded -} // namespace folly +} // namespace padded +} // namespace folly