File: cpp2011.qbk

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (215 lines) | stat: -rw-r--r-- 7,471 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
[/
 / Copyright (c) 2003-2023 Christopher M. Kohlhoff (chris at kohlhoff dot com)
 /
 / Distributed under the Boost Software License, Version 1.0. (See accompanying
 / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
 /]

[section:cpp2011 C++ 2011 Support]


[link boost_asio.overview.cpp2011.move_objects Movable I/O Objects]

[link boost_asio.overview.cpp2011.move_handlers Movable Handlers]

[link boost_asio.overview.cpp2011.variadic Variadic Templates]

[link boost_asio.overview.cpp2011.array Array Container]

[link boost_asio.overview.cpp2011.atomic Atomics]

[link boost_asio.overview.cpp2011.shared_ptr Shared Pointers]

[link boost_asio.overview.cpp2011.chrono Chrono]


[section:move_objects Movable I/O Objects]

When move support is available (via rvalue references), Boost.Asio allows move
construction and assignment of sockets, serial ports, POSIX descriptors and
Windows handles.

Move support allows you to write code like:

  tcp::socket make_socket(io_context& i)
  {
    tcp::socket s(i);
    ...
    std::move(s);
  }

or:

  class connection : public enable_shared_from_this<connection>
  {
  private:
    tcp::socket socket_;
    ...
  public:
    connection(tcp::socket&& s) : socket_(std::move(s)) {}
    ...
  };

  ...

  class server
  {
  private:
    tcp::acceptor acceptor_;
    ...
    void handle_accept(error_code ec, tcp::socket socket)
    {
      if (!ec)
        std::make_shared<connection>(std::move(socket))->go();
      acceptor_.async_accept(...);
    }
    ...
  };

as well as:

  std::vector<tcp::socket> sockets;
  sockets.push_back(tcp::socket(...));

A word of warning: There is nothing stopping you from moving these objects
while there are pending asynchronous operations, but it is unlikely to be a
good idea to do so. In particular, composed operations like [link
boost_asio.reference.async_read async_read()] store a reference to the stream object.
Moving during the composed operation means that the composed operation may
attempt to access a moved-from object.

Move support is automatically enabled for [^g++] 4.5 and later, when the
[^-std=c++0x] or [^-std=gnu++0x] compiler options are used. It may be disabled
by defining `BOOST_ASIO_DISABLE_MOVE`, or explicitly enabled for other compilers by
defining `BOOST_ASIO_HAS_MOVE`. Note that these macros also affect the availability
of [link boost_asio.overview.cpp2011.move_handlers movable handlers].

[endsect]

[section:move_handlers Movable Handlers]

With C++11 and later, user-defined completion handlers are only required to be
move constructible, and are not required to be copy constructible.

When move support is enabled, asynchronous that are documented as follows:

  template <typename Handler>
  void async_XYZ(..., Handler handler);

are actually declared as:

  template <typename Handler>
  void async_XYZ(..., Handler&& handler);

The handler argument is perfectly forwarded and the move construction occurs
within the body of `async_XYZ()`. This ensures that all other function
arguments are evaluated prior to the move. This is critical when the other
arguments to `async_XYZ()` are members of the handler. For example:

  struct my_operation
  {
    unique_ptr<tcp::socket> socket;
    unique_ptr<vector<char>> buffer;
    ...
    void operator(error_code ec, size_t length)
    {
      ...
      socket->async_read_some(boost::asio::buffer(*buffer), std::move(*this));
      ...
    }
  };

Move support is automatically enabled for [^g++] 4.5 and later, when the
[^-std=c++0x] or [^-std=gnu++0x] compiler options are used. It may be disabled
by defining `BOOST_ASIO_DISABLE_MOVE`, or explicitly enabled for other compilers by
defining `BOOST_ASIO_HAS_MOVE`. Note that these macros also affect the availability
of [link boost_asio.overview.cpp2011.move_objects movable I/O objects].

[endsect]

[section:variadic Variadic Templates]

When supported by a compiler, Boost.Asio can use variadic templates to implement the
[link boost_asio.reference.basic_socket_streambuf.connect
basic_socket_streambuf::connect()] and [link
boost_asio.reference.basic_socket_iostream.connect basic_socket_iostream::connect()]
functions.

Support for variadic templates is automatically enabled for [^g++] 4.3 and
later, when the [^-std=c++0x] or [^-std=gnu++0x] compiler options are used. It
may be disabled by defining `BOOST_ASIO_DISABLE_VARIADIC_TEMPLATES`, or explicitly
enabled for other compilers by defining `BOOST_ASIO_HAS_VARIADIC_TEMPLATES`.

[endsect]

[section:array Array Container]

Where the standard library provides `std::array<>`, Boost.Asio:

* Provides overloads for the [link boost_asio.reference.buffer buffer()] function.

* Uses it in preference to `boost::array<>` for the
  [link boost_asio.reference.ip__address_v4.bytes_type ip::address_v4::bytes_type] and
  [link boost_asio.reference.ip__address_v6.bytes_type ip::address_v6::bytes_type]
  types.

* Uses it in preference to `boost::array<>` where a fixed size array type is
  needed in the implementation.

Support for `std::array<>` is automatically enabled for [^g++] 4.3 and later,
when the [^-std=c++0x] or [^-std=gnu++0x] compiler options are used, as well as
for Microsoft Visual C++ 10. It may be disabled by defining
`BOOST_ASIO_DISABLE_STD_ARRAY`, or explicitly enabled for other compilers by
defining `BOOST_ASIO_HAS_STD_ARRAY`.

[endsect]

[section:atomic Atomics]

Boost.Asio's implementation can use `std::atomic<>` in preference to
`boost::detail::atomic_count`.

Support for the standard atomic integer template is automatically enabled for
[^g++] 4.5 and later, when the [^-std=c++0x] or [^-std=gnu++0x] compiler
options are used. It may be disabled by defining `BOOST_ASIO_DISABLE_STD_ATOMIC`, or
explicitly enabled for other compilers by defining `BOOST_ASIO_HAS_STD_ATOMIC`.

[endsect]

[section:shared_ptr Shared Pointers]

Boost.Asio's implementation can use `std::shared_ptr<>` and `std::weak_ptr<>` in
preference to the Boost equivalents.

Support for the standard smart pointers is automatically enabled for [^g++] 4.3
and later, when the [^-std=c++0x] or [^-std=gnu++0x] compiler options are used,
as well as for Microsoft Visual C++ 10. It may be disabled by defining
`BOOST_ASIO_DISABLE_STD_SHARED_PTR`, or explicitly enabled for other compilers by
defining `BOOST_ASIO_HAS_STD_SHARED_PTR`.

[endsect]

[section:chrono Chrono]

Boost.Asio provides timers based on the `std::chrono` facilities via the [link
boost_asio.reference.basic_waitable_timer basic_waitable_timer] class template.
The typedefs [link boost_asio.reference.system_timer system_timer], [link
boost_asio.reference.steady_timer steady_timer] and [link
boost_asio.reference.high_resolution_timer high_resolution_timer] utilise the
standard clocks `system_clock`, `steady_clock` and `high_resolution_clock`
respectively.

Support for the `std::chrono` facilities is automatically enabled for [^g++]
4.6 and later, when the [^-std=c++0x] or [^-std=gnu++0x] compiler options are
used. (Note that, for [^g++], the draft-standard `monotonic_clock` is used in
place of `steady_clock`.) Support may be disabled by defining
`BOOST_ASIO_DISABLE_STD_CHRONO`, or explicitly enabled for other compilers by
defining `BOOST_ASIO_HAS_STD_CHRONO`.

When standard `chrono` is unavailable, Boost.Asio will otherwise use the Boost.Chrono
library. The [link boost_asio.reference.basic_waitable_timer basic_waitable_timer]
class template may be used with either.

[endsect]

[endsect]