summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/flyweight/test/test_init.cpp
blob: 5421b808595593b4c086ab59ce1eb75ab3e53d91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Boost.Flyweight test of static data initialization facilities.
 *
 * Copyright 2006-2019 Joaquin M Lopez Munoz.
 * Distributed under the Boost Software License, Version 1.0.
 * (See accompanying file LICENSE_1_0.txt or copy at
 * http://www.boost.org/LICENSE_1_0.txt)
 *
 * See http://www.boost.org/libs/flyweight for library home page.
 */

#include "test_init.hpp"

#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
#include <boost/detail/lightweight_test.hpp>
#include <boost/flyweight.hpp> 

using namespace boost::flyweights;

template<bool* pmark,typename Entry,typename Value>
struct marked_hashed_factory_class:hashed_factory_class<Entry,Value>
{
  marked_hashed_factory_class(){*pmark=true;}
};

template<bool* pmark>
struct marked_hashed_factory:factory_marker
{
  template<typename Entry,typename Value>
  struct apply
  {
    typedef marked_hashed_factory_class<pmark,Entry,Value> type;
  };
};

namespace boost_flyweight_test{

bool mark1=false;
bool init1=flyweight<int,marked_hashed_factory<&mark1> >::init();

bool mark2=false;
flyweight<int,marked_hashed_factory<&mark2> >::initializer init2;

}

void test_init()
{
  BOOST_TEST(boost_flyweight_test::mark1);
  BOOST_TEST(boost_flyweight_test::mark2);
}