Skip to content

Commit

Permalink
Modernise: Use variable templates
Browse files Browse the repository at this point in the history
  • Loading branch information
rmisev committed Oct 22, 2024
1 parent cf1873f commit e2ec706
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
29 changes: 13 additions & 16 deletions include/upa/str_arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,19 @@ using string_view = std::string_view;
// Supported char and size types

template<class CharT>
struct is_char_type : std::integral_constant<bool,
constexpr bool is_char_type_v =
std::is_same_v<CharT, char> ||
#ifdef __cpp_char8_t
std::is_same_v<CharT, char8_t> ||
#endif
std::is_same_v<CharT, char16_t> ||
std::is_same_v<CharT, char32_t> ||
std::is_same_v<CharT, wchar_t>
> {};
std::is_same_v<CharT, wchar_t>;

template<class SizeT>
struct is_size_type : std::integral_constant<bool,
constexpr bool is_size_type_v =
std::is_convertible_v<SizeT, std::size_t> ||
std::is_convertible_v<SizeT, std::ptrdiff_t>
> {};
std::is_convertible_v<SizeT, std::ptrdiff_t>;


// string args helper class
Expand Down Expand Up @@ -169,7 +167,7 @@ struct str_arg_char<CharT*, CharT*> : std::remove_cv<CharT> {
// pointer and size
template<class CharT, class SizeT>
struct str_arg_char<CharT*, SizeT> : std::enable_if<
is_size_type<SizeT>::value,
is_size_type_v<SizeT>,
std::remove_cv_t<CharT>> {

template <typename T>
Expand All @@ -192,7 +190,7 @@ struct str_arg_char<CharT*> : std::remove_cv<CharT> {
template<class StrT>
struct str_arg_char<StrT> : std::enable_if<
std::is_pointer_v<detail::data_member_t<StrT>> &&
is_size_type<detail::length_member_t<StrT>>::value,
is_size_type_v<detail::length_member_t<StrT>>,
remove_cvptr_t<detail::data_member_t<StrT>>> {

template <class STR, typename T = typename STR::value_type>
Expand All @@ -213,7 +211,7 @@ using str_arg_char_t = typename str_arg_char_s<Args...>::type;

template<class ...Args>
using enable_if_str_arg_t = std::enable_if_t<
is_char_type<str_arg_char_t<Args...>>::value,
is_char_type_v<str_arg_char_t<Args...>>,
int>;


Expand All @@ -228,28 +226,27 @@ inline auto make_str_arg(Args&&... args) -> str_arg<str_arg_char_t<Args...>> {
// Convert to std::string or string_view

template<class CharT>
struct is_char8_type : std::integral_constant<bool,
constexpr bool is_char8_type_v =
std::is_same_v<CharT, char>
#ifdef __cpp_char8_t
|| std::is_same_v<CharT, char8_t>
#endif
> {};
;

template<class ...Args>
using enable_if_str_arg_to_char8_t = std::enable_if_t<
is_char8_type<str_arg_char_t<Args...>>::value,
is_char8_type_v<str_arg_char_t<Args...>>,
int>;

template<class CharT>
struct is_charW_type : std::integral_constant<bool,
constexpr bool is_charW_type_v =
std::is_same_v<CharT, char16_t> ||
std::is_same_v<CharT, char32_t> ||
std::is_same_v<CharT, wchar_t>
> {};
std::is_same_v<CharT, wchar_t>;

template<class ...Args>
using enable_if_str_arg_to_charW_t = std::enable_if_t<
is_charW_type<str_arg_char_t<Args...>>::value,
is_charW_type_v<str_arg_char_t<Args...>>,
int>;


Expand Down
4 changes: 2 additions & 2 deletions include/upa/url_search_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ using iterable_value_t = std::remove_cv_t<std::remove_reference_t<

// is iterable over the std::pair values
template<class T>
struct is_iterable_pairs : is_pair<iterable_value_t<T>> {};
constexpr bool is_iterable_pairs_v = is_pair<iterable_value_t<T>>::value;

// enable if `Base` is not the base class of `T`
template<class Base, class T>
Expand Down Expand Up @@ -120,7 +120,7 @@ class url_search_params
template<class ConT,
// do not hide the copy and move constructors:
detail::enable_if_not_base_of_t<url_search_params, ConT> = 0,
std::enable_if_t<detail::is_iterable_pairs<ConT>::value, int> = 0
std::enable_if_t<detail::is_iterable_pairs_v<ConT>, int> = 0
>
explicit url_search_params(ConT&& cont) {
for (const auto& p : cont) {
Expand Down

0 comments on commit e2ec706

Please sign in to comment.