Promote aligned_malloc and aligned_free
[folly.git] / folly / Utility.h
index bb196080c683ca52a4b86b0ac62bcda89983c765..94141c181c4f56b4980c59e2938d9a0ebf27598c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2016-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.
@@ -262,6 +262,28 @@ inline in_place_index_tag<I> in_place_index(in_place_index_tag<I> = {}) {
 struct initlist_construct_t {};
 constexpr initlist_construct_t initlist_construct{};
 
+/**
+ * A generic tag type to indicate that some constructor or method is in some way
+ * unsafe and should be used only with extreme care and with full test coverage,
+ * if ever.
+ *
+ * Example:
+ *
+ *  void takes_numbers(std::vector<int> alist) {
+ *    std::sort(alist.begin(), alist.end());
+ *    takes_numbers_assume_sorted(folly::unsafe, alist);
+ *  }
+ *
+ *  void takes_numbers_assume_sorted(folly::unsafe_t, std::vector<int> alist) {
+ *    assert(std::is_sorted(alist.begin(), alist.end())); // debug mode only
+ *    for (i : alist) {
+ *      // some behavior which is defined and safe only when alist is sorted ...
+ *    }
+ *  }
+ */
+struct unsafe_t {};
+constexpr unsafe_t unsafe{};
+
 /**
  * A simple function object that passes its argument through unchanged.
  *
@@ -310,4 +332,11 @@ class MoveOnly {
 } // namespace moveonly_
 
 using MoveOnly = moveonly_::MoveOnly;
+
+/**
+ * A pithy alias for std::integral_constant<bool, B>.
+ */
+template <bool B>
+using Bool = std::integral_constant<bool, B>;
+
 } // namespace folly