yoda
is hosted by
Hepforge
,
IPPP Durham
Home
C++ code docs
Python code docs
Plotting
Downloads
Source code
Contact
YODA - Yet more Objects for Data Analysis
2.0.2
include
YODA
Utils
sortedvector.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-2024 The YODA collaboration (see AUTHORS for details)
5
//
6
#ifndef YODA_SORTEDVECTOR_H
7
#define YODA_SORTEDVECTOR_H
8
9
#include <vector>
10
#include <algorithm>
11
#include <stdexcept>
12
#include <iostream>
13
14
namespace
YODA
{
15
namespace
Utils {
16
17
26
template
<
typename
T>
27
class
sortedvector :
public
std::vector<T> {
28
public
:
29
31
sortedvector() {}
32
34
sortedvector(
const
std::vector<T> & vec)
35
: std::vector<T>(vec) {
36
std::sort(this->begin(), this->end());
37
}
38
40
void
insert(
const
T& val) {
41
// Dumb way:
42
// std::vector<T>::push_back(val);
43
// std::sort(this->begin(), this->end());
44
//
45
// A bit better:
46
std::vector<T>::insert(std::upper_bound(std::vector<T>::begin(), std::vector<T>::end(), val), val);
47
}
48
49
50
private
:
51
53
void
push_back();
54
55
};
56
57
58
}
59
}
60
61
#endif
YODA
Anonymous namespace to limit visibility.
Definition
AnalysisObject.h:17
Generated on Mon Oct 28 2024 13:47:24 for YODA - Yet more Objects for Data Analysis by
1.9.8