//********************************************************
// The following code example is taken from the book
//  C++23 - The Complete Guide
//  by Nicolai M. Josuttis (www.josuttis.com)
//  http://www.cppstd23.com
//
// The code is licensed under a
//  Creative Commons Attribution 4.0 International License
//  http://creativecommons.org/licenses/by/4.0/
//********************************************************


#include <print>
#include <vector>
#include <array>
#include <ranges>

void printConstColl(const auto& coll)
{
  std::println("{}", coll);
}

int main()
{
  std::vector<std::string> rg1{"tic", "tac", "toe"};
  std::vector<std::string> rg2{"none"};
  std::vector<std::string> rg3{"one", "two"};
  std::array collOfColls{rg1, rg2, rg3};

  printConstColl(collOfColls);                                      // OK

  printConstColl(collOfColls | std::views::join_with("--"));        // OK

  // convert inner collections to plain values:
  auto collAsValue = [] (const auto& coll) { return coll; };
  auto collOfValueColls = collOfColls | std::views::transform(collAsValue);
  printConstColl(collOfValueColls | std::views::join_with("--"));   // ERROR
}

