Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chaining implicit conversion operators

I've got a class which I need to implicitly convert to a few things, with intermediate values, e.g.

struct outer {
    struct inner {
        operator T() { return T(); }
    };
    operator inner() { return inner(); }
};

If I have this structure, is it always valid to do, e.g.

void f(T t);
outer o;
f(o);
like image 707
Puppy Avatar asked Aug 25 '26 06:08

Puppy


1 Answers

§13.3.3.1.2 [over.ics.user] p1

A user-defined conversion sequence consists of an initial standard conversion sequence followed by a user-defined conversion (12.3) followed by a second standard conversion sequence.

Notice the singular and the missing of the word "sequence". Only one user-defined conversion will ever be considered during an implicit conversion sequence.

like image 192
Xeo Avatar answered Aug 27 '26 19:08

Xeo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!