projection.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 <iostream>
  21. #include <boost/bimap/bimap.hpp>
  22. #include <boost/bimap/multiset_of.hpp>
  23. using namespace boost::bimaps;
  24. void years_example()
  25. {
  26. //[ code_projection_years
  27. typedef bimap<std::string,multiset_of<int,std::greater<int> > > bm_type;
  28. bm_type bm;
  29. bm.insert( bm_type::value_type("John" ,34) );
  30. bm.insert( bm_type::value_type("Peter",24) );
  31. bm.insert( bm_type::value_type("Mary" ,12) );
  32. // Find the name of the next younger person after Peter
  33. bm_type::left_const_iterator name_iter = bm.left.find("Peter");
  34. bm_type::right_const_iterator years_iter = bm.project_right(name_iter);
  35. ++years_iter;
  36. std::cout << "The next younger person after Peter is " << years_iter->second;
  37. //]
  38. }
  39. int main()
  40. {
  41. years_example();
  42. return 0;
  43. }