I'm trying const_string lib that looks not bad, but it crashes at runtime with access violation(atomic_count, operator++()). The test code:
#include <boost/const_string/const_string.hpp>
#include <boost/const_string/concatenation.hpp>
typedef boost::const_string<wchar_t> wcstring;
class Test
{
private:
const wcstring &s1;
const wcstring &s2;
public:
Test()
: s1(L"")
, s2(L"")
{
}
const wcstring &GetS1()
{
return s1;
}
const wcstring &GetS2()
{
return s2;
}
};
Test t;
int _tmain(int argc, _TCHAR* argv[])
{
//Test t;
wcstring t1 = t.GetS1(); // crashes here
wcstring t2 = t.GetS2();
return 0;
}
It crashes only if t is global. If I move declaration into main(), it's ok. System: VS 2010, boost v. 1.47.0
The question: Am I doing something wrong or is it problem of library / compiler? Can someone recommend a more stable implementation of immutable strings for C++?