How to specify a concept that requires a const method?

May 3, 2023 at 5:20pm
Hi,

I have this:


1
2
3
4
class Circle : public GeoObj {
public:
    virtual void draw() const override;
};


So I have created a concept like this:

1
2
3
4
    template<typename T>
    concept GeoObject = requires(const T & x) {
        { x.draw() } -> std::convertible_to<void>;
    };


I require draw() to be a const method. Does this concept GeoObject ensure this is the case?

If not how can I change the concept in order that it enforces constness?

May 3, 2023 at 6:34pm
Yes, because it checks for x.draw() where x has type T const.

I think every type is convertible to void.
May 3, 2023 at 8:00pm
yes you are correct about every type being convertible to void!

Thanks!
Topic archived. No new replies allowed.