X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2FPadded.h;h=5eeabfdd8b4b55fdb50286797827789b7a04d2c2;hb=HEAD;hp=ca499aad0f70ad0626f620c06aca676caa400ce9;hpb=520e20a8baebc98a5ec84d67865da4cf9819f88a;p=folly.git diff --git a/folly/Padded.h b/folly/Padded.h index ca499aad..5eeabfdd 100644 --- a/folly/Padded.h +++ b/folly/Padded.h @@ -1,5 +1,5 @@ /* - * Copyright 2017 Facebook, Inc. + * Copyright 2012-present Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,8 +27,8 @@ #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