mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-31 11:17:35 +02:00
Add a macro to disallow the copy constructor and operator= functions.
This commit is contained in:
@ -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_); }
|
||||||
|
18
format.h
18
format.h
@ -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 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 {
|
|||||||
//
|
//
|
||||||
// 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> {
|
|||||||
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:
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user