const_assns_iter_t.cc
Go to the documentation of this file.
4 
5 #include <algorithm>
6 #include <cassert>
7 #include <string>
8 #include <type_traits>
9 #include <vector>
10 
11 using namespace art;
12 
13 using intvec_t = std::vector<int>;
14 using shortvec_t = std::vector<short>;
15 using strvec_t = std::vector<std::string>;
16 using floatvec_t = std::vector<float>;
20 
21 using ab_node_t = assns_ab_t::const_iterator::value_type;
22 using ab_node_first_t = ab_node_t::first_type;
23 using ab_node_second_t = ab_node_t::second_type;
24 using abd_node_t = ci_t::value_type;
25 using abd_node_first_t = abd_node_t::first_type;
26 using abd_node_second_t = abd_node_t::second_type;
28 
29 static_assert(std::is_same_v<ab_node_first_t, abd_node_first_t>);
30 static_assert(std::is_same_v<ab_node_second_t, abd_node_second_t>);
31 static_assert(std::is_same_v<abd_node_first_t, tuple_element_t<0, abd_node_t>>);
32 static_assert(
34 static_assert(std::is_same_v<abd_node_data_t, tuple_element_t<2, abd_node_t>>);
35 
36 int
38 {
39 
40  // initialization stuff
41  art::ProductID const viid{2};
42  art::ProductID const vfid{3};
43  intvec_t const vi{1, 2, 3};
44  floatvec_t const vf{1.0, 1.1, 2.0, 2.1, 3.0, 3.1};
45  shortvec_t const vs{10, 11, 20, 21, 30, 31};
46  intvec_t const vtest{1, 1, 2, 2, 3, 3};
47 
48  int k{};
49 
50  assns_abd_t assns;
51  assns_ab_t a1;
52 
53  for (long unsigned int i = 0; i < 3; ++i) {
54  auto p1 = art::Ptr<int>(viid, &vi[i], i);
55  for (long unsigned int j = 0; j < 2; ++j) {
56  auto p2 = art::Ptr<float>(vfid, &vf[k], k);
57  assns.addSingle(p1, p2, vs[k]);
58  a1.addSingle(p1, p2);
59  ++k;
60  }
61  }
62 
63  // iterator increment and dereference test
64  auto my_begin = assns.begin();
65  auto const my_end = assns.end();
66 
67  auto check_values =
68  [](auto const& r, short const s, float const f, int const j) {
69  auto const& first = get<abd_node_first_t>(r);
70  auto const& second = get<abd_node_second_t>(r);
71  auto const& data = get<abd_node_data_t>(r);
72 
73  auto const& firstA = get<0>(r);
74  auto const& secondA = get<1>(r);
75  auto const& dataA = get<2>(r);
76 
77  auto const& firstB = get<Ptr<int>>(r);
78  auto const& secondB = get<Ptr<float>>(r);
79  auto const& dataB = get<short>(r);
80 
81  assert(first == firstA);
82  assert(second == secondA);
83  assert(data == dataA);
84 
85  assert(first == firstB);
86  assert(second == secondB);
87  assert(data == dataB);
88 
89  assert(data == s);
90  assert(*second == f);
91  assert(*first == j);
92  };
93 
94  k = 0;
95  for (auto p = my_begin; p != my_end; ++p) {
96  auto const& r = *p;
97  check_values(r, vs[k], vf[k], vtest[k]);
98  ++k;
99  }
100 
101  // range-for loop test
102  k = 0;
103  for (auto const& p : assns) {
104  check_values(p, vs[k], vf[k], vtest[k]);
105  ++k;
106  }
107 
108  // std::for_each test
109  auto print = [](auto const& r) { std::cout << " " << *(r.data); };
110  std::for_each(assns.begin(), assns.end(), print);
111  std::cout << std::endl;
112 
113  static_assert(std::is_copy_constructible_v<ci_t>);
114  static_assert(std::is_copy_assignable_v<ci_t>);
115  static_assert(std::is_move_assignable_v<ci_t>);
116 
117  assert(*((*(my_begin + 4)).data) == 30);
118  my_begin += 4;
119  assert(*((*my_begin).data) == 30);
120  assert(my_begin - my_end == 2);
121  assert(*(my_begin[0].data) == 30);
122  assert(*(my_begin->data) == 30);
123  assert((my_begin < my_end) == true);
124  assert((my_begin <= my_end) == true);
125  assert((my_begin > my_end) == false);
126  assert((my_begin >= my_end) == false);
127 
128  // reverse iterator test
129  assns_abd_t empty_assns;
130  assert(empty_assns.rbegin() == empty_assns.rend());
131 
132  k = assns.size() - 1;
133  auto const my_rbegin = assns.rbegin();
134  auto const my_rend = assns.rend();
135  for (auto it = my_rbegin; it != my_rend; ++it) {
136  check_values(*it, vs[k], vf[k], vtest[k]);
137  --k;
138  }
139 
140  assert((my_rbegin < my_rend) == true);
141  assert((my_rbegin <= my_rend) == true);
142  assert((my_rbegin > my_rend) == false);
143  assert((my_rbegin >= my_rend) == false);
144 
145  return 0;
146 }
assns_abd_t::const_iterator ci_t
std::vector< short > shortvec_t
const_iterator begin() const
Definition: Assns.h:504
std::vector< int > intvec_t
ci_t::value_type abd_node_t
typename tuple_element< I, Node >::type tuple_element_t
Definition: AssnsNode.h:56
std::vector< float > floatvec_t
p
Definition: test.py:223
int main()
std::vector< std::string > strvec_t
const_iterator end() const
Definition: Assns.h:511
const_reverse_iterator rend() const
Definition: Assns.h:525
assns_ab_t::const_iterator::value_type ab_node_t
void addSingle(Ptr< left_t > const &left, Ptr< right_t > const &right, data_t const &data)
Definition: Assns.h:546
ab_node_t::second_type ab_node_second_t
abd_node_t::second_type abd_node_second_t
abd_node_t::first_type abd_node_first_t
ab_node_t::first_type ab_node_first_t
const_reverse_iterator rbegin() const
Definition: Assns.h:518
second_as<> second
Type of time stored in seconds, in double precision.
Definition: spacetime.h:85
Definition: fwd.h:31
static QCString * s
Definition: config.cpp:1042
typename art::const_AssnsIter< L, R, D, Direction::Forward > const_iterator
Definition: Assns.h:237
abd_node_t::data_type abd_node_data_t
QTextStream & endl(QTextStream &s)
#define a1