//********************************************************
// 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 <vector>
#include <functional>
#include <algorithm>

int main()
{
  std::vector coll{100, 2, 3, 4};
  std::println("coll:    {}", coll);

  // compute sum of all elements:
  auto sum = std::ranges::fold_left(coll, 0, std::plus<>{});
  std::println("sum:     {}", sum);

  // compute product of all elements:
  auto prod = std::ranges::fold_left(coll, 1, std::multiplies<>{});
  std::println("product: {}", prod);
}

