Skip to content

Commit 89fe615

Browse files
committed
[type_traits] is_noop_convertible: remove cv
1 parent f325880 commit 89fe615

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

include/itlib/type_traits.hpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,18 @@ struct type_identity {
7676
};
7777

7878
template <typename From, typename To>
79-
struct is_noop_convertible : std::integral_constant<bool,
80-
sizeof(From) == sizeof(To)
81-
&& std::is_scalar<From>::value
82-
&& std::is_scalar<To>::value
83-
&& std::is_floating_point<From>::value == std::is_floating_point<To>::value
79+
struct is_noop_convertible {
80+
using from_t = typename std::remove_cv<From>::type;
81+
using to_t = typename std::remove_cv<To>::type;
82+
83+
static constexpr bool value = sizeof(from_t) == sizeof(to_t)
84+
&& std::is_scalar<from_t>::value
85+
&& std::is_scalar<to_t>::value
86+
&& std::is_floating_point<from_t>::value == std::is_floating_point<to_t>::value
8487
// bool -> int8 is a noop, but int8 -> bool is not
85-
&& (std::is_same<To, bool>::value ? std::is_same<From, bool>::value : true)
86-
>
87-
{};
88+
&& (std::is_same<to_t, bool>::value ? std::is_same<from_t, bool>::value : true)
89+
;
90+
};
8891

8992
#if __cplusplus >= 201700
9093
template <template <typename...> class Template, typename Type>

test/t-type_traits-11.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,26 @@ struct S32 { int x; };
3535

3636
TEST_CASE("is_noop_convertible") {
3737
CCHECK(itlib::is_noop_convertible<int, int>::value);
38+
CCHECK(itlib::is_noop_convertible<const int, int>::value);
3839
CCHECK(itlib::is_noop_convertible<int, unsigned int>::value);
3940
CCHECK(itlib::is_noop_convertible<uint8_t, char>::value);
4041
CCHECK(itlib::is_noop_convertible<int8_t, char>::value);
41-
CCHECK(itlib::is_noop_convertible<uint8_t, char>::value);
42+
CCHECK(itlib::is_noop_convertible<uint8_t, const char>::value);
4243
CCHECK(itlib::is_noop_convertible<E32, int>::value);
44+
CCHECK(itlib::is_noop_convertible<const E32, int>::value);
4345
CCHECK(itlib::is_noop_convertible<void*, size_t>::value);
4446
CCHECK(itlib::is_noop_convertible<void*, intptr_t>::value);
4547
CCHECK(itlib::is_noop_convertible<double, double>::value);
4648
CCHECK(itlib::is_noop_convertible<bool, bool>::value);
4749
CCHECK(itlib::is_noop_convertible<bool, int8_t>::value);
50+
CCHECK(itlib::is_noop_convertible<bool, const bool>::value);
51+
CCHECK(itlib::is_noop_convertible<const bool, bool>::value);
4852

4953
CCHECK_FALSE(itlib::is_noop_convertible<int, float>::value);
5054
CCHECK_FALSE(itlib::is_noop_convertible<E32, float>::value);
5155
CCHECK_FALSE(itlib::is_noop_convertible<int, S32>::value);
5256
CCHECK_FALSE(itlib::is_noop_convertible<void*, float>::value);
5357
CCHECK_FALSE(itlib::is_noop_convertible<void*, double>::value);
5458
CCHECK_FALSE(itlib::is_noop_convertible<int8_t, bool>::value);
59+
CCHECK_FALSE(itlib::is_noop_convertible<int8_t, const bool>::value);
5560
}

0 commit comments

Comments
 (0)