Commit e52b2964 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Remove unsafe tag and add presorted tag

Summary:
[Folly] Remove `unsafe` tag and add `presorted` tag.

There are varieties of unsafety, so let us be more explicit about which variety of unsafety is invoked in each case.

Differential Revision: D6758520

fbshipit-source-id: d198a3c7601971460f91acc7787c9da02ae283c0
parent f3585b22
...@@ -263,26 +263,25 @@ struct initlist_construct_t {}; ...@@ -263,26 +263,25 @@ struct initlist_construct_t {};
constexpr initlist_construct_t initlist_construct{}; constexpr initlist_construct_t initlist_construct{};
/** /**
* A generic tag type to indicate that some constructor or method is in some way * A generic tag type to indicate that some constructor or method accepts a
* unsafe and should be used only with extreme care and with full test coverage, * presorted container.
* if ever.
* *
* Example: * Example:
* *
* void takes_numbers(std::vector<int> alist) { * void takes_numbers(std::vector<int> alist) {
* std::sort(alist.begin(), alist.end()); * std::sort(alist.begin(), alist.end());
* takes_numbers_assume_sorted(folly::unsafe, alist); * takes_numbers_assume_sorted(folly::presorted, alist);
* } * }
* *
* void takes_numbers_assume_sorted(folly::unsafe_t, std::vector<int> alist) { * void takes_numbers(folly::presorted_t, std::vector<int> alist) {
* assert(std::is_sorted(alist.begin(), alist.end())); // debug mode only * assert(std::is_sorted(alist.begin(), alist.end())); // debug mode only
* for (i : alist) { * for (i : alist) {
* // some behavior which is defined and safe only when alist is sorted ... * // some behavior which is defined and safe only when alist is sorted ...
* } * }
* } * }
*/ */
struct unsafe_t {}; struct presorted_t {};
constexpr unsafe_t unsafe{}; constexpr presorted_t presorted{};
/** /**
* A simple function object that passes its argument through unchanged. * A simple function object that passes its argument through unchanged.
......
...@@ -297,21 +297,21 @@ class sorted_vector_set ...@@ -297,21 +297,21 @@ class sorted_vector_set
Container&& container, Container&& container,
const Compare& comp = Compare()) const Compare& comp = Compare())
: sorted_vector_set( : sorted_vector_set(
unsafe, presorted,
detail::as_sorted(std::move(container), comp), detail::as_sorted(std::move(container), comp),
comp) {} comp) {}
// Construct a sorted_vector_set by stealing the storage of a prefilled // Construct a sorted_vector_set by stealing the storage of a prefilled
// container. The container must be sorted, as unsafe_t hints. This supports // container. The container must be sorted, as presorted_t hints. Supports
// bulk construction of sorted_vector_set with zero allocations, not counting // bulk construction of sorted_vector_set with zero allocations, not counting
// those performed by the caller. (The iterator range constructor performs at // those performed by the caller. (The iterator range constructor performs at
// least one allocation). // least one allocation).
// //
// Note that `sorted_vector_set(unsafe_t, const Container& container)` is not // Note that `sorted_vector_set(presorted_t, const Container& container)` is
// provided, since the purpose of this constructor is to avoid an unnecessary // not provided, since the purpose of this constructor is to avoid an extra
// copy. // copy.
sorted_vector_set( sorted_vector_set(
unsafe_t, presorted_t,
Container&& container, Container&& container,
const Compare& comp = Compare()) const Compare& comp = Compare())
: m_(comp, container.get_allocator()) { : m_(comp, container.get_allocator()) {
...@@ -626,21 +626,21 @@ class sorted_vector_map ...@@ -626,21 +626,21 @@ class sorted_vector_map
Container&& container, Container&& container,
const Compare& comp = Compare()) const Compare& comp = Compare())
: sorted_vector_map( : sorted_vector_map(
unsafe, presorted,
detail::as_sorted(std::move(container), value_compare(comp)), detail::as_sorted(std::move(container), value_compare(comp)),
comp) {} comp) {}
// Construct a sorted_vector_map by stealing the storage of a prefilled // Construct a sorted_vector_map by stealing the storage of a prefilled
// container. The container must be sorted, as unsafe_t hints. This supports // container. The container must be sorted, as presorted_t hints. S supports
// bulk construction of sorted_vector_map with zero allocations, not counting // bulk construction of sorted_vector_map with zero allocations, not counting
// those performed by the caller. (The iterator range constructor performs at // those performed by the caller. (The iterator range constructor performs at
// least one allocation). // least one allocation).
// //
// Note that `sorted_vector_map(unsafe_t, const Container& container)` is not // Note that `sorted_vector_map(presorted_t, const Container& container)` is
// provided, since the purpose of this constructor is to avoid an unnecessary // not provided, since the purpose of this constructor is to avoid an extra
// copy. // copy.
sorted_vector_map( sorted_vector_map(
unsafe_t, presorted_t,
Container&& container, Container&& container,
const Compare& comp = Compare()) const Compare& comp = Compare())
: m_(value_compare(comp), container.get_allocator()) { : m_(value_compare(comp), container.get_allocator()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment