Classes | Macros | Typedefs | Functions
RangeForWrapper_test.cc File Reference

Test for RangeForWrapper utilities. More...

#include "lardata/Utilities/RangeForWrapper.h"
#include <boost/test/unit_test.hpp>
#include <iterator>
#include <numeric>
#include <limits>
#include <type_traits>
#include <initializer_list>

Go to the source code of this file.

Classes

class  base_iterator< Value >
 
struct  begin_iterator_t
 
struct  end_iterator_t
 
struct  begin_const_iterator_t
 
struct  end_const_iterator_t
 
struct  Data
 

Macros

#define BOOST_TEST_MODULE   ( RangeForWrapper_test )
 

Typedefs

using wrapper_type = util::details::RangeForWrapperIterator< begin_iterator_t, end_iterator_t >
 
using const_wrapper_type = util::details::RangeForWrapperIterator< begin_const_iterator_t, end_const_iterator_t >
 

Functions

template<typename ValueL , typename ValueR >
bool operator!= (base_iterator< ValueL > const &a, base_iterator< ValueR > const &b)
 
template<typename T >
copy (T const &v)
 
template<typename DataColl >
void const_test (DataColl const &data, int expected_total)
 
template<typename DataColl >
void test (DataColl &data, int expected_total)
 
template<typename Iter , typename RefIter >
void iterator_tests (Iter iter, RefIter refIter, RefIter refEnd)
 
template<typename Iter , typename RefIter >
void const_input_iterator_tests (Iter iter, RefIter refIter, RefIter refEnd)
 
template<typename Iter , typename RefIter >
void input_iterator_tests (Iter iter, RefIter refIter, RefIter refEnd)
 
template<typename Iter , typename RefIter >
void const_output_iterator_tests (Iter iter, RefIter refIter, RefIter refEnd)
 
template<typename Iter , typename RefIter >
void output_iterator_tests (Iter iter, RefIter refIter, RefIter refEnd)
 
template<typename Iter , typename RefIter >
void const_forward_iterator_tests (Iter iter, RefIter refIter, RefIter refEnd)
 
template<typename Iter , typename RefIter >
void forward_iterator_tests (Iter iter, RefIter refIter, RefIter refEnd)
 
template<typename Iter , typename RefIter >
void const_bidirectional_iterator_tests (Iter iter, RefIter refIter, RefIter refEnd)
 
template<typename Iter , typename RefIter >
void bidirectional_iterator_tests (Iter iter, RefIter refIter, RefIter refEnd)
 
template<typename Iter , typename RefIter >
void const_random_access_iterator_tests (Iter iter, RefIter refIter, RefIter refEnd)
 
template<typename Iter , typename RefIter >
void random_access_iterator_tests (Iter iter, RefIter refIter, RefIter refEnd)
 
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t< IsConst > iterator_test_impl (Iter iter, RefIter refIter, RefIter refEnd, std::input_iterator_tag)
 
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<!IsConst > iterator_test_impl (Iter iter, RefIter refIter, RefIter refEnd, std::input_iterator_tag tag)
 
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t< IsConst > iterator_test_impl (Iter iter, RefIter refIter, RefIter refEnd, std::output_iterator_tag)
 
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<!IsConst > iterator_test_impl (Iter iter, RefIter refIter, RefIter refEnd, std::output_iterator_tag tag)
 
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t< IsConst > iterator_test_impl (Iter iter, RefIter refIter, RefIter refEnd, std::forward_iterator_tag)
 
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<!IsConst > iterator_test_impl (Iter iter, RefIter refIter, RefIter refEnd, std::forward_iterator_tag tag)
 
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t< IsConst > iterator_test_impl (Iter iter, RefIter refIter, RefIter refEnd, std::bidirectional_iterator_tag)
 
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<!IsConst > iterator_test_impl (Iter iter, RefIter refIter, RefIter refEnd, std::bidirectional_iterator_tag tag)
 
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t< IsConst > iterator_test_impl (Iter iter, RefIter refIter, RefIter refEnd, std::random_access_iterator_tag)
 
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<!IsConst > iterator_test_impl (Iter iter, RefIter refIter, RefIter refEnd, std::random_access_iterator_tag tag)
 
template<typename Iter , typename RefIter >
void iterator_test (Iter iter, RefIter refIter, RefIter refEnd)
 
template<bool IsConst>
void RangeForWrapperIteratorStandardsTest ()
 
 BOOST_AUTO_TEST_CASE (RangeForWrapperSameIterator_test)
 
 BOOST_AUTO_TEST_CASE (RangeForWrapperDifferentIterator_test)
 
 BOOST_AUTO_TEST_CASE (RangeForWrapperIteratorStandardsTestCase)
 

Detailed Description

Test for RangeForWrapper utilities.

Author
Gianluca Petrillo (petri.nosp@m.llo@.nosp@m.fnal..nosp@m.gov)
Date
December 29, 2016
See also
RangeForWrapper.h

The test is run with no arguments.

Definition in file RangeForWrapper_test.cc.

Macro Definition Documentation

#define BOOST_TEST_MODULE   ( RangeForWrapper_test )

Definition at line 16 of file RangeForWrapper_test.cc.

Typedef Documentation

Definition at line 69 of file RangeForWrapper_test.cc.

Definition at line 68 of file RangeForWrapper_test.cc.

Function Documentation

template<typename Iter , typename RefIter >
void bidirectional_iterator_tests ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 423 of file RangeForWrapper_test.cc.

424 {
425  const_bidirectional_iterator_tests(iter, refIter, refEnd);
426 } // bidirectional_iterator_tests()
void const_bidirectional_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
BOOST_AUTO_TEST_CASE ( RangeForWrapperSameIterator_test  )

Definition at line 618 of file RangeForWrapper_test.cc.

618  {
619 
620  std::vector vdata { 2, 3, 4 };
621 
622  // static checks
623  static_assert(std::is_same<
624  std::decay_t<decltype(vdata)>,
625  std::decay_t<decltype(vdata | util::range_for)>
626  >::value,
627  "util::range_for should be pass-through!"
628  );
629  static_assert(
630  std::is_lvalue_reference<decltype(vdata | util::range_for)>::value,
631  "Pass-through on a lvalue should return a lvalue reference"
632  );
633 
634  static_assert(
635  !std::is_lvalue_reference
636  <decltype(copy(vdata) | util::range_for)>::value,
637  "Pass-through on a rvalue should return a rvalue (or its reference)"
638  );
639 
640  BOOST_TEST(&vdata == &(vdata | util::range_for));
641 
642  auto const expected_total = std::accumulate(vdata.begin(), vdata.end(), 0);
643 
644  const_test(vdata, expected_total);
645 
646  test(vdata, expected_total);
647 
648 } // BOOST_AUTO_TEST_CASE(RangeForWrapperSameIterator_test_test)
struct vector vector
constexpr RangeForWrapperTag range_for
void const_test(DataColl const &data, int expected_total)
void test(DataColl &data, int expected_total)
T copy(T const &v)
BOOST_AUTO_TEST_CASE ( RangeForWrapperDifferentIterator_test  )

Definition at line 651 of file RangeForWrapper_test.cc.

651  {
652 
653  std::vector vdata { 2, 3, 4 };
654 
655  Data data { 2, 3, 4 };
656 
657  auto expected_total = std::accumulate(vdata.begin(), vdata.end(), 0);
658 
659  // static check
660  static_assert(!std::is_same<
661  std::decay_t<decltype(data)>,
662  std::decay_t<decltype(data | util::range_for)>
663  >::value,
664  "util::range_for should generate a wrapper!"
665  );
666 
667 // for (double d: data); // this should fail compilation
668 
669  const_test(data, expected_total);
670 
671  test(data, expected_total);
672 
673 } // BOOST_AUTO_TEST_CASE(RangeForWrapperDifferentIterator_test_test)
struct vector vector
constexpr RangeForWrapperTag range_for
void const_test(DataColl const &data, int expected_total)
void test(DataColl &data, int expected_total)
BOOST_AUTO_TEST_CASE ( RangeForWrapperIteratorStandardsTestCase  )

Definition at line 676 of file RangeForWrapper_test.cc.

676  {
677 
678  RangeForWrapperIteratorStandardsTest<false>(); // mutable range test
679  RangeForWrapperIteratorStandardsTest<true>(); // constant range test
680 
681 } // BOOST_AUTO_TEST_CASE(RangeForWrapperIteratorStandardsTestCase)
template<typename Iter , typename RefIter >
void const_bidirectional_iterator_tests ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 395 of file RangeForWrapper_test.cc.

396 {
397  const bool isEnd = refIter == refEnd;
398 // const bool isLast = std::next(refIter) == refEnd;
399  const bool isSingular = (iter == Iter());
400  const bool isNormal = !isEnd && !isSingular;
401  const bool isDereferenciable = isNormal;
402 
403  auto ia = isEnd? iter: std::next(iter);
404  auto iaRef = isEnd? refIter: std::next(refIter);
405 
406  auto ib = ia;
407  --ib;
408  BOOST_TEST((ib != ia));
409  BOOST_TEST((*ib == *std::prev(iaRef)));
410  BOOST_TEST((++ib == ia));
411  if (isDereferenciable) BOOST_TEST((*ib == *iaRef));
412 
413  ib--;
414  BOOST_TEST((ib != ia));
415  BOOST_TEST((*ib == *std::prev(iaRef)));
416  BOOST_TEST((++ib == ia));
417  if (isDereferenciable) BOOST_TEST((*ib == *iaRef));
418 
419 } // const_bidirectional_iterator_tests()
template<typename Iter , typename RefIter >
void const_forward_iterator_tests ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 345 of file RangeForWrapper_test.cc.

346 {
347  const bool isEnd = refIter == refEnd;
348  const bool isSingular = (iter == Iter());
349  const bool isNormal = !isEnd && !isSingular;
350  const bool isDereferenciable = isNormal;
351 
352  static_assert(std::is_default_constructible<Iter>(),
353  "Forward iterator concept violation");
354 
355  using traits_t = std::iterator_traits<Iter>;
356  using dereference_t = std::remove_reference_t<decltype(*iter)>;
357  constexpr bool isConst = std::is_const<dereference_t>();
358 
359  static_assert(
360  std::is_same<
361  typename traits_t::reference,
362  std::add_lvalue_reference_t<
363  std::conditional_t<isConst,
364  std::add_const_t<typename traits_t::value_type>,
365  typename traits_t::value_type
366  >
367  >
368  >(),
369  "Forward iterator concept violation"
370  );
371 
372  if (isDereferenciable) {
373  auto ia = iter, ib = iter;
374 
375  BOOST_TEST((ia == ib));
376 
377  BOOST_TEST((&*ia == &*ib));
378 
379  BOOST_TEST((++ia == ++ib));
380 
381  }
382 
383 } // const_forward_iterator_tests()
template<typename Iter , typename RefIter >
void const_input_iterator_tests ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 223 of file RangeForWrapper_test.cc.

224 {
225  const bool isEnd = refIter == refEnd;
226  const bool isSingular = (iter == Iter());
227  const bool isNormal = !isEnd && !isSingular;
228 // const bool isDereferenciable = isNormal;
229  const bool isLast = (std::next(refIter) == refEnd);
230 
231  static_assert(std::is_same<
232  typename std::iterator_traits<Iter>::reference,
233  decltype(Iter(iter).operator*())
234  >(), "Inconsistent return type for dereference operator");
235 
236  if (!isEnd) {
237  auto ia = iter;
238  if (!isSingular) BOOST_TEST(++ia != iter);
239  }
240 
241  if (isNormal) {
242  auto ia = iter, ib = iter;
243  ia++; ++ib;
244  BOOST_TEST(ia == ib);
245  if (!isLast) {
246  auto ia = iter;
247  BOOST_TEST(*(ia++) == *iter);
248  }
249  }
250 
251  {
252  auto ia = iter;
253  if (!isEnd)
254  (void)ia++;
255  }
256 
257 
258 } // const_input_iterator_tests()
template<typename Iter , typename RefIter >
void const_output_iterator_tests ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 270 of file RangeForWrapper_test.cc.

271 {
272  const bool isEnd = refIter == refEnd;
273  const bool isSingular = (iter == Iter());
274  const bool isNormal = !isEnd && !isSingular;
275 // const bool isDereferenciable = isNormal;
276 // const bool isLast = (std::next(refIter) == refEnd);
277 
278  static_assert(std::is_same<
279  typename std::iterator_traits<Iter>::reference,
280  decltype(Iter(iter).operator*())
281  >(), "Inconsistent return type for dereference operator");
282 
283  if (!isEnd) {
284  auto ia = iter;
285  auto addr = &ia;
286  if (!isSingular) {
287  BOOST_TEST((++ia != iter));
288  BOOST_TEST((&++ia == addr));
289  }
290  }
291 
292  if (isNormal) {
293  auto ia = iter, ib = iter;
294  ia++; ++ib;
295  BOOST_TEST(ia == ib);
296  }
297 
298  {
299  auto ia = iter;
300  if (!isEnd) (void)ia++;
301  }
302 
303 
304 } // const_output_iterator_tests()
constexpr std::enable_if_t< are_cv_compatible< TO, FROM >::value, std::add_pointer_t< std::remove_pointer_t< TO > > > addr(FROM &from)
Definition: ensurePointer.h:35
template<typename Iter , typename RefIter >
void const_random_access_iterator_tests ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 431 of file RangeForWrapper_test.cc.

432 {
433 } // const_random_access_iterator_tests()
template<typename DataColl >
void const_test ( DataColl const &  data,
int  expected_total 
)

Definition at line 104 of file RangeForWrapper_test.cc.

105 {
106  static_assert(
107  !std::is_lvalue_reference
108  <decltype(copy(data) | util::range_for)>::value,
109  "util::range_for on a rvalue should return a rvalue"
110  );
111 
112  int total = 0;
113  for (int d: data | util::range_for) total += d;
114 
115  BOOST_TEST(total == expected_total);
116 
117  // from a temporary
118  total = 0;
119  for (int d: copy(data) | util::range_for) total += d;
120 
121  BOOST_TEST(total == expected_total);
122 
123 } // const_test()
constexpr RangeForWrapperTag range_for
T copy(T const &v)
template<typename T >
T copy ( T const &  v)

Definition at line 98 of file RangeForWrapper_test.cc.

98 { return v; }
template<typename Iter , typename RefIter >
void forward_iterator_tests ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 387 of file RangeForWrapper_test.cc.

388 {
389  const_forward_iterator_tests(iter, refIter, refEnd);
390 } // forward_iterator_tests()
void const_forward_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<typename Iter , typename RefIter >
void input_iterator_tests ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 262 of file RangeForWrapper_test.cc.

263 {
264  const_input_iterator_tests(iter, refIter, refEnd);
265 } // input_iterator_tests()
void const_input_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<typename Iter , typename RefIter >
void iterator_test ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 539 of file RangeForWrapper_test.cc.

539  {
540  //
541  // dispatcher
542  //
543  using traits_t = std::iterator_traits<Iter>;
544  constexpr bool IsConst
545  = std::is_const<std::remove_reference_t<decltype(*iter)>>();
546 
547  iterator_test_impl<IsConst>
548  (iter, refIter, refEnd, typename traits_t::iterator_category{});
549 
550 } // iterator_test()
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<IsConst> iterator_test_impl ( Iter  iter,
RefIter  refIter,
RefIter  refEnd,
std::input_iterator_tag   
)

Definition at line 448 of file RangeForWrapper_test.cc.

449 {
450  iterator_tests(iter, refIter, refEnd);
451  const_input_iterator_tests(iter, refIter, refEnd);
452 } // iterator_test_impl<const>(input iterator)
void const_input_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
void iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<!IsConst> iterator_test_impl ( Iter  iter,
RefIter  refIter,
RefIter  refEnd,
std::input_iterator_tag  tag 
)

Definition at line 457 of file RangeForWrapper_test.cc.

458 {
459  iterator_tests(iter, refIter, refEnd);
460  input_iterator_tests(iter, refIter, refEnd);
461 } // iterator_test_impl<non-const>(input iterator)
void input_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
void iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<IsConst> iterator_test_impl ( Iter  iter,
RefIter  refIter,
RefIter  refEnd,
std::output_iterator_tag   
)

Definition at line 466 of file RangeForWrapper_test.cc.

467 {
468  iterator_tests(iter, refIter, refEnd);
469  const_output_iterator_tests(iter, refIter, refEnd);
470 } // iterator_test_impl<const>(output iterator)
void const_output_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
void iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<!IsConst> iterator_test_impl ( Iter  iter,
RefIter  refIter,
RefIter  refEnd,
std::output_iterator_tag  tag 
)

Definition at line 475 of file RangeForWrapper_test.cc.

476 {
477  iterator_tests(iter, refIter, refEnd);
478  output_iterator_tests(iter, refIter, refEnd);
479 } // iterator_test_impl<non-const>(output iterator)
void output_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
void iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<IsConst> iterator_test_impl ( Iter  iter,
RefIter  refIter,
RefIter  refEnd,
std::forward_iterator_tag   
)

Definition at line 484 of file RangeForWrapper_test.cc.

485 {
486  iterator_test_impl<IsConst>(iter, refIter, refEnd, std::input_iterator_tag{});
487  iterator_test_impl<IsConst>(iter, refIter, refEnd, std::output_iterator_tag{});
488  const_forward_iterator_tests(iter, refIter, refEnd);
489 } // iterator_test_impl<const>(random access iterator)
void const_forward_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<!IsConst> iterator_test_impl ( Iter  iter,
RefIter  refIter,
RefIter  refEnd,
std::forward_iterator_tag  tag 
)

Definition at line 494 of file RangeForWrapper_test.cc.

495 {
496  iterator_test_impl<IsConst>(iter, refIter, refEnd, std::input_iterator_tag{});
497  iterator_test_impl<IsConst>(iter, refIter, refEnd, std::output_iterator_tag{});
498  forward_iterator_tests(iter, refIter, refEnd);
499 } // iterator_test_impl<non-const>(forward iterator)
void forward_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<IsConst> iterator_test_impl ( Iter  iter,
RefIter  refIter,
RefIter  refEnd,
std::bidirectional_iterator_tag   
)

Definition at line 504 of file RangeForWrapper_test.cc.

505 {
506  iterator_test_impl<IsConst>(iter, refIter, refEnd, std::forward_iterator_tag{});
507  const_random_access_iterator_tests(iter, refIter, refEnd);
508 } // iterator_test_impl<const>(forward iterator)
void const_random_access_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<!IsConst> iterator_test_impl ( Iter  iter,
RefIter  refIter,
RefIter  refEnd,
std::bidirectional_iterator_tag  tag 
)

Definition at line 513 of file RangeForWrapper_test.cc.

514 {
515  iterator_test_impl<IsConst>(iter, refIter, refEnd, std::forward_iterator_tag{});
516  bidirectional_iterator_tests(iter, refIter, refEnd);
517 } // iterator_test_impl<non-const>(bidirectional iterator)
void bidirectional_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<IsConst> iterator_test_impl ( Iter  iter,
RefIter  refIter,
RefIter  refEnd,
std::random_access_iterator_tag   
)

Definition at line 522 of file RangeForWrapper_test.cc.

523 {
524  iterator_test_impl<IsConst>(iter, refIter, refEnd, std::bidirectional_iterator_tag{});
525  const_bidirectional_iterator_tests(iter, refIter, refEnd);
526 } // iterator_test_impl<const>(bidirectional iterator)
void const_bidirectional_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<bool IsConst, typename Iter , typename RefIter >
std::enable_if_t<!IsConst> iterator_test_impl ( Iter  iter,
RefIter  refIter,
RefIter  refEnd,
std::random_access_iterator_tag  tag 
)

Definition at line 531 of file RangeForWrapper_test.cc.

532 {
533  iterator_test_impl<IsConst>(iter, refIter, refEnd, std::bidirectional_iterator_tag{});
534  random_access_iterator_tests(iter, refIter, refEnd);
535 } // iterator_test_impl<non-const>(random access iterator)
void random_access_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<typename Iter , typename RefIter >
void iterator_tests ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 182 of file RangeForWrapper_test.cc.

183 {
184  // these asserts do not completely test the concepts;
185  // for example, the copy-constructable concept requires that the value of
186  // the copy-constructed object and the one it was constructed from are
187  // "equivalent", while std::is_copy_constructable only guarantees that
188  // copy construction can happen, not testing the equivalence.
189  static_assert
190  (std::is_move_constructible<Iter>(), "Iterator concept violation");
191  static_assert
192  (std::is_copy_constructible<Iter>(), "Iterator concept violation");
193  static_assert
194  (std::is_copy_assignable<Iter>(), "Iterator concept violation");
195  static_assert
196  (std::is_destructible<Iter>(), "Iterator concept violation");
197  // C++17
198 // static_assert
199 // (std::is_swappable<Iter>(), "Iterator concept violation");
200 
201  const bool isEnd = refIter == refEnd;
202  const bool isSingular = (iter == Iter());
203  const bool isDereferenciable = !isEnd && !isSingular;
204  const bool isLast = (std::next(refIter) == refEnd);
205 
206  Iter ia = iter;
207  BOOST_TEST(bool(ia == iter));
208 
209  if (isDereferenciable) {
210  //BOOST_TEST(*iter == *refIter);
211  BOOST_TEST((*iter == *refIter));
212  }
213  if (!isLast && !isEnd && !isSingular) {
214  //BOOST_TEST(*++iter == *++refIter);
215  BOOST_TEST((*++iter == *++refIter));
216  }
217 
218 } // iterator_tests()
template<typename ValueL , typename ValueR >
bool operator!= ( base_iterator< ValueL > const &  a,
base_iterator< ValueR > const &  b 
)

Definition at line 59 of file RangeForWrapper_test.cc.

60  { return a.ptr != b.ptr; }
template<typename Iter , typename RefIter >
void output_iterator_tests ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 308 of file RangeForWrapper_test.cc.

309 {
310  const bool isEnd = refIter == refEnd;
311 
312  const_output_iterator_tests(iter, refIter, refEnd);
313 
314  if (!isEnd) {
315  auto value = *iter;
316 
318 
319  *iter = newValue;
320 
321  // we couldn't check the result since an output operator is not expected
322  // to return anything useful with *iter; but since we have already used it
323  // to store the old value...
324  BOOST_TEST((*iter == newValue));
325 
326  *iter = value;
327  BOOST_TEST((*iter == value));
328 
329  auto ia = iter, ib = iter;
330 
331  *ia++ = newValue;
332  ++ib;
333  BOOST_TEST((*iter == newValue));
334  BOOST_TEST(ia == ib);
335 
336  *iter = value;
337  BOOST_TEST((*iter == value));
338  }
339 
340 } // output_iterator_tests()
void const_output_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
static int max(int a, int b)
template<typename Iter , typename RefIter >
void random_access_iterator_tests ( Iter  iter,
RefIter  refIter,
RefIter  refEnd 
)

Definition at line 437 of file RangeForWrapper_test.cc.

438 {
439  const_random_access_iterator_tests(iter, refIter, refEnd);
440 } // random_access_iterator_tests()
void const_random_access_iterator_tests(Iter iter, RefIter refIter, RefIter refEnd)
template<bool IsConst>
void RangeForWrapperIteratorStandardsTest ( )

Definition at line 554 of file RangeForWrapper_test.cc.

554  {
555 
556  using base_reference_container_t = std::vector<int>;
557  using reference_container_t = std::conditional_t
558  <IsConst, base_reference_container_t const, base_reference_container_t>;
559  reference_container_t vdata = { 2, 3, 4 };
560  using basic_container_t = Data;
561 
562  static_assert(std::is_same<basic_container_t::begin_iterator::reference, int&>());
563  static_assert(std::is_same<typename std::iterator_traits<basic_container_t::begin_iterator>::reference, int&>());
564 
565  static_assert(std::is_same<basic_container_t::begin_const_iterator::reference, std::add_const_t<int>&>());
566  static_assert(std::is_same<typename std::iterator_traits<basic_container_t::begin_const_iterator>::reference, std::add_const_t<int>&>());
567 
568  using container_t
569  = std::conditional_t<IsConst, basic_container_t const, basic_container_t>;
570  //
571  // non-const iterator interface (iterators may still be constant)
572  //
573  container_t data = { 2, 3, 4 };
574  auto range = data | util::range_for;
575  using std::begin;
576  using std::end;
577  auto rbegin = begin(range);
578  auto rend = end(range);
579 
580  auto vbegin = vdata.begin();
581  auto vend = vdata.end();
582 
583  BOOST_TEST((unsigned)std::distance(rbegin, rend) == vdata.size());
584 
585  iterator_test(rbegin, vbegin, vend);
586  iterator_test(rend, vend, vend);
587 
588 
589  //
590  // const iterator interface
591  //
592  using std::cbegin;
593  using std::cend;
594  auto rcbegin = cbegin(range);
595  auto rcend = cend(range);
596 
597  auto vcbegin = vdata.cbegin();
598  auto vcend = vdata.cend();
599 
600  BOOST_TEST((unsigned)std::distance(rcbegin, rcend) == vdata.size());
601 
602  iterator_test(rcbegin, vcbegin, vcend);
603  iterator_test(rcend, vcend, vcend);
604 
605  //
606  // extra access (partial support for random access)
607  //
608  BOOST_TEST(range.size() == data.size());
609  BOOST_TEST(range.empty() == data.empty());
610  for (std::size_t i = 0; i < data.size(); ++i) {
611  BOOST_TEST(range[i] == data[i]);
612  }
613 
614 } // RangeForWrapperIteratorStandardsTest()
end
while True: pbar.update(maxval-len(onlies[E][S])) #print iS, "/", len(onlies[E][S]) found = False for...
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:87
constexpr RangeForWrapperTag range_for
double distance(double x1, double y1, double z1, double x2, double y2, double z2)
Fw2dFFT::Data Data
void iterator_test(Iter iter, RefIter refIter, RefIter refEnd)
decltype(auto) constexpr cbegin(T &&obj)
ADL-aware version of std::cbegin.
Definition: StdUtils.h:82
decltype(auto) constexpr begin(T &&obj)
ADL-aware version of std::begin.
Definition: StdUtils.h:72
template<typename DataColl >
void test ( DataColl &  data,
int  expected_total 
)

Definition at line 127 of file RangeForWrapper_test.cc.

127  {
128  static_assert(
129  !std::is_lvalue_reference
130  <decltype(copy(data) | util::range_for)>::value,
131  "util::range_for on a rvalue should return a rvalue"
132  );
133 
134  //
135  // from a lvalue
136  //
137  int total = 0;
138  for (int d: data | util::range_for) total += d;
139 
140  BOOST_TEST(total == expected_total);
141 
142  //
143  // from a rvalue (temporary)
144  //
145  total = 0;
146  for (int d: copy(data) | util::range_for) total += d;
147 
148  BOOST_TEST(total == expected_total);
149 
150  //
151  // from a temporary, which is changed
152  //
153  total = 0;
154  for (int& d: copy(data) | util::range_for) total += (d *= 3);
155 
156  BOOST_TEST(total == 3 * expected_total);
157 
158  // original value is still unchanged
159  total = 0;
160  for (int d: data | util::range_for) total += d;
161 
162  BOOST_TEST(total == expected_total);
163 
164  //
165  // from a lvalue, which is changed
166  //
167  for (int& d: data | util::range_for) d *= 3;
168 
169  total = 0;
170  for (int d: data | util::range_for) total += d;
171 
172  BOOST_TEST(total == 3 * expected_total);
173 
174 } // test()
constexpr RangeForWrapperTag range_for
T copy(T const &v)