Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
clamp.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_ALGORITHM_CLAMP_HPP
9#define ADOBE_ALGORITHM_CLAMP_HPP
10
12#include <adobe/functional.hpp>
13
14#include <functional>
15
16namespace adobe {
17
18/**************************************************************************************************/
36
37/**************************************************************************************************/
38
44
45template <typename T, typename R>
46inline const T& clamp(const T& x, const T& min, const T& max, R r) {
47 return select_1_3_ac(min, x, max, std::bind(r, std::placeholders::_1, std::placeholders::_2));
48}
49
55
56template <typename T, typename R>
57inline T& clamp(T& x, T& min, T& max, R r) {
58 return select_1_3_ac(min, x, max, std::bind(r, std::placeholders::_1, std::placeholders::_2));
59}
60
66
67template <typename T>
68inline const T& clamp(const T& x, const T& min, const T& max) {
69 return select_1_3_ac(min, x, max, less());
70}
71
77
78template <typename T>
79inline T& clamp(T& x, T& min, T& max) {
80 return select_1_3_ac(min, x, max, less());
81}
82
87
88template <typename T, typename R>
89inline const T& clamp_unordered(const T& x, const T& min, const T& max, R r) {
90 return select_1_3(min, x, max, std::bind(r, std::placeholders::_1, std::placeholders::_2));
91}
92
97
98template <typename T, typename R>
99inline T& clamp_unordered(T& x, T& min, T& max, R r) {
100 return select_1_3(min, x, max, std::bind(r, std::placeholders::_1, std::placeholders::_2));
101}
102
107
108template <typename T>
109inline const T& clamp_unordered(const T& x, const T& min, const T& max) {
110 return select_1_3(min, x, max, less());
111}
112
117
118template <typename T>
119inline T& clamp_unordered(T& x, T& min, T& max) {
120 return select_1_3(min, x, max, less());
121}
122
123/**************************************************************************************************/
124
125} // namespace adobe
126
127#endif
const T & clamp(const T &x, const T &min, const T &max, R r)
clamp implementation
Definition clamp.hpp:46
const T & clamp_unordered(const T &x, const T &min, const T &max, R r)
clamp_unordered implementation
Definition clamp.hpp:89
const T & max(const T &a, const T &b, R r)
minmax implementation
Definition minmax.hpp:113
const T & min(const T &a, const T &b, R r)
minmax implementation
Definition minmax.hpp:69
const T & select_1_3_ac(const T &a, const T &b, const T &c, R r)
select_1_ab implementation
const T & select_1_3(const T &a, const T &b, const T &c, R r)
select_1 implementation