also, why not `std::min(segment_length, length)` - it shows what you're trying to do much more clearly.