test_observers.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Boost.MultiIndex test for observer memfuns.
  2. *
  3. * Copyright 2003-2013 Joaquin M Lopez Munoz.
  4. * Distributed under the Boost Software License, Version 1.0.
  5. * (See accompanying file LICENSE_1_0.txt or copy at
  6. * http://www.boost.org/LICENSE_1_0.txt)
  7. *
  8. * See http://www.boost.org/libs/multi_index for library home page.
  9. */
  10. #include "test_observers.hpp"
  11. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  12. #include <algorithm>
  13. #include <vector>
  14. #include "pre_multi_index.hpp"
  15. #include "employee.hpp"
  16. #include <boost/detail/lightweight_test.hpp>
  17. using namespace boost::multi_index;
  18. void test_observers()
  19. {
  20. employee_set es;
  21. const employee_set_by_name& i1=get<by_name>(es);
  22. const employee_set_by_age& i2=get<age>(es);
  23. es.insert(employee(0,"Joe",31,1123));
  24. es.insert(employee(1,"Robert",27,5601));
  25. es.insert(employee(2,"John",40,7889));
  26. es.insert(employee(3,"Albert",20,9012));
  27. es.insert(employee(4,"John",57,1002));
  28. {
  29. employee_set_by_name::key_from_value k=i1.key_extractor();
  30. employee_set_by_name::hasher h=i1.hash_function();
  31. employee_set_by_name::key_equal eq=i1.key_eq();
  32. employee_set_by_name::const_iterator it0=i1.equal_range("John").first;
  33. employee_set_by_name::const_iterator it1=it0;++it1;
  34. BOOST_TEST(k(*it0)=="John"&&k(*it1)=="John");
  35. BOOST_TEST(h(k(*it0))==h(k(*it1)));
  36. BOOST_TEST(eq(k(*it0),k(*it1))==true);
  37. }
  38. {
  39. employee_set_by_age::key_from_value k=i2.key_extractor();
  40. employee_set_by_age::key_compare c=i2.key_comp();
  41. employee_set_by_age::value_compare vc=i2.value_comp();
  42. employee_set_by_age::const_iterator it0=i2.find(31);
  43. employee_set_by_age::const_iterator it1=i2.find(40);
  44. BOOST_TEST(k(*it0)==31&&k(*it1)==40);
  45. BOOST_TEST(c(k(*it0),k(*it1))==true);
  46. BOOST_TEST(vc(*it0,*it1)==true);
  47. }
  48. }