C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Copy-construct, move-construct, and PR-construct

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 11 Sep 2023 14:45:53 +0100
On Sun, Sep 10, 2023 at 2:20 PM Frederick Virchanza Gotham wrote:
>
> If we were to instead mark the class, for example:


So we already looked at two possibilities:
(1) Mark the conversion operator
(2) Mark the class

The third possibility would be to have a base class that favours conversion:

    class Monkey : public std::priority_conversion< std::mutex > {
    public:
        operator std::mutex(void)
        {
            // return a mutex from in here
        }
    };

And so when the compiler encounters the invocation of a constructor
with just one argument, it checks to see if the argument is of a class
type that inherits from "std::priority_conversion", and if it does, it
invokes the conversion before passing the sole argument to the
constructor.

Received on 2023-09-11 13:46:10