X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FPadded.h;h=f30e22265bb9dd9dd91edc72beaaebf2b2aae0b4;hp=88282d9d12c80a7f04eb0cbd9ec4d6bde2e1dd68;hb=b22935cd23251a9958f73242cb1dc44dfc75c5f5;hpb=056261eb833b833e8b5edb90f37207c4c622a40d diff --git a/folly/Padded.h b/folly/Padded.h index 88282d9d..f30e2226 100644 --- a/folly/Padded.h +++ b/folly/Padded.h @@ -27,8 +27,8 @@ #include -#include #include +#include /** * Code that aids in storing data aligned on block (possibly cache-line) @@ -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. // @@ -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_++];