Skip to content

Commit

Permalink
to constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
SachiSakurane committed Dec 21, 2024
1 parent fe0859e commit 87d5d86
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
20 changes: 10 additions & 10 deletions include/riw/utility/brand.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,52 +104,52 @@ struct brand<T, B, std::enable_if_t<std::is_arithmetic_v<T>>> {
};

template <class T, template_string_literal B>
brand<T, B> operator*(const brand<T, B> &t1, const brand<T, B> &t2) {
inline constexpr brand<T, B> operator*(const brand<T, B> &t1, const brand<T, B> &t2) {
return brand<T, B>(t1) *= t2;
}

template <class T, template_string_literal B>
brand<T, B> operator/(const brand<T, B> &t1, const brand<T, B> &t2) {
inline constexpr brand<T, B> operator/(const brand<T, B> &t1, const brand<T, B> &t2) {
return brand<T, B>(t1) /= t2;
}

template <class T, template_string_literal B>
brand<T, B> operator%(const brand<T, B> &t1, const brand<T, B> &t2) {
inline constexpr brand<T, B> operator%(const brand<T, B> &t1, const brand<T, B> &t2) {
return brand<T, B>(t1) %= t2;
}

template <class T, template_string_literal B>
brand<T, B> operator+(const brand<T, B> &t1, const brand<T, B> &t2) {
inline constexpr brand<T, B> operator+(const brand<T, B> &t1, const brand<T, B> &t2) {
return brand<T, B>(t1) += t2;
}

template <class T, template_string_literal B>
brand<T, B> operator-(const brand<T, B> &t1, const brand<T, B> &t2) {
inline constexpr brand<T, B> operator-(const brand<T, B> &t1, const brand<T, B> &t2) {
return brand<T, B>(t1) -= t2;
}

template <class T, template_string_literal B>
brand<T, B> operator<<(const brand<T, B> &t, std::size_t n) {
inline constexpr brand<T, B> operator<<(const brand<T, B> &t, std::size_t n) {
return brand<T, B>(t) <<= n;
}

template <class T, template_string_literal B>
brand<T, B> operator>>(const brand<T, B> &t, std::size_t n) {
inline constexpr brand<T, B> operator>>(const brand<T, B> &t, std::size_t n) {
return brand<T, B>(t) >>= n;
}

template <class T, template_string_literal B>
bool operator==(const brand<T, B> &t1, const brand<T, B> &t2) {
inline constexpr bool operator==(const brand<T, B> &t1, const brand<T, B> &t2) {
return t1.value == t2.value;
}

template <class T, template_string_literal B>
bool operator<(const brand<T, B> &t1, const brand<T, B> &t2) {
inline constexpr bool operator<(const brand<T, B> &t1, const brand<T, B> &t2) {
return t1.value < t2.value;
}

template <class T, template_string_literal B>
bool operator<=>(const brand<T, B> &t1, const brand<T, B> &t2) {
inline constexpr bool operator<=>(const brand<T, B> &t1, const brand<T, B> &t2) {
return t1.value <=> t2.value;
}

Expand Down
12 changes: 12 additions & 0 deletions test/value_range/ranged.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <gtest/gtest.h>
#include <riw/utility/brand.hpp>
#include <riw/value_range/ranged.hpp>

static constexpr auto RANGE = riw::value_range{0, 100};
Expand Down Expand Up @@ -31,3 +32,14 @@ TEST(Utility_ValueRange_RangedTest, EqRanged) {
ASSERT_FALSE(r == t);
}
}

using branded = riw::brand<int, "brand">;
static constexpr auto BRANDED_RANGE = riw::value_range{static_cast<branded>(0), static_cast<branded>(42)};

TEST(Utility_ValueRange_RangedTest, BrandedRanged) {
{
riw::ranged<branded, BRANDED_RANGE> r{42}, s{42}, t{4242};
ASSERT_TRUE(r == s);
ASSERT_TRUE(r == t);
}
}

0 comments on commit 87d5d86

Please sign in to comment.