https://mooseframework.inl.gov
KokkosUtils.h
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #pragma once
11 
12 #include "KokkosHeader.h"
13 
14 namespace Moose
15 {
16 namespace Kokkos
17 {
18 namespace Utils
19 {
20 
28 template <typename T>
29 KOKKOS_INLINE_FUNCTION const T *
30 find(const T & target, const T * const begin, const T * const end)
31 {
32  if (begin == end)
33  return end;
34 
35  auto left = begin;
36  auto right = end - 1;
37 
38  while (left <= right)
39  {
40  auto mid = left + (right - left) / 2;
41 
42  if (*mid == target)
43  return mid;
44  else if (*mid < target)
45  left = mid + 1;
46  else
47  right = mid - 1;
48  }
49 
50  return end;
51 }
52 
53 } // namespace Utils
54 } // namespace Kokkos
55 } // namespace Moose
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
Definition: KokkosUtils.h:30
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...