X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FPadded.h;h=f30e22265bb9dd9dd91edc72beaaebf2b2aae0b4;hp=93b37ab4e4abfee37e47d73259150a220053db58;hb=015306906e2811cc0cf3dab0c4142d45434a2801;hpb=fa172175980b13569ba42008202a857af6e959dd diff --git a/folly/Padded.h b/folly/Padded.h index 93b37ab4..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 @@ -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