folly::FunctionScheduler: Adding support for uniform interval distribution
[folly.git] / folly / Padded.h
index e359ea117d3b8a1123ef42d5da778dd14f9ae25b..9f8af135e2d6b7d1499e829e539657a1888a3ce0 100644 (file)
@@ -28,6 +28,7 @@
 #include <boost/iterator/iterator_adaptor.hpp>
 
 #include <folly/Portability.h>
+#include <folly/ContainerTraits.h>
 
 /**
  * Code that aids in storing data aligned on block (possibly cache-line)
@@ -350,7 +351,7 @@ class Adaptor {
 
   Adaptor(const Adaptor&) = default;
   Adaptor& operator=(const Adaptor&) = default;
-  Adaptor(Adaptor&& other) /* may throw */
+  Adaptor(Adaptor&& other) noexcept
     : c_(std::move(other.c_)),
       lastCount_(other.lastCount_) {
     other.lastCount_ = Node::kElementCount;
@@ -424,12 +425,13 @@ class Adaptor {
     return c_.back().data()[lastCount_ - 1];
   }
 
+  template <typename... Args>
+  void emplace_back(Args&&... args) {
+    new (allocate_back()) value_type(std::forward<Args>(args)...);
+  }
+
   void push_back(value_type x) {
-    if (lastCount_ == Node::kElementCount) {
-      c_.emplace_back();
-      lastCount_ = 0;
-    }
-    c_.back().data()[lastCount_++] = std::move(x);
+    emplace_back(std::move(x));
   }
 
   void pop_back() {
@@ -490,6 +492,14 @@ class Adaptor {
   }
 
  private:
+  value_type* allocate_back() {
+    if (lastCount_ == Node::kElementCount) {
+      container_emplace_back_or_push_back(c_);
+      lastCount_ = 0;
+    }
+    return &c_.back().data()[lastCount_++];
+  }
+
   static Node fullNode(const value_type& value) {
     Node n;
     std::fill(n.data(), n.data() + kElementsPerNode, value);