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


#include <print>
#include <string>
#include <vector>
#include <ranges>

int main()
{
  std::vector<int> coll{47, 11, 0, 8, 15, 14, 13};
  std::println("{}", coll);

  auto diff = [](auto a, auto b) { return b - a; };
  for (auto val : coll | std::views::adjacent_transform<2>(diff)) {
    std::print("{} ", val);
  }
  std::println("");

  auto avg = [](auto a, auto b, auto c) { return (a + b + c) / 3.0; };
  for (auto val : coll | std::views::adjacent_transform<3>(avg)) {
    std::print("{:.3f} ", val);
  }
  std::println("");
}

