Replies: 6 comments 15 replies
-
Forward declarationsA class with a e.g. in #include <cluster/fwd.h>
class application {
public:
...
application::~application();
private:
...
std::unique_ptr<cluster::controller> controller;
}; And in application::~application() = default; |
Beta Was this translation helpful? Give feedback.
-
Runtime polymorphismWhen runtime polymorphism is required, prefer non-virtual public interface: // Header
class polymorphic final {
public:
struct impl {
virtual ~impl() = default;
virtual void apply() = 0;
};
explicit polymorphic(std::unique_ptr<impl> impl)
: _impl(std::move(impl)) {}
void apply() { _impl->apply(); }
private:
std::unique_ptr<impl> _impl;
};
polymorphic make_derived();
// Implementation
class derived_impl final : public polymorphic::impl {
void apply() final {}
};
polymorphic make_derived() {
return polymorphic{std::make_unique<derived_impl>()};
} Notes
Rationale
|
Beta Was this translation helpful? Give feedback.
-
Name LookupHidden friendshttps://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1601r0.pdf With hidden friends the function lookup is found by ADL only; i.e., it cannot be found by unqualified lookup. E.g. implement operators as friends, ideally inline: namespace bar {
struct foo {
int i;
friend std::ostream& operator<<(std::ostream& os, const foo& f) {
return os << f.i;
}
};
// namespace bar Notes
Rationale
|
Beta Was this translation helpful? Give feedback.
-
Customization Point DesignWhen you want a behaviour to be extensible. Customisation Point Object with
|
Beta Was this translation helpful? Give feedback.
-
Access SpecifiersOrderingclass type {
public:
protected:
private:
}; Duplicate sectionsIt's okay to use multiple instances of access specifiers to create logical groupings where needed. class type {
public:
// boiler plate
public:
// logical grouping of APIs
...
}; |
Beta Was this translation helpful? Give feedback.
-
Closing in favor of driving consensus through PR discussions #14812 |
Beta Was this translation helpful? Give feedback.
-
Forward declarations
Headers
Subsystems should define a
fwd.h
header containing forward declarations for exported components. For exampleraft/fwd.h
contains the following forward declarations.Then users of the exported components may include
subsystem/fwd.h
rather than the header containing the full class declaration. An important case to remember is thatseastar::sharded<T>&
will work with forward declarations:With std::unique_ptr
A class with a
std::unique_ptr<T>
member can use a forward declaration ofT
if the destructor is out of line:e.g. in
application.h
:And in
application.cc
:Rationale
std::function vs seastar::noncopyable_function
Rationale
Emulating seastar::future::finally with coroutines
Rationale
seastar::sleep vs seastar::sleep_abortable
Rationale
Beta Was this translation helpful? Give feedback.
All reactions