Remove non-copyable idioms

Two better ways of making a class non-copyable in C++11:

* Store the p. impl. in a unique_ptr (for the cases of classes with p. impl.),
  or:

* Define publicly the copy constructor and assignment as deleted

Lots of other classes could be cleaned up in this way.
This commit is contained in:
Guillaume Munch 2016-06-02 20:38:15 +01:00
parent 973618e1c1
commit 8d640dc776
4 changed files with 11 additions and 21 deletions

View File

@ -73,9 +73,8 @@ struct WordList::Impl {
};
WordList::WordList()
WordList::WordList() : d(new Impl)
{
d = new Impl;
d->c_ = 0;
#if 0
@ -86,12 +85,6 @@ WordList::WordList()
}
WordList::~WordList()
{
delete d;
}
docstring const & WordList::word(size_t idx) const
{
Impl::Words::const_iterator it = d->words_.find_summed_weight(idx);

View File

@ -14,18 +14,14 @@
#include "support/docstring.h"
#include <memory>
namespace lyx {
class WordList {
// noncopyable because of pimpl
WordList(WordList const &);
WordList & operator=(WordList const &);
public:
///
WordList();
///
~WordList();
///
docstring const & word(size_t idx) const;
///
@ -39,7 +35,7 @@ public:
private:
struct Impl;
Impl * d;
std::unique_ptr<Impl> d;
};
WordList * theWordList(std::string const & lang);

View File

@ -125,11 +125,11 @@ public:
* If it isn't found, return an empty std::string.
*/
std::string const getPreambleDefByName(std::string const & name) const;
/// noncopyable
TemplateManager(TemplateManager const &) = delete;
void operator=(TemplateManager const &) = delete;
private:
TemplateManager();
/// noncopyable
TemplateManager(TemplateManager const &);
void operator=(TemplateManager const &);
void readTemplates(support::FileName const & path);
void dumpTemplates(std::ostream &) const;

View File

@ -54,10 +54,11 @@ static const iconv_t invalid_cd = (iconv_t)(-1);
class IconvProcessor::Impl
{
// noncopyable because iconv_close() is called in destructor
Impl(Impl const &);
Impl & operator=(Impl const &);
public:
// noncopyable because iconv_close() is called in destructor
Impl(Impl const &) = delete;
Impl & operator=(Impl const &) = delete;
Impl(string const & to, string const & from)
: cd(invalid_cd), tocode_(to), fromcode_(from)
{}