...but still dynamically linking against the core lib But the actual template instantiations happen now within the two compilation units, which are linked statically. When looking into the symbol table, we can see that the static field is emitted two times readelf -W target/clang-static-init -s | c++filt |less
42 lines
539 B
C++
42 lines
539 B
C++
|
|
#include "lib/error.hpp"
|
|
|
|
#include "proc/config-resolver.hpp"
|
|
|
|
namespace test {
|
|
|
|
template<typename T>
|
|
struct Holder
|
|
{
|
|
static T* instance;
|
|
|
|
T&
|
|
get()
|
|
{
|
|
if (!instance)
|
|
{
|
|
instance = new T();
|
|
}
|
|
return *instance;
|
|
}
|
|
};
|
|
|
|
|
|
template<typename T>
|
|
T* Holder<T>::instance;
|
|
|
|
struct Subject
|
|
{
|
|
static int cnt;
|
|
|
|
Subject();
|
|
|
|
};
|
|
|
|
|
|
proc::ConfigResolver& fabricate();
|
|
|
|
|
|
|
|
|
|
} // namespace test
|