-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add an example for Type erasure #1625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
As you point out it's based on @RainerGrimm 's blog post about this Core Guidelines rule - is he ok with the example circling back here? |
Hi,
I'm totally fine with it and I hoped for it.
My post about the C++ Core Guidelines and my book about the C++ Core
Guidelines should help to improve the original document. The same holds
the other way around.
Rainer
On 5/28/20 4:06 PM, Sergey Zubkov wrote:
As you point out it's based on @RainerGrimm
<https://github.com/RainerGrimm> 's blog post about this Core
Guidelines rule - is he ok with the example circling back here?
In any case "Concept" is a rather loaded word
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1625 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AEN5M5PPVL7BKXLXIYO3P2LRTZVWTANCNFSM4ND46SKA>.
--
…--
Modernes C++
Online Seminare (Deutsch):
- Embedded Programmierung mit modernem C++: 07.07.2020 - 07.09.2020
Offene Seminare (Deutsch):
- Embedded Programmierung mit modernem C++: 24.08.2020 - 26.08.2020
Online seminar (English):
- C++11 and C+14: 13 July 2020 - 17 July 2020 (5 * 1/2 day)
- Clean Code with modern C++: 03 August 2020 - 07 August 2020 (5 * 1/2 day)
Rainer Grimm
Cottbuser Weg 20
72108 Rottenburg
Tel.: +49 7472 917441
Mobil: +49 152 31965939
Mail:schulung@ModernesCpp.de
www.ModernesCpp.de (Deutsch)
www.ModernesCpp.net (English)
|
Editors call: T.49 should have an example, but one that shows when and how to remove type erasure with something similar. This example belongs better in T.5 -- would you please move it there instead? |
I moved the example to T.5. |
CppCoreGuidelines.md
Outdated
|
||
class Object { | ||
public: | ||
template <typename T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line has a more space between template <typename T>
compared to other examples
CppCoreGuidelines.md
Outdated
class Object { | ||
public: | ||
template <typename T> | ||
Object(T && obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line has a more space between T &&
compared to other examples
CppCoreGuidelines.md
Outdated
virtual int get_id() const = 0; | ||
}; | ||
|
||
template <typename T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line has a more space between template <typename T>
compared to other examples
CppCoreGuidelines.md
Outdated
|
||
template <typename T> | ||
struct Model final : Concept { | ||
Model(T && obj) noexcept : object_(std::forward<T>(obj)) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line has a more space between T &&
compared to other examples
CppCoreGuidelines.md
Outdated
T object_; | ||
}; | ||
|
||
std::shared_ptr<Concept> concept_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this line start with 2 spaces but other lines start with 4 spaces
@hyukmyeong Thanks, I have fixed everything. |
@@ -16867,6 +16867,47 @@ Static helps dynamic: Use static polymorphism to implement dynamically polymorph | |||
Dynamic helps static: Offer a generic, comfortable, statically bound interface, but internally dispatch dynamically, so you offer a uniform object layout. | |||
Examples include type erasure as with `std::shared_ptr`'s deleter (but [don't overuse type erasure](#Rt-erasure)). | |||
|
|||
#include <memory> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you start the example with "##### Example"?
also I still feel the naming of Concept and concept_ is distractingly close to the keyword concept
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cubbimew The example is already in an example (the line before "Dynamic helps static...").
I change the name of classes to be the same than the "Static helps dynamic" example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great, thanks!
Based on :
https://www.modernescpp.com/index.php/c-core-guidelines-type-erasure-with-templates