bughunt: attempt to rebuild the problematic structure stand-alone... --> MISS

this is only a stripped-down version of the basic singleton, without
the indirection. Unsurprisingly, this doesn't exhibit the problem yet
This commit is contained in:
Fischlurch 2013-10-06 17:37:01 +02:00
parent 0e8a1f1e08
commit 675b2070ce
4 changed files with 28 additions and 16 deletions

View file

@ -14,7 +14,7 @@ envR.Append(CPPPATH='research')
# build additional test and administrative tools.... # build additional test and administrative tools....
experiments = [ envR.Program('try', ['try.cpp'] + support_lib) #### to try out some feature... experiments = [ envR.Program('try', ['try.cpp'] + support_lib) #### to try out some feature...
, envR.Program('clang-static-init', ['clang-static-init-1.cpp', 'clang-static-init-2.cpp'] + core) , envR.Program('clang-static-init', ['clang-static-init-1.cpp', 'clang-static-init-2.cpp'])
] ]
# #

View file

@ -1,11 +1,9 @@
#include "lib/test/run.hpp"
#include "clang-static-init.hpp" #include "clang-static-init.hpp"
#include <iostream> #include <iostream>
using ::test::Test;
using std::cout; using std::cout;
using std::endl; using std::endl;
@ -16,7 +14,7 @@ main (int, char**)
{ {
cout << "\n.gulp.\n"; cout << "\n.gulp.\n";
Subject& ref1 = fab(); Subject& ref1 = fab.get();
Subject& sub2 = test::fabricate(); Subject& sub2 = test::fabricate();
cout << "sub1="<< &ref1 << " sub2="<< &sub2 <<"\n"; cout << "sub1="<< &ref1 << " sub2="<< &sub2 <<"\n";

View file

@ -20,16 +20,16 @@ namespace test {
namespace { namespace {
lib::singleton::UseSubclass<Subject> typeID; //
} }
Factory fab(typeID); AccessPoint fab;
Subject& Subject&
fabricate() fabricate()
{ {
return fab(); return fab.get();
} }

View file

@ -1,12 +1,10 @@
#include "lib/error.hpp"
#include "lib/singleton-subclass.hpp"
namespace test { namespace test {
template<typename T> template<typename T
,template <class> class Fac
>
struct Holder struct Holder
{ {
static T* instance; static T* instance;
@ -16,15 +14,31 @@ namespace test {
{ {
if (!instance) if (!instance)
{ {
instance = new T(); instance = Fac<T>::create();
} }
return *instance; return *instance;
} }
}; };
template<typename T
,template <class> class F
>
T* Holder<T,F>::instance;
template<typename T> template<typename T>
T* Holder<T>::instance; struct Factory
{
static T*
create()
{
return new T();
}
};
struct Subject struct Subject
{ {
@ -34,9 +48,9 @@ namespace test {
}; };
typedef lib::SingletonSub<Subject> Factory; typedef Holder<Subject,Factory> AccessPoint;
extern Factory fab; extern AccessPoint fab;