ATLAS Offline Software
range_with_at.h
Go to the documentation of this file.
1 // This file's extension implies that it's C, but it's really -*- C++ -*-.
2 /*
3  * Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
4  */
13 #ifndef CXXUTILS_RANGE_WITH_AT_H
14 #define CXXUTILS_RANGE_WITH_AT_H
15 
16 
17 #include <ranges>
18 #include <stdexcept>
19 
20 
21 namespace CxxUtils {
22 
23 
30 template <class RANGE>
32  : public RANGE
33 {
34 public:
35  using RANGE::RANGE;
36 
37 
38  decltype(auto) at (size_t i)
39  {
40  if (i >= std::size(*this))
41  throw std::out_of_range ("CxxUtils::range_with_at");
42  return this->operator[] (i);
43  }
44 
45 
46  decltype(auto) at (size_t i) const
47  {
48  if (i >= std::size(*this))
49  throw std::out_of_range ("CxxUtils::range_with_at");
50  return this->operator[] (i);
51  }
52 };
53 
54 
56 template <std::ranges::input_range SPAN, class XFORM>
59 
60 
61 // Stand-alone begin/end functions, findable by ADL.
62 // Needed to work around issues seen when root 6.30.04 is used with gcc14.
63 template <class T>
64 auto begin (range_with_at<T>& s) { return s.begin(); }
65 template <class T>
66 auto begin (const range_with_at<T>& s) { return s.begin(); }
67 template <class T>
68 auto end (range_with_at<T>& s) { return s.end(); }
69 template <class T>
70 auto end (const range_with_at<T>& s) { return s.end(); }
71 
72 
73 } // namespace CxxUtils
74 
75 
76 #endif // not CXXUTILS_RANGE_WITH_AT_H
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
CxxUtils::range_with_at::at
decltype(auto) at(size_t i)
Definition: range_with_at.h:38
lumiFormat.i
int i
Definition: lumiFormat.py:92
CxxUtils
Definition: aligned_vector.h:29
CxxUtils::end
auto end(range_with_at< T > &s)
Definition: range_with_at.h:68
CxxUtils::range_with_at
Add at() methods to a range class.
Definition: range_with_at.h:33
CxxUtils::begin
auto begin(range_with_at< T > &s)
Definition: range_with_at.h:64