added Range template class
This commit is contained in:
parent
7550fa1c78
commit
82c7e2e76c
1 changed files with 26 additions and 0 deletions
26
range.h
Normal file
26
range.h
Normal file
|
@ -0,0 +1,26 @@
|
|||
#ifndef RANGE_H
|
||||
#define RANGE_H
|
||||
|
||||
template <typename T>
|
||||
class Range
|
||||
{
|
||||
public:
|
||||
Range(T mi, T ma) :
|
||||
min(mi), max(ma) { }
|
||||
|
||||
bool contains(T v)
|
||||
{
|
||||
return (v >= min && v <= max);
|
||||
}
|
||||
|
||||
T limit(T v)
|
||||
{
|
||||
if (v > max) return max;
|
||||
else if (v < min) return min;
|
||||
else return v;
|
||||
}
|
||||
|
||||
T min, max;
|
||||
};
|
||||
|
||||
#endif // RANGE_H
|
Loading…
Add table
Reference in a new issue