Permalink
Browse files

c++17 add clamp function

	modified:   src/cl-stl-algorithm.lisp
	modified:   src/cl-stl-base.lisp
	modified:   src/user-pacakge.lisp
  • Loading branch information...
show-matz committed Jan 3, 2019
1 parent 62aa665 commit cc014f15bbf0b8d3aa15864894223205939690e0
Showing with 53 additions and 0 deletions.
  1. +42 −0 src/cl-stl-algorithm.lisp
  2. +7 −0 src/cl-stl-base.lisp
  3. +4 −0 src/user-pacakge.lisp
@@ -5337,6 +5337,48 @@
;;
;;------------------------------------------------------------------------------

#-(or cl-stl-0x98 cl-stl-0x11 cl-stl-0x14)
(locally (declare (optimize speed))
(defun-overload clamp (val lo hi)
#+cl-stl-debug
(when (_< hi lo)
(error "clamp : (not (null (_< hi lo)))"))
(if (_< val lo)
lo
(if (_< hi val)
hi
val))))

#-(or cl-stl-0x98 cl-stl-0x11 cl-stl-0x14)
(locally (declare (optimize speed))
(defun-overload clamp (val lo hi comp)
#+cl-stl-debug
(when (funcall comp hi lo)
(error "clamp : (not (null (funcall comp hi lo)))"))
(if (funcall comp val lo)
lo
(if (funcall comp hi val)
hi
val))))

#-(or cl-stl-0x98 cl-stl-0x11 cl-stl-0x14)
(declare-function-overload clamp (3 4)
:documentation "
<<signature>>
1) (cl-stl:clamp val lo hi) [0x17]
2) (cl-stl:clamp val lo hi comp) [0x17]
<<parameters>>
val : a value of arbitrary type.
lo : a lower limit of arbitrary type.
hi : an upper limit of arbitrary type.
comp : functor for comparison.
<<return value>>
1) lo if (_< val lo), hi if (_< hi val), val otherwise.
2) lo if (funcall comp val lo), hi if (funcall comp hi val), val otherwise.
")

;;------------------------------------------------------------------------------
;; 25.1, non-modifying sequence operations:
;;------------------------------------------------------------------------------
@@ -272,6 +272,10 @@
;+-----------------------------------------+
;| algorithm |
;+-----------------------------------------+
#-(or
cl-stl-0x98
cl-stl-0x11
cl-stl-0x14) :clamp
; 25.1, non-modifying sequence operations:
#-cl-stl-0x98 :all_of
#-cl-stl-0x98 :any_of
@@ -1056,6 +1060,9 @@
;;
;;------------------------------------------------------------------------------

;;#-(or cl-stl-0x98 cl-stl-0x11 cl-stl-0x14)
;;(declare-function-overload clamp (3 4) ...) ;;MEMO : declare in cl-stl-algorithm.lisp

;;------------------------------------------------------------------------------
;; 25.1, non-modifying sequence operations:
;;------------------------------------------------------------------------------
@@ -269,6 +269,10 @@
;+-----------------------------------------+
;| algorithm |
;+-----------------------------------------+
#-(or
cl-stl-0x98
cl-stl-0x11
cl-stl-0x14) :clamp
; 25.1, non-modifying sequence operations:
#-cl-stl-0x98 :all_of
#-cl-stl-0x98 :any_of

0 comments on commit cc014f1

Please sign in to comment.