diff --git a/helpers.h b/helpers.h index a461462..61c2673 100644 --- a/helpers.h +++ b/helpers.h @@ -70,12 +70,6 @@ WEBLEGENDS_TYPES void name_translated(std::ostream & s, const df::language_name & name, bool only_last = false); -template -struct void_t -{ - typedef void type; -}; - #define WEBLEGENDS_TYPE(type, name) \ int32_t get_id(df::type *name); \ const df::language_name & get_name(df::type *name); \ diff --git a/helpers_event.h b/helpers_event.h index e643d41..6002a1c 100644 --- a/helpers_event.h +++ b/helpers_event.h @@ -39,6 +39,15 @@ std::string profession_name(df::historical_figure *hf, df::profession prof, bool void do_location(std::ostream & s, const event_context & context, int32_t site, int32_t region, int32_t layer, int32_t structure = -1, std::string separator = " in ", bool force = false); +// a helper for SFINAE (Substitution Failire Is Not An Error) +// typename sfinae_helper::type is equivalent to T if the remaining types can be determined +// otherwise, the template fails to substitute +template +struct sfinae_helper +{ + typedef T type; +}; + template struct do_location_structure_helper { @@ -55,22 +64,22 @@ struct do_location_structure_helper T *event; }; -template -inline typename void_t::type do_location(std::ostream & s, const event_context & context, T *event, std::string separator = " in ", bool force = false) +template::type = 0> +inline void do_location(std::ostream & s, const event_context & context, T *event, std::string separator = " in ", bool force = false) { do_location(s, context, event->site, event->subregion, event->feature_layer, do_location_structure_helper(event), separator, force); } -template -inline typename void_t::type do_location(std::ostream & s, const event_context & context, T *event, std::string separator = " in ", bool force = false) +template::type = 0> +inline void do_location(std::ostream & s, const event_context & context, T *event, std::string separator = " in ", bool force = false) { do_location(s, context, event->site, event->region, event->layer, do_location_structure_helper(event), separator, force); } void do_item_description(std::ostream & s, const event_context & context, df::item *item); -template -inline typename void_t::type do_item_description(std::ostream & s, const event_context & context, int16_t, int16_t mat_type, int32_t mat_index) +template::type = 0> +inline void do_item_description(std::ostream & s, const event_context & context, int16_t, int16_t mat_type, int32_t mat_index) { auto item = df::allocate(); item->race = mat_type; @@ -133,8 +142,8 @@ inline void do_item_description(std::ostream & s, const event_context & context, delete item; } -template -inline typename std::enable_if::value, typename void_t::type>::type do_item_description(std::ostream & s, const event_context & context, int16_t, int16_t mat_type, int32_t mat_index) +template::value, int>::type, decltype(T::mat_type)>::type = 0> +inline void do_item_description(std::ostream & s, const event_context & context, int16_t, int16_t mat_type, int32_t mat_index) { auto item = df::allocate(); item->mat_type = mat_type;