Transforming a stl vector according to its neighbors
What you have is probably good enough. If you want to try something crazy, you could always do:

boost::range::transform(boost::irange(0, N), block.begin(), [&amp;](const int i){
    int pre = i-1 &gt;= 0 ? state[i-1] : 1;
    int post = i+1 &lt; N ? state[i+1] : 1;
    return pre * state[i] * post;
});


Not sure I prefer that to the simple loop that you have, but just throwing it out as a potential alternative.