boostorg / algorithm

Boost.org algorithm module
http://boost.org/libs/algorithm
Boost Software License 1.0
112 stars 105 forks source link

Add is_clamped.hpp, is_clamped_test.cpp #86

Closed libbooze closed 2 years ago

libbooze commented 3 years ago

Hi, this is example code for addition of is_clamped.

I have never committed to boost, I asked on boost mailing list how to proceed if I want to add is_clampedand this was a suggested way to do it.

I did not update the docs, since I first wanted to get a feedback if there is interest in this.

Few other points.

  1. naming: is_clampedis symmetric in STL kind of way but maybe some people would prefer is_between or some other name
  2. formatting: is there some way to automatically format code(like clang-format), it was quite tricky for me to emulate the style of clamp_test.cpp
  3. there was(is?) proposal for std::is_clamped, I am not related to that
  4. I have test for std::string, normally people use this with numeric types, but I see nothing in docs for clamp preventing the use of types like std::string
  5. I have no idea what to put in Copyright/Author comments, and I did not want to spend too much time investigating this, most important thing is if there is interest in this algorithm or not.
  6. I have created separate file(both include and test) for this, not sure if you prefer to keep it all in clamp.hpp, again did not want to spend too much time investigating this since it is relatively simple change if there is interest in this algorithm.
  7. I have personally needed this algorithm a few times during past few years in my job, but not sure if there is some widespread need for it.