|
Boost : |
Subject: [boost] Mother of all Variants
From: Robert Ramey (ramey_at_[hidden])
Date: 2019-04-16 01:51:57
I'm way out of my depth in the variant discussion. Seems to me it
revolves around all the trade offs regarding design choices. Could we
perhaps decide not to decide. Suppose we create a type which looks like:
template<
bool BasicGuaranteeSupported,
bool StrongGuaranteeSupported,
bool EmptyStateProhibited,
bool AssignmentSupported,
bool MoveSupported,
class T ...
>
struct mother_of_variants{
// some trivial mp11 code
};
Now we could define:
using boost_variant = mother_of_all variants<
bool true, //BasicGuaranteeSupported,
bool true, //StrongGuaranteeSupported,
bool true, //EmptyStateProhibited,
bool true, //AssignmentSupported,
bool true, //MoveSupported,
>;
std_variant, std_optional, std_expect, boost_outcome, etc. would be
similarly defined. And some "extras" like no_except_variant,
trivial_variant, etc. would be added.
and of course my favorite candidate:
using safe_variant = mother_of_all variants<
bool true, //BasicGuaranteeSupported,
bool true, //StrongGuaranteeSupported,
bool true, //EmptyStateProhibited,
bool false, //AssignmentSupported,
bool false //MoveSupported,
>;
In addition, we'd have some type traits:
mother_of_all_variants::no_runtime_allocation<mov>;
mother_of_all_variants::no_double_instancen<mov>;
mother_of_all_variants::is_mother_of_all_variants<mov>;
etc.
Just think that of all the time we've spent on discussions about
optional, expected, std::variant, boost::variant, etc. At this rate,
these discussions will keep hounding us forever. Of course I realize
that the main purpose of having these variants of variants is to justify
the discussions - but perhaps we might be ready for a new topic.
Robert Ramey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk