Why is charconv header missing in macosx Mojave 10.14 with gcc5? - c++

I am trying to do some very fast conversions in C++ and charconv seems the way to go since it uses a very low level logic. The problem is that when I try to include this header and then call, say, std::to_chars(...), neither the header is found nor std has a 'to_chars' member. I updated and reinstalled gcc but this problem is still there. Now I have seen some threads that say that I should update somehow libc++17 but they are not very specific about what I should do, as things are a bit different for MacOS.
Some code to illustrate the library and it's use:
#include <iostream>
#include <typeinfo>
#include <charconv> //error: 'charconv' file not found
struct to_chars_result{
char *str;
std::errc err;
};
int main(int argc, const char * argv[]) {
std::string str("12Test");
auto result = std::to_chars(str.data(), str.data()+str.size(), 12345); //No
//member named 'to_chars' in namespace 'std'.
return 0;
}
As for gcc -v command output:
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin14.4.0/5.1.0/lto-
wrapper
Ziel: x86_64-apple-darwin14.4.0
Konfiguriert mit: ../gcc-5.1.0/configure --enable-languages=c++,fortran
Thread-Modell: posix
gcc-Version 5.1.0 (GCC)
Any help appreciated!

gcc 5.1 was released on April 22, 2015.
The paper that added to_chars to the C++17 standard was written in 2016.
Why do you expect that gcc5 will have implemented it?
[ Later: That was the paper that added the <charconv> header, too ]

Related

expint c++ method om Macos M1

i tried run method expint from cmath and got error, i used c++17, c++17 should support this method but it doesn't see it. C++ version Apple clang version 13.1.6 (clang-1316.0.21.2). which version should I use so that the expint method is available?
//#define __STDCPP_WANT_MATH_SPEC_FUNCS__ 1
//#define __STDCPP_MATH_SPEC_FUNCS__ 201003L
#include <cmath>
#include <iostream>
int main(int argc, const char * argv[]) {
std::cout << "Hello, World!\n";
std::expint(10.4);
return 0;
}
expint docs one more expint docs
error
c++ configs
It may be a compatibility issue with the updated MacOS version or even the M1 (if you have it) chipset. With just the info on the application, it is still undeterminable what the root cause may be.

Mac gcc doesn't allow calling std::string::~string explicitly

strdata->std::string::~string();
Here is the error I get:
error: '~' in destructor name should be after nested name specifier
strdata->std::string::~string();
^
I am using a cmake project... My gcc version installed via brew is following:
gcc --version
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.2 (clang-700.1.81)
Target: x86_64-apple-darwin15.2.0
Thread model: posix
I couldn't find the ~string() defined anywhere in the header files. I ended up changing it as follows and that works. It is ok for my use case for now.
strdata->std::string::~basic_string();
This original seems correct and works perfectly in GCC on Linux and CYGWIN. What is the issue which is preventing it from working on mac? Templates? Something else?
This isn't a complete answer. For some reason, using namespace std; works, but without that clang fails. Consider this example:
#include <new>
#include <type_traits>
namespace foo {
struct A {};
typedef A A_t;
}
int main() {
std::aligned_storage<sizeof(foo::A)>::type storage;
foo::A_t* obj = new(&storage) foo::A;
using namespace foo; // Without this line, clang fails.
obj->foo::A_t::~A_t();
}
Without the using namespace foo; line, clang will give an error expected the class name after '~' to name a destructor. But with that line, it works. Extending this to std::string:
#include <new>
#include <type_traits>
#include <string>
int main() {
std::aligned_storage<sizeof(std::string)>::type storage;
std::string* obj = new(&storage) std::string;
using namespace std; // Without this line, clang fails.
obj->std::string::~string();
}
it works. It also works with the narrower using std::string;.
This doesn't answer the question of why clang fails. I don't know if it's a bug in clang or in gcc. But at least a workaround exists.
It may be worth reporting this as a bug in clang, and then letting them decide whether or not it really is a bug.

(Software issue) Can anyone suggest a download that will definitely bring my Mingw32 compiler up to speed?

#include <iostream>
#include <string>
using namespace std;
int main(){
string s = "wassup", newVal = "though";
cout << *(s.insert(s.begin(), newVal.begin(), newVal.end()));
}
This brings up the problem that the return type of string's insert member function is void (error: void value not ignored as it ought to be). This link indicates C++98 returns void but the "new" standard C++11 does indeed return an iterator.
A bit of context, I actually faced this problem earlier. I was/am using CodeBlocks (GCC Compiler Collection) on Windows 7 64-bit and this program gave the same issue (dereferencing void):
#include <iostream>
#include <list>
int main(){
list<int> x = {1,2,3,4};
*(x.insert(++x.begin(), 3, 2));
for(auto c : x)
cout << c;
}
I posted my issue on a different forum and a user pointed out Mingw32 was missing that particular C++11 change, indicating Mingw-w64 does not have this issue. So I went straight to installing Mingw-w64 on Code::Blocks using this guide and the problem was resolved. It's only now I've found out that the overloaded function which takes three iterator parameters STILL returns void.
I'm a little confused as to why Code::Blocks Mingw32 didn't supply a fully updated C++11 standard. Can anyone suggest a download that will definitely bring my compiler up to speed?

Using regex_search from the C++ regex library

The regex_search function isn't quite behaving as expected.
#include <iostream>
#include <regex>
#include <string>
using namespace std;
int main()
{
string str = "Hello world";
const regex rx("Hello");
cout << regex_search(str.begin(), str.end(), rx) << endl;
return 0;
}
The output is
0
What's going on?
As pointed out in comments to the question, older implementations of the C++ standard libraries did not yet support all features in C++11. Of course, libc++ being an exception because it was originally built specifically for C++11.
According to this bug report support for <regex> in libstdc++ was only implemented for version 4.9 of GCC. You can check the current status on the libstdc++ status page.
One can confirm, that your example works with GCC 4.9 while still failing with GCC 4.8.

c++ mingw STL installation

I recently installed MinGW and MSYS on my Windows 32 machine and it seems to be running fine.
On the C++ compiler, I am including a vector container and getting no errors to that. But I`m getting compile-time errors when I try to use it.
So, the code
#include <vector> // include vector.h
#include <stdio.h> // include stdio.h
using namespace std;
main() {
// vector<int> A;
printf("\nHeya ..");
}
is running just fine. However, the moment I un-comment line 8-- the vector declaration line, I get the following error (shortened) in compile time:
undefined reference to 'operator delete(void*)'
undefined reference to '__gxx_personality_v0'
You're probably compiling with gcc instead of g++. The actual compiler is the same, but g++ tells the linker to use the default C++ libraries, were gcc only tells it to look at the C libraries. As soon as you use and C++-specific parts of the standard library, gcc will fail.
As an aside, C++ doesn't support the default int rule from old C, so you should really specify the return type from main.
I don't see how you are compiling your code. Your main method is invalid, incorrect signature and you aren't returning anything.
Should be like this:
#include <vector> // include vector.h
#include <stdio.h> // include stdio.h
using namespace std;
int main(int, char**) {
// vector<int> A;
printf("\nHeya ..");
return 0;
}
Also you need to compile this with g++ and not gcc.