diff --git a/include/ylt/standalone/iguana/dynamic.hpp b/include/ylt/standalone/iguana/dynamic.hpp index 47cf20154..898c53461 100644 --- a/include/ylt/standalone/iguana/dynamic.hpp +++ b/include/ylt/standalone/iguana/dynamic.hpp @@ -12,7 +12,12 @@ constexpr inline uint8_t ENABLE_ALL = 0x0F; template struct base_impl : public base { - base_impl() { [[maybe_unused]] static bool r = register_type(); } + base_impl() { + // make sure init T before main, and can register_type before main. + [[maybe_unused]] static auto t = + ylt::reflection::internal::wrapper::value; + [[maybe_unused]] static bool r = register_type(); + } void to_pb(std::string& str) const override { if constexpr ((ENABLE_FLAG & ENABLE_PB) != 0) { to_pb_adl((iguana_adl_t*)nullptr, *(static_cast(this)), str); diff --git a/include/ylt/standalone/iguana/json_writer.hpp b/include/ylt/standalone/iguana/json_writer.hpp index 1901d565b..75d4a70e9 100644 --- a/include/ylt/standalone/iguana/json_writer.hpp +++ b/include/ylt/standalone/iguana/json_writer.hpp @@ -12,8 +12,9 @@ template , int> = 0> IGUANA_INLINE void to_json(T &&t, Stream &s); namespace detail { -template -IGUANA_INLINE void to_json_impl(Stream &ss, const std::optional &val); +template , int> = 0> +IGUANA_INLINE void to_json_impl(Stream &ss, const T &val); template , int> = 0> @@ -151,8 +152,9 @@ IGUANA_INLINE void to_json_impl(Stream &ss, T val) { } } -template -IGUANA_INLINE void to_json_impl(Stream &ss, const std::optional &val) { +template , int>> +IGUANA_INLINE void to_json_impl(Stream &ss, const T &val) { if (!val) { ss.append("null"); } diff --git a/include/ylt/standalone/iguana/util.hpp b/include/ylt/standalone/iguana/util.hpp index 614040cc0..8c3fca9e2 100644 --- a/include/ylt/standalone/iguana/util.hpp +++ b/include/ylt/standalone/iguana/util.hpp @@ -47,8 +47,7 @@ template inline constexpr bool enum_v = std::is_enum_v>; template -constexpr inline bool optional_v = - is_template_instant_of>::value; +constexpr inline bool optional_v = ylt::reflection::optional; template struct is_container : std::false_type {};