[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] odd/rules_of_n eb5fef08 4/5: Follow the Rule of Five
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] odd/rules_of_n eb5fef08 4/5: Follow the Rule of Five |
Date: |
Sat, 9 Jul 2022 18:31:24 -0400 (EDT) |
branch: odd/rules_of_n
commit eb5fef08943a13ca5cd5b4e670b7e898467c5533
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>
Follow the Rule of Five
Identified by clang's '-Wdeprecated-copy-with-dtor'.
For concinnity, written thus:
- all ctors
- blank line
- the other five special members, in a consistent order
- blank line
All added special members are defaulted, except that they're deleted
for class any_entity. Perhaps they should all be deleted, initially at
least, and defaulted only if they're used.
---
any_entity.hpp | 6 ++++++
any_member_test.cpp | 7 +++++++
datum_base.hpp | 5 +++++
datum_sequence.hpp | 7 +++++--
datum_string.hpp | 5 +++++
tn_range.hpp | 5 +++++
6 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/any_entity.hpp b/any_entity.hpp
index ce2cabb4..d1b1e4a2 100644
--- a/any_entity.hpp
+++ b/any_entity.hpp
@@ -37,6 +37,12 @@
class any_entity
{
public:
+ any_entity() = default;
+
+ any_entity(any_entity const&) = default;
+ any_entity(any_entity&&) = delete;
+ any_entity& operator=(any_entity const&) = delete;
+ any_entity& operator=(any_entity&&) = delete;
virtual ~any_entity() = default;
any_entity& operator=(std::string const& s) {return assign(s);}
diff --git a/any_member_test.cpp b/any_member_test.cpp
index 34538588..c6f7140b 100644
--- a/any_member_test.cpp
+++ b/any_member_test.cpp
@@ -35,13 +35,20 @@
struct base_datum
{
base_datum() :sane(7) {}
+
+ base_datum(base_datum const&) = default;
+ base_datum(base_datum&&) = default;
+ base_datum& operator=(base_datum const&) = default;
+ base_datum& operator=(base_datum&&) = default;
virtual ~base_datum() = default; // Just to make it polymorphic.
+
virtual int virtual_function() = 0; // Just to make it abstract.
bool base_function()
{
std::cout << "base_datum::base_function() called " << sane <<
std::endl;
return true;
}
+
int sane;
};
diff --git a/datum_base.hpp b/datum_base.hpp
index 83be766c..90582460 100644
--- a/datum_base.hpp
+++ b/datum_base.hpp
@@ -34,6 +34,11 @@ class LMI_SO datum_base
{
public:
datum_base() = default;
+
+ datum_base(datum_base const&) = default;
+ datum_base(datum_base&&) = default;
+ datum_base& operator=(datum_base const&) = default;
+ datum_base& operator=(datum_base&&) = default;
virtual ~datum_base() = default;
void enable(bool);
diff --git a/datum_sequence.hpp b/datum_sequence.hpp
index 3ad1c5e3..d92a8c70 100644
--- a/datum_sequence.hpp
+++ b/datum_sequence.hpp
@@ -68,11 +68,14 @@ class datum_sequence
{
public:
datum_sequence();
- datum_sequence(datum_sequence const&) = default;
explicit datum_sequence(std::string const&);
- ~datum_sequence() override = 0;
+ datum_sequence(datum_sequence const&) = default;
+ datum_sequence(datum_sequence&&) = default;
datum_sequence& operator=(datum_sequence const&) = default;
+ datum_sequence& operator=(datum_sequence&&) = default;
+ ~datum_sequence() override = 0; // Pure: see note above.
+
datum_sequence& operator=(std::string const&);
void block_keyword_values(bool);
diff --git a/datum_string.hpp b/datum_string.hpp
index 258e24a5..3c08d2a8 100644
--- a/datum_string.hpp
+++ b/datum_string.hpp
@@ -38,6 +38,11 @@ class datum_string
public:
datum_string() = default;
explicit datum_string(std::string const&);
+
+ datum_string(datum_string const&) = default;
+ datum_string(datum_string&&) = default;
+ datum_string& operator=(datum_string const&) = default;
+ datum_string& operator=(datum_string&&) = default;
~datum_string() override = default;
datum_string& operator=(std::string const&);
diff --git a/tn_range.hpp b/tn_range.hpp
index d6cf7180..fe6de2ba 100644
--- a/tn_range.hpp
+++ b/tn_range.hpp
@@ -240,6 +240,11 @@ class tn_range final
tn_range();
explicit tn_range(Number);
explicit tn_range(std::string const&);
+
+ tn_range(tn_range const&) = default;
+ tn_range(tn_range&&) = default;
+ tn_range& operator=(tn_range const&) = default;
+ tn_range& operator=(tn_range&&) = default;
~tn_range() override = default;
tn_range& operator=(Number);
- [lmi-commits] [lmi] branch odd/rules_of_n created (now 84444422), Greg Chicares, 2022/07/09
- [lmi-commits] [lmi] odd/rules_of_n c90645b0 2/5: Follow the Rule of Zero, even expunging a virtual dtor, Greg Chicares, 2022/07/09
- [lmi-commits] [lmi] odd/rules_of_n eb5fef08 4/5: Follow the Rule of Five,
Greg Chicares <=
- [lmi-commits] [lmi] odd/rules_of_n 84444422 5/5: Enable clang's '-Wdeprecated-copy-with-dtor', Greg Chicares, 2022/07/09
- [lmi-commits] [lmi] odd/rules_of_n ab0a3dec 3/5: Follow the Rule of Zero (initializing all data members in class), Greg Chicares, 2022/07/09
- [lmi-commits] [lmi] odd/rules_of_n 4eab8b4a 1/5: Follow the Rule of Zero, Greg Chicares, 2022/07/09