C++ Logo

std-proposals

Advanced search

Re: [std-proposals] How should we tag a class? Use an empty base class or a typedef?

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Mon, 27 May 2024 12:59:22 +0100
On Sat, May 25, 2024 at 6:04 PM Frederick Virchanza Gotham wrote:
>
> So what should be the canonical way of doing this in C++26, not just
> for the standard library but also for programmers writing their own
> classes?


I'm thinking I'll go with the following strategy. The class
"std::elide" will contain a typedef as follows:

    typedef std::true_type tag_elide;

And then the constraint will be as follows:

    template<typename T>
    concept is_elider = T::tag_elide::value;

    template<typename... Params>
    requires (!( (1u==sizeof...(Params)) && (is_elider<Params> || ...) ))
    AwkwardClass(Params&&... arg) noexcept
    {
        . . .
    }

The benefit of this strategy is that you can derive your own class
from "std::elide" and change the tag from "true_type" to "false_type"
if you want to. I don't know why anyone would ever want to do that,
but the versatility and flexibility is there.

Received on 2024-05-27 11:59:35