assign.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Boost.Bimap
  2. //
  3. // Copyright (c) 2006-2007 Matias Capeletto
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. // (See accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. // VC++ 8.0 warns on usage of certain Standard Library and API functions that
  9. // can be cause buffer overruns or other possible security issues if misused.
  10. // See https://web.archive.org/web/20071014014301/http://msdn.microsoft.com/msdnmag/issues/05/05/SafeCandC/default.aspx
  11. // But the wording of the warning is misleading and unsettling, there are no
  12. // portable alternative functions, and VC++ 8.0's own libraries use the
  13. // functions in question. So turn off the warnings.
  14. #define _CRT_SECURE_NO_DEPRECATE
  15. #define _SCL_SECURE_NO_DEPRECATE
  16. // Boost.Bimap Example
  17. //-----------------------------------------------------------------------------
  18. #include <boost/config.hpp>
  19. #include <string>
  20. #include <boost/assign/list_of.hpp>
  21. #include <boost/assign/list_inserter.hpp>
  22. #include <boost/bimap/bimap.hpp>
  23. #include <boost/bimap/multiset_of.hpp>
  24. #include <boost/bimap/list_of.hpp>
  25. using namespace boost::bimaps;
  26. using namespace boost;
  27. int main()
  28. {
  29. //[ code_bimap_and_boost_assign
  30. typedef bimap< multiset_of< int >, list_of< std::string > > bm_type;
  31. // We can use assign::list_of to initialize the container.
  32. bm_type bm = assign::list_of< bm_type::relation > /*<
  33. Note that `bm_type::relation` has to be used instead of `bm_type::value_type`.
  34. Contrary to `value_type`, `relation` type stores the elements as non const, a
  35. requirement of `assign::list_of` >*/
  36. ( 1, "one" )
  37. ( 2, "two" )
  38. ( 3, "three" );
  39. // The left map view is a multiset, again we use insert
  40. assign::insert( bm.left )
  41. ( 4, "four" )
  42. ( 5, "five" )
  43. ( 6, "six" );
  44. // The right map view is a list so we use push_back here
  45. // Note the order of the elements in the list!
  46. assign::push_back( bm.right )
  47. ( "seven" , 7 )
  48. ( "eight" , 8 );
  49. assign::push_front( bm.right )
  50. ( "nine" , 9 )
  51. ( "ten" , 10 )
  52. ( "eleven", 11 );
  53. // Since it is left_based the main view is a multiset, so we use insert
  54. assign::insert( bm )
  55. ( 12, "twelve" )
  56. ( 13, "thirteen" );
  57. //]
  58. return 0;
  59. }