#define _CRT_SECURE_NO_DEPRECATE
#define _SCL_SECURE_NO_DEPRECATE
#include <boost/config.hpp>
#include <iostream>
#include <boost/tokenizer.hpp>
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/unordered_set_of.hpp>
#include <boost/bimap/list_of.hpp>
using namespace boost::bimaps;
struct counter {
counter() : c(0) {}
counter& operator++() { ++c; return *this; }
unsigned int operator++(int) { return c++; }
operator const unsigned int() const { return c; }
private:
unsigned int c;
};
int main()
{
typedef bimap
<
unordered_set_of< std::string >,
list_of< counter >
> word_counter;
typedef boost::tokenizer<boost::char_separator<char> > text_tokenizer;
std::string text=
"Relations between data in the STL are represented with maps."
"A map is a directed relation, by using it you are representing "
"a mapping. In this directed relation, the first type is related to "
"the second type but it is not true that the inverse relationship "
"holds. This is useful in a lot of situations, but there are some "
"relationships that are bidirectional by nature.";
word_counter wc;
text_tokenizer tok(text,boost::char_separator<char>(" \t\n.,;:!?'\"-"));
for( text_tokenizer::const_iterator it = tok.begin(), it_end = tok.end();
it != it_end ; ++it )
{
++ wc.left[*it];
}
for( word_counter::right_const_iterator
wit = wc.right.begin(), wit_end = wc.right.end();
wit != wit_end; ++wit )
{
std::cout << wit->second << ": " << wit->first;
}
return 0;
}