Simbody  3.7
IteratorRange.h
Go to the documentation of this file.
1 #ifndef SimTK_SimTKCOMMON_ITERATOR_RANGE_H_
2 #define SimTK_SimTKCOMMON_ITERATOR_RANGE_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm): SimTKcommon *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11  * *
12  * Portions copyright (c) 2016 Stanford University and the Authors. *
13  * Authors: Chris Dembia *
14  * Contributors: *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
27 namespace SimTK {
28 
56 // http://stackoverflow.com/questions/6167598/why-was-pair-range-access-removed-from-c11
57 template <class Iterator>
59 public:
62  IteratorRange(Iterator first, Iterator last)
63  : m_first(first), m_last(last) {}
64  explicit IteratorRange(const std::pair<Iterator, Iterator>& range)
65  : m_first(range.first), m_last(range.second) {}
66  Iterator begin() const { return m_first; }
67  Iterator end() const { return m_last; }
68 private:
69  const Iterator m_first;
70  const Iterator m_last;
71 };
72 
78 template <class Iterator>
79 IteratorRange<Iterator> makeIteratorRange(Iterator first, Iterator last) {
80  return IteratorRange<Iterator>(first, last);
81 }
86 template <class Iterator>
88  const std::pair<Iterator, Iterator>& range) {
89  return IteratorRange<Iterator>(range);
90 }
91 
92 } // namespace SimTK
93 
94 #endif // SimTK_SimTKCOMMON_ITERATOR_RANGE_H_
Iterator begin() const
Definition: IteratorRange.h:66
This is the top-level SimTK namespace into which all SimTK names are placed to avoid collision with o...
Definition: Assembler.h:37
IteratorRange< Iterator > makeIteratorRange(const std::pair< Iterator, Iterator > &range)
Make an IteratorRange object to be used in a range-based for loop, using an std::pair of iterators...
Definition: IteratorRange.h:87
IteratorRange(Iterator first, Iterator last)
This constructor allows you to iterate over the range [first, last); this means last won&#39;t be reached...
Definition: IteratorRange.h:62
Iterator end() const
Definition: IteratorRange.h:67
Helper class to use range-based for loops with a pair of iterators.
Definition: IteratorRange.h:58
IteratorRange(const std::pair< Iterator, Iterator > &range)
Definition: IteratorRange.h:64
IteratorRange< Iterator > makeIteratorRange(Iterator first, Iterator last)
Make an IteratorRange object to be used in a range-based for loop, using two iterators.
Definition: IteratorRange.h:79