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:
Karl Wiberg
2020-09-18 09:59:50 +02:00
committed by Commit Bot
parent 1eb3e4c9ba
commit 8d875587d5

View File

@ -24,13 +24,20 @@ namespace cancer_stick_castle_impl {
class CancerStickCastleReceivers { class CancerStickCastleReceivers {
public: public:
CancerStickCastleReceivers(); CancerStickCastleReceivers();
CancerStickCastleReceivers(const CancerStickCastleReceivers&) = delete;
CancerStickCastleReceivers& operator=(const CancerStickCastleReceivers&) =
delete;
CancerStickCastleReceivers(CancerStickCastleReceivers&&) = delete;
CancerStickCastleReceivers& operator=(CancerStickCastleReceivers&&) = delete;
~CancerStickCastleReceivers(); ~CancerStickCastleReceivers();
void AddReceiver(UntypedFunction&& f) { void AddReceiver(UntypedFunction&& f) {
AddReceiverImpl(&f); AddReceiverImpl(&f);
// Assume that f was moved from and is now trivially destructible. // Assume that f was moved from and is now trivially destructible.
// This helps the compiler optimize away the destructor call. // This helps the compiler optimize away the destructor call.
RTC_ASSUME(f.IsTriviallyDestructible()); RTC_ASSUME(f.IsTriviallyDestructible());
} }
void Foreach(rtc::FunctionView<void(UntypedFunction&)> fv); void Foreach(rtc::FunctionView<void(UntypedFunction&)> fv);
private: private:
@ -43,6 +50,8 @@ class CancerStickCastleReceivers {
// A collection of receivers (callable objects) that can be called all at once. // A collection of receivers (callable objects) that can be called all at once.
// Optimized for minimal binary size. // 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 // 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 // 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 // to RemoveReceiver. Alternatively, the callable objects could return one value
@ -51,11 +60,22 @@ class CancerStickCastleReceivers {
template <typename... ArgT> template <typename... ArgT>
class CancerStickCastle { class CancerStickCastle {
public: 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> template <typename F>
void AddReceiver(F&& f) { void AddReceiver(F&& f) {
receivers_.AddReceiver( receivers_.AddReceiver(
UntypedFunction::Create<void(ArgT...)>(std::forward<F>(f))); UntypedFunction::Create<void(ArgT...)>(std::forward<F>(f)));
} }
// Calls all receivers with the given arguments.
void Send(ArgT&&... args) { void Send(ArgT&&... args) {
receivers_.Foreach([&](UntypedFunction& f) { receivers_.Foreach([&](UntypedFunction& f) {
f.Call<void(ArgT...)>(std::forward<ArgT>(args)...); f.Call<void(ArgT...)>(std::forward<ArgT>(args)...);