Skip to content

Commit

Permalink
[src] Elevenize KALDI_DISALLOW_COPY_AND_ASSIGN() (kaldi-asr#4547)
Browse files Browse the repository at this point in the history
Before C++11 we declared the same members private, usually at the
very end of a class declaration. With standardization of the delete
keyword and adoption of the pattern, it is now idiomatic to make
deleted members public. The rationale is that deletion of copy members
is part of the public behavior of a type, namely its uncopyability,
and should be expressed in and readable from the public: section alone.

Google coding style, which we are generally following, does not
mention the 'DISALLOW_COPY_AND_ASSIGN' macro any more, and recommends
using the '= delete;' construct directly. From
https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types:

> Every class's public interface must make clear which copy and move
> operations the class supports. This should usually take the form of
> explicitly declaring and/or deleting the appropriate operations in
> the public section of the declaration.

Examples from the guide use the delete keyword straight without any
macro, but I think we should make an exception and continue using
the macro, which is more self-explanatory.

clang-tidy gets angry at non-public deleted members, too.
  • Loading branch information
kkm000 committed May 28, 2021
1 parent 436d243 commit 949696e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/base/kaldi-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,15 @@ void Sleep(double seconds);
(reinterpret_cast<char*>(&a))[1]=t;} while (0)


// Makes copy constructor and operator= private.
///\brief Declare deleted copy constructor and copy assignment operator=().
///
/// Use this macro in the \e public part of a class declaration in a header
/// file, next to its constructors, so that uncopyability of the type is
/// clearly readable. Place a semicolon after it.
///\param type The exact enclosing class name.
#define KALDI_DISALLOW_COPY_AND_ASSIGN(type) \
type(const type&); \
void operator = (const type&)
type(const type&) = delete; \
type& operator=(const type&) = delete

template<bool B> class KaldiCompileTimeAssert { };
template<> class KaldiCompileTimeAssert<true> {
Expand Down

0 comments on commit 949696e

Please sign in to comment.