Cancer Stick Castle: Clarify copyability and movability
Because the style guide wants it: https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types Bug: webrtc:11943 Change-Id: I17373f870496c6411b5edd80e7d50dbb15a7fbc0 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/184511 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Karl Wiberg <kwiberg@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32135}
This commit is contained in:
@ -24,13 +24,20 @@ namespace cancer_stick_castle_impl {
|
||||
class CancerStickCastleReceivers {
|
||||
public:
|
||||
CancerStickCastleReceivers();
|
||||
CancerStickCastleReceivers(const CancerStickCastleReceivers&) = delete;
|
||||
CancerStickCastleReceivers& operator=(const CancerStickCastleReceivers&) =
|
||||
delete;
|
||||
CancerStickCastleReceivers(CancerStickCastleReceivers&&) = delete;
|
||||
CancerStickCastleReceivers& operator=(CancerStickCastleReceivers&&) = delete;
|
||||
~CancerStickCastleReceivers();
|
||||
|
||||
void AddReceiver(UntypedFunction&& f) {
|
||||
AddReceiverImpl(&f);
|
||||
// Assume that f was moved from and is now trivially destructible.
|
||||
// This helps the compiler optimize away the destructor call.
|
||||
RTC_ASSUME(f.IsTriviallyDestructible());
|
||||
}
|
||||
|
||||
void Foreach(rtc::FunctionView<void(UntypedFunction&)> fv);
|
||||
|
||||
private:
|
||||
@ -43,6 +50,8 @@ class CancerStickCastleReceivers {
|
||||
// A collection of receivers (callable objects) that can be called all at once.
|
||||
// Optimized for minimal binary size.
|
||||
//
|
||||
// Neither copyable nor movable. Could easily be made movable if necessary.
|
||||
//
|
||||
// TODO(kwiberg): Add support for removing receivers, if necessary. AddReceiver
|
||||
// would have to return some sort of ID that the caller could save and then pass
|
||||
// to RemoveReceiver. Alternatively, the callable objects could return one value
|
||||
@ -51,11 +60,22 @@ class CancerStickCastleReceivers {
|
||||
template <typename... ArgT>
|
||||
class CancerStickCastle {
|
||||
public:
|
||||
CancerStickCastle() = default;
|
||||
CancerStickCastle(const CancerStickCastle&) = delete;
|
||||
CancerStickCastle& operator=(const CancerStickCastle&) = delete;
|
||||
CancerStickCastle(CancerStickCastle&&) = delete;
|
||||
CancerStickCastle& operator=(CancerStickCastle&&) = delete;
|
||||
|
||||
// Adds a new receiver. The receiver (a callable object or a function pointer)
|
||||
// must be movable, but need not be copyable. Its call signature should be
|
||||
// `void(ArgT...)`.
|
||||
template <typename F>
|
||||
void AddReceiver(F&& f) {
|
||||
receivers_.AddReceiver(
|
||||
UntypedFunction::Create<void(ArgT...)>(std::forward<F>(f)));
|
||||
}
|
||||
|
||||
// Calls all receivers with the given arguments.
|
||||
void Send(ArgT&&... args) {
|
||||
receivers_.Foreach([&](UntypedFunction& f) {
|
||||
f.Call<void(ArgT...)>(std::forward<ArgT>(args)...);
|
||||
|
Reference in New Issue
Block a user