/** This file is a part of rexy's general purpose library Copyright (C) 2020 rexy712 This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ #ifndef REXY_CX_UTILITY_HPP #define REXY_CX_UTILITY_HPP #include //forward, move #include namespace rexy::cx{ namespace{ template constexpr void swap(T& l, T& r) noexcept(std::is_nothrow_move_assignable::value && std::is_nothrow_move_constructible::value) { T tmp = std::move(l); l = std::move(r); r = std::move(tmp); } template constexpr T exchange(T& l, U&& r) noexcept(std::is_nothrow_assignable::value && std::is_nothrow_move_assignable::value) { T old = std::move(l); l = std::forward(r); return old; } template constexpr const T& min(const T& l, const T& r)noexcept{ return l < r ? l : r; } template constexpr const T& min(const T& l, const T& r, Compare cmp) noexcept(std::is_nothrow_invocable::value) { return cmp(l, r) ? l : r; } template constexpr const T& max(const T& l, const T& r)noexcept{ return l > r ? l : r; } template constexpr const T& max(const T& l, const T& r, Compare cmp) noexcept(std::is_nothrow_invocable::value) { return cmp(l, r) ? l : r; } constexpr size_t strlen(const char* c)noexcept{ size_t i = 0; for(;c[i];++i); return i; } constexpr int strcmp(const char* l, const char* r)noexcept{ using uchar = unsigned char; for(;*l == *r && *l;++l, ++r); return (static_cast(*l)) - (static_cast(*r)); } } } #endif