Converts a variant to a variant of another set of types.
Declared in <absl/types/variant.h>
template<
typename To,
typename Variant>
To
ConvertVariantTo(Variant&& variant);
Each alternative of the target variant must be constructible from any type held by the source variant.
Example:
std::variant<name1, name2, float> InternalReq(const Req&);
// name1 and name2 are convertible to name std::variant<name, float> ExternalReq(const Req& req) { return absl::ConvertVariantTo<std::variant<name, float>>( InternalReq(req)); }
A To constructed from the active alternative of variant.
| Name | Description |
|---|---|
| variant | The source variant to convert. |