diff --git a/include/stronk/can_decrement.h b/include/stronk/can_decrement.h new file mode 100644 index 0000000..7d69d1c --- /dev/null +++ b/include/stronk/can_decrement.h @@ -0,0 +1,23 @@ +#pragma once + +namespace twig +{ + +template +struct can_decrement +{ + constexpr auto operator--() noexcept -> StronkT& + { + --static_cast(*this).template unwrap(); + return static_cast(*this); + } + + constexpr auto operator--(int) noexcept -> StronkT + { + auto copy = static_cast(*this); + --static_cast(*this).template unwrap(); + return copy; + } +}; + +} // namespace twig diff --git a/include/stronk/can_increment.h b/include/stronk/can_increment.h new file mode 100644 index 0000000..9fbd400 --- /dev/null +++ b/include/stronk/can_increment.h @@ -0,0 +1,23 @@ +#pragma once + +namespace twig +{ + +template +struct can_increment +{ + constexpr auto operator++() noexcept -> StronkT& + { + ++static_cast(*this).template unwrap(); + return static_cast(*this); + } + + constexpr auto operator++(int) noexcept -> StronkT + { + auto copy = static_cast(*this); + ++static_cast(*this).template unwrap(); + return copy; + } +}; + +} // namespace twig diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dfb579e..0facc69 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,6 +19,8 @@ find_package(absl CONFIG REQUIRED) # ---- Tests ---- add_executable( stronk_test + src/can_decrement_tests.cpp + src/can_increment_tests.cpp src/extensions_tests.cpp src/specializers_tests.cpp src/stronk_tests.cpp diff --git a/tests/src/can_decrement_tests.cpp b/tests/src/can_decrement_tests.cpp new file mode 100644 index 0000000..f3eb168 --- /dev/null +++ b/tests/src/can_decrement_tests.cpp @@ -0,0 +1,22 @@ +#include +#include +#include + +namespace twig +{ + +struct an_int_decrement_test_type : stronk +{ + using stronk::stronk; +}; + +TEST(can_decrement, can_decrement_stronk_integer) +{ + auto a = an_int_decrement_test_type {1}; + + EXPECT_EQ(--a, an_int_decrement_test_type {0}); + EXPECT_EQ(a--, an_int_decrement_test_type {0}); + EXPECT_EQ(a, an_int_decrement_test_type {-1}); +} + +} // namespace twig diff --git a/tests/src/can_increment_tests.cpp b/tests/src/can_increment_tests.cpp new file mode 100644 index 0000000..d9d403f --- /dev/null +++ b/tests/src/can_increment_tests.cpp @@ -0,0 +1,38 @@ +#include + +#include +#include +#include + +namespace twig +{ + +struct an_int_increment_test_type : stronk +{ + using stronk::stronk; +}; + +TEST(can_increment, can_increment_stronk_integer) +{ + auto a = an_int_increment_test_type {-1}; + + EXPECT_EQ(++a, an_int_increment_test_type {0}); + EXPECT_EQ(a++, an_int_increment_test_type {0}); + EXPECT_EQ(a, an_int_increment_test_type {1}); +} + +struct a_uint64_t_increment_test_type : stronk +{ + using stronk::stronk; +}; + +TEST(can_increment, can_increment_stronk_uint64_t) +{ + auto a = a_uint64_t_increment_test_type {0}; + + EXPECT_EQ(++a, a_uint64_t_increment_test_type {1}); + EXPECT_EQ(a++, a_uint64_t_increment_test_type {1}); + EXPECT_EQ(a, a_uint64_t_increment_test_type {2}); +} + +} // namespace twig diff --git a/version.py b/version.py index 8879c6c..4ad67eb 100644 --- a/version.py +++ b/version.py @@ -1 +1 @@ -__version__ = "0.3.7" +__version__ = "0.3.8"