/usr/include/hphp/util/range.h is in hhvm-dev 3.11.1+dfsg-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | /*
+----------------------------------------------------------------------+
| HipHop for PHP |
+----------------------------------------------------------------------+
| Copyright (c) 2010-2015 Facebook, Inc. (http://www.facebook.com) |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
*/
#ifndef RANGE_H_
#define RANGE_H_
#include "hphp/util/meta.h"
namespace HPHP {
/**
* DefaultRangePolicy --
* MappedRangePolicy --
* KeyRangePolicy --
*
* Parameters to Range<...>.
*
* Type functions for pulling values out of types. Both a compile-time
* function providing the type value_type, and a runtime function extract().
*/
template<typename Iter>
struct DefaultRangePolicy {
typedef typename match_iterator<
Iter,
typename std::iterator_traits<Iter>::value_type
>::type value_type;
static value_type& extract(const Iter& i) {
return *i;
}
};
template<typename Iter>
struct MappedRangePolicy {
typedef typename match_iterator<
Iter,
typename Iter::value_type::second_type
>::type value_type;
static value_type& extract(const Iter& i) {
return i->second;
}
};
template<typename Iter>
struct KeyRangePolicy {
// The keys in a map cannot be mutable.
typedef typename boost::add_const<typename Iter::value_type::first_type
>::type value_type;
value_type& extract(const Iter& i) {
return i->first;
}
};
/**
* IterRange --
*
* A Range encapsulating forward iteration over typical iterators,
* including pointers.
*
* You can control mutability and the iterator type, and the mapping from
* iterators to range values, via It and RangePolicy. Mutation
* happens in the underlying containers, assuming well-behaved iterators.
*
* E.g., mutable range of ints:
* Range<vector<int>::iterator> rng;
*
* Immutable range of the ints in a string->int map:
* typedef map<string, int> SIMap;
* Range<SIMap::const_iterator, MappedRangePolicy> rng;
*/
template<typename Iter,
template<typename> class RangePolicy = DefaultRangePolicy>
class IterRange {
typedef RangePolicy<Iter> Extractor;
public:
typedef typename Extractor::value_type value_type;
IterRange(const Iter& begin, const Iter& end) :
m_next(begin), m_end(end) {}
IterRange(const IterRange& r) :
m_next(r.m_next), m_end(r.m_end) {}
IterRange& operator=(const IterRange& r) {
m_next = r.m_next;
m_end = r.m_end;
return *this;
}
value_type& front() const {
return Extractor::extract(m_next);
}
value_type& popFront() {
value_type& tmp = front();
m_next++;
return tmp;
}
bool empty() const { return m_next == m_end; }
// Support begin() and end() so this can be used with range-based
// for.
Iter begin() const { return m_next; }
Iter end() const { return m_end; }
private:
Iter m_next, m_end;
};
/**
* Range --
*
* A range that spans an STL-like container. Just adds a convenience constructor
* for begin()/end() ranges.
*/
template<typename Cont,
typename It = typename Cont::const_iterator,
template<typename> class RangePolicy = DefaultRangePolicy>
struct Range : public IterRange<It, RangePolicy> {
explicit Range(typename match_iterator<It, Cont>::type& c) :
IterRange<It, RangePolicy>(c.begin(), c.end()) { }
using IterRange<It,RangePolicy>::begin;
using IterRange<It,RangePolicy>::end;
};
}
#endif /* RANGE_H_ */
|