"fpclassify': ambiguous call to overloaded function - c++

I have a very similar problem to this one: How to resolve "fpclassify': ambiguous call to overloaded function
I have a large project with about 100 cpp-files and 100 header-files that work fine in Codeblocks using GNU GCC compiler, but I want to migrate the project to VS19. It seems to work fine except for one error: "fpclassify': ambiguous call to overloaded function
The error list in VS19 tells me it is located in corecrt_math.h on a return value at line 415:
template <class _Ty>
_Check_return_ inline bool isnan(_In_ _Ty _X) throw()
{
return fpclassify(_X) == FP_NAN;
}
When looking into my code I see that I use std::isna in 13 files, 24 locations (the error list does not refer to these places at all). However, unlike the problem that I linked to above, I do not see that I check if an int is na anywhere. Instead I have cases like this:
if (std::isnan(static_cast<double> (min)) && std::isnan(static_cast<double> (max)))
simulation_error("Error: No limits");
Where minand max are defined as const double & min = NAN and const double & max = NAN (min and max are set in the constructor).
Do you have any idea on how to find the error and how to solve it? I tried many hours yesterday - without any success.
Edit:
Full error message below:
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(415,1): error C2668: 'fpclassify': ambiguous call to overloaded function
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(300,31): message : could be 'int fpclassify(long double) noexcept'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(295,31): message : or 'int fpclassify(double) noexcept'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(290,31): message : or 'int fpclassify(float) noexcept'
1>C:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt\corecrt_math.h(415,1): message : while trying to match the argument list '(_Ty)'
1> with
1> [
1> _Ty=bool
1> ]
1>C:\Users\Name\Documents\C++\Project name\Project name\src\module.cpp(668): message : see reference to function template instantiation 'bool isnan<bool>(_Ty) noexcept' being compiled
1> with
1> [
1> _Ty=bool
1> ]
Which refers to:
std::vector<double> stoprule_rel;,
if (!(std::isnan(static_cast<double> (stoprule_rel[i])

The error message like fpclassify': ambiguous call to overloaded function is always accompanied by notes. For example, for a simple program
#include <cmath>
int main() {
std::isnan(5);
}
VS complains:
corecrt_math.h(415): error C2668: 'fpclassify': ambiguous call to overloaded function
corecrt_math.h(300): note: could be 'int fpclassify(long double) throw()'
corecrt_math.h(295): note: or 'int fpclassify(double) throw()'
corecrt_math.h(290): note: or 'int fpclassify(float) throw()'
corecrt_math.h(415): note: while trying to match the argument list '(_Ty)'
with [ _Ty=int ]
<source>(3): note: see reference to function template instantiation 'bool isnan<int>(_Ty) throw()' being compiled
with [ _Ty=int ]
From these notes we can infer that _Ty is int and that std::nan was called on the line 3 of our source code. Take a look at the full compiler output for your compilation, it will tell you the exact place in your code where the error is triggered.

Related

Having trouble making a thread for a member function with parameters | C++ | WxWidgets

My thread gives me no errors before compilation, but upon compilation, I get this error...
Error code:
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\thread(55,14): error C2672: 'invoke': no matching overloaded function found
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\thread(62): message : see reference to function template instantiation 'unsigned int std::thread::_Invoke<_Tuple,0,1,2,3,4>(void *) noexcept' being compiled
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\thread(66): message : see reference to function template instantiation 'unsigned int (__cdecl *std::thread::_Get_invoke<_Tuple,0,1,2,3,4>(std::integer_sequence<size_t,0,1,2,3,4>) noexcept)(void *) noexcept' being compiled
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\thread(89): message : see reference to function template instantiation 'void std::thread::_Start<_Ty,std::vector<std::string,std::allocator<std::string>>&,std::vector<std::string,std::allocator<std::string>>&,std::vector<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>,std::allocator<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>>>&,std::vector<std::string,std::allocator<std::string>>&>(_Fn &&,std::vector<std::string,std::allocator<std::string>> &,std::vector<std::string,std::allocator<std::string>> &,std::vector<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>,std::allocator<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>>> &,std::vector<std::string,std::allocator<std::string>> &)' being compiled
1> with
1> [
1> _Ty=void (__cdecl MyFrame::* )(std::vector<std::string,std::allocator<std::string>>,std::vector<std::string,std::allocator<std::string>>,std::vector<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>,std::allocator<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>>>,std::vector<std::string,std::allocator<std::string>>),
1> _Fn=void (__cdecl MyFrame::* )(std::vector<std::string,std::allocator<std::string>>,std::vector<std::string,std::allocator<std::string>>,std::vector<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>,std::allocator<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>>>,std::vector<std::string,std::allocator<std::string>>)
1> ]
1>C:\Users\Me\C++\Data-Mange-Bot-C++ver\DataManageApp\main.cpp(2578): message : see reference to function template instantiation 'std::thread::thread<void(__cdecl MyFrame::* )(std::vector<std::string,std::allocator<std::string>>,std::vector<std::string,std::allocator<std::string>>,std::vector<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>,std::allocator<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>>>,std::vector<std::string,std::allocator<std::string>>),std::vector<std::string,std::allocator<std::string>>&,std::vector<std::string,std::allocator<std::string>>&,std::vector<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>,std::allocator<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>>>&,std::vector<std::string,std::allocator<std::string>>&,0>(_Fn &&,std::vector<std::string,std::allocator<std::string>> &,std::vector<std::string,std::allocator<std::string>> &,std::vector<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>,std::allocator<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>>> &,std::vector<std::string,std::allocator<std::string>> &)' being compiled
1> with
1> [
1> _Fn=void (__cdecl MyFrame::* )(std::vector<std::string,std::allocator<std::string>>,std::vector<std::string,std::allocator<std::string>>,std::vector<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>,std::allocator<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>>>,std::vector<std::string,std::allocator<std::string>>)
1> ]
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\thread(51,5): error C2893: Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Ty1 &&,_Types2 &&...) noexcept(<expr>)'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\type_traits(1482): message : see declaration of 'std::invoke'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\thread(51,5): message : With the following template arguments:
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\thread(51,5): message : '_Callable=void (__cdecl MyFrame::* )(std::vector<std::string,std::allocator<std::string>>,std::vector<std::string,std::allocator<std::string>>,std::vector<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>,std::allocator<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>>>,std::vector<std::string,std::allocator<std::string>>)'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\thread(51,5): message : '_Ty1=std::vector<std::string,std::allocator<std::string>>'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\thread(51,5): message : '_Types2={std::vector<std::string,std::allocator<std::string>>, std::vector<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>,std::allocator<std::variant<std::string,std::vector<std::string,std::allocator<std::string>>>>>, std::vector<std::string,std::allocator<std::string>>}'
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\thread(51,5): error C2780: 'unknown-type std::invoke(_Callable &&) noexcept(<expr>)': expects 1 arguments - 5 provided
1>C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\type_traits(1476): message : see declaration of 'std::invoke'
This is despite following the solution provided in this question. Although the difference here is that I have multiple parameters and I'm starting the thread inside another member function.
I've looked at online resources and haven't turned up anything, if anyone can help that would be great.
Code:
class MyFrame : public wxFrame{
public:
MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
private:
void RightSearchBarTextChange(wxCommandEvent& event);
void RightSearchResultsCreate(std::vector<std::string> CategoryFilterMap, std::vector<std::string> SubCategoryFilterMap, std::vector<std::variant<std::string, std::vector<std::string>>> DateFilterMap, std::vector<std::string> TagFilterMap);
}
void MyFrame::RightSearchBarTextChange(wxCommandEvent& event) {
std::thread thread_object(&MyFrame::RightSearchResultsCreate, RightSearchCategoryFilterSelectedVector, RightSearchSubCategoryFilterSelectedVector, RightSearchDateFilterSelectedVector, RightSearchTagFilterSelectedVector);
thread_object.join();
}
void MyFrame::RightSearchResultsCreate(std::vector<std::string> CategoryFilterMap, std::vector<std::string> SubCategoryFilterMap, std::vector<std::variant<std::string, std::vector<std::string>>> DateFilterMap, std::vector<std::string> TagFilterMap) {
// do stuff here
}

User-defined types with {fmt} library and Visual Studio 2022 (17.2.2)

I am using https://github.com/fmtlib/fmt (commit hash 7e4ad40171aa552d38cb99a5c181a0d7b150facc - at the time of this writing pretty new) with the newest Visual Studio 2022 version (17.2.2) and following this tutorial here
I want to get this working:
struct complex
{
double a;
double b;
};
template<>
struct fmt::formatter<complex>
{
template<typename ParseContext>
constexpr auto parse(ParseContext& ctx) { return ctx.begin(); }
template<typename FormatContext>
auto format(complex const& number, FormatContext& ctx) {
return format_to(ctx.out(), "{0} +i{1}", number.a, number.b);
}
};
// ...
// somewhere in main
complex number{1, 2};
std::string message = fmt::format("The number is {}.\n", number);
I get the error message:
ERROR: G:/dev/piper/devertexwahn/flatland/tests/third_party/BUILD.bazel:42:8: Compiling flatland/tests/third_party/fmt_test.cpp failed: (Exit 2): cl.exe failed: error executing command C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\bin\HostX64\x64\cl.exe /nologo /DCOMPILER_MSVC /DNOMINMAX /D_WIN32_WINNT=0x0601 /D_CRT_SECURE_NO_DEPRECATE ... (remaining 44 arguments skipped)
flatland/tests/third_party/fmt_test.cpp(53): error C2668: 'std::format_to': ambiguous call to overloaded function
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\format(3046): note: could be '_OutputIt std::format_to<OutputIt,const double&,const double&>(_OutputIt,const std::_Basic_format_string<char,const double &,const double &>,const double &,const double &)' [found using argument-dependent lookup]
with
[
_OutputIt=fmt::v8::appender,
OutputIt=fmt::v8::appender
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(3195): note: or 'OutputIt fmt::v8::format_to<OutputIt,const double&,const double&,0>(OutputIt,fmt::v8::basic_format_string<char,const double &,const double &>,const double &,const double &)'
with
[
OutputIt=fmt::v8::appender
]
flatland/tests/third_party/fmt_test.cpp(52): note: while trying to match the argument list '(OutputIt, const char [10], const double, const double)'
with
[
OutputIt=fmt::v8::appender
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(713): note: see reference to function template instantiation 'auto fmt::v8::formatter<complex,char,void>::format<Context>(const complex &,FormatContext &)' being compiled
with
[
Context=fmt::v8::format_context,
FormatContext=fmt::v8::format_context
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1457): note: see reference to function template instantiation 'bool fmt::v8::detail::has_const_formatter<U,Context>(void)' being compiled
with
[
U=complex,
Context=fmt::v8::format_context
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1486): note: see reference to class template instantiation 'fmt::v8::detail::arg_mapper<Context>::formattable<const complex &,complex>' being compiled
with
[
Context=fmt::v8::format_context
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1697): note: see reference to alias template instantiation 'fmt::v8::detail::mapped_type_constant<complex,Context>' being compiled
with
[
Context=fmt::v8::format_context
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1858): note: see reference to function template instantiation 'unsigned __int64 fmt::v8::detail::encode_types<Context,complex,>(void)' being compiled
with
[
Context=fmt::v8::format_context
]
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(3167): note: see reference to class template instantiation 'fmt::v8::format_arg_store<fmt::v8::format_context,complex>' being compiled
flatland/tests/third_party/fmt_test.cpp(59): note: see reference to function template instantiation 'std::string fmt::v8::format<complex&>(fmt::v8::basic_format_string<char,complex &>,complex &)' being compiled
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1696): error C2062: type 'unknown-type' unexpected
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1696): error C2144: syntax error: 'unknown-type' should be preceded by '('
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1697): error C2039: 'value': is not a member of '`global namespace''
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1855): error C3615: constexpr function 'fmt::v8::detail::encode_types' cannot result in a constant expression
G:\bazel_output_base\execroot\de_vertexwahn\bazel-out\x64_windows-fastbuild\bin\external\fmt\_virtual_includes\fmt\fmt/core.h(1858): note: failure was caused by control reaching the end of a constexpr function
Target //flatland/tests/third_party:fmt_test failed to build
Use --verbose_failures to see the command lines of failed build steps.
The code seems to work with GCC9 on Ubuntu 20.04 and with Apple CLang on macOS. Any ideas what I am doing wrong here?
The error is caused by the std::format_to function introduced in C++20. To fix it, qualify your calls to fmt::format_to. For example, instead of
return format_to(ctx.out(), "{0} +i{1}", number.a, number.b);
do this instead:
return fmt::format_to(ctx.out(), "{0} +i{1}", number.a, number.b);
See this issue for more info: format conflict with Visual Studio 2022 17.2.0.

Conversion Error from 'unsigned __int64' to 'unsigned __int64 *' - Pybind11

After downloading this https://github.com/pybind/pybind11/archive/v2.2.3.zip
and creating a simple cpp file:
#include <pybind11/pybind11.h>
int add(int i, int j) { return i + j; }
PYBIND11_MODULE(example, m) {
m.doc() = "pybind11 example plugin"; // optional module docstring
m.def("add", &add, "A function which adds two numbers");
}
with
I get this error
Error C2446 '<': no conversion from 'unsigned __int64' to 'unsigned __int64 *' in c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector line 2326
Would anybody know what this could be referring to, and possibly how to fix it?
As requested, here the full error log:
1>------ Rebuild All started: Project: Test_CreatePythonBindings, Configuration: Debug x64 ------
1>example.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): error C2446: '<': no conversion from 'unsigned __int64' to 'unsigned __int64 *'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): note: Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2325): note: while compiling class template member function 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>> &std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>::operator +=(__int64)'
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2545): note: see reference to function template instantiation 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>> &std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>::operator +=(__int64)' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2490): note: see reference to class template instantiation 'std::_Vb_const_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(3094): note: see reference to class template instantiation 'std::_Vb_iterator<std::_Wrap_alloc<std::allocator<std::_Vbase>>>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(3093): note: while compiling class template member function 'void std::vector<bool,std::allocator<_Ty>>::push_back(const bool &)'
1> with
1> [
1> _Ty=bool
1> ]
1>c:\pybind11-2.2.3\include\pybind11\pybind11.h(513): note: see reference to function template instantiation 'void std::vector<bool,std::allocator<_Ty>>::push_back(const bool &)' being compiled
1> with
1> [
1> _Ty=bool
1> ]
1>c:\pybind11-2.2.3\include\pybind11\cast.h(1806): note: see reference to class template instantiation 'std::vector<bool,std::allocator<_Ty>>' being compiled
1> with
1> [
1> _Ty=bool
1> ]
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.14.26428\include\vector(2326): warning C4554: '&': check operator precedence for possible error; use parentheses to clarify precedence
1>Done building project "Test_CreatePythonBindings.vcxproj" -- FAILED.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
It appears to be a VS 2017 issue related to
std::vector<bool>
Separate question asked here:
Pushback on vector<bool> fails - VS 2017

Compiler Errors when using Eigen Library with MSVC2015

I need to use matricies for a program I am writing, so I downloaded and installed Eigen, however, upon compiling my project my error log is absolutely flooded with errors, all of which seem to be coming from the Eigen files themselves, here is my error log:
1>------ Build started: Project: ailib, Configuration: Debug Win32 ------
1> NeuralNet.cpp
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(52): error C2039: 'ReturnType': is not a member of 'Eigen::internal::scalar_product_traits<LhsScalar,RhsScalar>'
1> with
1> [
1> LhsScalar=float,
1> RhsScalar=Eigen::internal::result_of<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT> (float,float)>::type
1> ]
1> c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\util\meta.h(161): note: see reference to class template instantiation 'Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>' being compiled
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>
1> ]
1> c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\cwisebinaryop.h(58): note: see reference to class template instantiation 'Eigen::internal::result_of<BinaryOp (float,bool)>' being compiled
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT> (float,float)>::type>
1> ]
1> c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\cwisebinaryop.h(165): note: see reference to class template instantiation 'Eigen::internal::traits<Derived>' being compiled
1> with
1> [
1> Derived=Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT> (float,float)>::type>,const Eigen::ArrayWrapper<Eigen::Matrix<float,-1,1,0,-1,1>>,const Eigen::CwiseBinaryOp<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>,const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<float>,Eigen::Array<float,-1,1,0,-1,1>>,const Eigen::ArrayWrapper<Eigen::Matrix<float,-1,1,0,-1,1>>>>
1> ]
1> c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\cwisebinaryop.h(112): note: see reference to class template instantiation 'Eigen::CwiseBinaryOpImpl<BinaryOp,Lhs,Rhs,Eigen::Dense>' being compiled
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT> (float,float)>::type>,
1> Lhs=Eigen::ArrayWrapper<Eigen::Matrix<float,-1,1,0,-1,1>>,
1> Rhs=Eigen::CwiseBinaryOp<Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>,const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<float>,Eigen::Array<float,-1,1,0,-1,1>>,const Eigen::ArrayWrapper<Eigen::Matrix<float,-1,1,0,-1,1>>>
1> ]
1> c:\users\rick simone\documents\aioli\ailib\ailib\neuralnet.cpp(51): note: see reference to class template instantiation 'Eigen::CwiseBinaryOp<Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>,const Derived,const Eigen::CwiseBinaryOp<BinaryOp,const Eigen::CwiseNullaryOp<Eigen::internal::scalar_constant_op<float>,Eigen::Array<float,-1,1,0,-1,1>>,const Derived>>' being compiled
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>,
1> Derived=Eigen::ArrayWrapper<Eigen::Matrix<float,-1,1,0,-1,1>>
1> ]
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(52): error C3646: 'result_type': unknown override specifier
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(52): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(54): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(54): error C2143: syntax error: missing ';' before '('
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(54): error C2433: 'Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>::result_type': '__forceinline' not permitted on data declarations
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>
1> ]
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(59): error C2327: 'Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>::result_type': is not a type name, static, or enumerator
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>
1> ]
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(59): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(59): error C2433: 'result_type': '__forceinline' not permitted on data declarations
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(59): error C2365: 'Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>::result_type': redefinition; previous definition was 'data member'
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>
1> ]
1> c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(54): note: see declaration of 'Eigen::internal::scalar_product_op<float,Eigen::internal::result_of<BinaryOp (float,float)>::type>::result_type'
1> with
1> [
1> BinaryOp=Eigen::internal::scalar_cmp_op<float,Eigen::internal::cmp_LT>
1> ]
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(59): error C2061: syntax error: identifier 'predux'
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(61): error C2143: syntax error: missing ';' before '}'
1>c:\users\rick simone\documents\aioli\ailib\eigen\eigen\src\core\functors.h(61): error C2238: unexpected token(s) preceding ';'
The problem is, when I go to the files and lines indicated by the errors, they are in the Eigen source code (Which I haven't modified or touched), the snippet where all the errors come from is as follows:
template<typename LhsScalar,typename RhsScalar> struct scalar_product_op {
enum {
// TODO vectorize mixed product
Vectorizable = is_same<LhsScalar,RhsScalar>::value && packet_traits<LhsScalar>::HasMul && packet_traits<RhsScalar>::HasMul
};
typedef typename scalar_product_traits<LhsScalar,RhsScalar>::ReturnType result_type;
EIGEN_EMPTY_STRUCT_CTOR(scalar_product_op)
EIGEN_STRONG_INLINE const result_type operator() (const LhsScalar& a, const RhsScalar& b) const { return a * b; }
template<typename Packet>
EIGEN_STRONG_INLINE const Packet packetOp(const Packet& a, const Packet& b) const
{ return internal::pmul(a,b); }
template<typename Packet>
EIGEN_STRONG_INLINE const result_type predux(const Packet& a) const
{ return internal::predux_mul(a); }
};
Includes used:
#include <Eigen\Core>
#include <Eigen\Dense>
Line 51 NeuralNet.cpp: err = errIn.array() * (m_layerOut.array() > 0.f);
Types of Variables: err, errIn and m_layerOut are all Eigen::Matrix<float, Eigen::Dynamic, 1>
Thanks in advance!
As posted, your question is very hard to answer. There are a bunch of errors in template code which is determined by your usage at compile time. For future reference, it would make it much easier on both you and those attempting to answer if you tried to boil it down to a MCVE (also worth reading, How do I ask a good question?).
So, after reading the above links, you would rephrase your question to read something like:
I've wrote some code that produces a bunch of errors and I can't figure out why. Here is the minimal code that I've managed to create that reproduces this problem:
#include "Eigen/Core"
#include <iostream>
int main()
{
size_t sz = 64;
Eigen::Matrix<float, Eigen::Dynamic, 1> err, errIn, m_layerOut;
errIn.setRandom(sz);
m_layerOut.setRandom(sz);
err = errIn.array() * (m_layerOut.array() > 0.f);
std::cout << err;
return 0;
}
I tried to compile using g++ on MinGW (version 9.187 beta, 256bit) using g++ SO.cpp -I .. I have the same issues when using VS2048 using .
The errors I get are all related to the Eigen library (v3.9.6), which I know to be bug free (they're all features):
1>....\eigen\src/Core/Functors.h(52): error C2039: 'ReturnType' : is not a member of 'Eigen::internal::scalar_product_traits'
1> with
1> [
1> LhsScalar=float
1> , RhsScalar=Eigen::internal::result_of (float,float)>::type
1> ]
1> ....\eigen\src/Core/util/Meta.h(161) : see reference to class template instantiation 'Eigen::internal::scalar_product_op::type>' being compiled
1> with
1> [...
What is causing these compilation errors?
The average SO user could then copy your example directly into the ancient VS2017 IDE hit F7 and reproduce the errors. He would then realize that the expression
errIn.array() * (m_layerOut.array() > 0.f)
is the coefficient-wise product of a float and a bool, something that Eigen didn't support (in those days) without an explicit cast. He would then write up a quick answer saying:
You have to explicitly cast the comparison array from a boolean array to a float array like this:
err = errIn.array() * (m_layerOut.array() > 0.f).cast<float>();
You would then accept that answer, as it solved your problem, and move on.

sorting vector of structs by integer [duplicate]

This question already has answers here:
problem sorting using member function as comparator
(9 answers)
Closed 7 years ago.
Im trying to sort vector of structs. I saw this and this examples.
this is my code:
.h file:
// I didn't mention all the includes and namespace
class fileLoader
{
struct commands
{
int time;
string name;
};
commands resultStruct;
vector<commands> resultVector
private:
void sortFunction();
bool compareByTime(const commands &a, const commands &b);
}
.cpp file:
void fileLoader::sortResults()
{
sort(resultVector.begin(), resultVector.end(), compareByTime);
}
bool fileLoader::compareByTime(const commands &a, const commands &b)
{
return a.time < b.time;
}
this is the compilation error I get:
error C3867: 'fileLoader::compareByTime': function call missing argument list; use '&fileLoader::compareByTime' to create a pointer to member
error C2780: 'void std::sort(_RanIt,_RanIt)' : expects 2 arguments - 3 provided
c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(3639) : see declaration of 'std::sort'
when I tried to change compareByTime to &fileLoader::compareByTime, I got this compilation error:
error C2064: term does not evaluate to a function taking 2 arguments
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(3776) : see reference to function template instantiation 'std::pair<_Ty1,_Ty2> std::_Unguarded_partition<_RanIt,_Pr>(_RanIt,_RanIt,_Pr)' being compiled
1> with
1> [
1> _Ty1=fileLoader::commands *,
1> _Ty2=fileLoader::commands *,
1> _RanIt=fileLoader::commands *,
1> _Pr=bool (__thiscall fileLoader::* )(const fileLoader::commands &,const fileLoader::commands &)
1> ]
1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(3806) : see reference to function template instantiation 'void std::_Sort<fileLoader::commands*,__w64 int,_Pr>(_RanIt,_RanIt,_Diff,_Pr)' being compiled
1> with
1> [
1> _Pr=bool (__thiscall fileLoader::* )(const fileLoader::commands &,const fileLoader::commands &),
1> _RanIt=fileLoader::commands *,
1> _Diff=__w64 int
1> ]
std::sort<std::_Vector_iterator<_Myvec>,bool(__thiscall fileLoader::* )(const fileLoader::commands &,const fileLoader::commands &)>(_RanIt,_RanIt,_Pr)' being compiled
1> with
1> [
1> _Myvec=std::_Vector_val<fileLoader::commands,std::allocator<fileLoader::commands>>,
1> _RanIt=std::_Vector_iterator<std::_Vector_val<fileLoader::commands,std::allocator<fileLoader::commands>>>,
1> _Pr=bool (__thiscall fileLoader::* )(const fileLoader::commands &,const fileLoader::commands &)
1> ]
1>c:\program files (x86)\microsoft visual studio 10.0\vc\include\algorithm(3720): fatal error C1903: unable to recover from previous error(s); stopping compilation
1>
1>Build FAILED.
I will be happy for some help.
thanks.
First fix all the typos (missing semicolons etc).
Then change your sorting function to static bool compareByTime(const commands &a, const commands &b);
Short answer
Make compareByTime static (or 'global' outside class)
Explanation
Member functions require this to be passed to them somehow, so two argument member function is probably 3 argument function. So compiler can't use it when it needs 2 arguments comparator.