Use delete instead of hiding copy constructors and assignments (#1820)

This commit is contained in:
Benoit Blanchon
2023-02-17 10:58:02 +01:00
parent 33a4773fbd
commit b2b995edb3
5 changed files with 9 additions and 15 deletions

View File

@ -11,6 +11,7 @@ class CustomReader {
public:
CustomReader(const char* input) : _stream(input) {}
CustomReader(const CustomReader&) = delete;
int read() {
return _stream.get();
@ -20,7 +21,4 @@ class CustomReader {
_stream.read(buffer, static_cast<std::streamsize>(length));
return static_cast<size_t>(_stream.gcount());
}
private:
CustomReader(const CustomReader&);
};

View File

@ -12,6 +12,7 @@ class SpyingAllocator {
public:
SpyingAllocator(const SpyingAllocator& src) : _log(src._log) {}
SpyingAllocator(std::ostream& log) : _log(log) {}
SpyingAllocator& operator=(const SpyingAllocator& src) = delete;
void* allocate(size_t n) {
_log << "A" << n;
@ -23,8 +24,6 @@ class SpyingAllocator {
}
private:
SpyingAllocator& operator=(const SpyingAllocator& src);
std::ostream& _log;
};

View File

@ -8,6 +8,8 @@
class CustomWriter {
public:
CustomWriter() {}
CustomWriter(const CustomWriter&) = delete;
CustomWriter& operator=(const CustomWriter&) = delete;
size_t write(uint8_t c) {
_str.append(1, static_cast<char>(c));
@ -24,9 +26,6 @@ class CustomWriter {
}
private:
CustomWriter(const CustomWriter&); // non-copiable
CustomWriter& operator=(const CustomWriter&);
std::string _str;
};