diff --git a/_posts/2020-08-05-static-polymorphism.md b/_posts/2020-08-05-static-polymorphism.md index b563924..f4ee2dc 100644 --- a/_posts/2020-08-05-static-polymorphism.md +++ b/_posts/2020-08-05-static-polymorphism.md @@ -223,6 +223,18 @@ Alternate alternate form: ```c++ template +concept ConstMethod = + requires (const T a) { + { a.const_method() } -> std::same_as; + } && + requires (T a) { + { a.nonconst_method() } -> std::same_as; + { a.unnecessary_const_method() } -> std::same_as; + }; + +// Formulated inside a `requires` block: +/* +template concept ConstMethod = requires { requires requires (const T a) { { a.const_method() } -> std::same_as; @@ -233,6 +245,7 @@ concept ConstMethod = requires { { a.unnecessary_const_method() } -> std::same_as; }; }; +*/ ``` Third alternate form: @@ -240,21 +253,26 @@ Third alternate form: ```c++ template concept ConstMethods = requires (const T a) { - { a.const_method() } -> std::same_as; - }; + { a.const_method() } -> std::same_as; +}; template concept NonConstMethods = requires (T a) { - { a.nonconst_method() } -> std::same_as; - { a.unnecessary_const_method() } -> std::same_as; - }; + { a.nonconst_method() } -> std::same_as; + { a.unnecessary_const_method() } -> std::same_as; +}; +template +concept ConstMethod = ConstMethods && NonConstMethods; +// Formulated inside a requires block: +/* template concept ConstMethod = requires { requires ConstMethods; requires NonConstMethods; }; +*/ ``` ...which goes a long way towards explaining why the "requires requires" form is necessary. Not sure