C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Function overload set type information loss

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Wed, 31 Jul 2024 10:36:15 +0200
With function pointers you can achieve something like; in most cases even this is only possible at runtime: PFvvE PFvvE Just one function f. Just one function f. f<double> f<int> from https://godbolt.org/z/jz6qMn5f3 #include<iostream> usingnamespace std; template<typename T> void f() { cout << "Just one function f." << endl; } void printType(auto fkt) { if (fkt == f<double>) cout << "f<double>" << endl; if (fkt == f<int>) cout << "f<int>" << endl; } int main() { auto f1 = f<double>; auto f2 = f<int>; cout << typeid(f1).name() << endl; cout << typeid(f2).name() << endl; f1(); f2(); printType(f1); printType(f2); return0; }

Received on 2024-07-31 08:36:19