#pragma once #include "schema.hpp" namespace saw { template struct schema_factory { using Schema = T; static_assert(always_false, "Not supported"); }; template struct schema_factory...>> { private: public: using Schema = schema::Struct...>; template static constexpr bool has_key() noexcept { return schema_has_key::value; } template static constexpr bool has_member() noexcept { return schema_has_member, Schema>::value; } template constexpr auto add_maybe() const noexcept { if constexpr (!has_key()) { return schema_factory..., schema::Member>>{}; } else if constexpr (has_member() ){ return schema_factory...> >{}; } else { static_assert(always_false, "Struct already has the provided Key, but a mismatching Type"); } } template constexpr schema_factory...,schema::Member>> add() const noexcept { static_assert(!has_key(), "Can't add member. Name is already in use."); return {}; } }; template struct schema_factory...>> { using Schema = schema::Union...>; template static constexpr bool has_key() noexcept { return schema_has_key::value; } template constexpr schema_factory...,schema::Member>> add() const noexcept { static_assert(!has_key(), "Can't add member. Name is already in use."); return {}; } }; template struct schema_factory> { using Schema = schema::Tuple; template constexpr schema_factory> add() const noexcept { return {}; } }; /** * This creates the base schema. For example an empty struct,tuple,union or anything else. */ template constexpr schema_factory build_schema() noexcept { return {}; } }