View Single Post
Old 05-05-2014, 05:53 AM   #15
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
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.
davidfor is offline   Reply With Quote