File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -116,7 +116,7 @@ template <typename T, typename U>
116116 if constexpr (sizeof (T) == sizeof (U)) {
117117 return sz;
118118 } else if constexpr (sizeof (T) > sizeof (U)) {
119- return sz * ( sizeof (T) / sizeof (U));
119+ return ( sz * sizeof (T) / sizeof (U)) + ( sizeof (T) % sizeof (U) & 1u );
120120 } else {
121121 return (sz * sizeof (T) + sizeof (U) - 1 ) / sizeof (U);
122122 }
Original file line number Diff line number Diff line change 33#include < catch2/catch_template_test_macros.hpp>
44#include < catch2/catch_test_macros.hpp>
55
6+ #include < array>
67#include < cstdint>
78#include < string_view>
89#include < type_traits>
@@ -130,6 +131,18 @@ TEST_CASE("sized<T> aliases", "[utility]") {
130131 static_assert (stdx::sized64{1 }.in <std::uint64_t >() == 1 );
131132}
132133
134+ TEST_CASE (" sized<T> in (downsize not divisible)" , " [utility]" ) {
135+ using T = std::array<char , 3 >;
136+ static_assert (sizeof (T) == 3 );
137+ static_assert (stdx::sized<std::uint32_t >{2 }.in <T>() == 3 );
138+ }
139+
140+ TEST_CASE (" sized<T> in (upsize not divisible)" , " [utility]" ) {
141+ using T = std::array<char , 3 >;
142+ static_assert (sizeof (T) == 3 );
143+ static_assert (stdx::sized<T>{3 }.in <std::uint32_t >() == 3 );
144+ }
145+
133146TEST_CASE (" CX_VALUE structural value" , " [utility]" ) {
134147 auto x = CX_VALUE (42 );
135148 static_assert (x () == 42 );
You can’t perform that action at this time.
0 commit comments