2016-05-12 23:43:17 +03:00
|
|
|
/*
|
2019-06-20 02:58:25 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-05-12 23:43:17 +03:00
|
|
|
*
|
2019-06-20 02:58:25 +03:00
|
|
|
* This software may be used and distributed according to the terms of the
|
|
|
|
* GNU General Public License version 2.
|
2016-05-12 23:43:17 +03:00
|
|
|
*/
|
2019-10-11 15:26:59 +03:00
|
|
|
|
2016-05-12 23:43:17 +03:00
|
|
|
#pragma once
|
2018-01-03 21:57:03 +03:00
|
|
|
|
2017-11-04 01:58:04 +03:00
|
|
|
#include <algorithm>
|
2016-05-12 23:43:17 +03:00
|
|
|
|
|
|
|
namespace facebook {
|
|
|
|
namespace eden {
|
|
|
|
|
|
|
|
// Generic function to insert an item in sorted order
|
|
|
|
template <typename T, typename COMP, typename CONT>
|
|
|
|
inline typename CONT::iterator sorted_insert(CONT& vec, T&& val, COMP compare) {
|
|
|
|
auto find =
|
|
|
|
std::lower_bound(vec.begin(), vec.end(), std::forward<T>(val), compare);
|
|
|
|
if (find != vec.end() && !compare(val, *find)) {
|
|
|
|
// Already exists
|
|
|
|
return find;
|
|
|
|
}
|
|
|
|
return vec.emplace(find, val);
|
|
|
|
}
|
|
|
|
|
2017-11-04 01:58:04 +03:00
|
|
|
} // namespace eden
|
|
|
|
} // namespace facebook
|