CppUtils-Impl.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: CppUtils-Impl.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: C++ utility methods for CubbyFlow.
6 > Created Time: 2017/09/26
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_CPP_UTILS_IMPL_H
10 #define CUBBYFLOW_CPP_UTILS_IMPL_H
11 
12 #include <algorithm>
13 
14 namespace CubbyFlow
15 {
16  // Source code from:
17  // http://en.cppreference.com/w/cpp/algorithm/lower_bound
18  template <class ForwardIter, class T, class Compare>
19  ForwardIter BinaryFind(ForwardIter first, ForwardIter last, const T& value, Compare comp)
20  {
21  // Note: Both type T and the type after ForwardIt is dereferenced
22  // must be implicitly convertible to both Type1 and Type2, used in Compare.
23  // This is stricter than lower_bound requirement (see above)
24  first = std::lower_bound(first, last, value, comp);
25  return first != last && !comp(value, *first) ? first : last;
26  }
27 }
28 
29 #endif
ForwardIter BinaryFind(ForwardIter first, ForwardIter last, const T &value, Compare comp)
Definition: CppUtils-Impl.h:19
Definition: pybind11Utils.h:24