Hacker News new | ask | show | jobs
by nly 3736 days ago
It's hard to say what he was trying to accomplish, but he probably could have written something like this.

    auto index = std::distance (begin(replicas),
                   std::find(begin(replicas), end(replicas), my_ip));
    return (replicas.size() == index ? -1 : index);
1 comments

That's a bit harder to read isn't it? I think finding the location in first line and using distance in the ternary operator makes it more readable.
Like this?

    auto it = std::find(begin(replicas), end(replicas), my_ip);
    return (end(replicas) == it ? -1 : std::distance(begin(replicas), it));
Yeah, i'll go with that.
Yeah that's what I was thinking.