Skip to content

Commit 5a5ea37

Browse files
author
Hana Dusíková
committed
support for other types of arguments with a template function
1 parent ef125bd commit 5a5ea37

File tree

1 file changed

+8
-50
lines changed

1 file changed

+8
-50
lines changed

Diff for: include/ctre/functions.hpp

+8-50
Original file line numberDiff line numberDiff line change
@@ -47,84 +47,42 @@ constexpr auto & _input = input;
4747
// in moment when we get C++20 support this will start to work :)
4848

4949
#if __cpp_nontype_template_parameter_class
50-
template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto match(std::string_view sv) noexcept {
50+
template <ctll::basic_fixed_string input, typename... Args> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto match(Args && ... args) noexcept {
5151
constexpr auto _input = input; // workaround for GCC 9 bug 88092
5252
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
5353
static_assert(tmp(), "Regular Expression contains syntax error.");
5454
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
5555
auto re_obj = ctre::regular_expression<re>(re());
56-
return re_obj.match(sv);
56+
return re_obj.match(std::forward<Args>(args)...);
5757
}
5858
#else
59-
template <auto & input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto match(std::string_view sv) noexcept {
59+
template <auto & input, typename... Args> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto match(Args && ... args) noexcept {
6060
constexpr auto & _input = input;
6161
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
6262
static_assert(tmp(), "Regular Expression contains syntax error.");
6363
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
6464
auto re_obj = ctre::regular_expression<re>(re());
65-
return re_obj.match(sv);
65+
return re_obj.match(std::forward<Args>(args)...);
6666
}
6767
#endif
6868

69-
70-
#if __cpp_nontype_template_parameter_class
71-
template <ctll::basic_fixed_string input, typename ForwardIt> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto match(ForwardIt first, ForwardIt last) noexcept {
72-
constexpr auto _input = input; // workaround for GCC 9 bug 88092
73-
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
74-
static_assert(tmp(), "Regular Expression contains syntax error.");
75-
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
76-
return ctre::regular_expression(re()).match(first, last);
77-
}
78-
#else
79-
template <auto & input, typename ForwardIt> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto match(ForwardIt first, ForwardIt last) noexcept {
80-
constexpr auto & _input = input;
81-
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
82-
static_assert(tmp(), "Regular Expression contains syntax error.");
83-
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
84-
auto re_obj = ctre::regular_expression(re());
85-
return re_obj.match(first,last);
86-
}
87-
#endif
88-
89-
9069
#if __cpp_nontype_template_parameter_class
91-
template <ctll::basic_fixed_string input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto search(std::string_view sv) noexcept {
70+
template <ctll::basic_fixed_string input, typename... Args> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto search(Args && ... args) noexcept {
9271
constexpr auto _input = input; // workaround for GCC 9 bug 88092
9372
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
9473
static_assert(tmp(), "Regular Expression contains syntax error.");
9574
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
9675
auto re_obj = ctre::regular_expression(re());
97-
return re_obj.search(sv);
76+
return re_obj.search(std::forward<Args>(args)...);
9877
}
9978
#else
100-
template <auto & input> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto search(std::string_view sv) noexcept {
79+
template <auto & input, typename... Args> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto search(Args && ... args) noexcept {
10180
constexpr auto & _input = input;
10281
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
10382
static_assert(tmp(), "Regular Expression contains syntax error.");
10483
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
10584
auto re_obj = ctre::regular_expression(re());
106-
return re_obj.search(sv);
107-
}
108-
#endif
109-
110-
111-
#if __cpp_nontype_template_parameter_class
112-
template <ctll::basic_fixed_string input, typename ForwardIt> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto search(ForwardIt first, ForwardIt last) noexcept {
113-
constexpr auto _input = input; // workaround for GCC 9 bug 88092
114-
using tmp = typename ctll::parser<ctre::pcre, _input, ctre::pcre_actions>::template output<pcre_context<>>;
115-
static_assert(tmp(), "Regular Expression contains syntax error.");
116-
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
117-
auto re_obj = ctre::regular_expression(re());
118-
return re_obj.search(first, last);
119-
}
120-
#else
121-
template <auto & input, typename ForwardIt> CTRE_FLATTEN constexpr CTRE_FORCE_INLINE auto search(ForwardIt first, ForwardIt last) noexcept {
122-
constexpr auto & _input = input;
123-
using tmp = typename ctll::parser<ctre::pcre, input, ctre::pcre_actions>::template output<pcre_context<>>;
124-
static_assert(tmp(), "Regular Expression contains syntax error.");
125-
using re = decltype(ctll::front(typename tmp::output_type::stack_type()));
126-
auto re_obj = ctre::regular_expression(re());
127-
return re_obj.search(first, last);
85+
return re_obj.search(std::forward<Args>(args)...);
12886
}
12987
#endif
13088

0 commit comments

Comments
 (0)