chaley: I like it. My vote goes for the first version. The second version is a lot more flexible, but I think the first is much simpler to read and understand. With the second I know I would mess up the arguments and spend hours trying to sort out. And if I didn't put them in order, I would miss a range somewhere.
I sort of like the idea of having it as:
Code:
first_matching_compare(v, val1, lt1, val2, lt2, ..., ltn, elseval)
That reads to me as: val1 if v<lt1, val2 if lt1<=v<lt2, val3 if lt2<=v<lt3 and so on until elseval if v>=ltn. But, I think that would be inconsistent with the other template functions.