
Hi! Is there an easy way to use the exact type of what boost::bind(...) returns? The example above sheds some light of the source of this question. It would be much better (actually this is what bind is for, isn't it?) if I didn't have to define the plus_5 struct in order to be able to use transform_iterator. I wrote it in the comment what I'm thinking about. I could delve deeply into the bind header files and try to explicitly find what the exact class definition is, but I suspect it would not be too easy. Anyway, I may be forced to do that. Thx, Agoston // ------------------------------------------- #include <iostream> #include <functional> #include <algorithm> #include <boost/iterator/transform_iterator.hpp> #include <boost/bind.hpp> using namespace std; using namespace boost; struct plus_5 : public unary_function<int, int> { int operator()(int i) const { return i + 5; } }; typedef transform_iterator<plus_5, int*> Iterator; //------- *** ---------------------- //typedef transform_iterator< bind_type<plus<5>, _1, 5>, int* > Iterator; // how to easily get the return type of bind(plus<5>(), _1, 5) // in compilation time? //------- *** ------------------------ int _tmain(int argc, _TCHAR* argv[]) { int ia[] = {1,2,3,4,5}; copy(Iterator(ia), Iterator(ia+5), ostream_iterator<int>(cout, " ")); cout << endl; return 0; }

Agoston Bejo wrote:
Hi! Is there an easy way to use the exact type of what boost::bind(...) returns? The example above sheds some light of the source of this question. It would be much better (actually this is what bind is for, isn't it?) if I didn't have to define the plus_5 struct in order to be able to use transform_iterator. I wrote it in the comment what I'm thinking about. I could delve deeply into the bind header files and try to explicitly find what the exact class definition is, but I suspect it would not be too easy. Anyway, I may be forced to do
//------- *** ---------------------- //typedef transform_iterator< bind_type<plus<5>, _1, 5>, int* > Iterator; // how to easily get the return type of bind(plus<5>(), _1, 5) // in compilation time? //------- *** ------------------------
Try: typedef transform_iterator<function<int (int)>,int*> Iterator; (You may need to use function1<...> depending on your compiler) http://www.boost.org/doc/html/function.html Chapter 4. Boost.Function -- -- Grafik - Don't Assume Anything -- Redshift Software, Inc. - http://redshift-software.com -- rrivera/acm.org - grafik/redshift-software.com - 102708583/icq

Agoston Bejo wrote:
Hi! Is there an easy way to use the exact type of what boost::bind(...) returns?
The only way to obtain the exact type is to use an intermediate function template: template<class F> void g( F f ) { // use F here } int main() { g( bind(...) ); }
The example above sheds some light of the source of this question. It would be much better (actually this is what bind is for, isn't it?) if I didn't have to define the plus_5 struct in order to be able to use transform_iterator.
In this case, the intermediate function template is already written: make_transform_iterator.

"Peter Dimov" <pdimov@mmltd.net> wrote in message news:002701c4e5de$abea0e80$6401a8c0@pdimov2...
Agoston Bejo wrote:
Hi! Is there an easy way to use the exact type of what boost::bind(...) returns?
The only way to obtain the exact type is to use an intermediate function template:
template<class F> void g( F f ) { // use F here }
int main() { g( bind(...) ); }
The example above sheds some light of the source of this question. It would be much better (actually this is what bind is for, isn't it?) if I didn't have to define the plus_5 struct in order to be able to use transform_iterator.
In this case, the intermediate function template is already written: make_transform_iterator.
That won't do because I am creating a class that has an iterator typedef which would be some kind of transform_iterator. So the type must explicitly be stated.
participants (3)
-
Agoston Bejo
-
Peter Dimov
-
Rene Rivera