Blame view

3rdparty/boost_1_81_0/libs/hof/test/partial.cpp 5.02 KB
73ef4ff3   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
  /*=============================================================================
      Copyright (c) 2017 Paul Fultz II
      partial.cpp
      Distributed under the Boost Software License, Version 1.0. (See accompanying
      file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  ==============================================================================*/
  #include <boost/hof/partial.hpp>
  #include <boost/hof/limit.hpp>
  #include "test.hpp"
  
  static constexpr boost::hof::static_<boost::hof::partial_adaptor<binary_class> > binary_partial = {};
  
  static constexpr boost::hof::static_<boost::hof::partial_adaptor<unary_class> > unary_partial = {};
  
  static constexpr boost::hof::static_<boost::hof::partial_adaptor<mutable_class> > mutable_partial = {};
  
  static constexpr boost::hof::static_<boost::hof::partial_adaptor<void_class> > void_partial = {};
  
  static constexpr boost::hof::static_<boost::hof::partial_adaptor<mono_class> > mono_partial = {};
  
  static constexpr boost::hof::static_<boost::hof::partial_adaptor<move_class> > move_partial = {};
  
  constexpr boost::hof::partial_adaptor<binary_class> binary_partial_constexpr = {};
  
  constexpr boost::hof::partial_adaptor<unary_class> unary_partial_constexpr = {};
  
  constexpr boost::hof::partial_adaptor<void_class> void_partial_constexpr = {};
  
  constexpr boost::hof::partial_adaptor<mono_class> mono_partial_constexpr = {};
  
  BOOST_HOF_TEST_CASE()
  {
      boost::hof::partial_adaptor<void_class>()(1);
  
      void_partial(1);
      void_partial()(1);
      BOOST_HOF_TEST_CHECK(3 == binary_partial(1)(2));
      BOOST_HOF_TEST_CHECK(3 == binary_partial(1, 2));
      BOOST_HOF_TEST_CHECK(3 == unary_partial()(3));
      BOOST_HOF_TEST_CHECK(3 == unary_partial(3));
      BOOST_HOF_TEST_CHECK(3 == mono_partial(2));
      BOOST_HOF_TEST_CHECK(3 == mono_partial()(2));
  
      int i1 = 1;
      BOOST_HOF_TEST_CHECK(3 == binary_partial(2)(i1));
      BOOST_HOF_TEST_CHECK(3 == mutable_partial(std::ref(i1))(2));
      BOOST_HOF_TEST_CHECK(3 == i1);
      int i2 = 1;
      BOOST_HOF_TEST_CHECK(3 == mutable_partial(i2, 2));
      BOOST_HOF_TEST_CHECK(3 == i2);
      
  }
  
  BOOST_HOF_TEST_CASE()
  {
      BOOST_HOF_TEST_CHECK(3 == (move_class()(1, 2)));
      BOOST_HOF_TEST_CHECK(3 == (move_partial(1, 2)));
      BOOST_HOF_TEST_CHECK(3 == (move_partial(1)(2)));
      BOOST_HOF_TEST_CHECK(3 == (boost::hof::partial(move_class())(1)(2)));
      BOOST_HOF_TEST_CHECK(3 == (boost::hof::partial(move_class())(1, 2)));
  }
  
  BOOST_HOF_TEST_CASE()
  {
      void_partial_constexpr(1);
      void_partial_constexpr()(1);
      BOOST_HOF_STATIC_TEST_CHECK(3 == binary_partial_constexpr(1)(2));
      BOOST_HOF_STATIC_TEST_CHECK(3 == binary_partial_constexpr(1, 2));
      BOOST_HOF_STATIC_TEST_CHECK(3 == unary_partial_constexpr()(3));
      BOOST_HOF_STATIC_TEST_CHECK(3 == unary_partial_constexpr(3));
      BOOST_HOF_STATIC_TEST_CHECK(3 == mono_partial_constexpr(2));
      BOOST_HOF_STATIC_TEST_CHECK(3 == mono_partial_constexpr()(2));
  }
  #if BOOST_HOF_HAS_NOEXCEPT_DEDUCTION
  BOOST_HOF_TEST_CASE()
  {
      static_assert(noexcept(boost::hof::partial(binary_class{})(1)(2)), "noexcept partial");
  }
  #endif
  BOOST_HOF_TEST_CASE()
  {
      auto f = boost::hof::partial(boost::hof::limit_c<2>(binary_class()));
      static_assert(boost::hof::is_invocable<decltype(f), int>::value, "Passing the limit is not callable");
      static_assert(boost::hof::is_invocable<decltype(f), int, int>::value, "Passing the limit is not callable");
      static_assert(!boost::hof::is_invocable<decltype(f), int, int, int>::value, "Passing the limit is not callable");
      static_assert(!boost::hof::is_invocable<decltype(f), int, int, int, int>::value, "Passing the limit is not callable");
  
      auto g = f(0);
      static_assert(boost::hof::is_invocable<decltype(g), int>::value, "Passing the limit is not callable");
      static_assert(!boost::hof::is_invocable<decltype(g), int, int>::value, "Passing the limit is not callable");
      static_assert(!boost::hof::is_invocable<decltype(g), int, int, int>::value, "Passing the limit is not callable");
      static_assert(!boost::hof::is_invocable<decltype(g), int, int, int, int>::value, "Passing the limit is not callable");
  }
  
  BOOST_HOF_TEST_CASE()
  {
      auto f = boost::hof::partial(binary_class());
      static_assert(boost::hof::is_invocable<decltype(f), int>::value, "Passing the limit is not callable");
      static_assert(boost::hof::is_invocable<decltype(f), int, int>::value, "Passing the limit is not callable");
      static_assert(boost::hof::is_invocable<decltype(f), int, int, int>::value, "Passing the limit is not callable");
      static_assert(boost::hof::is_invocable<decltype(f), int, int, int, int>::value, "Passing the limit is not callable");
  
      auto g = f(0);
      static_assert(boost::hof::is_invocable<decltype(g), int>::value, "Passing the limit is not callable");
      static_assert(boost::hof::is_invocable<decltype(g), int, int>::value, "Passing the limit is not callable");
      static_assert(boost::hof::is_invocable<decltype(g), int, int, int>::value, "Passing the limit is not callable");
      static_assert(boost::hof::is_invocable<decltype(g), int, int, int, int>::value, "Passing the limit is not callable");
  }