CppUtils-Impl.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_CPP_UTILS_IMPL_HPP
12 #define CUBBYFLOW_CPP_UTILS_IMPL_HPP
13 
14 #include <algorithm>
15 
16 namespace CubbyFlow
17 {
18 // Source code from:
19 // http://en.cppreference.com/w/cpp/algorithm/lower_bound
20 template <class ForwardIter, class T, class Compare>
21 ForwardIter BinaryFind(ForwardIter first, ForwardIter last, const T& value,
22  Compare comp)
23 {
24  // Note: Both type T and the type after ForwardIt is dereferenced
25  // must be implicitly convertible to both Type1 and Type2, used in Compare.
26  // This is stricter than lower_bound requirement (see above)
27  first = std::lower_bound(first, last, value, comp);
28  return first != last && !comp(value, *first) ? first : last;
29 }
30 } // namespace CubbyFlow
31 
32 #endif
ForwardIter BinaryFind(ForwardIter first, ForwardIter last, const T &value, Compare comp)
Definition: CppUtils-Impl.hpp:21
Definition: pybind11Utils.hpp:20