ATLAS Offline Software
Loading...
Searching...
No Matches
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
18#include <ranges>
19#include <stdexcept>
20
21
22namespace CxxUtils {
23
24
31template <class RANGE>
33 : public RANGE
34{
35public:
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
57template <std::ranges::input_range SPAN, class 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.
64template <class T>
65auto begin (range_with_at<T>& s) { return s.begin(); }
66template <class T>
67auto begin (const range_with_at<T>& s) { return s.begin(); }
68template <class T>
69auto end (range_with_at<T>& s) { return s.end(); }
70template <class T>
71auto 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
Add at() methods to a range class.
auto end(range_with_at< T > &s)
range_with_at< std::ranges::transform_view< SPAN, XFORM > > transform_view_with_at
Helper to add at() methods to a transform_view.
void throw_out_of_range(const std::string &what, size_t index, size_t size, const void *obj)
Throw an out_of_range exception.
auto begin(range_with_at< T > &s)
Helpers for throwing out_of_range exceptions.