
Hi all, As part of the asio library I have been using named placeholders for the common arguments to callback functions. For example: asio::async_send_n(sock, buffer, length, boost::bind(mycallback, asio::arg::error, asio::arg::last_bytes_sent, asio::arg::total_bytes_sent)); rather than: asio::async_send_n(sock, buffer, length, boost::bind(mycallback, _1, _2, _3)); I find having named placeholders saves time and helps prevent errors to do with the ordering of the parameters (e.g. in the case of something like the last_bytes_sent/total_bytes_sent example where both are size_t, and so incorrect order will not be detected by the compiler). Unfortunately, from my reading of the TR1 bind doco at http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1455.htm it simply defines the placeholders as: namespace std { namespace placeholders { extern unspecified _1; extern unspecified _2; extern unspecified _3; // implementation defined number of additional placeholders } } and it doesn't say anything about the type of the placeholders. Since the placeholders are CopyConstructible, it seems like I ought to be able to do something using a typedef (if there was one), e.g: std::placeholders::_1_t my_placeholder(std::placeholders::_1); Is there some TR1-compatible (and therefore portable) way of working around it that's eluding me (other than #define :). It seems a shame not to have such a feature, especially if over time more libraries use complex function objects in their interfaces. Cheers, Chris

"Christopher Kohlhoff" <chris@kohlhoff.com> wrote in message news:20050808075405.12636.qmail@web32603.mail.mud.yahoo.com...
Hi all,
... named placeholder question ...
Chris, Peter Dimov is usually very good about responding to bind queries, so I'm guessing he is on vacation or otherwise tied up. You might want to repost in a week or two if you haven't had a reply. Or try comp.std.c++. --Beman

Christopher Kohlhoff wrote:
Hi all,
As part of the asio library I have been using named placeholders for the common arguments to callback functions. For example:
asio::async_send_n(sock, buffer, length, boost::bind(mycallback, asio::arg::error, asio::arg::last_bytes_sent, asio::arg::total_bytes_sent));
rather than:
asio::async_send_n(sock, buffer, length, boost::bind(mycallback, _1, _2, _3));
I find having named placeholders saves time and helps prevent errors to do with the ordering of the parameters (e.g. in the case of something like the last_bytes_sent/total_bytes_sent example where both are size_t, and so incorrect order will not be detected by the compiler).
Unfortunately, from my reading of the TR1 bind doco at
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2003/n1455.htm
it simply defines the placeholders as:
namespace std { namespace placeholders { extern unspecified _1; extern unspecified _2; extern unspecified _3; // implementation defined number of additional placeholders } }
and it doesn't say anything about the type of the placeholders. Since the placeholders are CopyConstructible, it seems like I ought to be able to do something using a typedef (if there was one), e.g:
std::placeholders::_1_t my_placeholder(std::placeholders::_1);
Is there some TR1-compatible (and therefore portable) way of working around it that's eluding me (other than #define :).
We decided to not expose the types of the default _N placeholders in TR1, but you can add your own placeholder types by specializing std::tr1::is_placeholder.

Hi Peter, --- Peter Dimov <pdimov@mmltd.net> wrote:
We decided to not expose the types of the default _N placeholders in TR1, but you can add your own placeholder types by specializing std::tr1::is_placeholder.
Ah, excellent. Now I understand the purpose of is_placeholder, and it's exactly what I'm after. Thanks! Cheers, Chris
participants (3)
-
Beman Dawes
-
Christopher Kohlhoff
-
Peter Dimov