C++ Logo

std-proposals

Advanced search

Non-type template overloading

From: Phil Bouchard <boost_at_[hidden]>
Date: Wed, 7 Apr 2021 16:23:31 -0400
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

Received on 2021-04-07 15:23:37