From 3575d367a4aafa1810feab9ba1effbad11a57702 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jul 2018 00:25:08 -0400 Subject: telemetry: Default copy/move constructors and assignment operators This provides the equivalent behavior, but without as much boilerplate. While we're at it, explicitly default the move constructor, since we have a move-assignment operator defined. --- src/common/telemetry.h | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'src/common/telemetry.h') diff --git a/src/common/telemetry.h b/src/common/telemetry.h index 7a09df0a7..2c945443b 100644 --- a/src/common/telemetry.h +++ b/src/common/telemetry.h @@ -58,21 +58,11 @@ public: Field(FieldType type, std::string name, T&& value) : name(std::move(name)), type(type), value(std::move(value)) {} - Field(const Field& other) : Field(other.type, other.name, other.value) {} + Field(const Field&) = default; + Field& operator=(const Field&) = default; - Field& operator=(const Field& other) { - type = other.type; - name = other.name; - value = other.value; - return *this; - } - - Field& operator=(Field&& other) { - type = other.type; - name = std::move(other.name); - value = std::move(other.value); - return *this; - } + Field(Field&&) = default; + Field& operator=(Field&& other) = default; void Accept(VisitorInterface& visitor) const override; -- cgit v1.2.3 From 0aebe6b3d52403e042522720cb5646ddbcb306d6 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jul 2018 00:27:34 -0400 Subject: telemetry: Make operator== and operator!= const member functions of Field These operators don't modify internal class state, so they can be made const member functions. While we're at it, drop the unnecessary inline keywords. Member functions that are defined in the class declaration are already inline by default. --- src/common/telemetry.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/common/telemetry.h') diff --git a/src/common/telemetry.h b/src/common/telemetry.h index 2c945443b..155cf59ff 100644 --- a/src/common/telemetry.h +++ b/src/common/telemetry.h @@ -84,11 +84,11 @@ public: return value; } - inline bool operator==(const Field& other) { + bool operator==(const Field& other) const { return (type == other.type) && (name == other.name) && (value == other.value); } - inline bool operator!=(const Field& other) { + bool operator!=(const Field& other) const { return !(*this == other); } -- cgit v1.2.3 From c65a8fafa0fe68371b8b07ba190df78744983327 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 18 Jul 2018 00:32:32 -0400 Subject: telemetry: Remove unnecessary Field constructor We can just take the value parameter by value which allows both moving into it, and copies at the same time, depending on the calling code. --- src/common/telemetry.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/common/telemetry.h') diff --git a/src/common/telemetry.h b/src/common/telemetry.h index 155cf59ff..3bab75b59 100644 --- a/src/common/telemetry.h +++ b/src/common/telemetry.h @@ -52,10 +52,7 @@ public: template class Field : public FieldInterface { public: - Field(FieldType type, std::string name, const T& value) - : name(std::move(name)), type(type), value(value) {} - - Field(FieldType type, std::string name, T&& value) + Field(FieldType type, std::string name, T value) : name(std::move(name)), type(type), value(std::move(value)) {} Field(const Field&) = default; -- cgit v1.2.3