Boost logo

Boost :

Subject: [boost] [bind] variant arg list template functions could have a forward declaration as doc & coding suggeustion
From: Huang Huan (mr.huanghuan_at_[hidden])
Date: 2012-05-08 05:13:56


Hi all,
  Before I do some change, no suggestion when I coding with Boost.Bind.
This is a big disadvantage for learning & using.
  Variant arg list template functions as follow are there in so many boost
code file.

// template<class F, class A1, ... class An>
// X foo(F f, A1 a1, ... An an);
template<class F>
X foo(F f) { ... }
template<class F, class A1>
X foo(F f, A1 a1) { ... }
template<class F, class A1, class A2>
X foo(F f, A1 a1, A2 a1) { ... }
...

Some code like the comment, the forward declaration could be good doc &
coding suggestion, such as following:

template<class F /*, class A1, ... class An */>
X foo(F f /*, A1 a1, ... An an */);
OR
template<class F, class A1, class A2 /*, ... */>
X foo(F f, A1 a1, A2 a2, ... );
OR
template<class F /*... */> // may no cxx11
X foo(F f , ... );
This may like BOOST_CONTAINERS_PERFECT_FORWARDING
Becase of the template grammar, this forward declaration has no
implementation.
The code is ONLY for coding suggestion & doc.

As an example [boost][bind]
When I write the code boost::bind( _ )
I want the suggestions as follow
______________________________________________
| [1 of 3] _bi::bind_t<_bi::unspecified, F, L> bind(F f, ...) |
|_____________________________________________|

A more difficulty is boost bind has a BOOST_BIND for redefine the name.
my patch as follow:

===================================================================
--- bind.hpp (revision 77278)
+++ bind.hpp (working copy)
@@ -1289,6 +1289,17 @@

 #ifndef BOOST_BIND
 #define BOOST_BIND bind
+
+template<class R, class F, class L>
+ _bi::bind_t<R, F, L>
+ bind(F f, ...);
+template<class R, class F, class L>
+ _bi::bind_t<R, F, L>
+ bind(boost::type<R>, F f, ...);
+template<class F, class L>
+ _bi::bind_t<_bi::unspecified, F, L>
+ bind(F f, ...);
+
 #endif

 // generic function objects


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk