Consider the following code:
#include <vector>
#include <algorithm>
template<typename T, typename R, typename Op>
inline
std::vector<T>
transform_inline(const R & collection, Op op)
{
std::vector<T> result;
std::transform
(
std::begin(collection),
std::end(collection),
std::back_inserter(result),
op
);
return result;
}
extern "C"
{
void myFunc()
{
std::vector<std::pair<double,int>> data;
transform_inline<double>
(
data,
[](auto & o){ return o.first; }
);
}
}
It compiles in gcc and clang, but visual studio says:
<source>(31): error C2894: templates cannot be declared to have 'C' linkage
Microsoft (R) C/C++ Optimizing Compiler Version 19.10.25017 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
Compiler returned: 2
See: https://godbolt.org/g/vGvL4t
That error is normally for when you define the template in the extern "C" block, which is obviously not the case here.
Seems like a visual studio bug...Am I correct?
Any known workarounds?