1 // Copyright 2020 The Pigweed Authors
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
7 // https://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
16 #include <type_traits>
18 #include "pw_polyfill/standard_library/namespace.h"
20 _PW_POLYFILL_BEGIN_NAMESPACE_STD
22 template <class InputIterator, class OutputIterator>
23 constexpr OutputIterator copy(InputIterator first,
25 OutputIterator dest) {
26 while (first != last) {
33 constexpr const T& min(const T& lhs, const T& rhs) {
34 return (rhs < lhs) ? rhs : lhs;
38 constexpr const T& max(const T& lhs, const T& rhs) {
39 return (lhs < rhs) ? rhs : lhs;
42 template <class InputIterator, typename T>
43 constexpr InputIterator find(InputIterator first,
46 for (; first != last; ++first) {
47 if (*first == value) {
55 constexpr T&& forward(remove_reference_t<T>& value) {
56 return static_cast<T&&>(value);
60 constexpr T&& forward(remove_reference_t<T>&& value) {
61 return static_cast<T&&>(value);
64 template <class LhsIterator, class RhsIterator>
65 constexpr bool equal(LhsIterator first_l,
69 while (first_l != last_l && first_r != last_r) {
70 if (*first_l != *first_r) {
76 return first_l == last_l && first_r == last_r;
79 template <class LhsIterator, class RhsIterator>
80 constexpr bool lexicographical_compare(LhsIterator first_l,
84 while (first_l != last_l && first_r != last_r) {
85 if (*first_l < *first_r) {
88 if (*first_r < *first_l) {
95 return (first_l == last_l) && (first_r != last_r);
98 _PW_POLYFILL_END_NAMESPACE_STD