binary search template function added (with 'upper_bound' logic)