I have the following function in one of my utility header files.
template<typename T>
static void rtrim(std::basic_string<T, std::char_traits<T>, std::allocator<T>> &t)
{
t.erase(find_if(t.rbegin(), t.rend(),
[](T& c)->bool{ return !isspace(c); }).base(), t.end());
}
I am building the code with Visual Studio 2012 with pre-compiled headers on (/Yu). The build fails with the following error.
1>stdafx.obj : error LNK2005: "public: void __cdecl ::operator()(class std::basic_string,class std::allocator > const &)const " (??R@@QEBAXAEBV?$basic_string@_WU?$char_traits@_W@std@@V?$allocator@_W@2@@std@@@Z) already defined in
If I remove /Yu
flag, it builds fine. Does it mean lambdas cannot be used with precompiled headers? Is there a work around?