[Bind] How to create a functor which returns one of its arguments?
Hello, All!
Is there a simple way to create a functor that returns one of its arguments
_1, _2, ...?
Does standard unary functor exist, which simply returns its argument
unchanged? I.e.:
template<typename T>
struct arg: public std::unary_function
2009/12/8 Vadim Guchenko
Hello, All!
Is there a simple way to create a functor that returns one of its arguments _1, _2, ...?
In Boost.Lambda _2 is a functor that returns its second argument and constant(true) is a functor that always returns true. The same works with Boost.Phoenix. Roman Perepelitsa.
On Tue, Dec 8, 2009 at 8:26 AM, Roman Perepelitsa
2009/12/8 Vadim Guchenko
Hello, All!
Is there a simple way to create a functor that returns one of its arguments _1, _2, ...?
In Boost.Lambda _2 is a functor that returns its second argument and constant(true) is a functor that always returns true. The same works with Boost.Phoenix.
What you are wanting is to return an argument, lazily. Boost.Bind is not built for that. Both Boost.Lambda and Boost.Phoenix are done lazily, and both do everything that Boost.Bind does, and Boost.Phoenix does everything that Boost.Lambda does.
Hello, Roman! You wrote on Tue, 8 Dec 2009 16:26:58 +0100:
Is there a simple way to create a functor that returns one of its arguments _1, _2, ...? RP> In Boost.Lambda _2 is a functor that returns its second argument and RP> constant(true) is a functor that always returns true. The same works RP> with Boost.Phoenix.
Thanks! Boost.Lambda allows to write more compact code than if functors from the <functional> header are used. -- Best regards, Vadim Guchenko [yhw at relost dot net].
Vadim Guchenko wrote:
Hello, All!
Is there a simple way to create a functor that returns one of its arguments _1, _2, ...? Does standard unary functor exist, which simply returns its argument unchanged? I.e.:
template<typename T> struct arg: public std::unary_function
{ T operator()(const T &x) const { return x; } };
It's not part of the current standard, but many implementations provide std::identity as an extension. (It will be standard in C++0x.)
Why would you do this?
(I mean the standard unary functor).
Thanks
Andrew
On Wed, Dec 9, 2009 at 11:10 AM, Peter Dimov
Vadim Guchenko wrote:
Hello, All!
Is there a simple way to create a functor that returns one of its arguments _1, _2, ...? Does standard unary functor exist, which simply returns its argument unchanged? I.e.:
template<typename T> struct arg: public std::unary_function
{ T operator()(const T &x) const { return x; } }; It's not part of the current standard, but many implementations provide std::identity as an extension. (It will be standard in C++0x.) _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
-- ___________________________________________ Andrew J. P. Maclean Centre for Autonomous Systems The Rose Street Building J04 The University of Sydney 2006 NSW AUSTRALIA Ph: +61 2 9351 3283 Fax: +61 2 9351 7474 URL: http://www.acfr.usyd.edu.au/ ___________________________________________
participants (5)
-
Andrew Maclean
-
OvermindDL1
-
Peter Dimov
-
Roman Perepelitsa
-
Vadim Guchenko