C++ Logo

std-proposals

Advanced search

Re: [External] Non-type template overloading

From: Phil Bouchard <boost_at_[hidden]>
Date: Wed, 7 Apr 2021 16:57:08 -0400
Wow nice! I am clearly outdated ;)

--
Phil Bouchard
Founder
C.: (819) 328-4743
> On Apr 7, 2021, at 4:33 PM, D'Alessandro, Luke K via Std-Proposals <std-proposals_at_[hidden]> wrote:
> 
>  http://open-std.org/JTC1/SC22/WG21/docs/papers/2019/p1045r1.html
> 
>> On Apr 7, 2021, at 1:23 PM, Phil Bouchard via Std-Proposals <std-proposals_at_[hidden]> wrote:
>> 
>> This message was sent from a non-IU address. Please exercise caution when clicking links or opening attachments from external sources.
>> 
>> Greetings,
>> 
>> In some cases it would be useful to overload functions based on knowing if a variable is a compile-time constant or not. For example:
>> 
>> void foo(int size)
>> {
>>     cout << 1 << endl;
>> }
>> 
>> template <int Size>
>>     void foo(int Size)
>>     {
>>         cout << 2 << endl;
>>     }
>> 
>> int main(int argc, char * argv[])
>> {
>>     foo(argc); // outputs 1
>>     foo(sizeof(int)); // outputs 2
>> }
>> 
>> 
>> Regards,
>> 
>> --
>> 
>> Phil Bouchard
>> Founder
>> C.: (819) 328-4743
>> 
>> 
>> -- 
>> Std-Proposals mailing list
>> Std-Proposals_at_[hidden]
>> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> 
> -- 
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2021-04-07 15:57:14