mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
add CCRef.{get_then_incr,incr_then_get} functions
This commit is contained in:
parent
55a4c7ef7a
commit
e2bc0cf55a
2 changed files with 16 additions and 0 deletions
|
|
@ -21,6 +21,14 @@ let iter f r = f !r
|
|||
|
||||
let update f r = r := (f !r)
|
||||
|
||||
let incr_then_get r =
|
||||
incr r; !r
|
||||
|
||||
let get_then_incr r =
|
||||
let x = !r in
|
||||
incr r;
|
||||
x
|
||||
|
||||
let compare f r1 r2 = f !r1 !r2
|
||||
|
||||
let equal f r1 r2 = f !r1 !r2
|
||||
|
|
|
|||
|
|
@ -24,6 +24,14 @@ val iter : ('a -> unit) -> 'a t -> unit
|
|||
val update : ('a -> 'a) -> 'a t -> unit
|
||||
(** Update the reference's content with the given function *)
|
||||
|
||||
val incr_then_get : int t -> int
|
||||
(** [incr_then_get r] increments [r] and returns its new value, think [++ r]
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val get_then_incr : int t -> int
|
||||
(** [get_then_incr r] increments [r] and returns its old value, think [r++]
|
||||
@since NEXT_RELEASE *)
|
||||
|
||||
val compare : 'a ord -> 'a t ord
|
||||
|
||||
val equal : 'a eq -> 'a t eq
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue