I just ran into something somewhat odd. I wonder if it's a bug, and if not I hope someone can explain the issue.
My issue is that when I create a templated function which takes an std::function as a defaulted parameter, I can only create one template instantiation of this function, otherwise I get an error.
Consider the following code:
#include <functional>
template<bool B>
void wut(std::function<void()> f = []() {})
{
f();
}
int main() {
wut<false>(); // works
wut<false>(); // still works
wut<true>(); // error
return 0;
}
When compiling this code I get the following error:
{standard input}: Assembler messages:
{standard input}:28: Error: symbol `_ZNSt14_Function_base13_Base_managerIUlvE_E10_M_managerERSt9_Any_dataRKS3_St18_Manager_operation' is already defined
{standard input}:127: Error: symbol `_ZNSt17_Function_handlerIFbvEUlvE_E9_M_invokeERKSt9_Any_data' is already defined