boost::sub_range

References

Headers

boost::sub_range is available by including any of the following headers:

  • boost/range/sub_range.hpp or
  • boost/range.hpp

Examples

sub_range.cpp

#include <iostream>
#include <iterator>
#include <sstream>

#include <boost/range.hpp>


int main() {
    std::string s = "Boost Range";

    // sub_range() creates a range object from a begin and end iterator,
    // just like iterator_range() does. However, sub_range() has the container
    // as template type instead of the iterator, making it easier to use.
    //
    // In C++11, auto + make_iterator_range() should largely eliminate the
    // need for explicitly using this class in client code.
    boost::sub_range<std::string> range(s.begin(), s.begin()+5);
    std::cout << range << std::endl;

    return 0;
}

Output:

Boost

 

Boost Range for Humans

This reference is part of Boost Range for Humans. Click the link to the overview.