yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.0
indexedset.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of YODA -- Yet more Objects for Data Analysis
4// Copyright (C) 2008-2023 The YODA collaboration (see AUTHORS for details)
5//
6#ifndef YODA_INDEXEDSET_H
7#define YODA_INDEXEDSET_H
8
9#include <set>
10#include <stdexcept>
11#include <iostream>
12
13namespace YODA {
14 namespace Utils {
15
16
23 template <typename T>
24 class indexedset : public std::set<T> {
25 public:
26
27
31 const T& operator[](size_t index) const {
32 if (index >= this->size()) {
33 throw std::range_error("Requested index larger than indexed set size");
34 }
35 size_t i = 0;
36 for (typename indexedset<T>::const_iterator it = this->begin(); it != this->end(); ++it) {
37 // std::cout << i << "/" << index << ", " << (*it) << std::endl;
38 if (i == index) return *it;
39 i += 1;
40 }
41 // This should never be called: just keeping the compiler happy:
42 return (*this)[0];
43 }
44
45
46 };
47
48
49 }
50}
51
52#endif
Anonymous namespace to limit visibility.