diff --git a/README.md b/README.md index 145a72a..ff0f965 100644 --- a/README.md +++ b/README.md @@ -153,6 +153,8 @@ The table below describes the built-in traits that can be applied to a given str | `multiplicable` | Two `T` objects can be multiplied to obtain a new `T`. | | `multiplicable_with` | A `T` object can be multiplied with a `U` object to obtain a new `T`. | | `dividable` | A `T` object can be divided by another `T` object to obtain a new `T`. | +| `dividable_by` | A `T` object can be divided by a `U` object to obtain a new `T`. | +| `dividable_to` | A `T` object can be divided by another `T` object to obtain a new `U`. | | `modulable` | A `T` object can be moduled from another `T` object to obtain a new `T`. | | `incrementable` | A `T` object can be pre-incremented and post-incremented. | | `decrementable` | A `T` object can be pre-decremented and post-decremented. | diff --git a/include/st/traits.hpp b/include/st/traits.hpp index 9ec2cb9..2031bda 100644 --- a/include/st/traits.hpp +++ b/include/st/traits.hpp @@ -310,6 +310,20 @@ namespace st using type = traits::dividable; }; + template + struct dividable_by + { + template + using type = traits::dividable; + }; + + template + struct dividable_to + { + template + using type = traits::dividable; + }; + struct modulable { template diff --git a/tests/strong_type-tests.cpp b/tests/strong_type-tests.cpp index 20310e7..d14d1de 100644 --- a/tests/strong_type-tests.cpp +++ b/tests/strong_type-tests.cpp @@ -21,7 +21,9 @@ using speed = st::type< struct speed_tag, st::addable, st::subtractable, - st::multiplicable_with + st::multiplicable_with, + st::dividable_by, + st::dividable_to >; using position = st::type< @@ -118,6 +120,10 @@ TEST(strong_type, multiplicable) TEST(strong_type, dividable) { static_assert((integer(4) / integer(2)).value() == integer(2).value()); + + static_assert((speed(4) / 2).value() == speed(2).value()); + static_assert(std::is_same_v); + static_assert((speed(4) / speed(2)).value() == acceleration(2).value()); } TEST(strong_type, modulable)