47 template <
typename... Types>
53 template <
typename Type>
54 struct variant_size<
neolib::variant<Type>> : variant_size<std::variant<std::monostate, Type>> {};
56 template <
typename... Types>
57 struct variant_size<
neolib::variant<Types...>> : variant_size<std::variant<std::monostate, Types...>> {};
59 template <
typename Visitor,
typename... Types>
62 return visit(std::forward<Visitor>(vis),
static_cast<std::variant<std::monostate, Types...
>&&>(std::move(var)));
65 template <
typename Visitor,
typename... Types>
68 return visit(std::forward<Visitor>(vis),
static_cast<std::variant<std::monostate, Types...
> const&>(var));
71 template <
typename Visitor,
typename... Types>
74 return visit(std::forward<Visitor>(vis),
static_cast<std::variant<std::monostate, Types...
>&>(var));
77 template <
typename T,
typename... Types>
80 return holds_alternative<T>(
static_cast<std::variant<std::monostate, Types...
> const&>(var));
83 template<
typename T,
typename... Types>
86 return get<T>(
static_cast<std::variant<std::monostate, Types...
>&>(var));
89 template<
typename T,
typename... Types>
92 return get<T>(
static_cast<std::variant<std::monostate, Types...
> &&>(std::move(var)));
95 template<
typename T,
typename... Types>
98 return get<T>(
static_cast<std::variant<std::monostate, Types...
> const&>(var));
101 template<
typename T,
typename... Types>
104 return get<T>(
static_cast<const std::variant<std::monostate, Types...
>&&>(std::move(var)));
113 template <
typename AbstractT,
typename Type>
115 template <bool,
typename AbstractT,
typename... Rest>
117 template <
typename AbstractT,
typename... Types>
119 template <
typename AbstractT,
typename Type>
121 template <
typename AbstractT,
typename Type,
typename Rest>
123 template <
typename AbstractT,
typename Type,
typename... Rest>
125 template <
typename AbstractT,
typename Type>
127 template <
typename AbstractT,
typename Type,
typename... Rest>
129 template <
typename AbstractT,
typename Type>
131 template <
typename AbstractT,
typename Type,
typename... Rest>
133 template <
typename AbstractT,
typename... Type>
136 template <
typename... Types>
139 using self_type =
variant<Types...>;
143 using std_type = std::variant<std::monostate, Types...>;
149 template <
typename T>
157 template <
typename T, std::enable_if_t<std::is_base_of_v<self_type, T> && is_copy_constructible_v,
int> = 0>
162 template <
typename T, std::enable_if_t<std::is_base_of_v<self_type, T> && is_move_constructible_v,
int> = 0>
167 template <
typename T, std::enable_if_t<std::is_same_v<T, abstract_type> && is_copy_constructible_v,
int> = 0>
169 std_type{ static_cast<self_type const&>(aOther) }
172 template <
typename T, std::enable_if_t<std::is_same_v<T, abstract_type> && is_move_constructible_v,
int> = 0>
174 std_type{ static_cast<self_type&&>(aOther) }
177 template <
typename T, std::enable_if_t<!std::is_base_of_v<self_type, T> && !std::is_abstract_v<T>,
int> = 0>
182 template <
typename T, std::enable_if_t<!std::is_base_of_v<self_type, T> && !std::is_abstract_v<T>,
int> = 0>
187 template <
typename T, std::enable_if_t<!std::is_same_v<T, abstract_type> && std::is_abstract_v<T>,
int> = 0>
192 template <
typename T, std::enable_if_t<!std::is_same_v<T, abstract_type> && std::is_abstract_v<T>,
int> = 0>
199 template <
typename T, std::enable_if_t<std::is_base_of_v<self_type, T> && is_copy_assignable_v,
int> = 0>
202 std_type::operator=(aOther);
205 template <
typename T, std::enable_if_t<std::is_base_of_v<self_type, T> && is_move_assignable_v,
int> = 0>
208 std_type::operator=(std::move(aOther));
211 template <
typename T, std::enable_if_t<std::is_same_v<T, abstract_type> && is_copy_assignable_v,
int> = 0>
214 std_type::operator=(
static_cast<self_type const&
>(aOther));
217 template <
typename T, std::enable_if_t<std::is_same_v<T, abstract_type> && is_move_assignable_v,
int> = 0>
220 std_type::operator=(
static_cast<self_type&&
>(aOther));
223 template <
typename T, std::enable_if_t<!std::is_base_of_v<self_type, T> && !std::is_abstract_v<T>,
int> = 0>
226 std_type::operator=(aValue);
229 template <
typename T, std::enable_if_t<!std::is_base_of_v<self_type, T> && !std::is_abstract_v<T>,
int> = 0>
232 std_type::operator=(std::move(aValue));
235 template <
typename T, std::enable_if_t<!std::is_same_v<T, abstract_type> && std::is_abstract_v<T>,
int> = 0>
238 std_type::operator=(
static_cast<from_abstract_t<T, Types...
> const&>(aValue));
241 template <
typename T, std::enable_if_t<!std::is_same_v<T, abstract_type> && std::is_abstract_v<T>,
int> = 0>
244 std_type::operator=(
static_cast<from_abstract_t<T, Types...
>&&>(aValue));
251 return std_type::index();
255 void const* ptr()
const override
257 void const* result =
nullptr;
258 std::visit([&](
auto&& arg)
266 return const_cast<void*
>(
to_const(*this).ptr());
270 template <
typename... Types>
273 return std::holds_alternative<std::monostate>(rhs);
276 template <
typename... Types>
279 return std::holds_alternative<std::monostate>(lhs);
282 template <
typename... Types>
285 return !std::holds_alternative<std::monostate>(rhs);
288 template <
typename... Types>
291 return !std::holds_alternative<std::monostate>(lhs);
294 template <
typename... Types>
297 return static_cast<std::variant<std::monostate, Types...
> const&>(lhs) ==
static_cast<std::variant<std::monostate, Types...
> const&>(rhs);
300 template <
typename... Types>
303 return static_cast<std::variant<std::monostate, Types...
> const&>(lhs) !=
static_cast<std::variant<std::monostate, Types...
> const&>(rhs);
306 template <
typename... Types>
309 return static_cast<std::variant<std::monostate, Types...
> const&>(lhs) <
static_cast<std::variant<std::monostate, Types...
> const&>(rhs);
312 template <
typename... Types>
315 return static_cast<std::variant<std::monostate, Types...
> const&>(lhs) <=
static_cast<std::variant<std::monostate, Types...
> const&>(rhs);
318 template <
typename... Types>
321 return static_cast<std::variant<std::monostate, Types...
> const&>(lhs) >
static_cast<std::variant<std::monostate, Types...
> const&>(rhs);
324 template <
typename... Types>
327 return static_cast<std::variant<std::monostate, Types...
> const&>(lhs) >=
static_cast<std::variant<std::monostate, Types...
> const&>(rhs);
330 template <
typename... Types>
333 return static_cast<std::variant<std::monostate, Types...
> const&>(lhs) <=>
static_cast<std::variant<std::monostate, Types...
> const&>(rhs);
337 template <
typename T,
typename Variant>
340 return std::get<std::decay_t<T>>(var);
344 template <
typename T,
typename Variant>
347 return std::get<std::decay_t<T>>(var);
352 template <
typename T,
typename Variant>
355 typedef T result_type;
356 std::optional<result_type> result;
357 visit([&result](
auto&& source)
359 typedef std::remove_cv_t<std::remove_reference_t<
decltype(source)>> source_type;
360 if constexpr (std::is_arithmetic_v<source_type>)
361 result =
static_cast<result_type
>(source);
363 if (result != std::nullopt)
368 template <
typename T,
typename Variant>
371 typedef T result_type;
372 typedef std::remove_cv_t<std::remove_reference_t<result_type>> alternative_type;
373 visit([&var](
auto&& source)
375 typedef std::remove_cv_t<std::remove_reference_t<
decltype(source)>> source_type;
376 if constexpr (std::is_arithmetic_v<source_type> && !std::is_same_v<alternative_type, source_type>)
377 var =
static_cast<alternative_type
>(source);
379 return static_variant_cast<T>(var);
382 template<
typename T,
typename Variant, std::
size_t index = 0>
385 if constexpr (index == std::variant_size_v<Variant>)
387 else if constexpr (std::is_same_v<std::variant_alternative_t<index, Variant>, T>)
390 return variant_index_of<T, Variant, index + 1>();
static constexpr bool is_copy_assignable_v
static constexpr bool is_copy_constructible_v
std::size_t index() const override
self_type & operator=(T const &aOther)
static constexpr bool is_move_assignable_v
self_type & operator=(T &&aValue)
variant(abstract_type &&aOther)
static constexpr bool is_alternative_v
static constexpr bool is_move_constructible_v
self_type & operator=(T const &aValue)
std::variant< std::monostate, Types... > std_type
self_type & operator=(T &&aOther)
typename detail::abstract_type< T >::type abstract_t
T static_numeric_variant_cast(const Variant &var)
bool operator>=(variant< Types... > const &lhs, variant< Types... > const &rhs) noexcept
std::partial_ordering operator<=>(const i_container< T, ConstIteratorType, IteratorType > &lhs, const i_container< T, ConstIteratorType, IteratorType > &rhs)
bool operator>(variant< Types... > const &lhs, variant< Types... > const &rhs) noexcept
to_const_reference_t< T > to_const(T &&object)
constexpr std::size_t variant_index_of()
typename from_abstract_next< AbstractT, Type... >::result_type from_abstract_t
constexpr bool is_variant_convertible_v
auto & static_variant_cast(const Variant &var)
constexpr decltype(auto) visit(Visitor &&vis, neolib::variant< Types... > &&var)
constexpr bool holds_alternative(neolib::variant< Types... > const &var) noexcept
constexpr T & get(neolib::variant< Types... > &var)
bad_numeric_variant_cast()
from_abstract_next< AbstractT, Rest... >::result_type result_type
from_abstract< is_variant_convertible_v< AbstractT, Type >, AbstractT, Type, Rest >::result_type result_type
from_abstract< is_variant_convertible_v< AbstractT, Type >, AbstractT, Type, Rest... >::result_type result_type
from_abstract< is_variant_convertible_v< AbstractT, Type >, AbstractT, Type >::result_type result_type