12#include "_detail/variant_helper.hpp"
40 template <
size_t I,
class T>
47 template <
class... TS>
50 static_assert(Detail::NoneIs<std::is_void<TS>::value...>,
"CVB: void types are not allowed");
51 static_assert(Detail::NoneIs<std::is_reference<TS>::value...>,
"CVB: reference types are not allowed");
52 static_assert(Detail::NoneIs<std::is_const<TS>::value...>,
"CVB: const types are not allowed");
53 static_assert(Detail::NoneIs<std::is_volatile<TS>::value...>,
"CVB: volatile types are not allowed");
55#pragma region friend access
56 template <
size_t I,
class... ETS>
58 template <
size_t I,
class... ETS>
60 template <
size_t I,
class... ETS>
62 template <
class... ETS>
64 template <
class... ETS>
68 static const constexpr size_t StorageSize = Detail::Max<
sizeof(TS)...>;
69 static const constexpr size_t StorageAlignment = Detail::Max<
alignof(TS)...>;
78 void delete_if_valid()
noexcept;
83 const constexpr auto exactIndex = Detail::IndexOf<T, TS...>;
84 const constexpr auto newIndex = exactIndex !=
variant_npos ? exactIndex : Detail::IndexOfAssignable<T, TS...>;
85 static_assert(newIndex !=
variant_npos,
"CVB: assigned type not compatible to alternatives list");
87 using NewT = Detail::TypeAt<newIndex, TS...>;
102 new (&data_) Detail::TypeAt<0, TS...>{};
147 template <class T, typename std::enable_if<!std::is_same<T, variant &>::value,
int>::type = 0>
165 template <class T, typename std::enable_if<!std::is_same<T, variant &>::value,
int>::type = 0>
180 template <
size_t I,
class... ARGS>
190 template <
class T,
class... ARGS>
193 const constexpr auto newIndex = Detail::IndexOf<T, TS...>;
194 static_assert(newIndex !=
variant_npos,
"CVB: assigned type not in alternatives list");
225#pragma region monostate
284#pragma region variant_alternative
286 template <
size_t I,
class... TS>
289 using type = Detail::TypeAt<I, TS...>;
292 template <
size_t I,
class T>
297 template <
size_t I,
class T>
298 struct variant_alternative<I, const T> : variant_alternative<I, typename std::remove_reference<T>::type>
302 template <
size_t I,
class T>
307 template <
size_t I,
class T>
315 template <
size_t I,
class T>
320#pragma region variant_size
329 template <
class... TS>
345 struct variant_size<volatile T> : variant_size<typename std::remove_reference<T>::type>
381 template <
size_t I,
class... TS>
384 static_assert(I <
sizeof...(TS),
"CVB: alternative index out of range");
385 if (I != var.
index())
395 template <
size_t I,
class... TS>
398 static_assert(I <
sizeof...(TS),
"CVB: alternative index out of range");
399 if (I != var.
index())
409 template <
size_t I,
class... TS>
412 static_assert(I <
sizeof...(TS),
"CVB: alternative index out of range");
413 if (I != var.index())
439 template <
class T,
class... TS>
442 static const constexpr size_t index = Detail::IndexOf<T, TS...>;
452 template <
class T,
class... TS>
455 static const constexpr size_t index = Detail::IndexOf<T, TS...>;
465 template <
class T,
class... TS>
468 static const constexpr size_t index = Detail::IndexOf<T, TS...>;
476#pragma region get_if<I>
489 template <
size_t I,
class... TS>
491 get_if(
const variant<TS...> *pvar)
noexcept
493 if (!pvar || pvar->index() != I)
503 template <
size_t I,
class... TS>
506 if (!pvar || pvar->index() != I)
514#pragma region get_if<I>
532 template <
class T,
class... TS>
535 static const constexpr size_t index = Detail::IndexOf<T, TS...>;
545 template <
class T,
class... TS>
548 static const constexpr size_t index = Detail::IndexOf<T, TS...>;
556#pragma region holds_alternative
566 template <
class T,
class... TS>
569 static_assert(Detail::Contains<T, TS...>,
"CVB: alternative is not contained in variant.");
570 return var.index() == Detail::IndexOf<T, TS...>;
577#pragma region VisitHelper
583 template <
class T,
size_t COUNT,
size_t I = 0>
586 template <
class VISITOR,
class VARIANT>
587 T operator()(VISITOR &&visitor, VARIANT &&var)
const
589 if (I == var.index())
596 template <
class T,
size_t COUNT>
597 struct VisitHelper1<T, COUNT, COUNT>
599 template <
class VISITOR,
class VARIANT>
600 T operator()(VISITOR &&, VARIANT &&)
const
602 throw bad_variant_access{};
621 template <
class VISITOR,
class VARIANT>
622 auto visit(VISITOR &&visitor, VARIANT &&var) ->
decltype(visitor(get<0>(var)))
624 using RESULT =
decltype(visitor(get<0>(var)));
625 using HELPER = Detail::VisitHelper1<RESULT, variant_alternatives_size_v<VARIANT>>;
622 auto visit(VISITOR &&visitor, VARIANT &&var) ->
decltype(visitor(get<0>(var))) {
…}
632#pragma region comparison operators
644 template <
class... TS>
661 template <
class... TS>
664 return !(lhs == rhs);
680 template <
class... TS>
685 || (lhs.
index() == rhs.
index() &&
visit(Detail::VariantLess{&lhs.data_}, rhs)));
696 template <
class... TS>
710 template <
class... TS>
724 template <
class... TS>
732#pragma region variant copy
734 template <
class... TS>
738 visit(Detail::VariantCopier{&data_}, rhs);
741 template <
class... TS>
747 visit(Detail::VariantCopier{&data_}, rhs);
756#pragma region variant move
758 template <
class... TS>
765 rhs.delete_if_valid();
773 template <
class... TS>
781 rhs.delete_if_valid();
789#pragma region variant swap
791 template <
class... TS>
803#pragma region variant::delete_if_valid
806 template <
class... TS>
807 void variant<TS...>::delete_if_valid() noexcept
811 if (!valueless_by_exception())
813 visit(Detail::VariantDestructor{}, *
this);
825#pragma region variant::emplace<I>
827 template <
class... TS>
828 template <
size_t I,
class... ARGS>
831 using NewT = Detail::TypeAt<I, TS...>;
851 template <
class... TS>
Error when accessing not set alternative.
Definition variant.hpp:26
bad_variant_access()=default
Default ctor.
This class is a replacement for C++17 std::variant.
Definition variant.hpp:49
variant & operator=(const variant &rhs)
Copy operator.
Definition variant.hpp:742
size_t index() const noexcept
Gets the zero-based index of the alternative held by this instance.
Definition variant.hpp:202
bool valueless_by_exception() const noexcept
Returns false only if this instance holds a value.
Definition variant.hpp:219
bool operator<=(const variant< TS... > &lhs, const variant< TS... > &rhs)
Less-than or equal operator for Shims::variant object.
Definition variant.hpp:697
variant() noexcept
Default ctor creating a variant with default value of the first alternative type.
Definition variant.hpp:99
variant(T &&value)
Ctor from an object of supported type T.
Definition variant.hpp:148
variant & operator=(T &&value)
Assignment from an object of supported type T.
Definition variant.hpp:166
static const constexpr size_t variant_alternatives_size_v
Get the number of alternatives in a variant.
Definition variant.hpp:359
std::add_pointer< constT >::type get_if(const variant< TS... > *pvar) noexcept
Tries to get the value of the given Shims::variant pointer pvar as the alternative with type T.
Definition variant.hpp:533
bool operator>(const variant< TS... > &lhs, const variant< TS... > &rhs)
Greater-than operator for Shims::variant object.
Definition variant.hpp:711
auto visit(VISITOR &&visitor, VARIANT &&var) -> decltype(visitor(get< 0 >(var)))
Visits the given Shims::variant var. Cvb::Shims::visit can only visit one variant (not multiple like ...
Definition variant.hpp:622
~variant() noexcept
Destructor.
Definition variant.hpp:106
void swap(variant &other)
Swaps the content of this variant with the other one.
Definition variant.hpp:792
std::add_pointer< T >::type get_if(variant< TS... > *pvar) noexcept
Tries to get the value of the given Shims::variant pointer pvar as the alternative with type T.
Definition variant.hpp:546
T & emplace(ARGS &&...args)
Emplaces an object as a type T.
Definition variant.hpp:191
const variant_alternative_t< I, variant< TS... > > & get(const variant< TS... > &var)
Gets the value of the given Shims::variant var as the alternative with index I.
Definition variant.hpp:382
bool operator<(const variant< TS... > &lhs, const variant< TS... > &rhs)
Less than operator for Shims::variant objects.
Definition variant.hpp:681
std::add_pointer< variant_alternative_t< I, variant< TS... > > >::type get_if(variant< TS... > *pvar) noexcept
Tries to get the value of the given Shims::variant pointer pvar as the alternative with index I.
Definition variant.hpp:504
T get(variant< TS... > &&var)
Gets the value of the given Shims::variant var as the alternative with type T.
Definition variant.hpp:466
variant_alternative_t< I, variant< TS... > > get(variant< TS... > &&var)
Gets the value of the given Shims::variant var as the alternative with index I.
Definition variant.hpp:410
variant_alternative< I, variant< TS... > >::type & emplace(ARGS &&...args)
Emplaces an object as alternative at index I.
Definition variant.hpp:829
bool operator>=(const variant< TS... > &lhs, const variant< TS... > &rhs)
Greater-than or equal operator for Shims::variant object.
Definition variant.hpp:725
bool operator!=(const variant< TS... > &lhs, const variant< TS... > &rhs)
Inequality operator for Shims::variant objects.
Definition variant.hpp:662
variant_alternative_t< I, variant< TS... > > & get(variant< TS... > &var)
Gets the value of the given Shims::variant var as the alternative with index I.
Definition variant.hpp:396
T & get(variant< TS... > &var)
Gets the value of the given Shims::variant var as the alternative with type T.
Definition variant.hpp:453
bool holds_alternative(const variant< TS... > &var) noexcept
Gets whether the Shims::variant var holds an instance of type T.
Definition variant.hpp:567
bool operator==(const variant< TS... > &lhs, const variant< TS... > &rhs)
Equality operator for Shims::variant objects.
Definition variant.hpp:645
const T & get(const variant< TS... > &var)
Gets the value of the given Shims::variant var as the alternative with type T.
Definition variant.hpp:440
bad_variant_access()=default
Default ctor.
Namespace to for standard types that are not available in C++14.
Definition variant_helper.hpp:20
static const constexpr size_t variant_npos
Returned by variant::index() on invalid state.
Definition variant.hpp:33
typename variant_alternative< I, T >::type variant_alternative_t
Helper type alias for Shims::variant_alternative.
Definition variant.hpp:316
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
static const constexpr size_t variant_npos
Returned by variant::index() on invalid state.
Definition variant.hpp:33
Unit type intended for use as a well-behaved empty alternative in Shims::variant.
Definition variant.hpp:237
constexpr bool operator>=(monostate, monostate) noexcept
Definition variant.hpp:263
constexpr bool operator!=(monostate, monostate) noexcept
Definition variant.hpp:277
constexpr bool operator<(monostate, monostate) noexcept
Definition variant.hpp:242
constexpr bool operator==(monostate, monostate) noexcept
Definition variant.hpp:270
constexpr bool operator<=(monostate, monostate) noexcept
Definition variant.hpp:256
constexpr bool operator>(monostate, monostate) noexcept
Definition variant.hpp:249
Compile-time index access to the type of the alternatives at index I.
Definition variant.hpp:41
Get the number of alternatives in a variant.
Definition variant.hpp:327