cc21: added the basics of an initializer list.

master
Michael Hope 6 years ago
parent dfed2c4a01
commit afb753f2c6
  1. 2
      cc21.cc
  2. 10
      libcc2x.cc

@ -21,7 +21,7 @@ IntItem* remove_duplicates(IntItem* head) {
}
TEST_CASE("cc21", "remove_duplicates") {
auto first = make_list();
auto first = make_list({2, 3, 4});
CHECK(to_string(first) == " 1 2 3 4");
first = filter(first, [](int v) { return v % 2 == 0; });
CHECK(to_string(first) == " 1 3");

@ -48,10 +48,14 @@ std::string to_string(const Item<T>* head) {
return w.str();
}
IntItem* make_list() {
template <typename T>
Item<T>* make_list(std::initializer_list<T> items) {
// TODO(michaelh): change to take an initialiser list.
auto first = new IntItem{1};
first->emplace(2)->emplace(3)->emplace(4);
auto first = new Item<T>{1};
auto at = first;
for (const auto& i : items) {
at = at->emplace(i);
}
return first;
}

Loading…
Cancel
Save