pointfree.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. /*=============================================================================
  2. Copyright (c) 2017 Paul Fultz II
  3. pointfree.cpp
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. /*=============================================================================
  8. Copyright (c) 2016 Paul Fultz II
  9. pointfree.cpp
  10. Distributed under the Boost Software License, Version 1.0. (See accompanying
  11. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  12. ==============================================================================*/
  13. #include "example.h"
  14. using namespace boost::hof;
  15. BOOST_HOF_STATIC_FUNCTION(simple_print) = BOOST_HOF_LIFT(std::ref(std::cout) << _);
  16. BOOST_HOF_STATIC_FUNCTION(print) = proj(simple_print);
  17. BOOST_HOF_STATIC_FUNCTION(print_lines) = proj(flow(simple_print, _ << std::integral_constant<char, '\n'>{}));
  18. BOOST_HOF_STATIC_FUNCTION(max) = fold(BOOST_HOF_LIFT(std::max));
  19. int main()
  20. {
  21. simple_print("Hello\n");
  22. print("Hello", "World\n");
  23. print_lines("Hello", "World");
  24. auto n = max(1, 2, 4, 3); // Returns 4
  25. auto m = max(0.1, 0.2, 0.5, 0.4); // Returns 0.5
  26. print_lines(n, m);
  27. }