Blame view

3rdparty/boost_1_81_0/boost/local_function.hpp 18.4 KB
598bfd3f   Hu Chunming   提交_GLIBCXX_USE_CX...
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
  
  // Copyright (C) 2009-2012 Lorenzo Caminiti
  // Distributed under the Boost Software License, Version 1.0
  // (see accompanying file LICENSE_1_0.txt or a copy at
  // http://www.boost.org/LICENSE_1_0.txt)
  // Home at http://www.boost.org/libs/local_function
  
  #ifndef BOOST_LOCAL_FUNCTION_HPP_
  #define BOOST_LOCAL_FUNCTION_HPP_
  
  #ifndef DOXYGEN
  
  #include <boost/local_function/aux_/macro/decl.hpp>
  #include <boost/local_function/aux_/macro/name.hpp>
  #include <boost/local_function/aux_/macro/typeof.hpp>
  #include <boost/local_function/aux_/preprocessor/traits/decl.hpp>
  #include <boost/local_function/detail/preprocessor/line_counter.hpp>
  #include <boost/local_function/detail/preprocessor/void_list.hpp>
  #include <boost/config.hpp>
  
  // PUBLIC //
  
  #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
  #   define BOOST_LOCAL_FUNCTION_ID(id, declarations) \
          BOOST_LOCAL_FUNCTION_AUX_DECL(id, 0 /* not within template */, \
                  BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS( \
                          BOOST_LOCAL_FUNCTION_DETAIL_PP_VOID_LIST( \
                                  declarations)))
  #   define BOOST_LOCAL_FUNCTION(declarations) \
          BOOST_LOCAL_FUNCTION_ID( \
                  BOOST_LOCAL_FUNCTION_DETAIL_PP_LINE_COUNTER, declarations)
  #   define BOOST_LOCAL_FUNCTION_ID_TPL(id, declarations) \
          BOOST_LOCAL_FUNCTION_AUX_DECL(id, 1 /* within template */, \
                  BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS( \
                          BOOST_LOCAL_FUNCTION_DETAIL_PP_VOID_LIST( \
                                  declarations)))
  #   define BOOST_LOCAL_FUNCTION_TPL(declarations) \
          BOOST_LOCAL_FUNCTION_ID_TPL( \
                  BOOST_LOCAL_FUNCTION_DETAIL_PP_LINE_COUNTER, declarations)
  #else // VARIADIC
  #   define BOOST_LOCAL_FUNCTION_ID(id, ...) \
          BOOST_LOCAL_FUNCTION_AUX_DECL(id, 0 /* not within template */, \
                  BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS( \
                          BOOST_LOCAL_FUNCTION_DETAIL_PP_VOID_LIST(__VA_ARGS__)))
  #   define BOOST_LOCAL_FUNCTION(...) \
          BOOST_LOCAL_FUNCTION_ID( \
                  BOOST_LOCAL_FUNCTION_DETAIL_PP_LINE_COUNTER, __VA_ARGS__)
  #   define BOOST_LOCAL_FUNCTION_ID_TPL(id, ...) \
          BOOST_LOCAL_FUNCTION_AUX_DECL(id, 1 /* within template */, \
                  BOOST_LOCAL_FUNCTION_AUX_PP_DECL_TRAITS( \
                          BOOST_LOCAL_FUNCTION_DETAIL_PP_VOID_LIST(__VA_ARGS__)))
  #   define BOOST_LOCAL_FUNCTION_TPL(...) \
          BOOST_LOCAL_FUNCTION_ID_TPL( \
                  BOOST_LOCAL_FUNCTION_DETAIL_PP_LINE_COUNTER, __VA_ARGS__)
  #endif // VARIADIC
  
  #define BOOST_LOCAL_FUNCTION_NAME(qualified_name) \
      BOOST_LOCAL_FUNCTION_AUX_NAME(0 /* not within template */, qualified_name)
  #define BOOST_LOCAL_FUNCTION_NAME_TPL(qualified_name) \
      BOOST_LOCAL_FUNCTION_AUX_NAME(1 /* within template */, qualified_name)
  
  #define BOOST_LOCAL_FUNCTION_TYPEOF(bound_variable_name) \
      BOOST_LOCAL_FUNCTION_AUX_TYPEOF_TYPE(bound_variable_name)
  
  // DOCUMENTATION //
  
  #else // DOXYGEN
  
  /** @file
  @brief Local functions allow to program functions locally, within other
  functions, and directly within the scope where they are needed.
  */
  
  /**
  @brief This macro is used to start a local function declaration.
  
  This macro must be used within a declarative context, it must follow the local
  function result type, it must be followed by the local function body code, and
  then by the @RefMacro{BOOST_LOCAL_FUNCTION_NAME} macro (see the
  @RefSect{tutorial, Tutorial} and @RefSect{advanced_topics, Advanced Topics}
  sections):
  @code
  { // Some declarative context.
      ...
      result_type BOOST_LOCAL_FUNCTION(declarations) {
          ... // Body code.
      } BOOST_LOCAL_FUNCTION_NAME(qualified_name)
      ...
  }
  @endcode
  
  As usual, exceptions specifications can be optionally programmed just after the
  macro and before the body code block <c>{ ... }</c> (but the exception
  specifications will only apply to the body code and not to the library code
  automatically generated by the macro expansion, see the
  @RefSect{advanced_topics, Advanced Topics} section).
  
  Within templates, the special macros @RefMacro{BOOST_LOCAL_FUNCTION_TPL}
  and @RefMacro{BOOST_LOCAL_FUNCTION_NAME_TPL} must be used.
  
  @Params
  @Param{declarations,
  On compilers that support variadic macros\, the parameter declarations are
  defined by the following grammar:
  @code
      declarations:
              void | declaration_tuple | declaration_sequence
      declaration_tuple:
              declaration\, declaration\, ...
      declaration_sequence:
              (declaration) (declaration) ...
      declaration:
              bound_variable | parameter | default_value | result_type
      bound_variable:
              [const] bind [(variable_type)] [&] variable_name
      parameter:
              [auto | register] parameter_type parameter_name
      default_value:
              default parameter_default_value
      result_type:
              return function_result_type
  @endcode
  On compilers that do not support variadic macros\, <c>declaration_tuple</c>
  cannot be used:
  @code
      declarations:
              void | declaration_sequence
  @endcode
  
  (Lexical conventions: <c>token1 | token2</c> means either <c>token1</c> or
  <c>token2</c>; <c>[token]</c> means either <c>token</c> or nothing;
  <c>{expression}</c> means the token resulting from the expression.)
  }
  @EndParams
   
  Note that on compilers that support variadic macros, commas can be used to
  separate the declarations resembling more closely the usual C++ function
  declaration syntax (this is the preferred syntax).
  However, for portability, on all C++ compilers (with and without variadic
  macros) the same library macros also accept parameter declarations specified as
  a Boost.Preprocessor sequence separated by round parenthesis <c>()</c>.
  
  When binding the object <c>this</c>, the special symbol <c>this_</c> needs to
  be used instead of <c>this</c> as the name of the variable to bind and also
  within the local function body to access the object.
  (Mistakenly using <c>this</c> instead of <c>this_</c> might not always result in a compiler error and will in general result in undefined behaviour.)
  
  The result type must either be specified just before the macro or within the
  macro declarations prefixed by <c>return</c> (but not in both places).
  
  Within the local function body it possible to access the result type using <c>result_type</c>, the type of the first parameter using <c>arg1_type</c>, the type of the second parameter using <c>arg2_type</c>, etc.
  The bound variable types can be accessed using @RefMacro{BOOST_LOCAL_FUNCTION_TYPEOF}.
  
  This macro cannot be portably expanded multiple times on the same line.
  In these cases, use the @RefMacro{BOOST_LOCAL_FUNCTION_ID} macro instead.
  
  The maximum number of local function parameters (excluding bound variables) is
  specified by the configuration macro
  @RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX}.
  The maximum number of bound variables is specified by the configuration macro
  @RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX}.
  The configuration macro
  @RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_LOCALS_AS_TPARAMS} can be used to force
  optimizations that reduce the local function call run-time overhead.
  
  @Note Local functions are functors so they can be assigned to other functors
  like <c>boost::function</c> (see Boost.Function).
  
  @See @RefSect{tutorial, Tutorial} section,
  @RefSect{advanced_topics, Advanced Topics} section,
  @RefMacro{BOOST_LOCAL_FUNCTION_NAME}, @RefMacro{BOOST_LOCAL_FUNCTION_TPL},
  @RefMacro{BOOST_LOCAL_FUNCTION_NAME_TPL},
  @RefMacro{BOOST_LOCAL_FUNCTION_TYPEOF}, @RefMacro{BOOST_LOCAL_FUNCTION_ID},
  @RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_ARITY_MAX},
  @RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_BIND_MAX},
  @RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_LOCALS_AS_TPARAMS}.
  */
  #define BOOST_LOCAL_FUNCTION(declarations)
  
  /**
  @brief This macro is used to start a local function declaration within
  templates.
  
  This macro must be used instead of @RefMacro{BOOST_LOCAL_FUNCTION} when
  declaring a local function within a template.
  A part from that, this macro has the exact same syntax a
  @RefMacro{BOOST_LOCAL_FUNCTION} (see @RefMacro{BOOST_LOCAL_FUNCTION} for more
  information):
  @code
  { // Some declarative context within a template.
      ...
      result_type BOOST_LOCAL_FUNCTION_TPL(declarations) {
          ... // Body code.
      } BOOST_LOCAL_FUNCTION_NAME_TPL(qualified_name)
      ...
  }
  @endcode
  
  Note that @RefMacro{BOOST_LOCAL_FUNCTION_NAME_TPL} must be used with this
  macro instead of @RefMacro{BOOST_LOCAL_FUNCTION_NAME}.
  
  This macro cannot be portably expanded multiple times on the same line.
  In these cases, use the @RefMacro{BOOST_LOCAL_FUNCTION_ID_TPL} macro instead.
  
  @Note C++03 does not allow to use <c>typename</c> outside templates.
  This library internally manipulates types, these operations require
  <c>typename</c> but only within templates.
  This macro is used to indicate to the library when the enclosing scope is a
  template so the library can correctly use <c>typename</c>.
  
  @See @RefSect{tutorial, Tutorial} section, @RefMacro{BOOST_LOCAL_FUNCTION},
  @RefMacro{BOOST_LOCAL_FUNCTION_ID_TPL},
  @RefMacro{BOOST_LOCAL_FUNCTION_NAME_TPL}.
  */
  #define BOOST_LOCAL_FUNCTION_TPL(declarations)
  
  /**
  @brief This macro allows to declare multiple local functions on the same line.
  
  This macro is equivalent to @RefMacro{BOOST_LOCAL_FUNCTION} but it can be
  expanded multiple times on the same line if different identifiers <c>id</c> are
  provided for each expansion (see the
  @RefSect{advanced_topics, Advanced Topics} section).
  
  @Params
  @Param{id,
  A unique identifier token which can be concatenated by the preprocessor
  (<c>__LINE__</c>\, <c>local_function_number_1_on_line_123</c>\, etc).
  }
  @Param{declarations,
  Same as the <c>declarations</c> parameter of the
  @RefMacro{BOOST_LOCAL_FUNCTION} macro.
  }
  @EndParams
  
  The @RefMacro{BOOST_LOCAL_FUNCTION_NAME} macro should be used to end each one
  of the multiple local function declarations as usual (and it will specify a
  unique name for each local function).
  
  Within templates, the special macros @RefMacro{BOOST_LOCAL_FUNCTION_ID_TPL}
  must be used.
  
  @Note This macro can be useful when the local function macros are expanded
  within user-defined macros (because macros all expand on the same line).
  On some compilers (e.g., MSVC which supports the non-standard
  <c>__COUNTER__</c> macro) it might not be necessary to use this macro but
  the use of this macro when expanding multiple local function macros on the same
  line is always necessary to ensure portability (this is because this library
  can only portably use <c>__LINE__</c> to internally generate unique
  identifiers).
  
  @See @RefSect{advanced_topics, Advanced Topics} section,
  @RefMacro{BOOST_LOCAL_FUNCTION}, @RefMacro{BOOST_LOCAL_FUNCTION_NAME},
  @RefMacro{BOOST_LOCAL_FUNCTION_ID_TPL}.
  */
  #define BOOST_LOCAL_FUNCTION_ID(id, declarations)
  
  /**
  @brief This macro allows to declare multiple local functions on the same line
  within templates.
  
  This macro must be used instead of @RefMacro{BOOST_LOCAL_FUNCTION_TPL} when
  declaring multiple local functions on the same line within a template.
  A part from that, this macro has the exact same syntax as
  @RefMacro{BOOST_LOCAL_FUNCTION_TPL} (see @RefMacro{BOOST_LOCAL_FUNCTION_TPL}
  for more information).
  
  @Params
  @Param{id,
  A unique identifier token which can be concatenated by the preprocessor
  (<c>__LINE__</c>\, <c>local_function_number_1_on_line_123</c>\, etc).
  }
  @Param{declarations,
  Same as the <c>declarations</c> parameter of the
  @RefMacro{BOOST_LOCAL_FUNCTION_TPL} macro.
  }
  @EndParams
  
  The @RefMacro{BOOST_LOCAL_FUNCTION_NAME} macro should be used to end each one
  of the multiple local function declarations as usual (and it will specify a
  unique name for each local function).
  
  Outside template, the macro @RefMacro{BOOST_LOCAL_FUNCTION_ID} should be used
  to declare multiple local functions on the same line.
  
  @Note This macro can be useful when the local function macros are expanded
  within user-defined macros (because macros all expand on the same line).
  On some compilers (e.g., MSVC which supports the non-standard
  <c>__COUNTER__</c> macro) it might not be necessary to use this macro but
  the use of this macro when expanding multiple local function macros on the same
  line is always necessary to ensure portability (this is because this library
  can only portably use <c>__LINE__</c> to internally generate unique
  identifiers).
  
  @See @RefSect{advanced_topics, Advanced Topics} section,
  @RefMacro{BOOST_LOCAL_FUNCTION_TPL}, @RefMacro{BOOST_LOCAL_FUNCTION_NAME},
  @RefMacro{BOOST_LOCAL_FUNCTION_ID}.
  */
  #define BOOST_LOCAL_FUNCTION_ID_TPL(id, declarations)
  
  /**
  @brief This macro is used to end a local function declaration specifying its
  name.
  
  This macro must follow the local function body code block <c>{ ... }</c>:
  @code
  { // Some declarative context.
      ...
      result_type BOOST_LOCAL_FUNCTION(declarations) {
          ... // Body code.
      } BOOST_LOCAL_FUNCTION_NAME(qualified_name)
      ...
  }
  @endcode
  
  Within templates, the special macros @RefMacro{BOOST_LOCAL_FUNCTION_TPL} and
  @RefMacro{BOOST_LOCAL_FUNCTION_NAME_TPL} must be used.
  
  @Params
  @Param{qualified_name,
  The name of the local function optionally qualified as follow:
  @code
      name:
              [inline] [recursive] local_function_name
  @endcode
  (Lexical conventions: <c>token1 | token2</c> means either <c>token1</c> or
  <c>token2</c>; <c>[token]</c> means either <c>token</c> or nothing;
  <c>{expression}</c> means the token resulting from the expression.)
  }
  @EndParams
  
  The local function name can be qualified by prefixing it with the keyword
  <c>inline</c> (see the @RefSect{advanced_topics, Advanced Topics} section):
  @code
      BOOST_LOCAL_FUNCTION_NAME(inline local_function_name)
  @endcode
  This increases the chances that the compiler will be able to inline the local
  function calls (thus reducing run-time).
  However, inline local functions cannot be passed as template parameters (e.g., to <c>std::for_each</c>) or assigned to other functors (e.g., to
  <c>boost::function</c>).
  That is true on C++03 compilers but inline local functions can instead be
  passed as template parameters on C++11 compilers.
  On C++11 compilers, there is no need to declare a local function lined because
  this library will automatically use C++11 specific features to inline the local
  function while always allowing to pass it as a template parameter.
  This optimization is automatically enabled when the Boost.Config macro
  <c>BOOST_NO_CXX11_LOCAL_CLASS_TEMPLATE_PARAMETERS</c> is not defined but it also be
  forced using @RefMacro{BOOST_LOCAL_FUNCTION_CONFIG_LOCALS_AS_TPARAMS}.
  
  The local function name can also be qualified by prefixing it with the
  "keyword" <c>recursive</c> (see the
  @RefSect{advanced_topics, Advanced Topics} section):
  @code
      BOOST_LOCAL_FUNCTION_NAME(recursive local_function_name)
  @endcode
  This allows the local function to recursively call itself from its body (as
  usual in C++).
  However, recursive local functions should only be called within their
  declaration scope (otherwise the result is undefined behaviour).
  Finally, compilers have not been observed to be able to inline recursive local
  function calls, not even when the recursive local function is also declared
  inline:
  @code
      BOOST_LOCAL_FUNCTION(inline recursive local_function_name)
  @endcode
  
  @Note The local function name cannot be the name of an operator
  <c>operator...</c> and it cannot be the same name of another local function
  declared within the same enclosing scope (but <c>boost::overloaded_function</c>
  can be used to overload local functions, see
  Boost.Functional/OverloadedFunction and the
  @RefSect{advanced_topics, Advanced Topics} section).
  
  @See @RefSect{tutorial, Tutorial} section,
  @RefSect{advanced_topics, Advanced Topics} section,
  @RefMacro{BOOST_LOCAL_FUNCTION},
  @RefMacro{BOOST_LOCAL_FUNCTION_NAME_TPL}.
  */
  #define BOOST_LOCAL_FUNCTION_NAME(qualified_name)
  
  /**
  @brief This macro is used to end a local function declaration specifying its
  name within templates.
  
  This macro must be used instead of @RefMacro{BOOST_LOCAL_FUNCTION_NAME} when
  declaring a local function within a template.
  A part from that, this macro has the exact same syntax a
  @RefMacro{BOOST_LOCAL_FUNCTION_NAME} (see @RefMacro{BOOST_LOCAL_FUNCTION_NAME}
  for more information):
  @code
  { // Some declarative context within a template.
      ...
      result_type BOOST_LOCAL_FUNCTION_TPL(declarations) {
          ... // Body code.
      } BOOST_LOCAL_FUNCTION_NAME_TPL(qualified_name)
      ...
  }
  @endcode
  
  Note that @RefMacro{BOOST_LOCAL_FUNCTION_TPL} must be used with this macro
  instead of @RefMacro{BOOST_LOCAL_FUNCTION}.
  
  @Note C++03 does not allow to use <c>typename</c> outside templates.
  This library internally manipulates types, these operations require
  <c>typename</c> but only within templates.
  This macro is used to indicate to the library when the enclosing scope is a
  template so the library can correctly use <c>typename</c>.
  
  @See @RefSect{tutorial, Tutorial} section,
  @RefMacro{BOOST_LOCAL_FUNCTION_NAME}, @RefMacro{BOOST_LOCAL_FUNCTION_TPL}.
  */
  #define BOOST_LOCAL_FUNCTION_NAME_TPL(name)
  
  /**
  @brief This macro expands to the type of the specified bound variable.
  
  This macro can be used within the local functions body to refer to the bound
  variable types so to declare local variables, check concepts (using
  Boost.ConceptCheck), etc (see the @RefSect{advanced_topics, Advanced Topics}
  section).
  This way the local function can be programmed entirely without explicitly
  specifying the bound variable types thus facilitating maintenance (e.g., if
  the type of a bound variable changes in the enclosing scope, the local function
  code does not have to change).
  
  @Params
  @Param{bound_variable_name,
  The name of one of the local function's bound variables.
  }
  @EndParams
  
  The type returned by the macro is fully qualified in that it contains the extra
  constant and reference qualifiers when the specified variable is bound by
  constant and by reference.
  For example, if a variable named <c>t</c> of type <c>T</c> is:
  @li Bound by value using <c>bind t</c> then
  <c>BOOST_LOCAL_FUNCTION_TYPEOF(t)</c> is <c>T</c>.
  @li Bound by constant value using <c>const bind t</c> then
  <c>BOOST_LOCAL_FUNCTION_TYPEOF(t)</c> is <c>const T</c>.
  @li Bound by reference using <c>bind& t</c> then
  <c>BOOST_LOCAL_FUNCTION_TYPEOF(t)</c> is <c>T&</c>.
  @li Bound by constant reference using <c>const bind& t</c> then
  <c>BOOST_LOCAL_FUNCTION_TYPEOF(t)</c> is <c>const T&</c>.
  
  This macro must be prefixed by <c>typename</c> when used within templates.
  
  @Note It is best to use this macro instead of Boost.Typeof so to reduce the
  number of times Boost.Typeof is used to deduce types (see the
  @RefSect{advanced_topics, Advanced Topics} section).
  
  @See @RefSect{advanced_topics, Advanced Topics} section,
  @RefMacro{BOOST_LOCAL_FUNCTION}.
  */
  #define BOOST_LOCAL_FUNCTION_TYPEOF(bound_variable_name)
  
  #endif // DOXYGEN
  
  #endif // #include guard