Topic: Function adaptors not in the standard


Author: Edward Diener <eddielee@abraxis.com>
Date: Mon, 12 Feb 2001 23:33:58 GMT
Raw View
A number of function obects and function adaptors mentioned in books
which I have on the  C++ standard library were left out of the standard.
Most notable are unary_compose<>, binary_compose<>, identity<>,
project1st<>, project2nd<>, select1st<>, and select2nd<>. Is there a
reason these were left out of the standard ? Were they seen as not being
popular or useful enough ?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "James Kuyper Jr." <kuyper@wizard.net>
Date: Tue, 13 Feb 2001 01:49:15 GMT
Raw View
Edward Diener wrote:
>
> A number of function obects and function adaptors mentioned in books
> which I have on the  C++ standard library were left out of the standard.
> Most notable are unary_compose<>, binary_compose<>, identity<>,
> project1st<>, project2nd<>, select1st<>, and select2nd<>. Is there a
> reason these were left out of the standard ? Were they seen as not being
> popular or useful enough ?

For the sake of those of us who are unfamiliar with them, could you
describe what they do?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Edward Diener <eddielee@abraxis.com>
Date: Tue, 13 Feb 2001 15:18:17 GMT
Raw View
First, they are all in Matt Austern's  "Generic Programming and the STL" book,
although he identifies them all as not being in the C++ standard but as being
common extensions. A number of them are mentioned in Mark Nelson's earlier
"C++ Programmer's Guide to the Standard Template Library" and some are
mentioned in Nicolai M. Josuttis' "The C++ Standard Library". The Josuttis
book also correctly explains that the compose function adaptors are not part
of the C++ standard, and the book by Mark Nelson was written before the C++
standard was officially established. The explanations below are from the
Austern book.

The identity<> function object takes a single argument and returns that value
unchanged.
The project1st<> function object takes two arguments and returns the 1st.
The project2st<> function object takes two arguments and returns the 2nd.
The select1st<> function object takes a pair and returns the pair's first
element.
The select2nd<> function object takes a pair and returns the pair's second
element.

The unary_compose<> is a function object adaptor that takes two unary function
object adaptors, call them f and g, and evaluates them in the order of
f(g(x)).

The binary_compose<> is a function object adaptor that takes a binary function
object adaptor, call it f, and two unary function object adaptors, call them
g1 and g2, and evaluates them in the order of f(g1(x),g2(x))

"James Kuyper Jr." wrote:

> Edward Diener wrote:
> >
> > A number of function obects and function adaptors mentioned in books
> > which I have on the  C++ standard library were left out of the standard.
> > Most notable are unary_compose<>, binary_compose<>, identity<>,
> > project1st<>, project2nd<>, select1st<>, and select2nd<>. Is there a
> > reason these were left out of the standard ? Were they seen as not being
> > popular or useful enough ?
>
> For the sake of those of us who are unfamiliar with them, could you
> describe what they do?

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: Matthew Austern <austern@research.att.com>
Date: Tue, 13 Feb 2001 16:10:13 GMT
Raw View
"James Kuyper Jr." <kuyper@wizard.net> writes:

> Edward Diener wrote:
> >
> > A number of function obects and function adaptors mentioned in books
> > which I have on the  C++ standard library were left out of the standard.
> > Most notable are unary_compose<>, binary_compose<>, identity<>,
> > project1st<>, project2nd<>, select1st<>, and select2nd<>. Is there a
> > reason these were left out of the standard ? Were they seen as not being
> > popular or useful enough ?
>
> For the sake of those of us who are unfamiliar with them, could you
> describe what they do?

unary_compose takes two function objects f(x) and g(x), and creates
a function object that computes f(g(x)).  binary_compose takes
three function object f(x, y), g1(x), and g2(x), and creates
a unary function object that computes f(g1(x), g2(x)).  project1st
takes two arguments, x and y, and returns x.  project2nd returns y.
identity takes one argument, x, and returns x.  select1st and
select2nd both take a single argument, a pair; select1st returns the
first argument, select2nd returns the second.

All of those functions were part of the original pre-standard STL, and
they were removed when the STL became partof the C++ standard.  My
guess is that those functions, or something like them but with small
interface changes, will become part of a future revision of the C++
standard.

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]





Author: "Andrei Iltchenko" <iltchenko@yahoo.com>
Date: Tue, 13 Feb 2001 16:11:35 GMT
Raw View
Read the interview with Alex Stepanov at
http://www.stlport.org/resources/StepanovUSA.html, there he mentions the
reasons for that.

> A number of function obects and function adaptors mentioned in books
> which I have on the  C++ standard library were left out of the standard.
> Most notable are unary_compose<>, binary_compose<>, identity<>,
> project1st<>, project2nd<>, select1st<>, and select2nd<>. Is there a
> reason these were left out of the standard ? Were they seen as not being
> popular or useful enough ?

Regards,

Andrei Iltchenko
Brainbench MVP for C++
http://www.brainbench.com



---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html                ]
[ Note that the FAQ URL has changed!  Please update your bookmarks.     ]