errors C2784, C2672 and C2664 in Visual studio 2015 - c++

I have following lines in visual studio 2015. It used to be compiled without error in visual studio 2013.
const std::basic_regex<wchar_t> e(_T("([eE][-+])(0)(\\d{2})"));
io_string = std::regex_replace(io_string, e, _T("$1$3"));
the error is:
error C2664: 'std::basic_regex>::basic_regex(std::basic_regex> &&) noexcept': cannot convert argument 1 from 'const char [21]' to 'const wchar_t *'
error C2672: 'std::regex_replace': no matching overloaded function found
4>
error C2784: 'std::basic_string<_Elem,std::char_traits<_Elem>,std::allocator<_Other>> std::regex_replace(const _Elem *,const std::basic_regex<_Elem,_RxTraits> &,const _Elem *,std::regex_constants::match_flag_type)': could not deduce template argument for 'const _Elem *' from 'std::string_t'
I know this issue is coming from change tchar.h. Any suggestion for resolving them. I also use CMake for project configuration and the project is running on windows 10.

Assuming you don't want to change your code, you need to ensure that your code is building for Unicode, so pass -D_UNICODE to the compiler. This post suggests:
ADD_DEFINITIONS(-DUNICODE)
ADD_DEFINITIONS(-D_UNICODE)
And this one illustrates how to enable Unicode through the GUI.

Related

how to use parallel_for over a recursive_directory_iterator?

I can't work out how to use the Concurrency::parallel_for over a recursive_directory_iterator, the compiler doesn't like the Step param.
Can you use the parallel_for[each] stuff with anything other than arrays?
simple code:
recursive_directory_iterator dir(cwd, directory_options::skip_permission_denied);
recursive_directory_iterator end_dir;
parallel_for(begin(dir), end(dir), begin(dir), [&](recursive_directory_iterator dir) {
});
results in a cahjillion errors about the third param _Step:
Error C2678 binary '<': no operator found which takes a left-hand operand of type 'std::filesystem::recursive_directory_iterator' (or there is no acceptable conversion) app c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\ppl.h 2501
Error C2678 binary '>=': no operator found which takes a left-hand operand of type 'std::filesystem::recursive_directory_iterator' (or there is no acceptable conversion) app c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\ppl.h 2507
Error C2784 'unknown-type std::operator -(const std::move_iterator<_RanIt> &,const std::move_iterator<_RanIt2> &)': could not deduce template argument for 'const std::move_iterator<_RanIt> &' from 'std::filesystem::recursive_directory_iterator' app c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\ppl.h 2514
Error C2784 'unknown-type std::operator -(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)': could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'std::filesystem::recursive_directory_iterator' app c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\ppl.h 2514
Error C2676 binary '-': 'std::filesystem::recursive_directory_iterator' does not define this operator or a conversion to a type acceptable to the predefined operator app c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\ppl.h 2514
Error C2672 '_Parallel_for_partitioned_impl': no matching overloaded function found app c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\ppl.h 2525
Error C2893 Failed to specialize function template 'void Concurrency::_Parallel_for_partitioned_impl(_Index_type,_Diff_type,_Diff_type,const _Function &,const Concurrency::auto_partitioner &)' app c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.14.26428\include\ppl.h 2525
It looks like I need to adapt the iterator somehow but I'm not sure how - I could convert the dir recurse to an array but that doesn't feel quite right.
Any ideas?
TIA

emplace_back different definitions

I'm using emplace_back function in a cpp project in visual studio and it works correctly. Visual studio shows following definition for it:
void std::vector<std::string>::emplace_back<CHAR(&)[1]>(CHAR(&_Val)[1])
Then, I'm going to move my cpp project files to a MFC project and use them in a dialog based app. When I moved codes to MFC project, emplace_back definition has changed to:
void std::vector<std::string>::emplace_back<WCHAR(&)[1]>(WCHAR(&_Val)[1])
And it leads to C2664 Error in xmemory0 after build:
Error C2664
std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string(const std::basic_string<char, std::char_traits<char>, std::allocator<char>> &)':
cannot convert argument 1 from 'WCHAR [1]' to 'std::initializer_list<_Elem>'
And in output it says:
note: see reference to function template instantiation 'void std::vector<std::string,std::allocator<_Ty>>::emplace_back<WCHAR(&)[1]>(WCHAR (&)[1])' being compiled
1> with
1> [
1> _Ty=std::string
1> ]
How can I deal with such problems? Is there any option in properties of Visual Studio Project to correct?
Thanks

Build error while using Armadillo on Windows platform

I had installed armadillo library on window visual studio 2013. When i attempted to build the solution. The following build error occurred. Any help will be appreciated.
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug x64 ------
1> Source.cpp
1>c:\users\haixun\desktop\test_programs\testingapplication\armadillo-5.100.2\include\armadillo_bits/diskio_meat.hpp(787): error C4146: unary minus operator applied to unsigned type, result still unsigned
1> c:\users\haixun\desktop\test_programs\testingapplication\armadillo-5.100.2\include\armadillo_bits/diskio_meat.hpp(1626) : see reference to function template instantiation 'bool arma::diskio::convert_naninf<eT>(eT &,const std::string &)' being compiled
1> with
1> [
1> eT=arma::u32
1> ]
1> c:\users\haixun\desktop\test_programs\testingapplication\armadillo-5.100.2\include\armadillo_bits/diskio_meat.hpp(1652) : see reference to function template instantiation 'bool arma::diskio::load_arma_ascii<arma::u32>(arma::Mat<arma::u32> &,std::istream &,std::string &)' being compiled
1> c:\users\haixun\desktop\test_programs\testingapplication\armadillo-5.100.2\include\armadillo_bits/diskio_meat.hpp(1571) : see reference to function template instantiation 'bool arma::diskio::load_arma_ascii<double>(arma::Mat<double> &,std::istream &,std::string &)' being compiled
1> c:\users\haixun\desktop\test_programs\testingapplication\armadillo-5.100.2\include\armadillo_bits/Mat_meat.hpp(6553) : see reference to function template instantiation 'bool arma::diskio::load_arma_ascii<double>(arma::Mat<double> &,const std::string &,std::string &)' being compiled
1> c:\users\haixun\desktop\test_programs\testingapplication\armadillo-5.100.2\include\armadillo_bits/Mat_meat.hpp(6536) : while compiling class template member function 'bool arma::Mat<double>::load(const std::string,const arma::file_type,const bool)'
1> Source.cpp(50) : see reference to function template instantiation 'bool arma::Mat<double>::load(const std::string,const arma::file_type,const bool)' being compiled
1> c:\users\haixun\desktop\test_programs\testingapplication\armadillo-5.100.2\include\armadillo_bits/typedef_mat_fixed.hpp(41) : see reference to class template instantiation 'arma::Mat<double>' being compiled
1>c:\users\haixun\desktop\test_programs\testingapplication\armadillo-5.100.2\include\armadillo_bits/diskio_meat.hpp(794): error C4146: unary minus operator applied to unsigned type, result still unsigned
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Sorry that someone downvoted your question; it seems reasonable to me.
These are warnings, which in this particular case are harmless. You must have the option turned on to treat warnings as errors. Your options seem to be:
Turn off the option to treat warnings as errors.
Turn off that particular warning (project wide).
Turn off that particular warning whenever you #include <armadillo>.
Option 3 is probably best, especially if the warnings as errors option is company policy. Make sure to push and pop the warning options; see this MSDN page on warning pragmas. You could put the whole lot (pragmas and include) into a little header file, which is probably a good idea anyway since Visual Studio won't autocomplete #include <armadillo> (since it doesn't have a file extension).

Visual Studio 2013 - C++ Errors

Some strange things happen. When I compile my program in Dev-C++ it gives me no errors and compiles clean. When I put it in Visual Studio I got a LOT of errors:
Error 1 error C2371: 'MailRecipient' : redefinition; different basic types
Error 2 error C3861: 'GetModuleFileName': identifier not found
Error 3 error C2664: 'HRESULT SHGetFolderPathW(HWND,int,HANDLE,DWORD,LPWSTR)' : cannot convert argument 5 from 'char [260]' to 'LPWSTR'
Error 4 error C3861: 'CopyFile': identifier not found
Error 5 error C2664: 'BOOL SetFileAttributesW(LPCWSTR,DWORD)' : cannot convert argument 1 from 'char [512]' to 'LPCWSTR'
Error 6 error C2664: 'HRESULT SHGetFolderPathW(HWND,int,HANDLE,DWORD,LPWSTR)' : cannot convert argument 5 from 'char [260]' to 'LPWSTR'
Error 7 error C2664: 'BOOL SetFileAttributesW(LPCWSTR,DWORD)' : cannot convert argument 1 from 'char []' to 'LPCWSTR'
Error 8 error C2664: 'LSTATUS RegOpenKeyExW(HKEY,LPCWSTR,DWORD,REGSAM,PHKEY)' : cannot convert argument 2 from 'const char [46]' to 'LPCWSTR'
Error 9 error C2664: 'HRESULT SHGetFolderPathW(HWND,int,HANDLE,DWORD,LPWSTR)' : cannot convert argument 5 from 'char [260]' to 'LPWSTR'
Error 10 error C2664: 'LSTATUS RegSetValueExW(HKEY,LPCWSTR,DWORD,DWORD,const BYTE *,DWORD)' : cannot convert argument 2 from 'const char [9]' to 'LPCWSTR'
It all works on Dev-C++ tho. I need to compile it in VS because I want to add something from the POCO library, which, ironically, doesn't compile in Dev-C++... Any help?
A Visual Studio project defines UNICODE by default.
You can either turn off Unicode in the project settings, or rework your program to use wchar_t based strings (e.g. L"Blah" instead of "Blah").
Or, you can #undef UNICODE before including <windows.h>, every place.
There seem to be some issues about #include statements in your Project. You need to figure out why MailRecipient gets redefined. You will probably have to adjust some of the project settings in Visual Studio. Also, as the first answer suggests Visual Studio uses UNICODE by default, which causes it to call the wide string versions of Windows API functions. You can use the std::widen function to convert your strings just for Windows API calls. For more information on this topic see utf8everywhere.org.

c++ - Error compiling Anax with Visual Studio 2013

I recently motivate myself to code ECS way. So i download anax and tryed to compile it. Here is the problem, i only tryed and didn't achieved it. I generated the file for Visual Studio and upgraded msvc12 to latest version. But now i get this error and I have no idea how to fix it :
error C2664: 'void std::vector>::emplace_back(anax::Entity::Id::int_type &,unsigned __int64 &)' : cannot convert argument 1 from 'anax::Entity::Id::int_type' to 'anax::Entity::Id::int_type &'
And here is the code line which throws the error :
m_freeList.emplace_back(static_cast<Entity::Id::int_type>(id.index), counter);
Does someone has an idea how to fix this ?