17#ifndef IOX_HOOFS_CXX_VARIANT_HPP
18#define IOX_HOOFS_CXX_VARIANT_HPP
20#include "iceoryx_hoofs/cxx/algorithm.hpp"
21#include "iceoryx_hoofs/internal/cxx/variant_internal.hpp"
28#include "iceoryx_hoofs/platform/platform_correction.hpp"
43 static constexpr uint64_t value = N;
70static constexpr uint64_t INVALID_VARIANT_INDEX = std::numeric_limits<uint64_t>::max();
105template <
typename... Types>
110 static constexpr uint64_t TYPE_SIZE = algorithm::max(
sizeof(Types)...);
125 template <uint64_t N, typename... CTorArguments>
135 template <typename T, typename... CTorArguments>
141 template <typename T,
142 typename = std::enable_if_t<!std::is_same<std::decay_t<T>,
variant>::value>,
143 typename std::enable_if_t<!internal::is_in_place_index<std::decay_t<T>>::value,
bool> = false,
144 typename std::enable_if_t<!internal::is_in_place_type<std::decay_t<T>>::value,
bool> = false>
179 template <typename T>
180 typename std::enable_if<!std::is_same<T,
variant<Types...>&>::value,
variant<Types...>>::type&
181 operator=(T&& rhs) noexcept;
190 template <uint64_t TypeIndex, typename... CTorArguments>
199 template <typename T, typename... CTorArguments>
200 bool emplace(CTorArguments&&... args) noexcept;
211 template <uint64_t TypeIndex>
212 typename internal::get_type_at_index<0, TypeIndex, Types...>::type*
get_at_index() noexcept;
223 template <uint64_t TypeIndex>
224 const typename internal::get_type_at_index<0, TypeIndex, Types...>::type*
get_at_index() const noexcept;
231 template <typename T>
232 const T*
get() const noexcept;
239 template <typename T>
245 template <typename T>
253 template <typename T>
254 const T*
get_if(const T* defaultValue) const noexcept;
259 constexpr uint64_t
index() const noexcept;
262 alignas(algorithm::max(alignof(Types)...)) internal::byte_t m_storage[TYPE_SIZE]{0u};
263 uint64_t m_type_index = INVALID_VARIANT_INDEX;
266 template <
typename T>
267 bool has_bad_variant_element_access() const noexcept;
268 static
void error_message(const
char* source, const
char* msg) noexcept;
270 void call_element_destructor() noexcept;
274template <typename T, typename... Types>
275constexpr
bool holds_alternative(const
variant<Types...>&
variant) noexcept;
280#include "iceoryx_hoofs/internal/cxx/variant.inl"
Variant implementation from the C++17 standard with C++11. The interface is inspired by the C++17 sta...
Definition: variant.hpp:107
internal::get_type_at_index< 0, TypeIndex, Types... >::type * get_at_index() noexcept
returns a pointer to the type stored at index TypeIndex. (not stl compliant)
bool emplace_at_index(CTorArguments &&... args) noexcept
calls the constructor of the type at index TypeIndex and perfectly forwards the arguments to this con...
constexpr uint64_t index() const noexcept
returns the index of the stored type in the variant. if the variant does not contain any type it retu...
constexpr variant() noexcept=default
the default constructor constructs a variant which does not contain an element and returns INVALID_VA...
T * get_if(T *defaultValue) noexcept
returns a pointer to the type T if its stored in the variant otherwise it returns the provided defaul...
bool emplace(CTorArguments &&... args) noexcept
calls the constructor of the type T and perfectly forwards the arguments to the constructor of T.
const T * get() const noexcept
returns a pointer to the type T stored in the variant. (not stl compliant)
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:29
helper struct to perform an emplacement at a predefined index in the constructor of a variant
Definition: variant.hpp:42
helper struct to perform an emplacement of a predefined type in in the constructor of a variant
Definition: variant.hpp:54