A lightweight, non‐owning view over a range of elements.
Synopsis
Declared in <folly/Range.h>
template<class Iter>
class Range;
Description
A Range refers to the half‐open interval [begin, end)] delimited by a pair of iterators. It does not own or manage the underlying data, so the referenced storage must outlive the range.
Type Aliases
Name |
Description |
The constant iterator type over the range. |
|
The corresponding range type with a constant element type. |
|
The constant reference type to an element of the range. |
|
The signed integer type used for iterator differences. |
|
The iterator type over the range. |
|
The reference type to an element of the range. |
|
The unsigned integer type used for sizes and offsets. |
|
The character‐traits‐like type used for element comparisons. |
|
The type of the elements referenced by the range. |
Member Functions
Name |
Description |
|
Constructors |
Assignment operators |
|
Advance the beginning of the range by a number of elements. |
|
Assign start and end iterators |
|
Access the element at a given index with bounds checking. |
|
Access the last element. |
|
Get the iterator to the first element. |
|
Get a copy of this range with a constant element type. |
|
Get the constant iterator to the first element. |
|
Get the constant iterator past the last element. |
|
Clear start and end iterators |
|
Lexicographically compare this range with another. |
|
|
|
Get a pointer or iterator to the first element. |
|
Check whether the range is empty. |
|
Get the iterator past the last element. |
|
|
|
|
|
Compare this range with another for equality, using a custom comparator. |
|
Remove the items in [b, e), as long as this subrange is at the beginning] or end of the Range. |
|
|
|
|
|
Access the first element. |
|
Access the element at a given index without bounds checking. |
|
Remove the last element from the range. |
|
Remove the first element from the range. |
|
|
|
|
|
Replaces all occurrences of 'source' with 'dest'. Returns number of replacements made. Source and dest have to have the same length. Throws if the lengths are different. If 'source' is a pattern that is overlapping with itself, we perform sequential replacement: "aaaaaaa".replaceAll("aa", "ba") ‐‐> "bababaa" |
|
Replaces the content of the range, starting at position 'pos', with contents of 'replacement'. Entire 'replacement' must fit into the range. Returns false if 'replacements' does not fit. Example use: |
|
|
|
Find the last occurrence of an element. |
|
Get the number of elements in the range. |
|
|
|
Get the iterator to the first element. |
|
|
|
|
|
Convert the range to a std::string. Works only for Range<const char*> and Range<char*>. |
|
Return a window into the current range, starting at first, and spanning length characters (or until the end of the current range, whichever comes first). |
|
Return a substring window into the range. Works only for character ranges. |
|
Retract the end of the range by a number of elements. |
|
Swap the contents of this range with another. |
|
|
|
Convert the range to a std::string. |
|
Advance the beginning of the range without bounds checking. |
|
Return a subrange window without bounds checking. |
|
Retract the end of the range without bounds checking. |
|
Get the number of elements by walking the iterators. |
|
Conversion operators |
Static Data Members
Name |
Description |
Sentinel offset returned by search functions when no match is found. |
Non-Member Functions
Name |
Description |
Create a constant range referencing a constant C array. |
|
Create a constant range referencing an initializer list. |
|
Create a constant range referencing the contents of a container. |
|
Create a constant range referencing a constant std::array. |
|
Decode a value from a given buffer, advances data past the returned value. Throws on error. |
|
Compare two ranges for inequality. |
|
Inequality operator |
|
Create a range from a |
|
Create a StringPiece from a |
|
Create a range from a |
|
Create a range from a |
|
Create a range from a |
|
Test whether one range is lexicographically less than another. |
|
Test whether one range is lexicographically less than or equal to another. |
|
Three‐way comparison operator |
|
Templated comparison operators |
|
Equality operator |
|
Test whether one range is lexicographically greater than another. |
|
Test whether one range is lexicographically greater than or equal to another. |
|
Finds the first occurrence of needle in haystack. The result is the offset reported to the beginning of haystack, or string::npos if needle wasn't found. |
|
Finds the first occurrence of needle in haystack. The algorithm is on average faster than O(haystack.size() * needle.size()) but not as fast as Boyer‐Moore. On the upside, it does not do any upfront preprocessing and does not allocate memory. |
|
Finds the first occurrence of any element of needle in haystack. The algorithm is O(haystack.size() * needle.size()). |
|
Find the first occurrence of any element of needles in haystack, using a custom comparator. |
|
Create a range referencing a C array. |
|
Create a range referencing a constant std::array. |
|
Create a range referencing the contents of a contiguous‐storage container. |
|
Create a range referencing an initializer list. |
|
Create a range from two iterators, with type deduction. |
|
Create a range referencing the contents of a constant container. |
|
Create a range referencing a std::array. |
|
Create a range referencing a constant C array. |
|
Finds the last occurrence of needle in haystack. The result is the offset reported to the beginning of haystack, or string::npos if needle wasn't found. |
|
Swap the contents of two ranges. |
|
Returns a range that enumerates the set in order‐preserving reinsertion order. |
|
Returns a range that enumerates the set in order‐preserving reinsertion order. |
|
Returns a range that enumerates the map in order‐preserving reinsertion order. |
|
A variant of decodeVarint() that does not throw on error. Useful in contexts where only part of a serialized varint may be attempted to be decoded, e.g., when a serialized varint arrives on the boundary of a network packet. |
Created with MrDocs