Challenge: adding new method overloads when existing consumers use {} with args
David Hurka
david.hurka at mailbox.org
Sat Jul 23 19:31:20 BST 2022
On Saturday, July 23, 2022 8:26:47 PM CEST David Hurka wrote:
> > Had not yet thought about this challenge myself before, so curious what
> > people think can be done here?
>
> Would it work to make foo(B) less tasty for implicit conversion with
> std::variant (or another small wrapper)?
>
> ```
> class C
> {
> public:
> void foo(A a);
> /** @since ... */
> void foo(std::variant<B> b);
> };
> ```
>
> My assumption is that std::variant requires a “user-defined conversion” [1],
> and therefore an explicitly provided B object can be implicitly converted
> to a std::variant<B>, but the ambiguous {} can’t.
[1] https://en.cppreference.com/w/cpp/language/implicit_conversion#Order_of_the_conversions
More information about the kde-devel
mailing list