mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Remove remaining boost::mpl usages
This commit is contained in:
		| @@ -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_arithmetic<Type>, std::is_enum<Type>, boost::is_class<Type> >::value, "Unsupported type for JsonNode::convertTo()!"); | ||||
| 			return JsonConvImpl<Type, boost::mpl::or_<std::is_enum<Type>, boost::is_class<Type> >::value >::convertImpl(node); | ||||
| 			static_assert(std::is_arithmetic_v<Type> || std::is_enum_v<Type> || std::is_class_v<Type>, "Unsupported type for JsonNode::convertTo()!"); | ||||
| 			return JsonConvImpl<Type, std::is_enum_v<Type> || std::is_class_v<Type> >::convertImpl(node); | ||||
|  | ||||
| 		} | ||||
| 	}; | ||||
|   | ||||
| @@ -22,7 +22,7 @@ public: | ||||
| 	template<typename T> | ||||
| 	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<T>, std::is_function<T >> ::value>::type *dummy = nullptr) | ||||
| 		typename std::enable_if_t < std::is_class_v<T> || std::is_function_v<T> > *dummy = nullptr) | ||||
| 		: TBase(t) | ||||
| 	{} | ||||
|  | ||||
|   | ||||
| @@ -9,9 +9,6 @@ | ||||
|  */ | ||||
| #pragma once | ||||
|  | ||||
| #include <boost/mpl/vector.hpp> | ||||
| #include <boost/mpl/for_each.hpp> | ||||
|  | ||||
| #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<typename Variant, typename Source> | ||||
| 	struct VariantLoaderHelper | ||||
| 	{ | ||||
| 		Source & source; | ||||
| 		std::vector<std::function<Variant()>> funcs; | ||||
|  | ||||
| 		template <class V> | ||||
| 		struct mpl_types_impl; | ||||
|  | ||||
| 		template <class... Ts> | ||||
| 		struct mpl_types_impl<std::variant<Ts...>> { | ||||
| 			using type = boost::mpl::vector<Ts...>; | ||||
| 		}; | ||||
|  | ||||
| 		template <class V> | ||||
| 		using mpl_types = typename mpl_types_impl<V>::type; | ||||
|  | ||||
| 		VariantLoaderHelper(Source & source): | ||||
| 			source(source) | ||||
| 		{ | ||||
| 			boost::mpl::for_each<mpl_types<Variant>>(std::ref(*this)); | ||||
| 		} | ||||
|  | ||||
| 		template<typename Type> | ||||
| 		void operator()(Type) | ||||
| 		{ | ||||
| 			funcs.push_back([&]() -> Variant | ||||
| 			{ | ||||
| 				Type obj; | ||||
| 				source.load(obj); | ||||
| 				return Variant(obj); | ||||
| 			}); | ||||
| 		} | ||||
| 	}; | ||||
|  | ||||
| 	template<typename Ser,typename T> | ||||
| 	struct LoadIfStackInstance | ||||
| 	{ | ||||
| @@ -510,17 +472,19 @@ public: | ||||
| 		this->read((void*)data.c_str(),length); | ||||
| 	} | ||||
|  | ||||
| 	template<typename T0, typename... TN> | ||||
| 	void load(std::variant<T0, TN...> & data) | ||||
| 	template<typename... TN> | ||||
| 	void load(std::variant<TN...> & data) | ||||
| 	{ | ||||
| 		using TVariant = std::variant<T0, TN...>; | ||||
|  | ||||
| 		VariantLoaderHelper<TVariant, BinaryDeserializer> 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<TN...> 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<typename T> | ||||
|   | ||||
| @@ -149,42 +149,49 @@ struct is_serializeable | ||||
| template <typename T> //metafunction returning CGObjectInstance if T is its derivate or T elsewise | ||||
| struct VectorizedTypeFor | ||||
| { | ||||
| 	using type = typename | ||||
| 		//if | ||||
| 		boost::mpl::eval_if<std::is_same<CGHeroInstance, T>, | ||||
| 		boost::mpl::identity<CGHeroInstance>, | ||||
| 		//else if | ||||
| 		boost::mpl::eval_if<std::is_base_of<CGObjectInstance, T>, | ||||
| 		boost::mpl::identity<CGObjectInstance>, | ||||
| 		//else | ||||
| 		boost::mpl::identity<T> | ||||
| 		>>::type; | ||||
| 	using type = std::conditional_t<std::is_base_of_v<CGObjectInstance, T>, CGObjectInstance, T>; | ||||
| }; | ||||
| template <typename U> | ||||
|  | ||||
| template <> | ||||
| struct VectorizedTypeFor<CGHeroInstance> | ||||
| { | ||||
| 	using type = CGHeroInstance; | ||||
| }; | ||||
|  | ||||
| template <typename T> | ||||
| struct VectorizedIDType | ||||
| { | ||||
| 	using type = typename | ||||
| 		//if | ||||
| 		boost::mpl::eval_if<std::is_same<CArtifact, U>, | ||||
| 		boost::mpl::identity<ArtifactID>, | ||||
| 		//else if | ||||
| 		boost::mpl::eval_if<std::is_same<CCreature, U>, | ||||
| 		boost::mpl::identity<CreatureID>, | ||||
| 		//else if | ||||
| 		boost::mpl::eval_if<std::is_same<CHero, U>, | ||||
| 		boost::mpl::identity<HeroTypeID>, | ||||
| 		//else if | ||||
| 		boost::mpl::eval_if<std::is_same<CArtifactInstance, U>, | ||||
| 		boost::mpl::identity<ArtifactInstanceID>, | ||||
| 		//else if | ||||
| 		boost::mpl::eval_if<std::is_same<CGHeroInstance, U>, | ||||
| 		boost::mpl::identity<HeroTypeID>, | ||||
| 		//else if | ||||
| 		boost::mpl::eval_if<std::is_base_of<CGObjectInstance, U>, | ||||
| 		boost::mpl::identity<ObjectInstanceID>, | ||||
| 		//else | ||||
| 		boost::mpl::identity<si32> | ||||
| 		>>>>>>::type; | ||||
| 	using type = std::conditional_t<std::is_base_of_v<CGObjectInstance, T>, ObjectInstanceID, int32_t>; | ||||
| }; | ||||
|  | ||||
| template <> | ||||
| struct VectorizedIDType<CArtifact> | ||||
| { | ||||
| 	using type = ArtifactID; | ||||
| }; | ||||
|  | ||||
| template <> | ||||
| struct VectorizedIDType<CCreature> | ||||
| { | ||||
| 	using type = CreatureID; | ||||
| }; | ||||
|  | ||||
| template <> | ||||
| struct VectorizedIDType<CHero> | ||||
| { | ||||
| 	using type = HeroTypeID; | ||||
| }; | ||||
|  | ||||
| template <> | ||||
| struct VectorizedIDType<CArtifactInstance> | ||||
| { | ||||
| 	using type = ArtifactInstanceID; | ||||
| }; | ||||
|  | ||||
| template <> | ||||
| struct VectorizedIDType<CGHeroInstance> | ||||
| { | ||||
| 	using type = HeroTypeID; | ||||
| }; | ||||
|  | ||||
| /// Base class for deserializers | ||||
|   | ||||
		Reference in New Issue
	
	Block a user