Macros | Functions
container_algs_test.cc File Reference
#include "boost/test/unit_test.hpp"
#include "cetlib/container_algorithms.h"
#include <map>
#include <utility>

Go to the source code of this file.

Macros

#define BOOST_TEST_MODULE   (container_algorithms test)
 

Functions

 BOOST_AUTO_TEST_CASE (copy_all)
 
 BOOST_AUTO_TEST_CASE (transform_all)
 
 BOOST_AUTO_TEST_CASE (for_all_with_index)
 

Macro Definition Documentation

#define BOOST_TEST_MODULE   (container_algorithms test)

Definition at line 1 of file container_algs_test.cc.

Function Documentation

BOOST_AUTO_TEST_CASE ( copy_all  )

Definition at line 63 of file container_algs_test.cc.

64 {
65  std::vector<int> a{1, 2, 3, 4};
66  std::vector<int> b;
67  cet::copy_all(a, std::back_inserter(b));
68  BOOST_TEST(a == b);
69 }
const double a
auto copy_all(FwdCont &, FwdIter)
static bool * b
Definition: config.cpp:1043
BOOST_AUTO_TEST_CASE ( transform_all  )

Definition at line 71 of file container_algs_test.cc.

72 {
73  using namespace std;
74 
75  vector<int> const v1{1, 2, 3, 4};
76  vector<char> const v2{'a', 'b', 'c', 'd'};
77 
78  // One-input version
79  vector<A<int>> is1, is2;
80  vector<A<char>> cs1, cs2;
81  map<A<int>, A<char>> p1, p2;
82 
83  transform(cbegin(v1), cend(v1), back_inserter(is1), MakeA<int>());
84  transform(cbegin(v2), cend(v2), back_inserter(cs1), MakeA<char>());
85  transform(cbegin(v1),
86  cend(v1),
87  cbegin(v2),
88  inserter(p1, begin(p1)),
89  MakeAPair<int, char>());
90 
91  cet::transform_all(v1, back_inserter(is2), MakeA<int>());
92  cet::transform_all(v2, back_inserter(cs2), MakeA<char>());
93  cet::transform_all(v1, v2, inserter(p2, begin(p2)), MakeAPair<int, char>());
94 
95  BOOST_TEST(is1 == is2);
96  BOOST_TEST(cs1 == cs2);
97 
98  BOOST_TEST(p1.size() == p2.size());
99 
100  auto p1_it = cbegin(p1);
101  auto p2_it = cbegin(p1);
102  for (; p1_it != cend(p1); ++p1_it, ++p2_it) {
103  BOOST_TEST(p1_it->first.t_ == p2_it->first.t_);
104  BOOST_TEST(p1_it->second.t_ == p2_it->second.t_);
105  }
106 }
decltype(auto) constexpr cend(T &&obj)
ADL-aware version of std::cend.
Definition: StdUtils.h:87
STL namespace.
auto transform_all(Container &, OutputIt, UnaryOp)
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
BOOST_AUTO_TEST_CASE ( for_all_with_index  )

Definition at line 108 of file container_algs_test.cc.

109 {
110  std::vector<std::string> names{"Alice", "Bob", "Cathy", "Dylan"};
111  auto firstNames = names;
112  auto const& refNames = names;
113  // Adjust names using non-const version of 'for_all_with_index'
115  names, [](unsigned const i, auto& name) { name += std::to_string(i); });
116  // Check adjusted names using const version
118  refNames, [&firstNames](unsigned const i, auto const& refName) {
119  auto const assembledName = firstNames[i] + std::to_string(i);
120  BOOST_TEST(refName == assembledName);
121  });
122 }
static QCString name
Definition: declinfo.cpp:673
void for_all_with_index(FwdCont &, Func)
static std::vector< std::string > const names
Definition: FragmentType.hh:8
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34