lmi
[Top][All Lists]
Advanced

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

[lmi] Various C++ m12ns


From: Greg Chicares
Subject: [lmi] Various C++ m12ns
Date: Wed, 1 Feb 2017 21:47:34 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0

[numeronym m12n = modernization, like i18n or l10n]

Vadim, what do you think about...

(1) Changing '> >' to '>>' to close template-parameter-lists? That seems
like the removal of a nuisance to me. (Of course, it creates a nuisance
for compiler writers, but they've already accommodated it.) However, does
it create a problem with any tools you use? E.g.:

http://stackoverflow.com/questions/7304699/what-are-all-the-syntax-problems-introduced-by-the-usage-of-angle-brackets-in-c/7304730#7304730

| ctags fails for some template definitions, which makes it
| unusable with our current C++ project

I'm not using ctags presently myself (though I should). With no plugins,
vim 7.3 with 'syntax on' highlights "> >" as though it were an error,
but doesn't complain about "> >", at least in the cases I've tried.

(2) Replacing

  class foo : private lmi::uncopyable<foo>

with

  class foo
  ...
      foo(foo const&) = delete;
      foo& operator=(foo const&) = delete;

? I'm not convinced that such a change should be made. If C++11 let us
write it the way we can write 'final':
  class foo : uncopyable
then that would be best. But declaring two extra member functions
requires writing the class's name four times, and typically those
declarations would be somewhere in the middle of the class declaration,
after public members and before other private members. It just seems
more verbose and less readable to me.

If we keep lmi::uncopyable, I suppose we should change it like this
[untested]:
-    uncopyable(uncopyable const&);
+    uncopyable(uncopyable const&) = delete;
-    uncopyable& operator=(uncopyable const&);
+    uncopyable& operator=(uncopyable const&) = delete;

BTW, Hinnant gives an example of a "space penalty" here:
  
http://stackoverflow.com/questions/7823990/what-are-the-advantages-of-boostnoncopyable/7841332#7841332
but, using lmi::uncopyable, there is none--the sandbox unit test with
the patch below prints "2".

---------8<--------8<--------8<--------8<--------8<--------8<--------8<-------
diff --git a/sandbox_test.cpp b/sandbox_test.cpp
index 401b86d..7049eb4 100644
--- a/sandbox_test.cpp
+++ b/sandbox_test.cpp
@@ -21,10 +21,39 @@
 
 #include "pchfile.hpp"
 
+#include "uncopyable_lmi.hpp"
+
 #include "test_tools.hpp"
 
+struct A
+    : private lmi::uncopyable<A>
+{
+};
+
+struct B
+    : public A
+{
+    B();
+    B(const B&);
+    B& operator=(const B&);
+};
+
+struct C
+    : public A
+{
+};
+
+struct D
+    : public B,
+      public C,
+      private lmi::uncopyable<D>
+{
+};
+
 int test_main(int, char*[])
 {
+    std::cout << sizeof(D) << '\n';
+
     return 0;
 }
 
--------->8-------->8-------->8-------->8-------->8-------->8-------->8-------




reply via email to

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