Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
pnt2fnct.cpp
Go to the documentation of this file.
1
29#include <algorithm> // for copy, transform
30#include <functional> // for ptr_fun
31#include <iostream> // cout, endl
32#include <iterator> // for ostream_iterator
33#include <deque> // for deque
34#include <vector> // for vector
35
36#include <examples.h>
37
38
39int factorial (int x)
40{
41 return x > 1 ? x * factorial (x - 1) : x;
42}
43
44
45int main ()
46{
47 typedef std::deque<int, std::allocator<int> > Deque;
48 typedef std::vector<int, std::allocator<int> > Vector;
49 typedef std::ostream_iterator<int, char, std::char_traits<char> > Iter;
50
51 // Initialize a deque with an array of integers.
52 const Deque::value_type a[] = { 1, 2, 3, 4, 5, 6, 7 };
53 Deque d (a + 0, a + sizeof a / sizeof *a);
54
55 // Create an empty vector to store the factorials.
56 Vector v (Vector::size_type (7));
57
58 // Compute factorials of the contents of `d' store results in `v'.
59 std::transform (d.begin (), d.end (), v.begin (),
60 std::ptr_fun (factorial));
61
62 // Print the results.
63 std::cout << "The following numbers: \n ";
64 std::copy (d.begin (), d.end (), Iter (std::cout," "));
65
66 std::cout << "\n\nHave the factorials: \n ";
67 std::copy (v.begin (), v.end (), Iter (std::cout, " "));
68 std::cout << std::endl;
69
70 return 0;
71}
#define d
Definition 17.names.cpp:115
#define v
Definition 17.names.cpp:138
#define x
Definition 17.names.cpp:140
#define a
Definition 17.names.cpp:109
std::vector< UserClass, std::allocator< UserClass > > Vector
std::ostream_iterator< int, char, std::char_traits< char > > Iter
Definition alg7.cpp:64
std::deque< std::string, std::allocator< std::string > > Deque
Definition deque.cpp:35
int main()
Definition pnt2fnct.cpp:45