ATLAS Offline Software
Control
CxxUtils
CxxUtils
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-2025 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 "
CxxUtils/throw_out_of_range.h
"
18
#include <ranges>
19
#include <stdexcept>
20
21
22
namespace
CxxUtils
{
23
24
31
template
<
class
RANGE>
32
class
range_with_at
33
:
public
RANGE
34
{
35
public
:
36
using
RANGE::RANGE;
37
38
39
decltype(
auto
)
at
(
size_t
i
)
40
{
41
if
(
i
>=
std::size
(*
this
))
42
throw_out_of_range
(__PRETTY_FUNCTION__,
i
,
std::size
(*
this
),
this
);
43
return
this->
operator[]
(i);
44
}
45
46
47
decltype(
auto
)
at
(
size_t
i
)
const
48
{
49
if
(
i
>=
std::size
(*
this
))
50
throw_out_of_range
(__PRETTY_FUNCTION__,
i
,
std::size
(*
this
),
this
);
51
return
this->
operator[]
(i);
52
}
53
};
54
55
57
template
<std::ranges::input_range SPAN,
class
XFORM>
58
using
transform_view_with_at
=
59
range_with_at<std::ranges::transform_view<SPAN, XFORM>
>;
60
61
62
// Stand-alone begin/end functions, findable by ADL.
63
// Needed to work around issues seen when root 6.30.04 is used with gcc14.
64
template
<
class
T>
65
auto
begin
(
range_with_at<T>
&
s
) {
return
s
.begin(); }
66
template
<
class
T>
67
auto
begin
(
const
range_with_at<T>
&
s
) {
return
s
.begin(); }
68
template
<
class
T>
69
auto
end
(
range_with_at<T>
&
s
) {
return
s
.end(); }
70
template
<
class
T>
71
auto
end
(
const
range_with_at<T>
&
s
) {
return
s
.end(); }
72
73
74
}
// namespace CxxUtils
75
76
77
#endif // not CXXUTILS_RANGE_WITH_AT_H
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:39
CxxUtils::throw_out_of_range
void throw_out_of_range(const std::string &what, size_t index, size_t size, const void *obj)
Throw an out_of_range exception.
Definition:
throw_out_of_range.cxx:27
lumiFormat.i
int i
Definition:
lumiFormat.py:85
throw_out_of_range.h
Helpers for throwing out_of_range exceptions.
CxxUtils
Definition:
aligned_vector.h:29
CxxUtils::end
auto end(range_with_at< T > &s)
Definition:
range_with_at.h:69
columnar::operator[]
ObjectId< CI, CM > operator[](std::size_t) const noexcept
Definition:
ObjectRange.h:169
CxxUtils::range_with_at
Add at() methods to a range class.
Definition:
range_with_at.h:34
python.SystemOfUnits.s
float s
Definition:
SystemOfUnits.py:147
CxxUtils::begin
auto begin(range_with_at< T > &s)
Definition:
range_with_at.h:65
Generated on Sun Oct 26 2025 21:16:52 for ATLAS Offline Software by
1.8.18