summaryrefslogtreecommitdiff
path: root/libs/fusion/doc/functional.qbk
blob: 19205527e08175a2ea28758dde7c1ed8260db4b0 (plain)
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
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
[/==============================================================================
    Copyright (C) 2006 Tobias Schwinger

    Use, modification and distribution is subject to 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 Functional]

Components to call functions and function objects and to make Fusion code
callable through a function object interface.

[heading Header]

  #include <boost/fusion/functional.hpp>

[heading Fused and unfused forms]

What is a function call?

    f (a,b,c)

It is a name and a tuple written next to each other, left-to-right.

Although the C++ syntax does not allow to replace [^(a,b,c)] with some Fusion
__sequence__, introducing yet another function provides a solution:

   invoke(f,my_sequence)

Alternatively it is possible to apply a simple transformation to [^f] in order
to achieve the same effect:

   f tuple <=> ``f'`` (tuple)

Now, [^f'] is an unary function that takes the arguments to `f` as a tuple;
[^f'] is the /fused/ form of `f`.
Reading the above equivalence right-to-left to get the inverse transformation,
`f` is the /unfused/ form of [^f'].

[heading Calling functions and function objects]

Having generic C++ code call back arbitrary functions provided by the client
used to be a heavily repetitive task, as different functions can differ in
arity, invocation syntax and other properties that might be part of the type.
Transporting arguments as Fusion sequences and factoring out the invocation
makes Fusion algorithms applicable to function arguments and also reduces
the problem to one invocation syntax and a fixed arity (instead of an arbitrary
number of arbitrary arguments times several syntactic variants times additional
properties).

Transforming an unfused function into its fused counterpart allows n-ary
calls from an algorithm that invokes an unary __poly_func_obj__ with
__sequence__ arguments.

The library provides several function templates to invoke different kinds of
functions and adapters to transform them into fused form, respectively.
Every variant has a corresponding generator function template that returns
an adapter instance for the given argument.

Constructors can be called applying __boost_func_factory__.

[heading Making Fusion code callable through a function object interface]

Transforming a fused function into its unfused counterpart allows to create
function objects to accept arbitrary calls. In other words, an unary function
object can be implemented instead of (maybe heavily overloaded) function
templates or function call operators.

The library provides both a strictly typed and a generic variant for this
transformation. The latter should be used in combination with
__boost_func_forward__ to attack __the_forwarding_problem__.

Both variants have a corresponding generator function template that returns an
adapter instance for the given argument.

[/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]

[section Concepts]


[section:callable Callable Object]

[heading Description]

A pointer to a function, a pointer to member function, a pointer to member
data, or a class type whose objects can appear immediately to the left of a
function call operator.

[heading Models]
* function pointer types
* member (function or data) pointer types
* all kinds of function objects

[heading Examples]

  & a_free_function
  & a_class::a_static_member_function
  & a_class::a_nonstatic_data_member
  & a_class::a_nonstatic_member_function
  std::less<int>()
  // using namespace boost;
  bind(std::less<int>(), _1, 5)
  lambda::_1 += lambda::_2;
  fusion::__make_fused_function_object__(std::less<int>())


[endsect]


[section:reg_callable Regular Callable Object]

[heading Description]

A non-member-pointer __callable_obj__ type: A pointer to a function or a class
type whose objects can appear immediately to the left of a function call operator.

[heading Refinement of]
* __callable_obj__

[variablelist Notation
    [[`F`][A possibly const qualified Deferred Callable Object type]]
    [[`f`][An object or reference to an object of type F]]
    [[`A1 ...AN`][Argument types]]
    [[`a1 ...aN`][Objects or references to objects with types `A1 ...AN`]]
]

[heading Expression requirements]

[table
    [[Expression][Return Type][Runtime Complexity]]
    [[`f(a1, ...aN)`][Unspecified][Unspecified]]
]

[heading Models]
* function pointer types
* all kinds of function objects

[heading Examples]

  & a_free_function
  & a_class::a_static_member_function
  std::less<int>()
  // using namespace boost;
  bind(std::less<int>(), _1, 5)
  lambda::_1 += lambda::_2;
  fusion::__make_fused_function_object__(std::less<int>())

[endsect]


[section:def_callable Deferred Callable Object]

[heading Description]

__callable_obj__ types that work with __boost_result_of__ to determine the
result of a call.

[heading Refinement of]
* __callable_obj__

[blurb note Once C++ supports the [^decltype] keyword, all models of
__callable_obj__ will also be models of __def_callable_obj__, because
function objects won't need client-side support for `result_of`.
]

[variablelist Notation
    [[`F`][A possibly const qualified Deferred Callable Object type]]
    [[`A1 ...AN`][Argument types]]
    [[`a1 ...aN`][Objects or references to objects with types `A1 ...AN`]]
    [[`T1 ...TN`][`T`i is `A`i `&` if `a`i is an __lvalue__, same as `A`i, otherwise]]
]

[heading Expression requirements]

[table
    [[Expression][Type]]
    [[__boost_result_of_call__`< F(T1 ...TN) >::type`][Result of a call with `A1 ...AN`-typed arguments]]
]

[heading Models]
* __poly_func_obj__ types
* member (function or data) pointer types

[heading Examples]

  & a_free_function
  & a_class::a_static_member_function
  & a_class::a_nonstatic_data_member
  & a_class::a_nonstatic_member_function
  std::less<int>()
  // using namespace boost;
  bind(std::less<int>(), _1, 5)
  // Note: Boost.Lambda expressions don't work with __boost_result_of__
  fusion::__make_fused_function_object__(std::less<int>())

[endsect]


[section:poly Polymorphic Function Object]

[heading Description]

A non-member-pointer __def_callable_obj__ type.

[heading Refinement of]
* __reg_callable_obj__
* __def_callable_obj__

[variablelist Notation
    [[`F`][A possibly const-qualified Polymorphic Function Object type]]
    [[`f`][An object or reference to an object of type F]]
    [[`A1 ...AN`][Argument types]]
    [[`a1 ...aN`][Objects or references to objects with types `A1 ...AN`]]
    [[`T1 ...TN`][`T`i is `A`i `&` if `a`i is an __lvalue__, same as `A`i, otherwise]]
]

[heading Expression requirements]

[table
    [[Expression][Return Type][Runtime Complexity]]
    [[`f(a1, ...aN)`][`result_of< F(T1, ...TN) >::type`][Unspecified]]
]

[heading Models]
* function pointers
* function objects of the Standard Library
* all Fusion __functional_adapters__

[heading Examples]

  & a_free_function
  & a_class::a_static_member_function
  std::less<int>()
  // using namespace boost;
  bind(std::less<int>(), _1, 5)
  // Note: Boost.Lambda expressions don't work with __boost_result_of__
  fusion::__make_fused_function_object__(std::less<int>())

[endsect]


[endsect]

[/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]

[section Invocation]

[section Functions]

[section invoke]

[heading Description]

Calls a __def_callable_obj__ with the arguments from a __sequence__.

The first template parameter can be specialized explicitly to avoid copying
and/or to control the const qualification of a function object.

If the target function is a pointer to a class members, the corresponding
object can be specified as a reference, pointer, or smart pointer.
In case of the latter, a freestanding [^get_pointer] function must be
defined (Boost provides this function for [^std::auto_ptr] and
__boost_shared_ptr_call__).

Constructors can be called applying __boost_func_factory__.

[heading Synopsis]
    template<
        typename Function,
        class Sequence
        >
    typename __result_of_invoke__<Function, Sequence>::type
    invoke(Function f, Sequence & s);

    template<
        typename Function,
        class Sequence
        >
    typename __result_of_invoke__<Function, Sequence const>::type
    invoke(Function f, Sequence const & s);

[heading Parameters]
[table
    [[Parameter]  [Requirement]                    [Description]]
    [[`f`]        [A __def_callable_obj__]         [The function to call.]]
    [[`s`]        [A __forward_sequence__]         [The arguments.]]
]

[heading Expression Semantics]

    invoke(f,s);

[*Return type]: Return type of `f` when invoked with the elements in `s` as its
arguments.

[*Semantics]: Invokes `f` with the elements in `s` as arguments and returns
the result of the call expression.

[heading Header]

  #include <boost/fusion/functional/invocation/invoke.hpp>

[heading Example]
    __std_plus_doc__<int> add;
    assert(invoke(add,__make_vector__(1,1)) == 2);

[heading See also]
* __invoke_procedure__
* __invoke_function_object__
* __result_of_invoke__
* __fused__
* __make_fused__

[endsect]

[section:invoke_proc invoke_procedure]

[heading Description]

Calls a __callable_obj__ with the arguments from a __sequence__. The result
of the call is ignored.

The first template parameter can be specialized explicitly to avoid copying
and/or to control the const qualification of a function object.

For pointers to class members corresponding object can be specified as
a reference, pointer, or smart pointer. In case of the latter, a freestanding
[^get_pointer] function must be defined (Boost provides this function for
[^std::auto_ptr] and __boost_shared_ptr_call__).

The target function must not be a pointer to a member object (dereferencing
such a pointer without returning anything does not make sense, so it isn't
implemented).

[heading Synopsis]
    template<
        typename Function,
        class Sequence
        >
    typename __result_of_invoke_procedure__<Function, Sequence>::type
    invoke_procedure(Function f, Sequence & s);

    template<
        typename Function,
        class Sequence
        >
    typename __result_of_invoke_procedure__<Function, Sequence const>::type
    invoke_procedure(Function f, Sequence const & s);

[heading Parameters]
[table
    [[Parameter]  [Requirement]                    [Description]]
    [[`f`]        [Model of __callable_obj__]      [The function to call.]]
    [[`s`]        [Model of __forward_sequence__]  [The arguments.]]
]

[heading Expression Semantics]

    invoke_procedure(f,s);

[*Return type]: `void`

[*Semantics]: Invokes `f` with the elements in `s` as arguments.

[heading Header]

  #include <booost/fusion/functional/invocation/invoke_procedure.hpp>

[heading Example]
    __vector__<int,int> v(1,2);
    using namespace boost::lambda;
    invoke_procedure(_1 += _2, v);
    assert(__front__(v) == 3);

[heading See also]
* __invoke__
* __invoke_function_object__
* __result_of_invoke_procedure__
* __fused_procedure__
* __make_fused_procedure__

[endsect]

[section:invoke_fobj invoke_function_object]

[heading Description]

Calls a __poly_func_obj__ with the arguments from a __sequence__.

The first template parameter can be specialized explicitly to avoid copying
and/or to control the const qualification of a function object.

Constructors can be called applying __boost_func_factory__.

[heading Synopsis]
    template<
        typename Function,
        class Sequence
        >
    typename __result_of_invoke_function_object__<Function, Sequence>::type
    invoke_function_object(Function f, Sequence & s);

    template<
        typename Function,
        class Sequence
        >
    typename __result_of_invoke_function_object__<Function, Sequence const>::type
    invoke_function_object(Function f, Sequence const & s);

[heading Parameters]
[table
    [[Parameter]  [Requirement]                    [Description]]
    [[`f`]        [Model of __poly_func_obj__]     [The function object to call.]]
    [[`s`]        [Model of __forward_sequence__]  [The arguments.]]
]

[heading Expression Semantics]

    invoke_function_object(f,s);

[*Return type]: Return type of `f` when invoked with the elements in `s` as its
arguments.

[*Semantics]: Invokes `f` with the elements in `s` as arguments and returns the
result of the call expression.

[heading Header]

  #include <boost/fusion/functional/invocation/invoke_function_object.hpp>

[heading Example]
    struct sub
    {
        template <typename Sig>
        struct result;

        template <class Self, typename T>
        struct result< Self(T,T) >
        { typedef typename remove_reference<T>::type type; };

        template<typename T>
        T operator()(T lhs, T rhs) const
        {
            return lhs - rhs;
        }
    };

    void try_it()
    {
        sub f;
        assert(f(2,1) == invoke_function_object(f,__make_vector__(2,1)));
    }

[heading See also]
* __invoke__
* __invoke_procedure__
* __result_of_invoke_function_object__
* __fused_function_object__
* __make_fused_function_object__

[endsect]

[endsect] [/ Functions]

[section Metafunctions]

[section invoke]

[heading Description]
Returns the result type of __invoke__.

[heading Synopsis]
    namespace result_of
    {
        template<
            typename Function,
            class Sequence
            >
        struct invoke
        {
            typedef __unspecified__ type;
        };
    }

[heading See also]
* __invoke__
* __fused__

[endsect]

[section:invoke_proc invoke_procedure]

[heading Description]
Returns the result type of __invoke_procedure__.

[heading Synopsis]
    namespace result_of
    {
        template<
            typename Function,
            class Sequence
            >
        struct invoke_procedure
        {
            typedef __unspecified__ type;
        };
    }

[heading See also]
* __invoke_procedure__
* __fused_procedure__

[endsect]

[section:invoke_fobj invoke_function_object]

[heading Description]
Returns the result type of __invoke_function_object__.

[heading Synopsis]
    namespace result_of
    {
        template<
            class Function,
            class Sequence
            >
        struct invoke_function_object
        {
            typedef __unspecified__ type;
        };
    }

[heading See also]
* __invoke_function_object__
* __fused_function_object__

[endsect]

[endsect] [/ Metafunctions ]

[section Limits]

[heading Header]

  #include <boost/fusion/functional/invocation/limits.hpp>

[heading Macros]

The following macros can be defined to change the maximum arity.
The default is 6.

* BOOST_FUSION_INVOKE_MAX_ARITY
* BOOST_FUSION_INVOKE_PROCEDURE_MAX_ARITY
* BOOST_FUSION_INVOKE_FUNCTION_OBJECT_MAX_ARITY

[endsect]

[endsect] [/ Invocation ]

[/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]

[section:adapters Adapters]

Function object templates to transform a particular target function.

[section fused]

[heading Description]

An unary __poly_func_obj__ adapter template for __def_callable_obj__ target
functions. It takes a __forward_sequence__ that contains the arguments for the
target function.

The type of the target function is allowed to be const qualified or a
reference. Const qualification is preserved and propagated appropriately
(in other words, only const versions of [^operator()] can be used for a
target function object that is const or, if the target function object
is held by value, the adapter is const - these semantics have nothing to
do with the const qualification of a member function, which is referring
to the type of object pointed to by [^this] which is specified with the
first element in the sequence passed to the adapter).

If the target function is a pointer to a class members, the corresponding
object can be specified as a reference, pointer, or smart pointer.
In case of the latter, a freestanding [^get_pointer] function must be
defined (Boost provides this function for [^std::auto_ptr] and
__boost_shared_ptr_call__).

[heading Header]

  #include <boost/fusion/functional/adapter/fused.hpp>

[heading Synopsis]
    template <typename Function>
    class fused;

[heading Template parameters]

[table
    [[Parameter]            [Description]                   [Default]]
    [[`Function`]           [A __def_callable_obj__]        []]
]

[heading Model of]

* __poly_func_obj__
* __def_callable_obj__

[variablelist Notation
    [[`R`] [A possibly const qualified __def_callable_obj__ type or reference type thereof]]
    [[`r`] [An object convertible to `R`]]
    [[`s`] [A __sequence__ of arguments that are accepted by `r`]]
    [[`f`] [An instance of `fused<R>`]]
]

[heading Expression Semantics]

[table
    [[Expression]    [Semantics]]
    [[`fused<R>(r)`] [Creates a fused function as described above, initializes the target function with `r`.]]
    [[`fused<R>()`]  [Creates a fused function as described above, attempts to use `R`'s default constructor.]]
    [[`f(s)`]        [Calls `r` with the elements in `s` as its arguments.]]
]

[heading Example]
    fused< __std_plus_doc__<long> > f;
    assert(f(__make_vector__(1,2l)) == 3l);

[heading See also]

* __fused_procedure__
* __fused_function_object__
* __invoke__
* __make_fused__
* __deduce__

[endsect]

[section fused_procedure]

[heading Description]

An unary __poly_func_obj__ adapter template for __callable_obj__ target
functions. It takes a __forward_sequence__ that contains the arguments for
the target function.

The result is discared and the adapter's return type is `void`.

The type of the target function is allowed to be const qualified or a
reference. Const qualification is preserved and propagated appropriately
(in other words, only const versions of [^operator()] can be used for a
target function object that is const or, if the target function object
is held by value, the adapter is const - these semantics have nothing to
do with the const qualification of a member function, which is referring
to the type of object pointed to by [^this] which is specified with the
first element in the sequence passed to the adapter).

If the target function is a pointer to a members function, the corresponding
object can be specified as a reference, pointer, or smart pointer.
In case of the latter, a freestanding [^get_pointer] function must be
defined (Boost provides this function for [^std::auto_ptr] and
__boost_shared_ptr_call__).

The target function must not be a pointer to a member object (dereferencing
such a pointer without returning anything does not make sense, so this case
is not implemented).

[heading Header]

  #include <boost/fusion/functional/adapter/fused_procedure.hpp>

[heading Synopsis]
    template <typename Function>
    class fused_procedure;

[heading Template parameters]

[table
    [[Parameter]            [Description]                   [Default]]
    [[`Function`]           [__callable_obj__ type]         []]
]

[heading Model of]

* __poly_func_obj__
* __def_callable_obj__

[variablelist Notation
    [[`R`] [A possibly const qualified __callable_obj__ type or reference type thereof]]
    [[`r`] [An object convertible to `R`]]
    [[`s`] [A __sequence__ of arguments that are accepted by `r`]]
    [[`f`] [An instance of `fused<R>`]]
]

[heading Expression Semantics]

[table
    [[Expression]              [Semantics]]
    [[`fused_procedure<R>(r)`] [Creates a fused function as described above, initializes the target function with `r`.]]
    [[`fused_procedure<R>()`]  [Creates a fused function as described above, attempts to use `R`'s default constructor.]]
    [[`f(s)`]                  [Calls `r` with the elements in `s` as its arguments.]]
]

[heading Example]
    template<class SequenceOfSequences, class Func>
    void n_ary_for_each(SequenceOfSequences const & s, Func const & f)
    {
        __for_each__(__zip_view__<SequenceOfSequences>(s),
            fused_procedure<Func const &>(f));
    }

    void try_it()
    {
        __vector__<int,float> a(2,2.0f);
        __vector__<int,float> b(1,1.5f);
        using namespace boost::lambda;
        n_ary_for_each(__vector_tie__(a,b), _1 -= _2);
        assert(a == __make_vector__(1,0.5f));
    }

[heading See also]

* __fused__
* __fused_function_object__
* __invoke_procedure__
* __make_fused_procedure__

[endsect]

[section fused_function_object]

[heading Description]

An unary __poly_func_obj__ adapter template for a __poly_func_obj__ target
function. It takes a __forward_sequence__ that contains the arguments for the
target function.

The type of the target function is allowed to be const qualified or a
reference. Const qualification is preserved and propagated appropriately
(in other words, only const versions of [^operator()] can be used for an
target function object that is const or, if the target function object
is held by value, the adapter is const).

[heading Header]

  #include <boost/fusion/functional/adapter/fused_function_object.hpp>

[heading Synopsis]
    template <class Function>
    class fused_function_object;

[heading Template parameters]

[table
    [[Parameter]            [Description]                   [Default]]
    [[`Function`]           [__poly_func_obj__ type]        []]
]

[heading Model of]

* __poly_func_obj__
* __def_callable_obj__

[variablelist Notation
    [[`R`] [A possibly const qualified __poly_func_obj__ type or reference type thereof]]
    [[`r`] [An object convertible to `R`]]
    [[`s`] [A __sequence__ of arguments that are accepted by `r`]]
    [[`f`] [An instance of `fused<R>`]]
]

[heading Expression Semantics]

[table
    [[Expression]                    [Semantics]]
    [[`fused_function_object<R>(r)`] [Creates a fused function as described above, initializes the target function with `r`.]]
    [[`fused_function_object<R>()`]  [Creates a fused function as described above, attempts to use `R`'s default constructor.]]
    [[`f(s)`]                        [Calls `r` with the elements in `s` as its arguments.]]
]

[heading Example]
    template<class SeqOfSeqs, class Func>
    typename __result_of_transform__< zip_view<SeqOfSeqs> const,
        fused_function_object<Func const &> >::type
    n_ary_transform(SeqOfSeqs const & s, Func const & f)
    {
        return __transform__(zip_view<SeqOfSeqs>(s),
            fused_function_object<Func const &>(f));
    }

    struct sub
    {
        template <typename Sig>
        struct result;

        template <class Self, typename T>
        struct result< Self(T,T) >
        { typedef typename remove_reference<T>::type type; };

        template<typename T>
        T operator()(T lhs, T rhs) const
        {
            return lhs - rhs;
        }
    };

    void try_it()
    {
        __vector__<int,float> a(2,2.0f);
        __vector__<int,float> b(1,1.5f);
        __vector__<int,float> c(1,0.5f);
        assert(c == n_ary_transform(__vector_tie__(a,b), sub()));
    }

[heading See also]

* __fused__
* __fused_procedure__
* __invoke_function_object__
* __make_fused_function_object__
* __deduce__

[endsect]


[section unfused]

[heading Description]

An n-ary __poly_func_obj__ adapter template for an unary __poly_func_obj__
target function. When called, its arguments are bundled to a
__random_access_sequence__ of references that is passed to the target function
object.

The nullary overload of the call operator can be removed by setting the
second template parameter to `false`, which is very useful if the result type
computation would result in a compile error, otherwise (nullary call
operator's prototypes can't be templates and thus are instantiated as early
as the class template).

Only __lvalue__ arguments are accepted. To overcome this limitation, apply
__boost_func_forward__.

The type of the target function is allowed to be const qualified or a
reference. Const qualification is preserved and propagated appropriately.
In other words, only const versions of [^operator()] can be used if
the target function object is const - or, in case the target function
object is held by value, the adapter is const.

[heading Header]

  #include <boost/fusion/functional/adapter/unfused.hpp>

[heading Synopsis]
    template <class Function, bool AllowNullary = true>
    class unfused;

[heading Template parameters]

[table
    [[Parameter]  [Description]               [Default]]
    [[`Function`] [A unary __poly_func_obj__] []]
    [[`AllowNullary`] [Boolean constant] [true]]
]

[heading Model of]

* __poly_func_obj__
* __def_callable_obj__

[variablelist Notation
    [[`F`]         [A possibly const qualified, unary __poly_func_obj__ type or reference type thereof]]
    [[`f`]         [An object convertible to `F`]]
    [[`UL`]        [The type `unfused<F>`]]
    [[`ul`]        [An instance of `UL`, initialized with `f`]]
    [[`a0`...`aN`] [Arguments to `ul`]]
]

[heading Expression Semantics]

[table
    [[Expression]      [Semantics]]
    [[`UL(f)`]         [Creates a fused function as described above, initializes the target function with `f`.]]
    [[`UL()`]          [Creates a fused function as described above, attempts to use `F`'s default constructor.]]
    [[`ul(a0`...`aN)`] [Calls `f` with a __sequence__ that contains references to the arguments `a0`...`aN`.]]
]

[heading Example]
    struct fused_incrementer
    {
        template <class Seq>
        struct result
        {
            typedef void type;
        };

        template <class Seq>
        void operator()(Seq const & s) const
        {
            __for_each__(s,++boost::lambda::_1);
        }
    };

    void try_it()
    {
        unfused<fused_incrementer> increment;
        int a = 2; char b = 'X';
        increment(a,b);
        assert(a == 3 && b == 'Y');
    }

[heading See also]
* __unfused_typed__
* __make_unfused__

[endsect]

[section unfused_typed]

[heading Description]

An n-ary __poly_func_obj__ adapter template for an unary __poly_func_obj__
target function. When called, its arguments are bundled to a
__random_access_sequence__ that is passed to the target function object.

The call operators of  esulting function objects are strictly typed
(in other words, non-templatized) with the types from a __sequence__.

The type of the target function is allowed to be const qualified or a
reference. Const qualification is preserved and propagated appropriately
(in other words, only const versions of [^operator()] can be used if
the target function object is const - or, in case the target function object
is held by value, the adapter is const).

[blurb __note__ For Microsoft Visual C++ 7.1 (Visual Studio 2003) the detection
of the Function Object's const qualification easily causes an internal error.
Therefore the adapter is always treated as if it was const. ]

[blurb __tip__ If the type sequence passed to this template contains
non-reference elements, the element is copied only once - the call operator's
signature is optimized automatically to avoid by-value parameters.]

[heading Header]

  #include <boost/fusion/functional/adapter/unfused_typed.hpp>

[heading Synopsis]
    template <class Function, class Sequence>
    class unfused_typed;

[heading Template parameters]

[table
    [[Parameter]  [Description]               [Default]]
    [[`Function`] [A unary __poly_func_obj__] []]
    [[`Sequence`] [A __sequence__]            []]
]

[heading Model of]

* __poly_func_obj__
* __def_callable_obj__

[variablelist Notation
    [[`F`]         [A possibly const qualified, unary __poly_func_obj__ type or reference type thereof]]
    [[`f`]         [An object convertible to `F`]]
    [[`S`]         [A __sequence__ of parameter types]]
    [[`UT`]        [The type `unfused_typed<F,S>`]]
    [[`ut`]        [An instance of `UT`, initialized with `f`]]
    [[`a0`...`aN`] [Arguments to `ut`, convertible to the types in `S`]]
]

[heading Expression Semantics]

[table
    [[Expression]      [Semantics]]
    [[`UT(f)`]         [Creates a fused function as described above, initializes the target function with `f`.]]
    [[`UT()`]          [Creates a fused function as described above, attempts to use `F`'s default constructor.]]
    [[`ut(a0`...`aN)`] [Calls `f` with an instance of `S` (or a subsequence of `S` starting at the first element,
                        if fewer arguments are given and the overload hasn't been disabled) initialized with
                        `a0`...`aN`.]]
]

[heading Example]
    struct add_assign // applies operator+=
    {
        typedef void result_type; // for simplicity

        template <typename T>
        void operator()(T & lhs, T const & rhs) const
        {
            lhs += rhs;
        }
    };

    template <class Tie>
    class fused_parallel_adder
    {
        Tie tie_dest;
    public:
        explicit fused_parallel_adder(Tie const & dest)
            : tie_dest(dest)
        { }

        typedef void result_type;

        template <class Seq>
        void operator()(Seq const & s) const
        {
            for_each( zip(tie_dest,s), fused<add_assign>() );
        }
    };

    // accepts a tie and creates a typed function object from it
    struct fused_parallel_adder_maker
    {
        template <typename Sig>
        struct result;

        template <class Self, class Seq>
        struct result< Self(Seq) >
        {
            typedef typename remove_reference<Seq>::type seq;

            typedef unfused_typed< fused_parallel_adder<seq>,
                typename mpl::transform<seq, remove_reference<_> >::type > type;
        };

        template <class Seq>
        typename result< void(Seq) >::type operator()(Seq const & tie)
        {
            return typename result< void(Seq) >::type(
                fused_parallel_adder<Seq>(tie) );
        }
    };
    unfused<fused_parallel_adder_maker> parallel_add;

    void try_it()
    {
        int a = 2; char b = 'X';
        // the second call is strictly typed with the types deduced from the
        // first call
        parallel_add(a,b)(3,2);
        parallel_add(a,b)(3);
        parallel_add(a,b)();
        assert(a == 8 && b == 'Z');
    }

[heading See also]
* __unfused__
* __deduce__
* __deduce_sequence__

[endsect]

[section Limits]

[heading Header]

  #include <boost/fusion/functional/adapter/limits.hpp>

[heading Macros]

The following macros can be defined to change the maximum arity.
The value used for these macros must not exceed `FUSION_MAX_VECTOR_SIZE`.
The default is 6.

* BOOST_FUSION_UNFUSED_MAX_ARITY
* BOOST_FUSION_UNFUSED_TYPE_MAX_ARITY

[endsect]

[endsect] [/ Adapters]

[/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ]

[section Generation]

[section Functions]

[section:mk_fused make_fused]

[heading Description]
Creates a __fused__ adapter for a given __def_callable_obj__. The usual
__element_conversion__ is applied to the target function.

[heading Synopsis]
    template <typename F>
    inline typename __result_of_make_fused__<F>::type
    make_fused(F const & f);

[heading Parameters]
[table
    [[Parameter]  [Requirement]                    [Description]]
    [[`f`]        [Model of __def_callable_obj__]  [The function to transform.]]
]

[heading Expression Semantics]

    make_fused(f);

[*Return type]: A specialization of __fused__.

[*Semantics]: Returns a __fused__ adapter for `f`.

[heading Header]

    #include <boost/fusion/functional/generation/make_fused.hpp>
    #include <boost/fusion/include/make_fused.hpp>

[heading Example]
    float sub(float a, float b) { return a - b; }

    void try_it()
    {
        __vector__<int,float> a(2,2.0f);
        __vector__<int,float> b(1,1.5f);
        __vector__<float,float> c(1.0f,0.5f);
        assert(c == __transform__(__zip__(a,b), make_fused(& sub)));
        assert(c == __transform__(__zip__(a,b), make_fused(__std_minus_doc__<float>())));
    }

[heading See also]
* __fused__
* __deduce__
* __result_of_make_fused__

[endsect]

[section:mk_fused_proc make_fused_procedure]

[heading Description]
Creates a __fused_procedure__ adapter for a given __def_callable_obj__.
The usual __element_conversion__ applied to the target function.

[heading Synopsis]
    template <typename F>
    inline typename __result_of_make_fused_procedure__<F>::type
    make_fused_procedure(F const & f);

[heading Parameters]
[table
    [[Parameter]  [Requirement]                    [Description]]
    [[`f`]        [Model of __callable_obj__]      [The function to transform.]]
]

[heading Expression Semantics]

    make_fused_procedure(f);

[*Return type]: A specialization of __fused_procedure__.

[*Semantics]: Returns a __fused_procedure__ adapter for `f`.

[heading Header]

    #include <boost/fusion/functional/generation/make_fused_procedure.hpp>
    #include <boost/fusion/include/make_fused_procedure.hpp>

[heading Example]
    __vector__<int,int,int> v(1,2,3);
    using namespace boost::lambda;
    make_fused_procedure(_1 += _2 - _3)(v);
    assert(__front__(v) == 0);

[heading See also]
* __fused_procedure__
* __deduce__
* __result_of_make_fused_procedure__

[endsect]

[section:mk_fused_fobj make_fused_function_object]

[heading Description]
Creates a __fused_function_object__ adapter for a given __def_callable_obj__.
The usual __element_conversion__ is applied to the target function.

[heading Synopsis]
    template <typename F>
    inline typename __result_of_make_fused_function_object__<F>::type
    make_fused_function_object(F const & f);

[heading Parameters]
[table
    [[Parameter]  [Requirement]                    [Description]]
    [[`f`]        [Model of __poly_func_obj__]     [The function to transform.]]
]

[heading Expression Semantics]

    make_fused_function_object(f);

[*Return type]: A specialization of __fused_function_object__.

[*Semantics]: Returns a __fused_function_object__ adapter for `f`.

[heading Header]

    #include <boost/fusion/functional/generation/make_fused_function_object.hpp>
    #include <boost/fusion/include/make_fused_function_object.hpp>

[heading Example]
    struct sub
    {
        template <typename Sig>
        struct result;

        template <class Self, typename T>
        struct result< Self(T,T) >
        { typedef typename remove_reference<T>::type type; };

        template<typename T>
        T operator()(T lhs, T rhs) const
        {
            return lhs - rhs;
        }
    };

    void try_it()
    {
        __vector__<int,float> a(2,2.0f);
        __vector__<int,float> b(1,1.5f);
        __vector__<int,float> c(1,0.5f);
        assert(c == __transform__(__zip__(a,b), make_fused_function_object(sub())));
    }

[heading See also]
* __fused_function_object__
* __deduce__
* __result_of_make_fused_function_object__

[endsect]

[section:mk_unfused make_unfused]

[heading Description]
Creates a __unfused__ adapter for a given, unary __poly_func_obj__.
The usual __element_conversion__ is applied to the target function.

[heading Synopsis]
    template <typename F>
    inline typename __result_of_make_unfused__<F>::type
    make_unfused(F const & f);

[heading Parameters]
[table
    [[Parameter]  [Requirement]                    [Description]]
    [[`f`]        [Model of __poly_func_obj__]     [The function to transform.]]
]

[heading Expression Semantics]

    make_unfused(f);

[*Return type]: A specialization of __unfused__.

[*Semantics]: Returns a __unfused__ adapter for `f`.

[heading Header]

    #include <boost/fusion/functional/generation/make_unfused.hpp>
    #include <boost/fusion/include/make_unfused.hpp>

[heading Example]
    struct fused_incrementer
    {
        template <class Seq>
        struct result
        {
            typedef void type;
        };

        template <class Seq>
        void operator()(Seq const & s) const
        {
            __for_each__(s,++boost::lambda::_1);
        }
    };

    void try_it()
    {
        int a = 2; char b = 'X';
        make_unfused(fused_incrementer())(a,b);
        assert(a == 3 && b == 'Y');
    }

[heading See also]
* __unfused__
* __deduce__
* __result_of_make_unfused__

[endsect]

[endsect] [/ Functions]

[section Metafunctions]

[section:mk_fused make_fused]

[heading Description]
Returns the result type of __make_fused__.

[heading Header]

    #include <boost/fusion/functional/generation/make_fused.hpp>
    #include <boost/fusion/include/make_fused.hpp>

[heading Synopsis]
    namespace result_of
    {
        template<typename Function>
        struct make_fused
        {
            typedef __unspecified__ type;
        };
    }

[heading See also]
* __make_fused__

[endsect]

[section:mk_fused_proc make_fused_procedure]

[heading Description]
Returns the result type of __make_fused_procedure__.

[heading Header]

    #include <boost/fusion/functional/generation/make_fused_procedure.hpp>
    #include <boost/fusion/include/make_fused_procedure.hpp>

[heading Synopsis]
    namespace result_of
    {
        template<typename Function>
        struct make_fused_procedure
        {
            typedef __unspecified__ type;
        };
    }

[heading See also]
* __make_fused_procedure__

[endsect]

[section:mk_fused_fobj make_fused_function_object]

[heading Description]
Returns the result type of __make_fused_function_object__.

[heading Header]

    #include <boost/fusion/functional/generation/make_fused_function_object.hpp>
    #include <boost/fusion/include/make_fused_function_object.hpp>

[heading Synopsis]
    namespace result_of
    {
        template<typename Function>
        struct make_fused_function_object
        {
            typedef __unspecified__ type;
        };
    }

[heading See also]
* __make_fused_function_object__

[endsect]

[section:mk_unfused make_unfused]

[heading Description]
Returns the result type of __make_unfused__.

[heading Header]

    #include <boost/fusion/functional/generation/make_unfused.hpp>
    #include <boost/fusion/include/make_unfused.hpp>

[heading Synopsis]
    namespace result_of
    {
        template<typename Function>
        struct make_unfused
        {
            typedef __unspecified__ type;
        };
    }

[heading See also]
* __make_unfused__

[endsect]

[endsect] [/ Metafunctions]

[endsect] [/ Generation]

[endsect] [/ Functional ]