online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <cstddef> #include <array> namespace detail { constexpr std::size_t ipow(std::size_t base, std::size_t exponent) noexcept { std::size_t p = 1; while (exponent) { if (exponent % 2 != 0) { p *= base; } exponent /= 2; base *= base; } return p; } } template<std::size_t range, std::size_t sets> constexpr std::array<std::array<std::size_t, sets>, detail::ipow(range, sets)> cartesian_product() noexcept { constexpr std::size_t size = detail::ipow(range, sets); std::array<std::array<std::size_t, sets>, size> result{}; for (std::size_t i = 0; i < size; ++i) { std::size_t place = size; for (std::size_t j = 0; j < sets; ++j) { place /= range; result[i][j] = (i / place) % range; } } return result; } #include <iostream> int main() { constexpr auto crt = cartesian_product<4, 6>(); for (auto [a, b, c, d, e, f] : crt) { std::cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << '\n'; } }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue