Somewhat
Over the years I have seen several posts that talk about doing sequences of compares. I have considered adding a new template function to make this easier. Two questions:
1) exactly what to do? and
2) would anyone use it?
As for what to do, I see two choices. The first would be a function like first_non_empty, but doing a compare. Something like
Code:
first_matching_compare(v, lt1, val1, lt2, val2, ..., elseval)
Example:
Code:
first_matching_compare(words, 7500, 'Short Story', 17500, 'Novella', 40000, 'Novel', 'Long')
The second would be something like
Code:
first_matching_compare(v, gt_eq1, lt1, val1, gt_eq2, lt2, val2, ..., elseval)
This one would check the ranges until it found a match. Example:
Code:
first_matching_compare(words, 0, 7500, 'Short Story', 17500, 40000, 'Novel', 7500, 17500, 'Novella', 'Long')
The advantage of the second is that the values do not need to be in ascending order. The disadvantage is that it requires more typing and might in fact be more confusing.
Which of these two is better?
Would anyone use either of them?