algorithm_test.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // bll_and_function.cpp - The Boost Lambda Library -----------------------
  2. //
  3. // Copyright (C) 2000-2003 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
  4. // Copyright (C) 2000-2003 Gary Powell (powellg@amazon.com)
  5. //
  6. // Distributed under the Boost Software License, Version 1.0. (See
  7. // accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // For more information, see www.boost.org
  11. // test using BLL and boost::function
  12. #include <boost/test/minimal.hpp> // see "Header Implementation Option"
  13. #include "boost/lambda/lambda.hpp"
  14. #include "boost/lambda/bind.hpp"
  15. #include "boost/lambda/algorithm.hpp"
  16. #include <vector>
  17. #include <map>
  18. #include <set>
  19. #include <string>
  20. #include <iostream>
  21. void test_foreach() {
  22. using namespace boost::lambda;
  23. int a[10][20];
  24. int sum = 0;
  25. std::for_each(a, a + 10,
  26. bind(ll::for_each(), _1, _1 + 20,
  27. protect((_1 = var(sum), ++var(sum)))));
  28. sum = 0;
  29. std::for_each(a, a + 10,
  30. bind(ll::for_each(), _1, _1 + 20,
  31. protect((sum += _1))));
  32. BOOST_CHECK(sum == (199 + 1)/ 2 * 199);
  33. }
  34. // More tests needed (for all algorithms)
  35. int test_main(int, char *[]) {
  36. test_foreach();
  37. return 0;
  38. }