Skip to content

Commit

Permalink
sorted_unique_t, sorted_equivalent_t
Browse files Browse the repository at this point in the history
Summary:
[Folly] `sorted_unique_t`, `sorted_equivalent_t`, backporting from p0429 and C++20.

Note that the existing `presorted_t` is ambiguous between `sorted_unique_t` as is assumed in `sorted_vector_set` and `sorted_vector_map` and `sorted_equivalent` as is assumed in `TDigest`.

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p0429r6.pdf

Reviewed By: Orvid

Differential Revision: D15215532

fbshipit-source-id: d90379d609088c6b306a0fc5c7db9b1ad3cdeee8
  • Loading branch information
yfeldblum authored and facebook-github-bot committed May 10, 2019
1 parent fe95b7f commit 1c0529a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions folly/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,53 @@ inline in_place_index_tag<I> in_place_index(in_place_index_tag<I> = {}) {
struct initlist_construct_t {};
constexpr initlist_construct_t initlist_construct{};

// sorted_unique_t, sorted_unique
//
// A generic tag type and value to indicate that some constructor or method
// accepts a container in which the values are sorted and unique.
//
// Example:
//
// void takes_numbers(folly::sorted_unique_t, std::vector<int> alist) {
// assert(std::is_sorted(alist.begin(), alist.end()));
// assert(std::unique(alist.begin(), alist.end()) == alist.end());
// for (i : alist) {
// // some behavior which safe only when alist is sorted and unique
// }
// }
// void takes_numbers(std::vector<int> alist) {
// std::sort(alist.begin(), alist.end());
// alist.erase(std::unique(alist.begin(), alist.end()), alist.end());
// takes_numbers(folly::sorted_unique, alist);
// }
//
// mimic: std::sorted_unique_t, std::sorted_unique, p0429r6
struct sorted_unique_t {};
constexpr sorted_unique_t sorted_unique;

// sorted_equivalent_t, sorted_equivalent
//
// A generic tag type and value to indicate that some constructor or method
// accepts a container in which the values are sorted but not necessarily
// unique.
//
// Example:
//
// void takes_numbers(folly::sorted_equivalent_t, std::vector<int> alist) {
// assert(std::is_sorted(alist.begin(), alist.end()));
// for (i : alist) {
// // some behavior which safe only when alist is sorted
// }
// }
// void takes_numbers(std::vector<int> alist) {
// std::sort(alist.begin(), alist.end());
// takes_numbers(folly::sorted_equivalent, alist);
// }
//
// mimic: std::sorted_equivalent_t, std::sorted_equivalent, p0429r6
struct sorted_equivalent_t {};
constexpr sorted_equivalent_t sorted_equivalent;

/**
* A generic tag type to indicate that some constructor or method accepts a
* presorted container.
Expand Down

0 comments on commit 1c0529a

Please sign in to comment.