diff --git a/_posts/2020-08-05-static-polymorphism.md b/_posts/2020-08-05-static-polymorphism.md index b8dda6f..b563924 100644 --- a/_posts/2020-08-05-static-polymorphism.md +++ b/_posts/2020-08-05-static-polymorphism.md @@ -219,8 +219,46 @@ int main() { } ``` -May be better off defining `const T` methods in one concept, `T` methods in another, and then having -one concept that `requires` the sub-concepts, but just trying to demonstrate what is possible. +Alternate alternate form: + +```c++ +template +concept ConstMethod = requires { + requires requires (const T a) { + { a.const_method() } -> std::same_as; + }; + + requires requires (T a) { + { a.nonconst_method() } -> std::same_as; + { a.unnecessary_const_method() } -> std::same_as; + }; +}; +``` + +Third alternate form: + +```c++ +template +concept ConstMethods = requires (const T a) { + { 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; + }; + + +template +concept ConstMethod = requires { + requires ConstMethods; + requires NonConstMethods; +}; +``` + +...which goes a long way towards explaining why the "requires requires" form is necessary. Not sure +what the "best practices" form is, just trying to demonstrate what is possible. Working with `const` parameters can be a bit weird because of implicit copies: