Skip to content

Commit

Permalink
✨ Add new helpful type trait for sizeof/alignof checking
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Sep 11, 2022
1 parent 37beee0 commit c690317
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
32 changes: 20 additions & 12 deletions include/ztd/idk/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ namespace ztd {
template <typename... T, template <typename...> class Templ>
struct __is_specialization_of_impl<Templ<T...>, Templ> : ::std::true_type { };

template<typename _It>
template <typename _It>
using __weakly_incrementable_test = decltype(++::std::declval<_It&>());

template<typename _It>
template <typename _It>
using __weakly_decrementable_test = decltype(--::std::declval<_It&>());

} // namespace __idk_detail
Expand Down Expand Up @@ -144,16 +144,16 @@ namespace ztd {
inline constexpr bool is_code_unit_v = is_code_unit<_Type>::value;

//////
/// @brief Checks if the given type is one of the types that is usable in the standard with the @c std::char_traits traits type that's used for @c std::string_view , @c std::string and others.
/// @brief Checks if the given type is one of the types that is usable in the standard with the @c std::char_traits
/// traits type that's used for @c std::string_view , @c std::string and others.
template <typename _Type>
class is_char_traitable : public ::std::integral_constant<bool,
::std::is_same_v<_Type, char> || ::std::is_same_v<_Type, wchar_t> ||
::std::is_same_v<_Type, char> || ::std::is_same_v<_Type, wchar_t> ||
#if ZTD_IS_ON(ZTD_NATIVE_CHAR8_T)
::std::is_same_v<_Type, char8_t> ||
::std::is_same_v<_Type, char8_t> ||
#endif
::std::is_same_v<_Type, char16_t> ||
::std::is_same_v<_Type, char32_t>
> {};
::std::is_same_v<_Type, char16_t> || ::std::is_same_v<_Type, char32_t>> {
};
// clang-format on

//////
Expand Down Expand Up @@ -305,13 +305,21 @@ namespace ztd {

//////
/// @brief Detects whether a type has a pre-increment operation.
template<typename _It>
inline constexpr bool weakly_incrementable_v = ::ztd::is_detected_v<__idk_detail::__weakly_incrementable_test, _It>;
template <typename _It>
inline constexpr bool weakly_incrementable_v
= ::ztd::is_detected_v<__idk_detail::__weakly_incrementable_test, _It>;

//////
/// @brief Detects whether a type has a post-increment operation.
template<typename _It>
inline constexpr bool weakly_decrementable_v = ::ztd::is_detected_v<__idk_detail::__weakly_decrementable_test, _It>;
template <typename _It>
inline constexpr bool weakly_decrementable_v
= ::ztd::is_detected_v<__idk_detail::__weakly_decrementable_test, _It>;

//////
/// @brief Detects whether two types have the same sizeof() and alignof() values.
template <typename _Left, typename _Right>
inline constexpr bool is_same_sizeof_alignof_v
= (sizeof(_Left) == sizeof(_Right)) && (alignof(_Left) == alignof(_Right));

ZTD_IDK_INLINE_ABI_NAMESPACE_CLOSE_I_
} // namespace ztd
Expand Down
2 changes: 1 addition & 1 deletion include/ztd/ranges/word_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ namespace ztd { namespace ranges {
// God's given, handwritten, bit-splittin'
// one-way """memcpy""". 😵
__underlying_value_type __bit_value
= any_enum_or_char_to_undeerlying(static_cast<value_type>(__val));
= ::ztd::any_enum_or_char_to_underlying(static_cast<value_type>(__val));
auto __write_storage_it = __write_storage + 0;
for (::std::size_t __index = 0; __index < __base_values_per_word; ++__index) {
__underlying_value_type __bit_position
Expand Down

0 comments on commit c690317

Please sign in to comment.