C++ Logo


Advanced search

Re: [std-proposals] Allow downcasting at compile time if Derived has no extra member objects

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 23 Feb 2023 12:30:33 +0000
On Thu, Feb 23, 2023 at 11:26 AM Jonathan Wakely wrote:
> They might be good ideas, or they might not, but proposing things for standardization
> as soon as you think of them is not a good use of anybody's time.

There are some ideas that you can jump straight into, and immediately
float among the community to get people thinking, although perhaps
instead of just allowing 'static_cast' in the way I described, maybe
there should be a new keyword such as 'interface' or 'facade',
something like:

    namespace std {
        class binary_semaphore { /* stuff goes here */ };

       interface lockable_binary_semaphore : binary_semaphore {
           void lock (void) noexcept(false) { return this->acquire(); }
           void unlock(void) noexcept(false) { return this->release(); }

If the new function has the same signature as the old function, then
maybe allow the following shorthand:

    interface lockable_binary_semaphore : binary_semaphore {
        lock = acquire;
        unlock = release;

And then in the code we could do:

    extern std::binary_semaphore g_sem;

    int main(void)
        std::lock_guard<lockable_binary_semaphore>( g_sem ); //
implicit conversion from binary_semaphore& to

Received on 2023-02-23 12:30:45