39typedef std::ostream_iterator<int, char, std::char_traits<char> >
71 char text[] =
"Now is the time to begin";
73#ifdef _RWSTD_STRICT_ANSI
75 ecount = std::count (text, text +
sizeof text,
'e');
76 vowelCount = std::count_if (text, text +
sizeof text,
isVowel);
80 std::count (text, text +
sizeof text,
'e', ecount);
81 std::count_if (text, text +
sizeof text,
isVowel, vowelCount);
85 std::cout <<
"There are " << ecount
86 <<
" letter e's " << std::endl
87 <<
"and " << vowelCount
88 <<
" vowels in the text:" << text
94std::list<int, std::allocator<int> >&
106 int numbers[] = { 1, 2, 3, 4, 5 };
107 int sum = std::accumulate (numbers, numbers+5, 0);
108 int product = std::accumulate (numbers,
109 numbers+5, 1, std::multiplies<int> ());
111 std::cout <<
"The sum of the first five numbers is "
114 std::cout <<
"The product of the first five numbers is "
119 std::list<int, std::allocator<int> > nums;
120 nums = std::accumulate (numbers, numbers+5, nums,
intReplicate);
122 std::copy (nums.begin (), nums.end (),
ostrm_iter_type (std::cout,
" "));
124 std::cout << std::endl;
131 int a[] = { 4, 3, -2 };
132 int b[] = { 7, 3, 2 };
135 int in1 = std::inner_product (
a,
a+3,
b, 0);
136 std::cout <<
"Inner product is " << in1 << std::endl;
139 bool anyequal = std::inner_product (
a,
a+3,
b,
true,
140 std::logical_or<bool> (),
141 std::equal_to<int> ());
143 std::cout <<
"any equal? " << anyequal << std::endl;
150 int a[] = { 4, 5, 3 };
151 int b[] = { 4, 3, 3 };
152 int c[] = { 4, 5, 3 };
154 std::cout <<
"a = b is:" << std::equal (
a,
a+3,
b) << std::endl;
155 std::cout <<
"a = c is:" << std::equal (
a,
a+3,
c) << std::endl;
156 std::cout <<
"a pair-wise-greater_equal b is"
157 << std::equal (
a,
a+3,
b, std::greater_equal<int> ())
165 char wordOne[] =
"everything";
166 char wordTwo[] =
"everybody";
168 std::cout <<
"compare everybody to everything "
169 << std::lexicographical_compare (wordTwo,
170 wordTwo +
sizeof wordTwo,
172 wordOne +
sizeof wordOne)
175 int a[] = { 3, 4, 5, 2 };
176 int b[] = { 3, 4, 5 };
179 std::cout <<
"compare a to b: "
180 << std::lexicographical_compare (
a,
a+4,
b,
b+3) << std::endl;
181 std::cout <<
"compare a to c: "
182 << std::lexicographical_compare (
a,
a+4,
c,
c+2) << std::endl;
187 std::cout <<
"STL generic algorithms -- "\
188 <<
"algorithms that produce scalar results" << std::endl;
196 std::cout <<
"End of scalar algorithms test" << std::endl;
std::ostream_iterator< int, char, std::char_traits< char > > ostrm_iter_type
void accumulate_example()
void inner_product_example()
std::list< int, std::allocator< int > > & intReplicate(std::list< int, std::allocator< int > > &nums, int n)
std::ostream_iterator< int, char, std::char_traits< char > > ostrm_iter_type
void lexical_comparison_example()