Brian Silverman | ce4aa8d | 2018-08-04 23:36:03 -0700 | [diff] [blame^] | 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:limitations Limitations] |
| 11 | |
| 12 | As a general rule, the function objects generated by `bind` take their |
| 13 | arguments by reference and cannot, therefore, accept non-const temporaries or |
| 14 | literal constants. This is an inherent limitation of the C++ language in its |
| 15 | current (2003) incarnation, known as the [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2002/n1385.htm forwarding problem]. |
| 16 | (It will be fixed in the next standard, usually called C++0x.) |
| 17 | |
| 18 | The library uses signatures of the form |
| 19 | |
| 20 | template<class T> void f(T & t); |
| 21 | |
| 22 | to accept arguments of arbitrary types and pass them on unmodified. As noted, |
| 23 | this does not work with non-const r-values. |
| 24 | |
| 25 | On compilers that support partial ordering of function templates, a possible |
| 26 | solution is to add an overload: |
| 27 | |
| 28 | template<class T> void f(T & t); |
| 29 | template<class T> void f(T const & t); |
| 30 | |
| 31 | Unfortunately, this requires providing 512 overloads for nine arguments, which |
| 32 | is impractical. The library chooses a small subset: for up to two arguments, |
| 33 | it provides the const overloads in full, for arities of three and more it |
| 34 | provides a single additional overload with all of the arguments taken by const |
| 35 | reference. This covers a reasonable portion of the use cases. |
| 36 | |
| 37 | [endsect] |