iteration_range.h revision 80afd02024d20e60b197d3adfbb43cc303cf29e0
1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef ART_RUNTIME_BASE_ITERATION_RANGE_H_ 18#define ART_RUNTIME_BASE_ITERATION_RANGE_H_ 19 20namespace art { 21 22// Helper class that acts as a container for range-based loops, given an iteration 23// range [first, last) defined by two iterators. 24template <typename Iter> 25class IterationRange { 26 public: 27 typedef Iter iterator; 28 typedef typename std::iterator_traits<Iter>::difference_type difference_type; 29 typedef typename std::iterator_traits<Iter>::value_type value_type; 30 typedef typename std::iterator_traits<Iter>::pointer pointer; 31 typedef typename std::iterator_traits<Iter>::reference reference; 32 33 IterationRange(iterator first, iterator last) : first_(first), last_(last) { } 34 35 iterator begin() const { return first_; } 36 iterator end() const { return last_; } 37 iterator cbegin() const { return first_; } 38 iterator cend() const { return last_; } 39 40 private: 41 iterator first_; 42 iterator last_; 43}; 44 45} // namespace art 46 47#endif // ART_RUNTIME_BASE_ITERATION_RANGE_H_ 48