Re: fix for intel's compiler

Posted by Kakhkhor Abdijalilov on
URL: http://quantlib.414.s1.nabble.com/fix-for-intel-s-compiler-tp9222p9229.html

I could run several examples but the test suite crashes instantly with
memory access violation error. Can someone try the test suite with the
singleton attached below?

////////////////////////////////////////////////////////////////////
#ifndef quantlib_singleton_hpp
#define quantlib_singleton_hpp

#include <ql/types.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <map>

namespace QuantLib {

    #if defined(QL_ENABLE_SESSIONS)
    Integer sessionId();
    #endif

    template <class T>
    class Singleton : private boost::noncopyable {
    public:
        static T& instance() {
            #if defined(QL_ENABLE_SESSIONS)
            Integer id = sessionId();
            #else
            Integer id = 0;
            #endif
            boost::shared_ptr<T>& p = instances_[id];
            if (!p)
                p.reset(new T);
            return *p;
        }

    protected:
        Singleton() {}
    private:
        typedef std::map<Integer, boost::shared_ptr<T> > map_type;
        static map_type instances_;
    };

    template <typename T>
    typename Singleton<T>::map_type Singleton<T>::instances_;

}

#endif

------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:

Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
_______________________________________________
QuantLib-dev mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/quantlib-dev