[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Define special member functions inline?

From: Greg Chicares
Subject: Re: [lmi] Define special member functions inline?
Date: Mon, 6 Mar 2017 10:41:40 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0

On 2017-03-04 02:42, Vadim Zeitlin wrote:
> On Sat, 4 Mar 2017 02:01:07 +0000 Greg Chicares <address@hidden> wrote:
> My personal rule is to define all defaulted special functions inline
> (because of the above efficiency considerations and also because it avoids
> unnecessary repetition)

Okay, then our guideline so far is
  Write explicitly-defaulted special member functions inline, in the
  class definition.
with the rationale that
  This makes the code clearer, and lets the compiler optimize better.
[plain text because I don't know '.md']

If we cannot write them in the class definition, should we still write
them in the header? IOW, would you revert the following (not yet pushed)
commit? I'll push it anyway because I've committed numerous little
changes like this locally, but I don't mind reverting it later (except
for the commentary changes).

Writing it outside the class definition loses optimization benefits,
as the dtor is not trivial (a pure virtual dtor cannot be trivial).
Does it make have the other advantage--making the code clearer? IMO it
doesn't. We read '.cpp' file only when we want to understand the
implementation (less often), but we read the '.hpp' file whenever we
want to understand the interface (more often). Alternatively put:
this is an *implementation* detail [I think I got that .md right].

But whichever we decide, I just want there to be a guideline so that we
can always write code like this in the same well-chosen way without
re-thinking the style each time.

commit 3a2c252930b2196b00cb994618ccf00045f7b664
Author: Gregory W. Chicares <address@hidden>
Date:   2017-03-06 10:14:02 +0000

    Implement pure virtual dtor inline in header

diff --git a/datum_sequence.cpp b/datum_sequence.cpp
index f14a390..f97fa15 100644
--- a/datum_sequence.cpp
+++ b/datum_sequence.cpp
@@ -46,8 +46,6 @@ datum_sequence::datum_sequence(std::string const& s)
-datum_sequence::~datum_sequence() = default;
 datum_sequence& datum_sequence::operator=(std::string const& s)
diff --git a/datum_sequence.hpp b/datum_sequence.hpp
index 09f9e17..1e218d3 100644
--- a/datum_sequence.hpp
+++ b/datum_sequence.hpp
@@ -33,7 +33,7 @@
 #include <map>
 #include <string>
-/// Base class for MVC input sequences.
+/// Abstract base class for MVC input sequences.
 /// Sequences are formed of values and intervals. Intervals may always
 /// be specified by numbers, keywords, or a combination of both. Each
@@ -94,6 +94,15 @@ class datum_sequence
     bool keyword_values_are_blocked_;
+/// Implementation of pure virtual destructor.
+/// Neither this explicitly-defaulted implementation nor any other can
+/// be written inside the class definition because C++11 [10.4/3] says
+/// "a function declaration cannot provide both a pure-specifier and a
+/// definition".
+inline datum_sequence::~datum_sequence() = default;
 bool operator==(datum_sequence const&, datum_sequence const&);
 // Specialize value_cast<> for each derived class, e.g., as follows:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]