C++ Logo

std-proposals

Advanced search

Re: [std-proposals] std::arithmetic (concept)

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Thu, 17 Apr 2025 13:11:02 +0200
So etwas?   template <typename T> requires std::is_base_of_v<MyString, std::remove_cvref_t<T>> constexpr bool enable_arithmetic<T> = true;   -----Ursprüngliche Nachricht----- Von:Frederick Virchanza Gotham via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Do 17.04.2025 12:44 Betreff:Re: [std-proposals] std::arithmetic (concept) An:std-proposals_at_[hidden]; CC:Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>; On Thu, Apr 17, 2025 at 10:54 AM Sebastian Wittmeier wrote: > > Can you also use inheritance with the first way? By specializing the template or disallowing for derived types. No I don't think the first way can accommodate derived classes. In order to adapt the first way to work with derived class, I think you'd have to do something like the following:    class IsArithmetic {};    class MyString : IsArithmetic {    public:        MyString(char const*){}        template<typename T>        MyString &operator+=(T&&){ return *this; }    };    template <typename T>    concept arithmetic = std::is_arithmetic_v<T> || std::is_base_of_v< IsArithmetic, MyString >; As you can see, there's maybe 3 or 4 or 5 ways of 'tagging' a class. Which I think is why we should standardise it, and give it the feature that you can specify whether the tag is inherited or not, and perhaps be able to mark any given derived class as opting out of inheriting tags from its base classes. So maybe something like:    class MyString {        _Tag arithmetic;    };    class MyDerivedString : public MyString {};  // automatically has the 'arithmetic' tag    class MyOtherDerivedString : public notags MyString {};  // doesn't inherit any tags from MyString And then maybe consider allowing the addition of tag outside of the class:    class MyString {};    _Tag arithmetic >> MyString; -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-04-17 11:17:25