mCRL2
Loading...
Searching...
No Matches
fixed_vector.h
Go to the documentation of this file.
1// Author(s): David N. Jansen, Radboud Universiteit, Nijmegen, The Netherlands
2//
3// Copyright: see the accompanying file COPYING or copy at
4// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
5//
6// Distributed under the Boost Software License, Version 1.0.
7// (See accompanying file LICENSE_1_0.txt or copy at
8// http://www.boost.org/LICENSE_1_0.txt)
9
23
24#ifndef FIXED_VECTOR_H
25#define FIXED_VECTOR_H
26
27#include <vector>
28#include <cassert>
29
30namespace mcrl2
31{
32namespace lts
33{
34namespace detail
35{
36
37template <class T>
38class fixed_vector : public std::vector<T>
39// class fixed_vector : private std::vector<T> The elements of vector should not be made public. However, with this, the
40// destructor of an iterator does not become visible on windows leading to compilation issues.
41{
42public:
43 // only reveal as much of the interface of std::vector<T> as is needed:
44 using typename std::vector<T>::iterator;
45 using typename std::vector<T>::const_iterator;
46 using typename std::vector<T>::size_type;
47 using std::vector<T>::begin;
48 using std::vector<T>::cbegin;
49 using std::vector<T>::cend;
50 using std::vector<T>::end;
51 using std::vector<T>::front;
52 using std::vector<T>::back;
53 using std::vector<T>::size;
54 using std::vector<T>::clear;
55 using std::vector<T>::empty;
56 using std::vector<T>::data;
57
58 // define pointer access to what is basically &*end().
59 // the compiler will optimize the addition away.
60 T* data_end() { return data() + size(); }
61 const T* data_end() const { return data() + size(); }
62 const T* data_cend() const { return data() + size(); }
63
64 explicit fixed_vector(size_type n) :std::vector<T>(n) { }
65 explicit fixed_vector(size_type n, T init) :std::vector<T>(n, init) { }
66
67#ifdef NDEBUG
68 using std::vector<T>::operator[];
69#else
70 // operator[] calls std::vector<T>::at because the latter checks bounds.
71 T& operator[](size_type n) { return std::vector<T>::at(n); }
72 const T& operator[](size_type n) const { return std::vector<T>::at(n); }
73#endif
74};
75
76} // end namespace detail
77} // end namespace lts
78} // end namespace mcrl2
79
80#endif // #ifndef FIXED_VECTOR_H
A vector class in which aterms can be stored.
Definition vector.h:34
fixed_vector(size_type n, T init)
const T & operator[](size_type n) const
MCRL2_EXPORT bool init(rewriter_interface *i, RewriterCompilingJitty *this_rewriter)
static void clear(CONTAINER &c)
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72
STL namespace.