Date: Sun, 3 Sep 2023 20:22:53 +0100
On Sun, Sep 3, 2023 at 7:52 PM Jason McKesson via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> A more reasonable idea is to tag either the class as a whole or the
> conversion operator with an actual language feature. That feature
> would mean that, when the type is used as the source of an implicit
> conversion (or the specific operator is possible in such a
> conversion), constructors on the destination type are ignored. I'm not
> sure if an existing keyword can be used here (`explicit` is absolutely
> the wrong one), but there would need to be some property applied to
> the type/operator itself. It could even in theory be a contextual
> keyword like `final`.
Something like:
struct Monkey final {
operator mutex(void) priority
{
// our code in here returns a mutex
}
};
If a conversion operator is marked as 'priority' then in the following
circumstance:
::new(p) T( Monkey() );
Even if T has a template constructor that could accept an object of
type 'Monkey', the compiler instead will search inside the class
'Monkey' for a conversion operator marked 'priority', and if found,
will invoke it. Two rules for marking a conversion operator as
'priority':
(Rule 1) A class definition shall contain at most one conversion
operator marked as 'priority'.
(Rule 2) Only a class marked as 'final' may contain a conversion
operator marked as 'priority'.
<std-proposals_at_[hidden]> wrote:
>
> A more reasonable idea is to tag either the class as a whole or the
> conversion operator with an actual language feature. That feature
> would mean that, when the type is used as the source of an implicit
> conversion (or the specific operator is possible in such a
> conversion), constructors on the destination type are ignored. I'm not
> sure if an existing keyword can be used here (`explicit` is absolutely
> the wrong one), but there would need to be some property applied to
> the type/operator itself. It could even in theory be a contextual
> keyword like `final`.
Something like:
struct Monkey final {
operator mutex(void) priority
{
// our code in here returns a mutex
}
};
If a conversion operator is marked as 'priority' then in the following
circumstance:
::new(p) T( Monkey() );
Even if T has a template constructor that could accept an object of
type 'Monkey', the compiler instead will search inside the class
'Monkey' for a conversion operator marked 'priority', and if found,
will invoke it. Two rules for marking a conversion operator as
'priority':
(Rule 1) A class definition shall contain at most one conversion
operator marked as 'priority'.
(Rule 2) Only a class marked as 'final' may contain a conversion
operator marked as 'priority'.
Received on 2023-09-03 19:23:05