mirror of
https://github.com/red0124/ssp.git
synced 2025-01-23 04:55:20 +01:00
Replace ss::ternary_t with std::conditional_t
This commit is contained in:
parent
a9e9783e6a
commit
a4ecbd4dc8
@ -102,7 +102,7 @@ class converter {
|
|||||||
constexpr static auto string_error = setup<Matchers...>::string_error;
|
constexpr static auto string_error = setup<Matchers...>::string_error;
|
||||||
constexpr static auto default_delimiter = ",";
|
constexpr static auto default_delimiter = ",";
|
||||||
|
|
||||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// parses line with given delimiter, returns a 'T' object created with
|
// parses line with given delimiter, returns a 'T' object created with
|
||||||
|
@ -17,7 +17,7 @@ class parser {
|
|||||||
constexpr static auto string_error = setup<Matchers...>::string_error;
|
constexpr static auto string_error = setup<Matchers...>::string_error;
|
||||||
|
|
||||||
using multiline = typename setup<Matchers...>::multiline;
|
using multiline = typename setup<Matchers...>::multiline;
|
||||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||||
|
|
||||||
constexpr static bool escaped_multiline_enabled =
|
constexpr static bool escaped_multiline_enabled =
|
||||||
multiline::enabled && setup<Matchers...>::escape::enabled;
|
multiline::enabled && setup<Matchers...>::escape::enabled;
|
||||||
@ -151,8 +151,8 @@ public:
|
|||||||
template <bool get_object, typename T, typename... Ts>
|
template <bool get_object, typename T, typename... Ts>
|
||||||
struct iterable {
|
struct iterable {
|
||||||
struct iterator {
|
struct iterator {
|
||||||
using value =
|
using value = std::conditional_t<get_object, T,
|
||||||
ss::ternary_t<get_object, T, no_void_validator_tup_t<T, Ts...>>;
|
no_void_validator_tup_t<T, Ts...>>;
|
||||||
|
|
||||||
iterator() : parser_{nullptr} {
|
iterator() : parser_{nullptr} {
|
||||||
}
|
}
|
||||||
|
@ -111,8 +111,8 @@ struct get_matcher<Matcher, T, Ts...> {
|
|||||||
static_assert(count_v<is_matcher, T, Ts...> <= 1,
|
static_assert(count_v<is_matcher, T, Ts...> <= 1,
|
||||||
"the same matcher is cannot"
|
"the same matcher is cannot"
|
||||||
"be defined multiple times");
|
"be defined multiple times");
|
||||||
using type = ternary_t<is_matcher<T>::value, T,
|
using type = std::conditional_t<is_matcher<T>::value, T,
|
||||||
typename get_matcher<Matcher, Ts...>::type>;
|
typename get_matcher<Matcher, Ts...>::type>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <template <char...> class Matcher>
|
template <template <char...> class Matcher>
|
||||||
@ -149,8 +149,8 @@ struct get_multiline;
|
|||||||
|
|
||||||
template <typename T, typename... Ts>
|
template <typename T, typename... Ts>
|
||||||
struct get_multiline<T, Ts...> {
|
struct get_multiline<T, Ts...> {
|
||||||
using type = ternary_t<is_instance_of_multiline<T>::value, T,
|
using type = std::conditional_t<is_instance_of_multiline<T>::value, T,
|
||||||
typename get_multiline<Ts...>::type>;
|
typename get_multiline<Ts...>::type>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
@ -227,8 +227,10 @@ public:
|
|||||||
using quote = get_matcher_t<quote, Ts...>;
|
using quote = get_matcher_t<quote, Ts...>;
|
||||||
using escape = get_matcher_t<escape, Ts...>;
|
using escape = get_matcher_t<escape, Ts...>;
|
||||||
|
|
||||||
using trim_left = ternary_t<trim_all::enabled, trim_all, trim_left_only>;
|
using trim_left =
|
||||||
using trim_right = ternary_t<trim_all::enabled, trim_all, trim_right_only>;
|
std::conditional_t<trim_all::enabled, trim_all, trim_left_only>;
|
||||||
|
using trim_right =
|
||||||
|
std::conditional_t<trim_all::enabled, trim_all, trim_right_only>;
|
||||||
|
|
||||||
using multiline = get_multiline_t<Ts...>;
|
using multiline = get_multiline_t<Ts...>;
|
||||||
constexpr static bool string_error = (count_string_error == 1);
|
constexpr static bool string_error = (count_string_error == 1);
|
||||||
|
@ -23,10 +23,10 @@ private:
|
|||||||
constexpr static auto string_error = setup<Ts...>::string_error;
|
constexpr static auto string_error = setup<Ts...>::string_error;
|
||||||
constexpr static auto is_const_line = !quote::enabled && !escape::enabled;
|
constexpr static auto is_const_line = !quote::enabled && !escape::enabled;
|
||||||
|
|
||||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using line_ptr_type = ternary_t<is_const_line, const char*, char*>;
|
using line_ptr_type = std::conditional_t<is_const_line, const char*, char*>;
|
||||||
|
|
||||||
bool valid() const {
|
bool valid() const {
|
||||||
if constexpr (string_error) {
|
if constexpr (string_error) {
|
||||||
|
@ -357,26 +357,6 @@ struct is_instance_of<Template, Template<Ts...>> {
|
|||||||
template <template <typename...> class Template, typename... Ts>
|
template <template <typename...> class Template, typename... Ts>
|
||||||
constexpr bool is_instance_of_v = is_instance_of<Template, Ts...>::value;
|
constexpr bool is_instance_of_v = is_instance_of<Template, Ts...>::value;
|
||||||
|
|
||||||
////////////////
|
|
||||||
// ternary
|
|
||||||
////////////////
|
|
||||||
|
|
||||||
template <bool B, typename T, typename U>
|
|
||||||
struct ternary;
|
|
||||||
|
|
||||||
template <typename T, typename U>
|
|
||||||
struct ternary<true, T, U> {
|
|
||||||
using type = T;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T, typename U>
|
|
||||||
struct ternary<false, T, U> {
|
|
||||||
using type = U;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <bool B, typename T, typename U>
|
|
||||||
using ternary_t = typename ternary<B, T, U>::type;
|
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
// tuple to struct
|
// tuple to struct
|
||||||
////////////////
|
////////////////
|
||||||
|
49
ssp.hpp
49
ssp.hpp
@ -17,7 +17,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#define SSP_DISABLE_FAST_FLOAT
|
#define SSP_DISABLE_FAST_FLOAT
|
||||||
|
|
||||||
|
|
||||||
namespace ss {
|
namespace ss {
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
@ -372,26 +371,6 @@ struct is_instance_of<Template, Template<Ts...>> {
|
|||||||
template <template <typename...> class Template, typename... Ts>
|
template <template <typename...> class Template, typename... Ts>
|
||||||
constexpr bool is_instance_of_v = is_instance_of<Template, Ts...>::value;
|
constexpr bool is_instance_of_v = is_instance_of<Template, Ts...>::value;
|
||||||
|
|
||||||
////////////////
|
|
||||||
// ternary
|
|
||||||
////////////////
|
|
||||||
|
|
||||||
template <bool B, typename T, typename U>
|
|
||||||
struct ternary;
|
|
||||||
|
|
||||||
template <typename T, typename U>
|
|
||||||
struct ternary<true, T, U> {
|
|
||||||
using type = T;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T, typename U>
|
|
||||||
struct ternary<false, T, U> {
|
|
||||||
using type = U;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <bool B, typename T, typename U>
|
|
||||||
using ternary_t = typename ternary<B, T, U>::type;
|
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
// tuple to struct
|
// tuple to struct
|
||||||
////////////////
|
////////////////
|
||||||
@ -415,7 +394,6 @@ T to_object(U&& data) {
|
|||||||
|
|
||||||
} /* trait */
|
} /* trait */
|
||||||
|
|
||||||
|
|
||||||
namespace ss {
|
namespace ss {
|
||||||
|
|
||||||
////////////////
|
////////////////
|
||||||
@ -799,8 +777,8 @@ struct get_matcher<Matcher, T, Ts...> {
|
|||||||
static_assert(count_v<is_matcher, T, Ts...> <= 1,
|
static_assert(count_v<is_matcher, T, Ts...> <= 1,
|
||||||
"the same matcher is cannot"
|
"the same matcher is cannot"
|
||||||
"be defined multiple times");
|
"be defined multiple times");
|
||||||
using type = ternary_t<is_matcher<T>::value, T,
|
using type = std::conditional_t<is_matcher<T>::value, T,
|
||||||
typename get_matcher<Matcher, Ts...>::type>;
|
typename get_matcher<Matcher, Ts...>::type>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <template <char...> class Matcher>
|
template <template <char...> class Matcher>
|
||||||
@ -837,8 +815,8 @@ struct get_multiline;
|
|||||||
|
|
||||||
template <typename T, typename... Ts>
|
template <typename T, typename... Ts>
|
||||||
struct get_multiline<T, Ts...> {
|
struct get_multiline<T, Ts...> {
|
||||||
using type = ternary_t<is_instance_of_multiline<T>::value, T,
|
using type = std::conditional_t<is_instance_of_multiline<T>::value, T,
|
||||||
typename get_multiline<Ts...>::type>;
|
typename get_multiline<Ts...>::type>;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
@ -915,8 +893,10 @@ public:
|
|||||||
using quote = get_matcher_t<quote, Ts...>;
|
using quote = get_matcher_t<quote, Ts...>;
|
||||||
using escape = get_matcher_t<escape, Ts...>;
|
using escape = get_matcher_t<escape, Ts...>;
|
||||||
|
|
||||||
using trim_left = ternary_t<trim_all::enabled, trim_all, trim_left_only>;
|
using trim_left =
|
||||||
using trim_right = ternary_t<trim_all::enabled, trim_all, trim_right_only>;
|
std::conditional_t<trim_all::enabled, trim_all, trim_left_only>;
|
||||||
|
using trim_right =
|
||||||
|
std::conditional_t<trim_all::enabled, trim_all, trim_right_only>;
|
||||||
|
|
||||||
using multiline = get_multiline_t<Ts...>;
|
using multiline = get_multiline_t<Ts...>;
|
||||||
constexpr static bool string_error = (count_string_error == 1);
|
constexpr static bool string_error = (count_string_error == 1);
|
||||||
@ -973,10 +953,10 @@ private:
|
|||||||
constexpr static auto string_error = setup<Ts...>::string_error;
|
constexpr static auto string_error = setup<Ts...>::string_error;
|
||||||
constexpr static auto is_const_line = !quote::enabled && !escape::enabled;
|
constexpr static auto is_const_line = !quote::enabled && !escape::enabled;
|
||||||
|
|
||||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using line_ptr_type = ternary_t<is_const_line, const char*, char*>;
|
using line_ptr_type = std::conditional_t<is_const_line, const char*, char*>;
|
||||||
|
|
||||||
bool valid() const {
|
bool valid() const {
|
||||||
if constexpr (string_error) {
|
if constexpr (string_error) {
|
||||||
@ -1400,7 +1380,6 @@ public:
|
|||||||
|
|
||||||
} /* ss */
|
} /* ss */
|
||||||
|
|
||||||
|
|
||||||
#ifndef SSP_DISABLE_FAST_FLOAT
|
#ifndef SSP_DISABLE_FAST_FLOAT
|
||||||
#else
|
#else
|
||||||
#endif
|
#endif
|
||||||
@ -1838,7 +1817,7 @@ class converter {
|
|||||||
constexpr static auto string_error = setup<Matchers...>::string_error;
|
constexpr static auto string_error = setup<Matchers...>::string_error;
|
||||||
constexpr static auto default_delimiter = ",";
|
constexpr static auto default_delimiter = ",";
|
||||||
|
|
||||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// parses line with given delimiter, returns a 'T' object created with
|
// parses line with given delimiter, returns a 'T' object created with
|
||||||
@ -2219,7 +2198,6 @@ private:
|
|||||||
|
|
||||||
} /* ss */
|
} /* ss */
|
||||||
|
|
||||||
|
|
||||||
namespace ss {
|
namespace ss {
|
||||||
|
|
||||||
template <typename... Matchers>
|
template <typename... Matchers>
|
||||||
@ -2227,7 +2205,7 @@ class parser {
|
|||||||
constexpr static auto string_error = setup<Matchers...>::string_error;
|
constexpr static auto string_error = setup<Matchers...>::string_error;
|
||||||
|
|
||||||
using multiline = typename setup<Matchers...>::multiline;
|
using multiline = typename setup<Matchers...>::multiline;
|
||||||
using error_type = ss::ternary_t<string_error, std::string, bool>;
|
using error_type = std::conditional_t<string_error, std::string, bool>;
|
||||||
|
|
||||||
constexpr static bool escaped_multiline_enabled =
|
constexpr static bool escaped_multiline_enabled =
|
||||||
multiline::enabled && setup<Matchers...>::escape::enabled;
|
multiline::enabled && setup<Matchers...>::escape::enabled;
|
||||||
@ -2362,7 +2340,8 @@ public:
|
|||||||
struct iterable {
|
struct iterable {
|
||||||
struct iterator {
|
struct iterator {
|
||||||
using value =
|
using value =
|
||||||
ss::ternary_t<get_object, T, no_void_validator_tup_t<T, Ts...>>;
|
std::conditional_t<get_object, T,
|
||||||
|
no_void_validator_tup_t<T, Ts...>>;
|
||||||
|
|
||||||
iterator() : parser_{nullptr} {
|
iterator() : parser_{nullptr} {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user