rotate.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*=============================================================================
  2. Copyright (c) 2017 Paul Fultz II
  3. rotate.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. #include <boost/hof/rotate.hpp>
  8. #include <boost/hof/placeholders.hpp>
  9. #include <boost/hof/compose.hpp>
  10. #include <boost/hof/repeat.hpp>
  11. #include "test.hpp"
  12. struct head
  13. {
  14. template<class T, class... Ts>
  15. constexpr T operator()(T x, Ts&&...) const
  16. BOOST_HOF_RETURNS_DEDUCE_NOEXCEPT(x)
  17. {
  18. return x;
  19. }
  20. };
  21. #if BOOST_HOF_HAS_NOEXCEPT_DEDUCTION
  22. BOOST_HOF_TEST_CASE()
  23. {
  24. static_assert(noexcept(boost::hof::rotate(head{})(1, 2, 3, 4)), "noexcept rotate");
  25. static_assert(noexcept(boost::hof::repeat(std::integral_constant<int, 5>{})(boost::hof::rotate)(head{})(1, 2, 3, 4, 5, 6, 7, 8, 9)), "noexcept rotate");
  26. }
  27. #endif
  28. BOOST_HOF_TEST_CASE()
  29. {
  30. BOOST_HOF_TEST_CHECK(2 == boost::hof::rotate(head{})(1, 2, 3, 4));
  31. BOOST_HOF_STATIC_TEST_CHECK(2 == boost::hof::rotate(head{})(1, 2, 3, 4));
  32. }
  33. BOOST_HOF_TEST_CASE()
  34. {
  35. BOOST_HOF_TEST_CHECK(3 == boost::hof::compose(boost::hof::rotate, boost::hof::rotate)(head{})(1, 2, 3, 4));
  36. BOOST_HOF_STATIC_TEST_CHECK(3 == boost::hof::compose(boost::hof::rotate, boost::hof::rotate)(head{})(1, 2, 3, 4));
  37. }
  38. BOOST_HOF_TEST_CASE()
  39. {
  40. BOOST_HOF_TEST_CHECK(6 == boost::hof::repeat(std::integral_constant<int, 5>{})(boost::hof::rotate)(head{})(1, 2, 3, 4, 5, 6, 7, 8, 9));
  41. BOOST_HOF_STATIC_TEST_CHECK(6 == boost::hof::repeat(std::integral_constant<int, 5>{})(boost::hof::rotate)(head{})(1, 2, 3, 4, 5, 6, 7, 8, 9));
  42. }
  43. BOOST_HOF_TEST_CASE()
  44. {
  45. BOOST_HOF_TEST_CHECK(3 == boost::hof::rotate(boost::hof::_ - boost::hof::_)(2, 5));
  46. BOOST_HOF_STATIC_TEST_CHECK(3 == boost::hof::rotate(boost::hof::_ - boost::hof::_)(2, 5));
  47. }
  48. #if defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 7
  49. #define FINAL
  50. #else
  51. #define FINAL final
  52. #endif
  53. struct f FINAL {
  54. int operator()(int i, void *) const {
  55. return i;
  56. }
  57. };
  58. BOOST_HOF_TEST_CASE()
  59. {
  60. BOOST_HOF_TEST_CHECK(boost::hof::rotate(f())(nullptr, 2) == 2);
  61. }