//******************************************************** // 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 #include #include int innerProduct(auto&&... rgs) { int result = 0; for (auto tpl : std::views::zip(rgs...)) std::apply([&](auto&&... vals) { result += (1 * ... * vals); }, tpl); return result; } int main() { std::cout << innerProduct(std::array{1, 2, 3}, std::array{4, 5, 6}) << '\n'; // 32 std::cout << innerProduct() << '\n'; // 0 }