diff options
author | Neil <nyamatongwe@gmail.com> | 2018-01-22 08:20:37 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2018-01-22 08:20:37 +1100 |
commit | 90c59a98bbd0bf42faf2312eb03430c11540071d (patch) | |
tree | 4ce470ac9b6bc7487def454bcd2fb18c041f521f | |
parent | 08e295764cdb0ab8fce8b49ace033cd44e96fcc5 (diff) | |
download | scintilla-mirror-90c59a98bbd0bf42faf2312eb03430c11540071d.tar.gz |
Backport: Make clamp generic so can be used on more types.
Updated comments.
Backport based on changeset 6431:e77030fd6411, but modified for C++11.
-rw-r--r-- | src/Position.h | 15 |
1 files changed, 4 insertions, 11 deletions
diff --git a/src/Position.h b/src/Position.h index 258eb177f..804d8681a 100644 --- a/src/Position.h +++ b/src/Position.h @@ -11,6 +11,7 @@ /** * A Position is a position within a document between two characters or at the beginning or end. * Sometimes used as a character index where it identifies the character after the position. + * A Line is a document or screen line. */ namespace Sci { @@ -18,19 +19,11 @@ namespace Sci { typedef int Position; typedef int Line; -// A later version (4.x) of this file may: -//#if defined(SCI_LARGE_FILE_SUPPORT) -//typedef std::ptrdiff_t Position; -// or may allow runtime choice between different position sizes. - const Position invalidPosition = -1; -inline int clamp(int val, int minVal, int maxVal) { - if (val > maxVal) - val = maxVal; - if (val < minVal) - val = minVal; - return val; +template <typename T> +inline constexpr T clamp(T val, T minVal, T maxVal) { + return (val > maxVal) ? maxVal : ((val < minVal) ? minVal : val); } } |