test_init.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Boost.Flyweight test of static data initialization facilities.
  2. *
  3. * Copyright 2006-2019 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/flyweight for library home page.
  9. */
  10. #include "test_init.hpp"
  11. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  12. #include <boost/detail/lightweight_test.hpp>
  13. #include <boost/flyweight.hpp>
  14. using namespace boost::flyweights;
  15. template<bool* pmark,typename Entry,typename Value>
  16. struct marked_hashed_factory_class:hashed_factory_class<Entry,Value>
  17. {
  18. marked_hashed_factory_class(){*pmark=true;}
  19. };
  20. template<bool* pmark>
  21. struct marked_hashed_factory:factory_marker
  22. {
  23. template<typename Entry,typename Value>
  24. struct apply
  25. {
  26. typedef marked_hashed_factory_class<pmark,Entry,Value> type;
  27. };
  28. };
  29. namespace boost_flyweight_test{
  30. bool mark1=false;
  31. bool init1=flyweight<int,marked_hashed_factory<&mark1> >::init();
  32. bool mark2=false;
  33. flyweight<int,marked_hashed_factory<&mark2> >::initializer init2;
  34. }
  35. void test_init()
  36. {
  37. BOOST_TEST(boost_flyweight_test::mark1);
  38. BOOST_TEST(boost_flyweight_test::mark2);
  39. }