C++20 introduces the views::elements, views::keys and views::values to easily deal with range of tuple-like values:
std::vector v{std::tuple{'A', 1}, {'B', 2}, {'C', 3}}; auto it = std::ranges::find(v | std::views::elements<0>, 'B'); assert(*it == 'B'); After applying the adaptor, v | std::views::elements<0> become a range of the first element of each tuple, so the return type of the ranges::find is the iterator type of that transformed range.
But is there a possible way to transform it back to the origin iterator type to get the origin tuple?
assert(*magic_revert(it) == std::tuple{'B', 2}); https://stackoverflow.com/questions/65912645/is-there-any-possible-way-to-get-origin-value-using-transformed-iterator January 27, 2021 at 11:49AM
没有评论:
发表评论