Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/function/example/sum_avg.cpp @ 35

Last change on this file since 35 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 916 bytes
Line 
1// Boost.Function library examples
2
3//  Copyright Douglas Gregor 2001-2003. Use, modification and
4//  distribution is subject to the Boost Software License, Version
5//  1.0. (See accompanying file LICENSE_1_0.txt or copy at
6//  http://www.boost.org/LICENSE_1_0.txt)
7
8// For more information, see http://www.boost.org
9
10#include <iostream>
11#include <boost/function.hpp>
12
13void do_sum_avg(int values[], int n, int& sum, float& avg)
14{
15  sum = 0;
16  for (int i = 0; i < n; i++)
17    sum += values[i];
18  avg = (float)sum / n;
19}
20
21int
22main()
23{
24  // The second parameter should be int[], but some compilers (e.g., GCC)
25  // complain about this
26  boost::function<void (int*, int, int&, float&)> sum_avg;
27
28  sum_avg = &do_sum_avg;
29
30  int values[5] = { 1, 1, 2, 3, 5 };
31  int sum;
32  float avg;
33  sum_avg(values, 5, sum, avg);
34
35  std::cout << "sum = " << sum << std::endl;
36  std::cout << "avg = " << avg << std::endl;
37  return 0;
38}
Note: See TracBrowser for help on using the repository browser.