[libcxx-commits] [PATCH] D143914: [libc++] Clean up pair's constructors and assignment operators

Jordan Rupprecht via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Feb 13 21:21:37 PST 2023


rupprecht added a comment.

The only other breakage I found so far that might be worthy of mention is that constructing containers requires begin/end iterators of pairs, not tuples, but frameworks for doing functional-style programming often tuples to be fully generic, so this breaks. This seems like an intended effect of this patch, but makes things a little less ergonomic. Is there an idiomatic way to do that w/o having to write your own tuple->pair boilerplate?

  void func2() {
    std::vector<int> v1 = {1, 2, 3};
    std::vector<std::string> v2 = {"One", "Two", "Three"};
  
    // Using a framework like https://github.com/ryanhaining/cppitertools
    auto v = iter::zip(v1, v2);  // Elements are `tuple<int &, std::string &>`
  
    // std::map constructor accepts iterator<pair>, not iterator<tuple>, so this no longer works
    std::map<int, std::string> m(v.begin(), v.end());
  
    // Now mapping it to pairs is required:
    auto v_pairs =
        v | iter::imap([](const auto& tuple) {
          return std::make_pair(std::get<0>(tuple), std::get<1>(tuple));
        });
    // OK
    std::map<int, std::string> m2(v_pairs.begin(), v_pairs.end());
  }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143914/new/

https://reviews.llvm.org/D143914



More information about the libcxx-commits mailing list