C++ Logo


Advanced search

Re: [std-proposals] Concept Overloading in C++

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Tue, 19 Dec 2023 09:44:25 +0100
The concepts shown here are templates. It is about template specialization, not function overloading. Templates can also be specialized according to parameter values, functions can be overloaded only according to types and numbers of parameters.   So better compare concepts to templates than to functions.   -----Ursprüngliche Nachricht----- Von:JIMMY HU via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Di 19.12.2023 09:13 Betreff:[std-proposals] Concept Overloading in C++ An:New proposal discussion <std-proposals_at_[hidden]>; CC:JIMMY HU <s103360021_at_[hidden]>; Hi,  The meaning of function overloading is that two or more functions can have the same name but different parameters. In C++20, concept has been introduced. I think that the same logic should be applied to concepts in C++: two or more concepts can have the same name but different number of parameters, and the usage of concept depends on the number of given parameters.  Example: template<typenameT> concept is_summable = requires(T x) { x + x; };             //  one parameter version //  error: redefinition of concept 'is_summable' with different template parameters or requirements template<typenameT> concept is_summable = requires(T x, T y) { x + y; };        //  two parameter version template<is_summableT>                                     //  the usage of one parameter version voidfoo(Tinput) { } template<classT1, classT2> requires(is_summable<T1, T2>)                               //  the usage of two parameter version { } -- Jimmy Hu  Dec. 19, 2023  Email: s103360021_at_[hidden] <mailto:s103360021_at_[hidden]> -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2023-12-19 08:44:27