mirror of
https://github.com/facebook/sapling.git
synced 2024-10-10 00:45:18 +03:00
cdc6af4e72
Summary: Fixing merge screw-up in D6597696 Reviewed By: simpkins Differential Revision: D6662096 fbshipit-source-id: 9d0a615a6991e673c24b591171caf2c7dc19165e
31 lines
845 B
C++
31 lines
845 B
C++
/*
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
*/
|
|
#pragma once
|
|
|
|
#include <algorithm>
|
|
|
|
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);
|
|
}
|
|
|
|
} // namespace eden
|
|
} // namespace facebook
|