nmh-workers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Nmh-workers] C++


From: Joel Uckelman
Subject: Re: [Nmh-workers] C++
Date: Wed, 14 Feb 2018 11:54:56 +0100

Thus spake Paul Vixie:
> >
> > The RAII technique goes like this:
> >
> > struct ReadFP : boost::non_copyable
> > {
> >     ReadFP(std::string&  fname)
> >          {
> >             d_fp = fopen(fname.c_str(), "r")
> >             if(!d_fd)
> >             throw runtime_error("Opening file "+fname+": "+strerror(errno);
> >     }
> >     ~ReadFD()
> >     {
> >             fclose(d_fp);
> >     }
> >     FILE* d_fp;
> > };
> >
> > Written like this, you'll never leak an fd 'ever'. The 'boost::non_copyable'
> > makes sure no one can copy this struct, which would complicate things. Use:

NB: You could also make it non-copyable without boost by deleting the
copy ctor:

  ReadFP(const ReadFP&) = delete;

That's the canonical way with C++11 and later.

I'm in favor of using C++ for nmh should I ever dig myself out of the
hole I'm in and have time to contribute.

-- 
J.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]