Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-27 07:23:57

0001 // This file is part of the ACTS project.
0002 //
0003 // Copyright (C) 2016 CERN for the benefit of the ACTS project
0004 //
0005 // This Source Code Form is subject to the terms of the Mozilla Public
0006 // License, v. 2.0. If a copy of the MPL was not distributed with this
0007 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
0008 
0009 #pragma once
0010 
0011 // Project include(s)
0012 #include "detray/definitions/detail/qualifiers.hpp"
0013 #include "detray/utils/find_bound.hpp"
0014 #include "detray/utils/ranges/detail/iterator_functions.hpp"
0015 #include "detray/utils/sort.hpp"
0016 
0017 // System include(s)
0018 #include <algorithm>
0019 
0020 namespace detray {
0021 
0022 /// @brief sequential (single thread) sort function
0023 template <std::random_access_iterator rand_iter_t,
0024           std::sentinel_for<rand_iter_t> sentinel_t>
0025 DETRAY_HOST_DEVICE inline void sequential_sort(rand_iter_t first,
0026                                                sentinel_t last) {
0027 #if defined(DETRAY_NO_DEVICE)
0028   std::ranges::sort(first, last);
0029 #else
0030   detray::detail::selection_sort(first, last);
0031 #endif
0032 }
0033 
0034 /// @brief find_if implementation for host/device (single thread)
0035 template <std::random_access_iterator rand_iter_t,
0036           std::sentinel_for<rand_iter_t> sentinel_t, class Predicate>
0037 DETRAY_HOST_DEVICE inline auto find_if(rand_iter_t first, sentinel_t last,
0038                                        Predicate&& comp) {
0039   for (rand_iter_t i = first; i != last; ++i) {
0040     if (std::forward<Predicate>(comp)(*i)) {
0041       return i;
0042     }
0043   }
0044 
0045   return last;
0046 }
0047 
0048 /// @brief lower_bound implementation for host/device
0049 template <std::forward_iterator forw_iter_t,
0050           std::sentinel_for<forw_iter_t> sentinel_t, typename Value>
0051 DETRAY_HOST_DEVICE inline auto lower_bound(forw_iter_t first, sentinel_t last,
0052                                            const Value& value) {
0053 #if defined(DETRAY_NO_DEVICE)
0054   return std::ranges::lower_bound(first, last, value);
0055 #else
0056   return detray::detail::lower_bound(first, last, value);
0057 #endif
0058 }
0059 
0060 /// @brief upper_bound implementation for host/device
0061 template <std::forward_iterator forw_iter_t,
0062           std::sentinel_for<forw_iter_t> sentinel_t, typename Value>
0063 DETRAY_HOST_DEVICE inline auto upper_bound(forw_iter_t first, sentinel_t last,
0064                                            const Value& value) {
0065 #if defined(DETRAY_NO_DEVICE)
0066   return std::ranges::upper_bound(first, last, value);
0067 #else
0068   return detray::detail::upper_bound(first, last, value);
0069 #endif
0070 }
0071 
0072 }  // namespace detray