KASKADE 7 development version
views.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2002-2011 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef UTILITIES_VIEWS_HH
14#define UTILITIES_VIEWS_HH
15
16#include <iterator>
17
18namespace Kaskade
19{
23template <class It>
25{
26public:
27 typedef It iterator;
28 typedef It const_iterator;
29 typedef typename std::iterator_traits<It>::value_type value_type;
30
31
32
33 RangeView(It first_, It last_): first(first_), last(last_) {}
34
35 const iterator begin() const { return first; }
36 const iterator end() const { return last; }
37
38 bool empty() const { return first==last; }
39 size_t size() const { return std::distance(first,last); }
40
41
42
43 value_type const& operator[](int i) const
44 {
45 iterator it = first;
46 std::advance(it,i);
47 return *it;
48 }
49
50private:
51 iterator first, last;
52};
53
54
58template <class It>
59RangeView<It> rangeView(It first, It last) { return RangeView<It>(first,last); }
60} // end of namespace Kaskade
61
62#endif
DEPRECATED. Use boost::iterator_range instead.
Definition: views.hh:25
RangeView(It first_, It last_)
Definition: views.hh:33
const iterator begin() const
Definition: views.hh:35
const iterator end() const
Definition: views.hh:36
value_type const & operator[](int i) const
Definition: views.hh:43
std::iterator_traits< It >::value_type value_type
Definition: views.hh:29
bool empty() const
Definition: views.hh:38
size_t size() const
Definition: views.hh:39
Scalar distance(Point< Scalar, dim > const &first, Point< Scalar, dim > const &second)
RangeView< It > rangeView(It first, It last)
Convenience function for constructing range views on the fly.
Definition: views.hh:59