| Example Program Rooted Iterators Example for some functions for handling (rooted) iterators. File "rooted_iterator.cpp"
1 | #include <iostream>
2 | #include <seqan/sequence.h>
3 | #include <seqan/file.h>
4 |
5 | int main()
6 | {
7 | seqan::String<char> str = "abcdefg";
The Iterator metafunction returns a rooted iterator by default. We can also specify the iterator kind explicitly by passing the iterator spec Rooted as second argument.
8 | seqan::Iterator<seqan::String<char>, seqan::Rooted>::Type it = begin(str);
The same iterator spec can be used as a tag for functions that return an iterator, e.g. begin or end
9 | it = end(str, seqan::Rooted());
A rooted iterator "knows" its container, so it supports the function container:
10 | std::cout << container(it); //output: "abcdefg"
Moreover, it is possible to apply functions like goBegin or position to rooted iterators without specify the container.
11 | std::cout << position(it); //output: 7
12 |
13 | return 0;
14 | }
See container, end, Iterator, Iterator Spec, position See Also Iterator Basics SeqAn - Sequence Analysis Library - www.seqan.de