Skip to content

Commit

Permalink
fix sfinae
Browse files Browse the repository at this point in the history
  • Loading branch information
poor-circle committed Aug 22, 2023
1 parent 37d80b2 commit af5a420
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions include/ylt/struct_pack/reflection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,30 @@ template <typename T, typename = void>
} && (Type{}.size()+7)/8 == sizeof(Type);
#else
template <typename T, typename = void>
struct bitset_container_impl : std::false_type {};
struct bitset_impl : std::false_type {};


template <typename T>
struct bitset_container_impl<T, std::void_t<
typename std::array<int,std::declval<T>().size()>,
struct bitset_impl<T, std::void_t<
decltype(std::declval<T>().flip()),
decltype(std::declval<T>().set()),
decltype(std::declval<T>().reset()),
decltype(std::declval<T>().count())>>
decltype(std::declval<T>().count()),
decltype(std::declval<T>().size())>>
: std::true_type {};

template<typename T>
constexpr bool bitset_size_checker() {
if constexpr (bitset_impl<T>::value) {
return (T{}.size()+7)/8==sizeof(T);
}
else {
return false;
}
}

template <typename T>
constexpr bool bitset = bitset_container_impl<T>::value && sizeof(T)==(T{}.size()+7)/8;
constexpr bool bitset = bitset_impl<T>::value && bitset_size_checker<T>();
#endif

#if __cpp_concepts >= 201907L
Expand Down

0 comments on commit af5a420

Please sign in to comment.