Ticket #3435: trivial_singleton.hpp.patch

File trivial_singleton.hpp.patch, 1.5 KB (added by Andrey Semashev, 13 years ago)

The fix modifies the way singleton instance is acquired

  • ./boost/test/utils/

    old new  
    3535template<typename Derived>
    3636class singleton : private boost::noncopyable {
    3737public:
    38     static Derived& instance() { static Derived the_inst; return the_inst; }   
     38    static Derived& instance();
    3939protected:
    4040    singleton()  {}
    4141    ~singleton() {}
    4242};
    4343
    44 } // namespace unit_test
     44
     45#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
     46template< typename T >
     47T& get_static_instance()
     48{
     49    static T inst;
     50    return inst;
     51}
     52
     53template<typename Derived>
     54inline Derived& singleton< Derived >::instance()
     55{
     56    return get_static_instance< Derived >();
     57}
     58
     59#define BOOST_TEST_SINGLETON_CONS( type )       \
     60template< typename T > friend T& boost::unit_test::get_static_instance(); \
     61type() {}                                       \
     62/**/
     63
     64#else // BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
     65
     66template<typename Derived>
     67inline Derived& singleton< Derived >::instance()
     68{
     69    static Derived the_inst;
     70    return the_inst;
     71}
    4572
    4673#define BOOST_TEST_SINGLETON_CONS( type )       \
    4774friend class boost::unit_test::singleton<type>; \
    4875type() {}                                       \
    4976/**/
    5077
     78#endif // BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1310))
     79
     80} // namespace unit_test
     81
     82
    5183#if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
    5284
    5385#define BOOST_TEST_SINGLETON_INST( inst ) \