Invert-range operation in a circular vector
Bug

Your previous() function doesn't wrap around well:

int previous(const int i) {
    return (i - 1) % vec.size();
}


When i reaches 0, this function will return -1, not vec.size() - 1 as you might be expecting.  You could either go with:

int previous(const int i) {
    return (i - 1 + vec.size()) % vec.size();
}


or perhaps:

int previous(const int i) {
    if (i == 0)
        return vec.size() - 1;
    return i - 1;
}


Unnecessary use of float

The Floating Point Police™ disapprove of your unnecessary use of floating point here:


if(j &lt; i ){
    segment_size = std::ceil(((vec.size() - i) + j) / 2.0);
} else {
    segment_size = std::ceil(std::abs(j - i) / 2.0);
}



All you are doing is rounding up, so you could just do:

if(j &lt; i ){
    segment_size = (vec.size() - i) + j;
} else {
    segment_size = j - i;
}
segment_size = (segment_size + 1) / 2;


Technically, there could be a problem with the above if your segment size can be INT_MAX.  If this is possible, then replace that last line with this instead:

segment_size = (segment_size / 2) + (segment_size &amp; 1);


But if your segment size could be INT_MAX, then your next() function would need to be fixed as well.