Make traits constexpr

This commit is contained in:
Joshua Ashton 2023-01-11 14:09:52 +00:00
parent 48d460c855
commit 63d2a6e318
1 changed files with 15 additions and 15 deletions

View File

@ -170,7 +170,7 @@ namespace orange
namespace Util
{
template <typename InputIt, typename OutputIt, typename UnaryOperation>
OutputIt Transform(InputIt inFirst, InputIt inLast,
constexpr OutputIt Transform(InputIt inFirst, InputIt inLast,
OutputIt outFirst, UnaryOperation unaryOp)
{
while (inFirst != inLast)
@ -179,7 +179,7 @@ namespace orange
}
template<typename InputIt1, typename InputIt2, typename OutputIt, typename BinaryOperation>
OutputIt Transform(InputIt1 first1, InputIt1 last1, InputIt2 first2,
constexpr OutputIt Transform(InputIt1 first1, InputIt1 last1, InputIt2 first2,
OutputIt outFirst, BinaryOperation binOp)
{
while (first1 != last1)
@ -188,7 +188,7 @@ namespace orange
}
template <typename T, typename InputIt, typename UnaryOperation>
T TransformResult(InputIt first, InputIt last, UnaryOperation op)
constexpr T TransformResult(InputIt first, InputIt last, UnaryOperation op)
{
T result;
Transform(first, last, result.begin(), op);
@ -196,7 +196,7 @@ namespace orange
}
template <typename T, typename InputIt1, typename InputIt2, typename BinaryOperation>
T TransformResult(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryOperation op)
constexpr T TransformResult(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryOperation op)
{
T result;
Transform(first1, last1, first2, result.begin(), op);
@ -221,7 +221,7 @@ namespace orange
}
template <typename InputIt1, typename InputIt2>
bool Equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
constexpr bool Equal(InputIt1 first1, InputIt1 last1, InputIt2 first2)
{
for (; first1 != last1; ++first1, ++first2)
{
@ -232,7 +232,7 @@ namespace orange
}
template <typename InputIt1, typename InputIt2, typename BinaryPredicate>
bool Equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryPredicate p)
constexpr bool Equal(InputIt1 first1, InputIt1 last1, InputIt2 first2, BinaryPredicate p)
{
for (; first1 != last1; ++first1, ++first2)
{
@ -243,7 +243,7 @@ namespace orange
}
template <typename InputIt, typename OutputIt>
OutputIt Copy(InputIt first, InputIt last, OutputIt d_first)
constexpr OutputIt Copy(InputIt first, InputIt last, OutputIt d_first)
{
for (; first != last; (void)++first, (void)++d_first)
*d_first = *first;
@ -251,7 +251,7 @@ namespace orange
}
template <typename InputIt, typename OutputIt, typename UnaryPredicate>
OutputIt CopyIf(InputIt first, InputIt last,
constexpr OutputIt CopyIf(InputIt first, InputIt last,
OutputIt d_first, UnaryPredicate pred)
{
for (; first != last; ++first)
@ -266,7 +266,7 @@ namespace orange
}
template <typename ForwardIt, typename T>
void Fill(ForwardIt first, ForwardIt last, const T& value)
constexpr void Fill(ForwardIt first, ForwardIt last, const T& value)
{
for (; first != last; ++first)
*first = value;
@ -275,12 +275,12 @@ namespace orange
// Math ops
namespace Math
{
template <typename T> T Negate(const T& x) { return -x; }
template <typename T> constexpr T Negate(const T& x) { return -x; }
template <typename T> T Add (const T& x, const T& y) { return x + y; }
template <typename T> T Subtract (const T& x, const T& y) { return x - y; }
template <typename T> T Multiply (const T& x, const T& y) { return x * y; }
template <typename T> T Divide (const T& x, const T& y) { return x / y; }
template <typename T> T Modulo (const T& x, const T& y) { return x % y; }
template <typename T> constexpr T Add (const T& x, const T& y) { return x + y; }
template <typename T> constexpr T Subtract (const T& x, const T& y) { return x - y; }
template <typename T> constexpr T Multiply (const T& x, const T& y) { return x * y; }
template <typename T> constexpr T Divide (const T& x, const T& y) { return x / y; }
template <typename T> constexpr T Modulo (const T& x, const T& y) { return x % y; }
}
}