Boost logo

Boost Users :

From: Ovanes Markarian (om_boost_at_[hidden])
Date: 2008-01-29 09:35:34


I mean the idea of defining the singleton type

struct my_singleton : boost::singleton<my_singleton>
{
   ...
   void DoSmth()const;
   ...
};

And the more important now, the possibility to access it:
my_singleton::instance->DoSmth();

I found it extremely useful to be able to overload the operator -> for
accessing the singleton members and may be doing smth. meaningful before and
after accessing the member, e.g. monitoring.

I was going to write a review, but somehow missed it...

IMO I would like to have this lib in Boost (would give my YES vote).

Controlling the multi-threaded creation handling via BOOST_HAS_THREADS can
be nice by default, but should also be possible to finetune it without
redefining macros or including singleton headers before this macro was
defined.

So I would prefer smth. like this:

#ifdef BOOST_HAS_TREADS
# define BOOST_SINGLETON_DEFAULT_LOCKING_POLICY
boost::singleton_default_locking
#else
# define BOOST_SINGLETON_DEFAULT_LOCKING_POLICY
boost::singleton_no_locking
#endif

namespace boost
{
template<class Derived, class
LockingPolicy=BOOST_SINGLETON_DEFAULT_LOCKING_POLICY>
struct singleton
{
   ...
};

}

After all I can write:

struct my_singleton : boost::singleton<my_singleton>
{};

Or if I really want to control locking policy:

struct my_singleton : boost::singleton<my_singleton, no_locking>
{};

I would not like using "macro interface" to control the locking policy of
the singleton. As well as it is not always so that if my app has threads I
need lockable singleton. I agree that might be needed for shared_ptr to make
safe locks, since it might be used in some "local" thread somewhere in the
app, but if I for sure know that my singlegon will be instantiated in main()
before any threads will start running and that it will be a read-only
singleton, I don't need locking.

Many thanks,
Ovanes

On Jan 29, 2008 3:14 PM, John Torjo <john.groups_at_[hidden]> wrote:

> Ovanes Markarian wrote:
> > These are very sad news. I started to use it in my current project and
> > am highly satisfied with it for my current needs. I hope that the
> > interface (accessing the singleton) would remain the same.
> >
> Do you mean just the function name, or more?
>
> Best,
> John
>
> --
> http://John.Torjo.com -- C++ expert
> ... call me only if you want things done right
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net