Range.h
Go to the documentation of this file.
1 /*!
2  *
3  *
4  * \brief Helper Methods to use with boost range.
5  *
6  *
7  *
8  *
9  * \author Oswin Krause
10  * \date 2012
11  *
12  *
13  * \par Copyright 1995-2015 Shark Development Team
14  *
15  * <BR><HR>
16  * This file is part of Shark.
17  * <http://image.diku.dk/shark/>
18  *
19  * Shark is free software: you can redistribute it and/or modify
20  * it under the terms of the GNU Lesser General Public License as published
21  * by the Free Software Foundation, either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * Shark is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU Lesser General Public License for more details.
28  *
29  * You should have received a copy of the GNU Lesser General Public License
30  * along with Shark. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
33 #ifndef SHARK_CORE_RANGE_H
34 #define SHARK_CORE_RANGE_H
35 #include <boost/range.hpp>
36 #include <utility>
37 #include <shark/Core/Exception.h>
38 
39 namespace shark{
40 ///\brief returns the size of a range
41 ///
42 /// This is just a fix to a bug of boost::size which produces a lot of useless warnings
43 template<class Range>
44 std::size_t size(Range const& range){
45  return (std::size_t)boost::size(range);
46 }
47 ///\brief returns the i-th element of a range
48 template<class Range>
49 typename boost::range_reference<Range>::type
50 get( Range& range, std::size_t i){
51  SIZE_CHECK(i < shark::size(range));
52  typename boost::range_iterator<Range>::type pos=boost::begin(range);
53  std::advance(pos,i);
54  return *pos;
55 }
56 template<class Range>
57 typename boost::range_reference<Range const>::type
58 get( Range const& range, std::size_t i){
59  SIZE_CHECK(i < shark::size(range));
60  typename boost::range_iterator<Range const>::type pos=boost::begin(range);
61  std::advance(pos,i);
62  return *pos;
63 }
64 
65 
66 }
67 #endif