Skip to content

Commit

Permalink
some improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Sep 23, 2024
1 parent fc773e6 commit 5bd83d3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
7 changes: 6 additions & 1 deletion include/ylt/standalone/iguana/dynamic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ constexpr inline uint8_t ENABLE_ALL = 0x0F;

template <typename T, uint8_t ENABLE_FLAG = ENABLE_PB>
struct base_impl : public base {
base_impl() { [[maybe_unused]] static bool r = register_type<T>(); }
base_impl() {
// make sure init T before main, and can register_type before main.
[[maybe_unused]] static auto t =
ylt::reflection::internal::wrapper<T>::value;
[[maybe_unused]] static bool r = register_type<T>();
}
void to_pb(std::string& str) const override {
if constexpr ((ENABLE_FLAG & ENABLE_PB) != 0) {
to_pb_adl((iguana_adl_t*)nullptr, *(static_cast<T const*>(this)), str);
Expand Down
10 changes: 6 additions & 4 deletions include/ylt/standalone/iguana/json_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ template <bool Is_writing_escape = true, typename Stream, typename T,
std::enable_if_t<ylt_refletable_v<T>, int> = 0>
IGUANA_INLINE void to_json(T &&t, Stream &s);
namespace detail {
template <bool Is_writing_escape = true, typename Stream, typename T>
IGUANA_INLINE void to_json_impl(Stream &ss, const std::optional<T> &val);
template <bool Is_writing_escape = true, typename Stream, typename T,
std::enable_if_t<optional_v<T>, int> = 0>
IGUANA_INLINE void to_json_impl(Stream &ss, const T &val);

template <bool Is_writing_escape = true, typename Stream, typename T,
std::enable_if_t<fixed_array_v<T>, int> = 0>
Expand Down Expand Up @@ -151,8 +152,9 @@ IGUANA_INLINE void to_json_impl(Stream &ss, T val) {
}
}

template <bool Is_writing_escape, typename Stream, typename T>
IGUANA_INLINE void to_json_impl(Stream &ss, const std::optional<T> &val) {
template <bool Is_writing_escape, typename Stream, typename T,
std::enable_if_t<optional_v<T>, int>>
IGUANA_INLINE void to_json_impl(Stream &ss, const T &val) {
if (!val) {
ss.append("null");
}
Expand Down
3 changes: 1 addition & 2 deletions include/ylt/standalone/iguana/util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ template <typename T>
inline constexpr bool enum_v = std::is_enum_v<std::decay_t<T>>;

template <typename T>
constexpr inline bool optional_v =
is_template_instant_of<std::optional, std::remove_cvref_t<T>>::value;
constexpr inline bool optional_v = ylt::reflection::optional<T>;

template <class, class = void>
struct is_container : std::false_type {};
Expand Down

0 comments on commit 5bd83d3

Please sign in to comment.