]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [/ |
2 | / Copyright (c) 2001, 2002 Peter Dimov and Multi Media Ltd. | |
3 | / Copyright (c) 2003-2008 Peter Dimov | |
4 | / | |
5 | / Distributed under the Boost Software License, Version 1.0. (See | |
6 | / accompanying file LICENSE_1_0.txt or copy at | |
7 | / http://www.boost.org/LICENSE_1_0.txt) | |
8 | /] | |
9 | ||
10 | [section:faq Frequently Asked Questions] | |
11 | ||
12 | [section Why doesn't this compile?] | |
13 | ||
14 | See the dedicated [link bind.troubleshooting Troubleshooting section]. | |
15 | ||
16 | [endsect] | |
17 | ||
18 | [section Why does this compile? It should not.] | |
19 | ||
20 | Probably because you used the general `bind<R>(f, ...)` syntax, thereby | |
21 | instructing `bind` to not "inspect" f to detect arity and return type errors. | |
22 | ||
23 | [endsect] | |
24 | ||
25 | [section:Q_forms What is the difference between `bind(f, ...)` and `bind<R>(f, ...)`?] | |
26 | ||
27 | The first form instructs `bind` to inspect the type of `f` in order to | |
28 | determine its arity (number of arguments) and return type. Arity errors will | |
29 | be detected at "bind time". This syntax, of course, places some requirements | |
30 | on `f`. It must be a function, function pointer, member function pointer, or a | |
31 | function object that defines a nested type named `result_type`; in short, it | |
32 | must be something that `bind` can recognize. | |
33 | ||
34 | The second form instructs `bind` to not attempt to recognize the type of `f`. | |
35 | It is generally used with function objects that do not, or cannot, expose | |
36 | `result_type`, but it can also be used with nonstandard functions. For example, | |
37 | the current implementation does not automatically recognize variable-argument | |
38 | functions like `printf`, so you will have to use `bind<int>(printf, ...)`. | |
39 | Note that an alternative `bind(type<R>(), f, ...)` syntax is supported for | |
40 | portability reasons. | |
41 | ||
42 | Another important factor to consider is that compilers without partial | |
43 | template specialization or function template partial ordering support cannot | |
44 | handle the first form when `f` is a function object, and in most cases will | |
45 | not handle the second form when `f` is a function (pointer) or a member | |
46 | function pointer. | |
47 | ||
48 | [endsect] | |
49 | ||
50 | [section Does bind work with Windows API functions?] | |
51 | ||
52 | Yes, if you [link bind.implementation.stdcall `#define | |
53 | BOOST_BIND_ENABLE_STDCALL`]. An alternative is to treat the function as a | |
54 | [link bind.purpose.with_function_objects generic function object] and use the | |
55 | `bind<R>(f, ...)` syntax. | |
56 | ||
57 | [endsect] | |
58 | ||
59 | [section Does bind work with COM methods?] | |
60 | ||
61 | Yes, if you [link bind.implementation.stdcall `#define | |
62 | BOOST_MEM_FN_ENABLE_STDCALL`]. | |
63 | ||
64 | [endsect] | |
65 | ||
66 | [section Does bind work with Mac toolbox functions?] | |
67 | ||
68 | Yes, if you [link bind.implementation.stdcall `#define | |
69 | BOOST_BIND_ENABLE_PASCAL`]. An alternative is to treat the function as a [link | |
70 | bind.purpose.with_function_objects generic function object] and use the | |
71 | `bind<R>(f, ...)` syntax. | |
72 | ||
73 | [endsect] | |
74 | ||
75 | [section Does bind work with extern "C" functions?] | |
76 | ||
77 | Sometimes. On some platforms, pointers to extern "C" functions are equivalent | |
78 | to "ordinary" function pointers, so they work fine. Other platforms treat them | |
79 | as different types. A platform-specific implementation of `bind` is expected | |
80 | to handle the problem transparently; this implementation does not. As usual, | |
81 | the workaround is to treat the function as a [link | |
82 | bind.purpose.with_function_objects generic function object] and use the | |
83 | `bind<R>(f, ...)` syntax. | |
84 | ||
85 | [endsect] | |
86 | ||
87 | [section Why doesn't bind automatically recognize nonstandard functions?] | |
88 | ||
89 | Non-portable extensions, in general, should default to off to prevent vendor | |
90 | lock-in. Had the [link bind.implementation.stdcall appropriate macros] been | |
91 | defined automatically, you could have accidentally taken advantage of them | |
92 | without realizing that your code is, perhaps, no longer portable. In addition, | |
93 | some compilers have the option to make `__stdcall` (`__fastcall`) their | |
94 | default calling convention, in which case no separate support would be | |
95 | necessary. | |
96 | ||
97 | [endsect] | |
98 | ||
99 | [endsect] |