diff --git a/lib/JsonNode.h b/lib/JsonNode.h index 91eddce76..47ae9a1a0 100644 --- a/lib/JsonNode.h +++ b/lib/JsonNode.h @@ -247,8 +247,8 @@ namespace JsonDetail static Type convert(const JsonNode & node) { ///this should be triggered only for numeric types and enums - static_assert(boost::mpl::or_, std::is_enum, boost::is_class >::value, "Unsupported type for JsonNode::convertTo()!"); - return JsonConvImpl, boost::is_class >::value >::convertImpl(node); + static_assert(std::is_arithmetic_v || std::is_enum_v || std::is_class_v, "Unsupported type for JsonNode::convertTo()!"); + return JsonConvImpl || std::is_class_v >::convertImpl(node); } }; diff --git a/lib/bonuses/BonusSelector.h b/lib/bonuses/BonusSelector.h index 672fcfdc2..4e2ebbc74 100644 --- a/lib/bonuses/BonusSelector.h +++ b/lib/bonuses/BonusSelector.h @@ -22,7 +22,7 @@ public: template CSelector(const T &t, //SFINAE trick -> include this c-tor in overload resolution only if parameter is class //(includes functors, lambdas) or function. Without that VC is going mad about ambiguities. - typename std::enable_if < boost::mpl::or_ < std::is_class, std::is_function> ::value>::type *dummy = nullptr) + typename std::enable_if_t < std::is_class_v || std::is_function_v > *dummy = nullptr) : TBase(t) {} diff --git a/lib/serializer/BinaryDeserializer.h b/lib/serializer/BinaryDeserializer.h index 2ed7d553d..caa36ee7d 100644 --- a/lib/serializer/BinaryDeserializer.h +++ b/lib/serializer/BinaryDeserializer.h @@ -9,9 +9,6 @@ */ #pragma once -#include -#include - #include "CTypeList.h" #include "../mapObjects/CGHeroInstance.h" #include "../../Global.h" @@ -37,41 +34,6 @@ public: /// Effectively revesed version of BinarySerializer class DLL_LINKAGE BinaryDeserializer : public CLoaderBase { - template - struct VariantLoaderHelper - { - Source & source; - std::vector> funcs; - - template - struct mpl_types_impl; - - template - struct mpl_types_impl> { - using type = boost::mpl::vector; - }; - - template - using mpl_types = typename mpl_types_impl::type; - - VariantLoaderHelper(Source & source): - source(source) - { - boost::mpl::for_each>(std::ref(*this)); - } - - template - void operator()(Type) - { - funcs.push_back([&]() -> Variant - { - Type obj; - source.load(obj); - return Variant(obj); - }); - } - }; - template struct LoadIfStackInstance { @@ -510,17 +472,19 @@ public: this->read((void*)data.c_str(),length); } - template - void load(std::variant & data) + template + void load(std::variant & data) { - using TVariant = std::variant; - - VariantLoaderHelper loader(*this); - si32 which; load( which ); - assert(which < loader.funcs.size()); - data = loader.funcs.at(which)(); + assert(which < sizeof...(TN)); + + // Create array of variants that contains all default-constructed alternatives + const std::variant table[] = { TN{ }... }; + // use appropriate alternative for result + data = table[which]; + // perform actual load via std::visit dispatch + std::visit([this](auto& o) { load(o); }, data); } template diff --git a/lib/serializer/CSerializer.h b/lib/serializer/CSerializer.h index 706a0de9b..525caf2bc 100644 --- a/lib/serializer/CSerializer.h +++ b/lib/serializer/CSerializer.h @@ -149,42 +149,49 @@ struct is_serializeable template //metafunction returning CGObjectInstance if T is its derivate or T elsewise struct VectorizedTypeFor { - using type = typename - //if - boost::mpl::eval_if, - boost::mpl::identity, - //else if - boost::mpl::eval_if, - boost::mpl::identity, - //else - boost::mpl::identity - >>::type; + using type = std::conditional_t, CGObjectInstance, T>; }; -template + +template <> +struct VectorizedTypeFor +{ + using type = CGHeroInstance; +}; + +template struct VectorizedIDType { - using type = typename - //if - boost::mpl::eval_if, - boost::mpl::identity, - //else if - boost::mpl::eval_if, - boost::mpl::identity, - //else if - boost::mpl::eval_if, - boost::mpl::identity, - //else if - boost::mpl::eval_if, - boost::mpl::identity, - //else if - boost::mpl::eval_if, - boost::mpl::identity, - //else if - boost::mpl::eval_if, - boost::mpl::identity, - //else - boost::mpl::identity - >>>>>>::type; + using type = std::conditional_t, ObjectInstanceID, int32_t>; +}; + +template <> +struct VectorizedIDType +{ + using type = ArtifactID; +}; + +template <> +struct VectorizedIDType +{ + using type = CreatureID; +}; + +template <> +struct VectorizedIDType +{ + using type = HeroTypeID; +}; + +template <> +struct VectorizedIDType +{ + using type = ArtifactInstanceID; +}; + +template <> +struct VectorizedIDType +{ + using type = HeroTypeID; }; /// Base class for deserializers