Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:05:32

0001 #ifndef TrackingTools_DetLayers_rangesIntersect_h
0002 #define TrackingTools_DetLayers_rangesIntersect_h
0003 
0004 /** Utility for checking efficiently if two one-dimantional intervals
0005  *  intersect.
0006  *  Precondition: the intervals are not empty, i.e. for i in a,b
0007  *  i.first <= i.second.
0008  *  The Range template argument is expected to have the std::pair
0009  *  interface, i.e. for Range instance r r.first is the beginning of
0010  *  the interval and r.second is the end of the interval.
0011  */
0012 
0013 // Disable bitwise-instead-of-logical warning, see discussion in
0014 // https://github.com/cms-sw/cmssw/issues/39105
0015 
0016 #if defined(__clang__) && defined(__has_warning)
0017 #if __has_warning("-Wbitwise-instead-of-logical")
0018 #pragma clang diagnostic push
0019 #pragma clang diagnostic ignored "-Wbitwise-instead-of-logical"
0020 #endif
0021 #endif
0022 
0023 template <typename Range>
0024 inline bool rangesIntersect(const Range& a, const Range& b) {
0025   return !((a.first > b.second) | (b.first > a.second));
0026 }
0027 
0028 template <typename Range, typename Less>
0029 inline bool rangesIntersect(const Range& a, const Range& b, Less const& less) {
0030   return !(less(b.second, a.first) | less(a.second, b.first));
0031 }
0032 template <typename Range, typename T>
0033 inline bool rangesIntersect(const Range& a, const Range& b, bool (*less)(T, T)) {
0034   return !(less(b.second, a.first) | less(a.second, b.first));
0035 }
0036 
0037 #if defined(__clang__) && defined(__has_warning)
0038 #if __has_warning("-Wbitwise-instead-of-logical")
0039 #pragma clang diagnostic pop
0040 #endif
0041 #endif
0042 
0043 #endif