CPP/Boost/Bimap

From ProgrammingExamples
< CPP
Revision as of 20:53, 10 March 2011 by Daviddoria (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Bimap.cpp

#include <iostream>
#include <map>
#include <string>
 
#include <boost/bimap/bimap.hpp>
#include <boost/bimap/set_of.hpp>
 
int main()
{
  typedef boost::bimaps::bimap< boost::bimaps::set_of<std::string>, boost::bimaps::set_of<int> > bimap_type;
  bimap_type bm;
  typedef bimap_type::left_map LeftMapType;
  LeftMapType& leftMap = bm.left;
  typedef LeftMapType::value_type LeftValueType;
  typedef LeftMapType::const_iterator ConstLeftIterator;
 
  leftMap.insert( LeftValueType("one",1) );
  ConstLeftIterator leftIterator = leftMap.find("one");
  std::cout << leftIterator->first << " --> " << leftIterator->second << std::endl;
 
  /////////////////////
  typedef bimap_type::right_map RightMapType;
  RightMapType& rightMap = bm.right;
  typedef RightMapType::value_type RightValueType;
  typedef RightMapType::const_iterator ConstRightIterator;
 
  rightMap.insert( RightValueType(2,"two") );
  ConstRightIterator rightIterator = rightMap.find(2);
  std::cout << rightIterator->first << " --> " << rightIterator->second << std::endl;;
 
  return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)
 
Project(Bimap)
 
ADD_EXECUTABLE(Bimap Bimap.cpp)
TARGET_LINK_LIBRARIES(Bimap)