Boost logo

Boost :

From: Daryle Walker (darylew_at_[hidden])
Date: 2006-01-11 15:33:46


On 1/9/06 11:33 AM, "Toon Knapen" <toon.knapen_at_[hidden]> wrote:

> While using the boost::rational MSVC7.1 generates errors saying:
>
> warning C4512: 'boost::detail::resetter' : assignment operator could not
> be generated
>
> So I propose following diff to boost::detail::resetter that makes this
> warning go away
>
> RCS file: /cvsroot/boost/boost/boost/rational.hpp,v
> retrieving revision 1.16
> diff -u -r1.16 rational.hpp
> --- rational.hpp 27 Dec 2005 11:38:27 -0000 1.16
> +++ rational.hpp 9 Jan 2006 16:32:12 -0000
> @@ -462,11 +462,16 @@
>
> // A utility class to reset the format flags for an istream at end
> // of scope, even in case of exceptions
> - struct resetter {
> + class resetter {
> + public:
> resetter(std::istream& is) : is_(is), f_(is.flags()) {}
> ~resetter() { is_.flags(f_); }
> std::istream& is_;
> std::istream::fmtflags f_; // old GNU c++ lib has no ios_base
> + private:
> + // MSVC 7.1 complains that he is unable to generate the assignment-
> + // operator so we generate it for him as to avoid the warning.
> + resetter& operator=(const resetter&) ;
> };
>
> }

You could also define "is_" to be a pointer instead of a reference (and
change the ctr & dtr appropriately). Then automatic copying could work just
fine. Of course, you could say that copying shouldn't be allowed, then we
could just inherit from boost::noncopyable instead. Finally, I added a
bunch of utility classes like this many years ago (boost::rational is even
older) so we could switch to that. Actually, maybe I should submit a patch
to do the I/O functions for any stream (right now, they're just for istream
and ostream, for use in pre-StdIO systems).

-- 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT hotmail DOT com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk