Commit 83a7b79c authored by Victor Zverovich's avatar Victor Zverovich

Add a macro to disallow the copy constructor and operator= functions.

parent 5dee2904
...@@ -1634,8 +1634,7 @@ TEST(FormatIntTest, FormatDec) { ...@@ -1634,8 +1634,7 @@ TEST(FormatIntTest, FormatDec) {
class File { class File {
private: private:
int fd_; int fd_;
File(const File &); FMT_DISALLOW_COPY_AND_ASSIGN(File);
void operator=(const File &);
public: public:
File(int fd) : fd_(fd) {} File(int fd) : fd_(fd) {}
~File() { close(fd_); } ~File() { close(fd_); }
......
...@@ -99,6 +99,12 @@ ...@@ -99,6 +99,12 @@
# define FMT_NOEXCEPT(expr) # define FMT_NOEXCEPT(expr)
#endif #endif
// A macro to disallow the copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define FMT_DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&); \
void operator=(const TypeName&)
#if _MSC_VER #if _MSC_VER
# pragma warning(push) # pragma warning(push)
# pragma warning(disable: 4521) // 'class' : multiple copy constructors specified # pragma warning(disable: 4521) // 'class' : multiple copy constructors specified
...@@ -165,9 +171,7 @@ class Array { ...@@ -165,9 +171,7 @@ class Array {
} }
} }
// Do not implement! FMT_DISALLOW_COPY_AND_ASSIGN(Array);
Array(const Array &);
void operator=(const Array &);
public: public:
Array() : size_(0), capacity_(SIZE), ptr_(data_) {} Array() : size_(0), capacity_(SIZE), ptr_(data_) {}
...@@ -1266,9 +1270,7 @@ class BasicFormatter { ...@@ -1266,9 +1270,7 @@ class BasicFormatter {
// //
// This is done because BasicFormatter objects should normally exist // This is done because BasicFormatter objects should normally exist
// only as temporaries returned by one of the formatting functions. // only as temporaries returned by one of the formatting functions.
// Do not implement. FMT_DISALLOW_COPY_AND_ASSIGN(BasicFormatter);
BasicFormatter(const BasicFormatter &);
BasicFormatter& operator=(const BasicFormatter &);
protected: protected:
const Char *TakeFormatString() { const Char *TakeFormatString() {
...@@ -1405,9 +1407,7 @@ class Formatter : private Action, public BasicFormatter<Char> { ...@@ -1405,9 +1407,7 @@ class Formatter : private Action, public BasicFormatter<Char> {
BasicWriter<Char> writer_; BasicWriter<Char> writer_;
bool inactive_; bool inactive_;
// Forbid copying other than from a temporary. Do not implement. FMT_DISALLOW_COPY_AND_ASSIGN(Formatter);
Formatter(const Formatter &);
Formatter& operator=(const Formatter &);
public: public:
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment