- Range(const Range<Iter>& str,
- size_t startFrom,
- size_t size) {
- if (UNLIKELY(startFrom > str.size())) {
- throw std::out_of_range("index out of range");
- }
- b_ = str.b_ + startFrom;
- if (str.size() - startFrom < size) {
- e_ = str.e_;
- } else {
- e_ = b_ + size;
- }
- }
- // Works only for Range<const char*>
- /* implicit */ Range(const fbstring& str)
- : b_(str.data()), e_(b_ + str.size()) { }
- // Works only for Range<const char*>
- Range(const fbstring& str, fbstring::size_type startFrom) {
- if (UNLIKELY(startFrom > str.size())) {
- throw std::out_of_range("index out of range");
+
+ Range(const Range& other, size_type first, size_type length = npos)
+ : Range(other.subpiece(first, length)) {}
+
+ template <
+ class Container,
+ class = typename std::enable_if<
+ std::is_same<Iter, typename Container::const_pointer>::value>::type,
+ class = decltype(
+ Iter(std::declval<Container const&>().data()),
+ Iter(
+ std::declval<Container const&>().data() +
+ std::declval<Container const&>().size()))>
+ /* implicit */ constexpr Range(Container const& container)
+ : b_(container.data()), e_(b_ + container.size()) {}
+
+ template <
+ class Container,
+ class = typename std::enable_if<
+ std::is_same<Iter, typename Container::const_pointer>::value>::type,
+ class = decltype(
+ Iter(std::declval<Container const&>().data()),
+ Iter(
+ std::declval<Container const&>().data() +
+ std::declval<Container const&>().size()))>
+ Range(Container const& container, typename Container::size_type startFrom) {
+ auto const cdata = container.data();
+ auto const csize = container.size();
+ if (UNLIKELY(startFrom > csize)) {
+ std::__throw_out_of_range("index out of range");