transform.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*=============================================================================
  2. Copyright (c) 2008 Dan Marsden
  3. Use modification and distribution are subject to the Boost Software
  4. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ==============================================================================*/
  7. #include <boost/fusion/include/transform.hpp>
  8. #include <boost/fusion/include/for_each.hpp>
  9. #include <boost/fusion/include/vector.hpp>
  10. namespace fusion = boost::fusion;
  11. namespace
  12. {
  13. template<int n, int batch>
  14. struct distinct
  15. {
  16. static const int value = n;
  17. };
  18. struct f
  19. {
  20. typedef int result_type;
  21. template<typename T>
  22. result_type operator()(T const& t) const
  23. {
  24. return T::value;
  25. }
  26. };
  27. struct touch
  28. {
  29. template<typename T>
  30. void operator()(T const&) const
  31. {}
  32. };
  33. template<int batch>
  34. void test()
  35. {
  36. fusion::vector<
  37. distinct<0, batch>, distinct<1, batch>, distinct<2, batch>, distinct<3, batch>, distinct<4, batch>,
  38. distinct<5, batch>, distinct<6, batch>, distinct<7, batch>, distinct<8, batch>, distinct<9, batch> > v;
  39. // We're testing transform really
  40. // for_each call is to force iteration through the lazy
  41. // transform, otherwise very little will happen.
  42. fusion::for_each(fusion::transform(v, f()), touch());
  43. }
  44. }
  45. #include "./driver.hpp"