1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Service requirements</title> 5<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../../boost_asio.html" title="Boost.Asio"> 8<link rel="up" href="../reference.html" title="Reference"> 9<link rel="prev" href="Sender.html" title="Sender concepts"> 10<link rel="next" href="SettableSerialPortOption.html" title="Settable serial port option requirements"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr> 14<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td> 15<td align="center"><a href="../../../../index.html">Home</a></td> 16<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td> 17<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 18<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 19<td align="center"><a href="../../../../more/index.htm">More</a></td> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="Sender.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="SettableSerialPortOption.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="boost_asio.reference.Service"></a><a class="link" href="Service.html" title="Service requirements">Service requirements</a> 28</h3></div></div></div> 29<p> 30 A class is a <span class="emphasis"><em>service</em></span> if it is publicly and unambiguously 31 derived from <code class="computeroutput">execution_context::service</code>, or if it is publicly 32 and unambiguously derived from another service. For a service <code class="computeroutput">S</code>, 33 <code class="computeroutput">S::key_type</code> shall be valid and denote a type (C++Std [temp.deduct]), 34 <code class="computeroutput">is_base_of_v<typename S::key_type, S></code> shall be <code class="computeroutput">true</code>, 35 and <code class="computeroutput">S</code> shall satisfy the <code class="computeroutput">Destructible</code> requirements 36 (C++Std [destructible]). 37 </p> 38<p> 39 The first parameter of all service constructors shall be an lvalue reference 40 to <code class="computeroutput">execution_context</code>. This parameter denotes the <code class="computeroutput">execution_context</code> 41 object that represents a set of services, of which the service object will 42 be a member. [<span class="emphasis"><em>Note:</em></span> These constructors may be called 43 by the <code class="computeroutput">make_service</code> function. —<span class="emphasis"><em>end note</em></span>] 44 </p> 45<p> 46 A service shall provide an explicit constructor with a single parameter of 47 lvalue reference to <code class="computeroutput">execution_context</code>. [<span class="emphasis"><em>Note:</em></span> 48 This constructor may be called by the <code class="computeroutput">use_service</code> function. 49 —<span class="emphasis"><em>end note</em></span>] 50 </p> 51<pre class="programlisting">class my_service : public execution_context::service 52{ 53public: 54 typedef my_service key_type; 55 explicit my_service(execution_context& ctx); 56 my_service(execution_context& ctx, int some_value); 57private: 58 virtual void shutdown() noexcept override; 59 ... 60}; 61</pre> 62<p> 63 A service's <code class="computeroutput">shutdown</code> member function shall destroy all copies 64 of user-defined function objects that are held by the service. 65 </p> 66</div> 67<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 68<td align="left"></td> 69<td align="right"><div class="copyright-footer">Copyright © 2003-2020 Christopher M. 70 Kohlhoff<p> 71 Distributed under the Boost Software License, Version 1.0. (See accompanying 72 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>) 73 </p> 74</div></td> 75</tr></table> 76<hr> 77<div class="spirit-nav"> 78<a accesskey="p" href="Sender.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../reference.html"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../boost_asio.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="SettableSerialPortOption.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a> 79</div> 80</body> 81</html> 82