Boost C++ Libraries Home Libraries People FAQ More


Getting started

How to use
Example needle in a haystack

The boost::segmented_tree::seq container supports the interfaces of std::vector and std::deque, it can be used in the same way as these containers with a few exceptions:

Boost.SegmentedTree is a header only C++11 library and it does not depend on any other Boost libraries. Simply include boost/segmented_tree/seq.hpp to start using it.

#include <algorithm>
#include <iostream>
#include <boost/segmented_tree/seq.hpp>

int main() {
  boost::segmented_tree::seq<std::string> haystack(100000, "hay");
  haystack.insert(haystack.nth(33333), "needle");
  auto first = haystack.begin();
  auto last = haystack.end();
  auto it = std::find(first, last, "needle");
  if (it != last) {
    std::cout << "Found needle at index: " << haystack.index_of(it) << "\n";