ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> boost
boost
Re: [boost] Re: MPL usage for code generation
by =?iso-8859-1?Q?Terje_Sletteb=F8?= other posts by this author
Jan 23 2003 10:17AM messages near this date
Re: [boost] Re: MPL usage for code generation | Re: [boost] Re: MPL usage for code generation
> From: "David Abrahams" <dave@[...].com>

>  > Terje Slettebø <tslettebo@[...].no> writes:
>  >
>  > Perhaps it might be possible to do some compile-time/run-time lambda
>  > (similar to Boost.Lambda for runtime, and MPL's lambda), so you could do
>  > something like:
>  >
>  > mpl::for_each<my_list>(my_function<_>(s));
>  >
>  > It would then transform the function call "my_function<_>(s)" into an
>  > instantiated function object of the kind suitable for mpl::for_each.
> 
>  I'm afraid that particular syntax won't work for this particular case,
>  though.  If my_function is a function template, my_function<_> is a
>  function, and my_function<_>(s) calls that function.

Yes, even with function template template parameters, the syntax would have
to be changed. I realised that you can't just pass the address of a
function, since in this case, it's a function template. Besides, it wouldn't
help to use the placeholder in that place (unless you specialised the
user-supplied function, but that would be no point). The above was just to
sketch the idea of it.

>  Since there are no (function template) template parameters, only
>  (class template) template parameters, there doesn't appear to be any
>  way to make this one particularly easy except by using the
>  preprocessor to define some kind of function object.

Yes, I realised that later, as well. Is there any good reason for not
allowing function templates as template template parameters? I think it's
amazing that we got the template facility that exists, in the standard, so
maybe it simply wasn't time to consider this, to avoid delaying
standardisation.

If this was possible, you might have done something like this, instead
(using TTP):

mpl::for_each<my_list, std::string &, my_function> (s);

>  It appears to be just bad luck that higher order functional
>  programming with function templates is impossible in C++.

Well, it might be changed in a future revision of the standard, if it turns
out to be practical.

I can imagine something like this:

template<class Sequence, class T, template<class>  void Function(T)>
struct for_each;

Possibly using overloaded class templates, as well (another possible
extension). Anyway, this goes beyond the topic of Boost.


Regards,

Terje

_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Thread:
Hugo Duncan
Andrei Alexandrescu
Hugo Duncan
Hugo Duncan
Hugo Duncan
David Abrahams
Peter Dimov
David Abrahams
=?iso-8859-1?Q?Terje_Sletteb=F8?=
=?iso-8859-1?Q?Terje_Sletteb=F8?=
=?iso-8859-1?Q?Terje_Sletteb=F8?=
David Abrahams
Hugo Duncan
Andrei Alexandrescu
David Abrahams
David Abrahams
Andrei Alexandrescu
David Abrahams
Douglas Paul Gregor
David Abrahams
Douglas Paul Gregor
David Abrahams
Douglas Paul Gregor
David Abrahams
Douglas Paul Gregor

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved