Boost C++ 库
...one of the most highly regarded and expertly designed C++ library projects in the world.
— Herb Sutter and Andrei Alexandrescu, C++ Coding Standards
如果一个类是公开且明确地从 execution_context::service 派生的,或者它是公开且明确地从另一个服务派生的,那么它就是一个服务。对于一个服务 S,S::key_type 必须是有效的并表示一个类型 (C++Std [temp.deduct]),is_base_of_v<typename S::key_type, S> 必须为 true,并且 S 必须满足 Destructible 要求 (C++Std [destructible])。
所有服务构造函数的第一个参数都应该是对 execution_context 的左值引用。这个参数表示一个代表一组服务的 execution_context 对象,服务对象将是该组的成员。 [注意: 这些构造函数可能由 make_service 函数调用。 —结束注意]
服务应该提供一个显式的构造函数,该构造函数带有一个对 execution_context 的左值引用的单个参数。 [注意: 这个构造函数可能由 use_service 函数调用。 —结束注意]
class my_service : public execution_context::service { public: typedef my_service key_type; explicit my_service(execution_context& ctx); my_service(execution_context& ctx, int some_value); private: virtual void shutdown() noexcept override; ... };
服务的 shutdown 成员函数应该销毁服务所持有的所有用户定义函数对象的副本。