fork download
  1. #include <iostream>
  2. #include <utility>
  3. #include <vector>
  4.  
  5. template<int Begin, int End>
  6. struct axis_limits
  7. {
  8. static constexpr int first = Begin;
  9. static constexpr int last = End;
  10. static constexpr int range = End - Begin + 1;
  11. };
  12.  
  13. struct point
  14. {
  15. explicit point(int x, int y, int z) : x(x), y(y), z(z) {}
  16. int x; int y; int z;
  17. };
  18.  
  19. namespace detail
  20. {
  21.  
  22. template <typename X, typename Y, typename Z, std::size_t... Is>
  23. std::vector<point> generate_point_space_impl(std::index_sequence<Is...>)
  24. {
  25. return {point(
  26. int(Is / (Z::range * Y::range)) % X::range + X::first,
  27. int(Is / Z::range) % Y::range + Y::first,
  28. int(Is) % Z::range + Z::first)...
  29. };
  30. }
  31.  
  32. }
  33.  
  34. template <typename X, typename Y, typename Z>
  35. std::vector<point> generate_point_space()
  36. {
  37. return detail::generate_point_space_impl<X, Y, Z>(std::make_index_sequence<X::range * Y::range * Z::range>());
  38. }
  39.  
  40. int main()
  41. {
  42. auto points = generate_point_space<axis_limits<-2, 2>, axis_limits<-2, 2>, axis_limits<-2, 2>>();
  43.  
  44. for (const auto& p : points) {
  45. std::cout << "(" << p.x << ", " << p.y << ", " << p.z << ")" << std::endl;
  46. }
  47. }
  48.  
Success #stdin #stdout 0s 3276KB
stdin
Standard input is empty
stdout
(-2, -2, -2)
(-2, -2, -1)
(-2, -2, 0)
(-2, -2, 1)
(-2, -2, 2)
(-2, -1, -2)
(-2, -1, -1)
(-2, -1, 0)
(-2, -1, 1)
(-2, -1, 2)
(-2, 0, -2)
(-2, 0, -1)
(-2, 0, 0)
(-2, 0, 1)
(-2, 0, 2)
(-2, 1, -2)
(-2, 1, -1)
(-2, 1, 0)
(-2, 1, 1)
(-2, 1, 2)
(-2, 2, -2)
(-2, 2, -1)
(-2, 2, 0)
(-2, 2, 1)
(-2, 2, 2)
(-1, -2, -2)
(-1, -2, -1)
(-1, -2, 0)
(-1, -2, 1)
(-1, -2, 2)
(-1, -1, -2)
(-1,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