Here's a variant without nested loops. I've tried to use a similar to your question notation.
// g++ 26neighbours.cpp -o 26neighbours && 26neighbours
#include <algorithm>
#include <iostream>
#include <iterator>
#include <vector>
namespace {
struct Pos {
double x, y, z;
template<class Char, class Traits>
friend std::basic_ostream<Char, Traits>&
operator<< (std::basic_ostream<Char, Traits>& out, const Pos& p)
{
return out << p.x << " " << p.y << " " << p.z;
}
explicit Pos(double x_ = 0, double y_ = 0, double z_ = 0)
: x(x_), y(y_), z(z_)
{
}
};
template <class OutputPosIterator, class InputPosIterator, class Number>
void translate(OutputPosIterator first, OutputPosIterator last,
InputPosIterator delta, Number factor)
{
for ( ; first != last; ++first, ++delta) {
first->x += delta->x * factor;
first->y += delta->y * factor;
first->z += delta->z * factor;
}
}
}
int main(int argc, char *argv[])
{
const Pos delta[] = {
// ruby -e"(-1..1).each{|i| (-1..1).each{|j| (-1..1).each{|k| printf(\"Pos(%2d,%2d,%2d),\n\", i, j, k) if (i!=0 || j!=0 || k!=0)}}}"
Pos(-1,-1,-1),
Pos(-1,-1, 0),
Pos(-1,-1, 1),
Pos(-1, 0,-1),
Pos(-1, 0, 0),
Pos(-1, 0, 1),
Pos(-1, 1,-1),
Pos(-1, 1, 0),
Pos(-1, 1, 1),
Pos( 0,-1,-1),
Pos( 0,-1, 0),
Pos( 0,-1, 1),
Pos( 0, 0,-1),
Pos( 0, 0, 1),
Pos( 0, 1,-1),
Pos( 0, 1, 0),
Pos( 0, 1, 1),
Pos( 1,-1,-1),
Pos( 1,-1, 0),
Pos( 1,-1, 1),
Pos( 1, 0,-1),
Pos( 1, 0, 0),
Pos( 1, 0, 1),
Pos( 1, 1,-1),
Pos( 1, 1, 0),
Pos( 1, 1, 1),
};
const int N = sizeof(delta) / sizeof(*delta);
// find neighbours of somePos
double cube_size = 0.5;
Pos somePos(0.5, 0.5, 0.5);
std::vector<Pos> neighbours(N, somePos);
translate(neighbours.begin(), neighbours.end(), delta, cube_size);
// print neighbours
std::copy(neighbours.begin(), neighbours.end(),
std::ostream_iterator<Pos>(std::cout, "\n"));
std::cout << std::endl;
return 0;
}