sapling/eden/fs/utils/SortedInsert.h
Sergey Zhupanov cdc6af4e72 Fixing merge screw-up caught by Adam TYVM
Summary: Fixing merge screw-up in D6597696

Reviewed By: simpkins

Differential Revision: D6662096

fbshipit-source-id: 9d0a615a6991e673c24b591171caf2c7dc19165e
2018-01-04 14:35:26 -08:00

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