|
Boost : |
From: Frank Mori Hess (frank.hess_at_[hidden])
Date: 2007-12-18 13:24:36
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Tuesday 18 December 2007 11:48 am, Howard Hinnant wrote:
> That being said, a non-movable boost::mutex does not prohibit a
> wrapper around that type from being movable, if you're willing to
> accept alternative semantics. I'm not familiar with the boost move
> library, but the C++0X syntax would simply be:
>
> class my_wrapper
> {
> std::mutex mut_; // or boost::mutex
> public:
> my_wrapper() {}
> my_wrapper(my_wrapper&&) {} // same as default ctor
> my_wrapper& operator=(my_wrapper&&) {return *this;} // do nothing
>
> void lock() {mut_.lock();}
> bool try_lock() {return mut_.try_lock();}
> void unlock() {mut_.unlock();}
> };
What I'm thinking of is more along the lines of
template<typename Mutex>
class my_wrapper
{
Mutex mut_;
public:
my_wrapper(Mutex &&mut): mut_(mut);
// ...
};
So I can have a my_wrapper<Mutex> without worrying about whether the template
Mutex type has some weird constructor, or even if it is default
constructible. I guess the best I could do along those lines is to have a
constructor that allows the user to pass in a dynamically allocated Mutex,
which the wrapper would take ownership of. Note, I've never really done
anything with rvalue references or moveable types, so maybe this is an abuse
of them?
- --
Frank
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
iD8DBQFHaBBp5vihyNWuA4URAkM5AKC8cqksDE3Rs94i2DoT2C3nP4jMpACdF0uQ
l5w1kCn4p7XFcCkBXX6fits=
=/nDt
-----END PGP SIGNATURE-----
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk