Class optional_variant_policy

Synopsis

#include <include/type_safe/variant.hpp>

class optional_variant_policy

Description

A variant policy for [ts::basic_variant]() that creates a variant with explicit empty state.

It allows an empty variant explicitly. When changing the type of the variant throws an exception, the variant will be left in that empty state. \module variant

Methods

change_value

Source

Lines 822-833 in include/type_safe/variant.hpp.

class optional_variant_policy
{
public:
    using allow_empty = std::true_type;

    template <typename T, typename... Types, typename... Args>
    static void change_value(union_type<T> type, tagged_union<Types...>& storage, Args&&... args)
    {
        destroy(storage);
        storage.emplace(type, std::forward<Args>(args)...);
    }
};





Add Discussion as Guest

Log in