ATLAS Offline Software
Toggle main menu visibility
Loading...
Searching...
No Matches
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
*/
11
12
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
CxxUtils::range_with_at
Add at() methods to a range class.
Definition
range_with_at.h:34
CxxUtils::range_with_at< std::ranges::transform_view< SPAN, XFORM > >::at
decltype(auto) at(size_t i)
Definition
range_with_at.h:39
CxxUtils
Definition
aligned_vector.h:29
CxxUtils::begin
const_iterator begin() const
Return a begin iterator.
CxxUtils::transform_view_with_at
range_with_at< std::ranges::transform_view< SPAN, XFORM > > transform_view_with_at
Helper to add at() methods to a transform_view.
Definition
range_with_at.h:58
CxxUtils::end
const_iterator end() const
Return an end iterator.
CxxUtils::operator[]
bool operator[](bit_t bit) const
Return the value of one bit.
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
throw_out_of_range.h
Helpers for throwing out_of_range exceptions.
Generated on
for ATLAS Offline Software by
1.17.0