Skip to content

Commit

Permalink
add enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
SachiSakurane committed Dec 24, 2024
1 parent ddae683 commit 9966212
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/riw/concepts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <riw/concepts/arithmetic.hpp>
#include <riw/concepts/convertible_to.hpp>
#include <riw/concepts/enumeration.hpp>
#include <riw/concepts/floating_point.hpp>
#include <riw/concepts/integral.hpp>
#include <riw/concepts/signed_integral.hpp>
Expand Down
5 changes: 5 additions & 0 deletions include/riw/value_range/value_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ struct value_range {
const Type min, max;
constexpr value_range(Type _min, Type _max)
: min{std::min(_min, _max)}, max{std::max(_min, _max)} {}

template <std::convertible_to<Type> U>
operator value_range<U>() const {
return value_range<U>(min, max);
}
};

template <std::totally_ordered Type>
Expand Down
10 changes: 10 additions & 0 deletions test/value_range/value_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,13 @@ TEST(Utility_ValueRange_ValueRangeTest, BlandedType) {
ASSERT_EQ(actual.max, 42);
}
}

TEST(Utility_ValueRange_ValueRangeTest, Convert) {
using branded = riw::brand<int, "brand">;
{
riw::value_range b{static_cast<branded>(0), static_cast<branded>(100)};
riw::value_range<int> actual = b;
ASSERT_EQ(actual.min, 0);
ASSERT_EQ(actual.max, 100);
}
}

0 comments on commit 9966212

Please sign in to comment.