Skip to content

Commit

Permalink
Correct test for, and use of, concepts for numeric_limits
Browse files Browse the repository at this point in the history
  • Loading branch information
rollbear committed Feb 3, 2023
1 parent cae1528 commit 4b91c17
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* Corrected the test for, and use of, concepts when specializing
std::numeric_limits<> for strong::arithmetic types. Thank you
Björn Schäpers for reporting.

v9 2023-01-23

* Lowered the minimum required CMake version to 3.7, unless unit-tests
Expand Down
7 changes: 4 additions & 3 deletions include/strong_type/arithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,12 @@ class arithmetic::modifier
}

template <typename T, typename Tag, typename ... Ms>
#if defined(__cpp_concepts)
requires strong::type_is_v<strong::type<T, Tag, Ms...>, strong::arithmetic>
class std::numeric_limits<strong::type<T, Tag, Ms...>>
#if __cplusplus >= 202003L
requires strong::type_is<strong::type<T, Tag, Ms...>, strong::arithmetic>
: public std::numeric_limits<T>
: public std::numeric_limits<T>
#else
class std::numeric_limits<strong::type<T, Tag, Ms...>>
: public std::conditional<
strong::type_is_v<strong::type<T, Tag, Ms...>, strong::arithmetic>,
std::numeric_limits<T>,
Expand Down
5 changes: 5 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ using uint = unsigned int;
using handle = strong::type<int, struct handle_tag>;

static_assert(!std::numeric_limits<handle>::is_specialized, "");
#if defined(__cpp_concepts)
static_assert(!std::is_base_of<std::numeric_limits<void>, std::numeric_limits<handle>>{},"");
#else
static_assert(std::is_base_of<std::numeric_limits<void>, std::numeric_limits<handle>>{},"");
#endif
static_assert(std::is_same<int, strong::underlying_type_t<handle>>{},"");
static_assert(std::is_same<int, strong::underlying_type_t<int>>{},"");

Expand Down

0 comments on commit 4b91c17

Please sign in to comment.