40#include <boost/type_traits.hpp>
60 template <
typename V,
typename T,
typename... Types>
64 [](V& aThis,
const void* aData)
66 typedef std::decay_t<T> type;
68 aThis = *
static_cast<const assign_type*
>(aData);
82 template <
typename V,
typename T,
typename... Types>
86 [](V& aThis,
void* aData)
88 typedef std::decay_t<T> type;
90 aThis =
static_cast<move_assign_type&&
>(*
static_cast<move_assign_type*
>(aData));
97 template <
typename Id,
typename... Types>
100 public std::variant<std::monostate, Types...>
112 using variant_type::variant_type;
116 do_assign(aOther.
which(), aOther.data());
121 do_move_assign(aOther.which(), aOther.data());
126 do_assign(aOther.
which(), aOther.data());
131 do_move_assign(aOther.which(), aOther.data());
135 variant_type::operator=(aOther);
140 variant_type::operator=(std::move(aOther));
145 variant_type::operator=(std::monostate{});
148 using abstract_type::operator=;
153 return std::holds_alternative<std::monostate>(*
this);
157 if (index() != that.index())
160 std::visit([
this, &that, &result](
auto&& v)
162 typedef std::decay_t<
decltype(v)> type;
164 if constexpr (boost::has_equal_to<comparison_type, comparison_type>::value)
165 result = (*
static_cast<const comparison_type*
>(data()) == *
static_cast<const comparison_type*
>(that.data()));
173 if (index() != that.index())
174 return index() < that.index();
178 std::visit([
this, &that, &result](
auto&& v)
180 typedef std::decay_t<
decltype(v)> type;
182 if constexpr (boost::has_less<comparison_type, comparison_type>::value)
183 result = (*
static_cast<const comparison_type*
>(data()) < *
static_cast<const comparison_type*
>(that.data()));
192 return std::partial_ordering::equivalent;
193 else if (*
this < that)
194 return std::partial_ordering::less;
196 return std::partial_ordering::greater;
202 variant_type::operator=(std::monostate{});
207 return static_cast<id_t>(index() - 1u);
212 return std::holds_alternative<std::monostate>(*
this);
226 return iEnum.enumerators();
230 return ids().enumerators().find(
which())->second.to_std_string();
234 std::size_t index() const final
236 return variant_type::index();
238 const void* data() const final
240 const void* result =
nullptr;
241 std::visit([&result](
auto&& v) { result = &v; },
as_std_variant());
246 void* result =
nullptr;
252 return new self_type{ *
this };
256 static detail::plugin_variant::funky_assign_list_t<variant_type> funks;
258 if (
static_cast<std::size_t
>(aType) < n)
259 funks[
static_cast<std::size_t
>(aType)](*
this, aData);
261 throw std::bad_variant_access();
266 static detail::plugin_variant::funky_move_assign_list_t<variant_type> funks;
268 if (
static_cast<std::size_t
>(aType) < n)
269 funks[
static_cast<std::size_t
>(aType)](*
this, aData);
271 throw std::bad_variant_access();
276 const enum_t<id_t> iEnum;
282 template <
typename Visitor,
typename Id,
typename... Types>
288 template <
typename Visitor,
typename Id,
typename... Types>
virtual bool empty() const =0
virtual id_t which() const =0
std::string which_as_string() const
variant_type & as_std_variant()
self_type & operator=(const self_type &aOther)
std::variant< std::monostate, Types... > variant_type
plugin_variant(const abstract_type &aOther)
const variant_type & as_std_variant() const
plugin_variant(self_type &&aOther) noexcept
std::partial_ordering operator<=>(const self_type &that) const
bool operator<(const abstract_type &that) const final
plugin_variant(const self_type &aOther)
plugin_variant(abstract_type &&aOther) noexcept
bool operator==(const abstract_type &that) const final
self_type & operator=(none_t)
self_type & operator=(self_type &&aOther) noexcept
i_plugin_variant< Id, abstract_t< Types >... > abstract_type
bool operator==(none_t) const
const i_enum_t< Id >::enumerators_t & ids() const final
std::vector< funky_move_assign_t< V > > funky_move_assign_list_t
std::size_t funky_gen_assign(funky_assign_list_t< V > &aList)
std::vector< funky_assign_t< V > > funky_assign_list_t
std::size_t funky_gen_move_assign(funky_move_assign_list_t< V > &aList)
std::function< void(V &, const void *)> funky_assign_t
std::function< void(V &, void *)> funky_move_assign_t
typename detail::abstract_type< T >::type abstract_t
i_basic_enum< std::underlying_type_t< T > > i_enum_t
constexpr decltype(auto) visit(Visitor &&vis, neolib::variant< Types... > &&var)