UnboundedQueue: Use alignas instead of FOLLY_ALIGNED
[folly.git] / folly / ConstexprMath.h
index 1650c02c9119d8f75ba12b6899f0bf17e13c52c1..5b0bc51d57d514f713a8b6932fdef62ac012e244 100644 (file)
@@ -41,7 +41,23 @@ constexpr T constexpr_min(T a) {
 }
 template <typename T, typename... Ts>
 constexpr T constexpr_min(T a, T b, Ts... ts) {
-  return b < a ? constexpr_max(b, ts...) : constexpr_max(a, ts...);
+  return b < a ? constexpr_min(b, ts...) : constexpr_min(a, ts...);
+}
+
+template <typename T, typename Less>
+constexpr T const&
+constexpr_clamp(T const& v, T const& lo, T const& hi, Less less) {
+  return less(v, lo) ? lo : less(hi, v) ? hi : v;
+}
+
+template <typename T>
+constexpr T const& constexpr_clamp(T const& v, T const& lo, T const& hi) {
+  struct Less {
+    constexpr bool operator()(T const& a, T const& b) const {
+      return a < b;
+    }
+  };
+  return constexpr_clamp(v, lo, hi, Less{});
 }
 
 namespace detail {
@@ -99,4 +115,11 @@ constexpr T constexpr_log2(T t) {
   return detail::constexpr_log2(T(0), t);
 }
 
+template <typename T>
+constexpr T constexpr_ceil(T t, T round) {
+  return round == T(0)
+      ? t
+      : ((t + (t < T(0) ? T(0) : round - T(1))) / round) * round;
+}
+
 } // namespace folly