3 #include <ozo/detail/functional.h>
4 #include <ozo/core/concept.h>
5 #include <ozo/type_traits.h>
31 template <
typename T,
typename = hana::when<true>>
32 struct to_const_char_impl {};
35 struct to_const_char_impl<T, hana::when<HanaString<T>>> {
36 static constexpr
const char* apply(
const T& v) noexcept {
37 return hana::to<const char*>(v);
42 struct to_const_char_impl<std::string> {
43 static const char* apply(
const std::string& v) noexcept {
49 struct to_const_char_impl<std::string_view> {
50 static constexpr
const char* apply(std::string_view v) noexcept {
56 struct to_const_char_impl<const char*> {
57 static constexpr
const char* apply(
const char* v) noexcept {
62 #ifdef OZO_DOCUMENTATION
100 template <
typename T>
101 inline constexpr detail::result_of<to_const_char_impl, T>
to_const_char(
const T& v) noexcept {
102 static_assert(noexcept(detail::apply<to_const_char_impl>(v)),
103 "to_const_char_impl::apply() should be noexcept");
104 static_assert(std::is_same_v<
const char*, detail::result_of<to_const_char_impl, T>>,
105 "to_const_char_impl::apply() should return const char*");
106 return detail::apply<to_const_char_impl>(v);
110 template <
class,
class = std::
void_t<>>
111 struct is_query_text : std::false_type {};
114 struct is_query_text<T, std::void_t<
115 decltype(ozo::to_const_char(std::declval<const T&>()))
116 >> : std::true_type {};
137 template <
typename T>
139 inline constexpr
auto QueryText = is_query_text<std::decay_t<T>>::value;
142 template <
typename T,
typename = hana::when<true>>
143 struct get_query_text_impl;
145 #ifdef OZO_DOCUMENTATION
176 template <
typename Query>
179 template <
typename T>
180 inline constexpr detail::result_of<get_query_text_impl, T>
get_query_text(T&& query) {
181 return detail::apply<get_query_text_impl>(std::forward<T>(query));
185 template <
typename T,
typename = hana::when<true>>
186 struct get_query_params_impl;
188 #ifdef OZO_DOCUMENTATION
218 template <
typename T>
221 template <
typename T>
222 inline constexpr detail::result_of<get_query_params_impl, T>
get_query_params(T&& query) {
223 return detail::apply<get_query_params_impl>(std::forward<T>(query));
227 template <
class,
class = std::
void_t<>>
228 struct is_query : std::false_type {};
231 struct is_query<T, std::void_t<
232 decltype(get_query_text(std::declval<const T&>())),
233 decltype(get_query_params(std::declval<const T&>()))
234 >> : std::bool_constant<
235 QueryText<decltype(get_query_text(std::declval<const T&>()))>
236 && HanaSequence<decltype(get_query_params(std::declval<const T&>()))>
266 template <
typename T>
268 inline constexpr
auto Query = is_query<std::decay_t<T>>::value;
295 template <
class QueryText ,
class ... Params>
298 template <
class ... ParamsT>
299 inline constexpr
auto make_query(
const char* text, ParamsT&& ... params) {
300 return make_query(std::string_view(text), std::forward<ParamsT>(params)...);
303 template <
class T,
class = Require<Query<T>>>
304 decltype(
auto) get_text(const T& query) {
308 template <
class T,
class = Require<Query<T>>>
309 decltype(
auto) get_params(const T& query) {
315 #include <ozo/impl/query.h>