We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hello,
I want to use std::regex with a nlohmann::json value but I have somme problems.
My C++ file :
// g++ -std=c++14 moderncpp_json.cpp -o moderncpp_json #include <iostream> #include <regex> #include "json.hpp" int main(int argc, char *argv[]) { using json = nlohmann::json; json j = R"({"name": "jmchoulet"})"_json; std::regex r{R"(^(.+)$)"}; std::smatch m; //-- works but need to create a std::string variable !!! //const std::string value = j["name"].get<std::string>(); //if (std::regex_match(value, m, r)) if (std::regex_match(j["name"].get<std::string>(), m, r)) { std::string s; if (m.size()) { std::string tmp = m[1]; s += "m[1]: " + tmp; std::cout << s << std::endl; } } return 0; }
Compiler g++ output :
$ g++ -std=c++14 moderncpp_json.cpp -o moderncpp_json moderncpp_json.cpp: In function ‘int main(int, char**)’: moderncpp_json.cpp:19:60: error: use of deleted function ‘bool std::regex_match(const std::__cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&, std::__cxx11::match_results<typename std::__cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>::const_iterator, _Alloc>&, const std::__cxx11::basic_regex<_Ch_type, _Rx_traits>&, std::regex_constants::match_flag_type) [with _Ch_traits = std::char_traits<char>; _Ch_alloc = std::allocator<char>; _Alloc = std::allocator<std::__cxx11::sub_match<__gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> > > >; _Ch_type = char; _Rx_traits = std::__cxx11::regex_traits<char>; typename std::__cxx11::basic_string<_Ch_type, _Ch_traits, _Ch_alloc>::const_iterator = __gnu_cxx::__normal_iterator<const char*, std::__cxx11::basic_string<char> >]’ if (std::regex_match(j["name"].get<std::string>(), m, r)) ^ In file included from /usr/include/c++/5/regex:61:0, from moderncpp_json.cpp:3: /usr/include/c++/5/bits/regex.h:2073:5: note: declared here regex_match(const basic_string<_Ch_type, _Ch_traits, _Ch_alloc>&&,
How to avoid this error?
Thank,
Jean-Marc
The text was updated successfully, but these errors were encountered:
This seems to be this issue: https://stackoverflow.com/questions/33154890/simple-stdregex-search-code-wont-compile-with-apple-clang-std-c14 and related to a change in C++14
As a solution, query a reference with
if (std::regex_match(j["name"].get_ref<std::string&>(), m, r))
Sorry, something went wrong.
Does this work for you, @jm130794?
No branches or pull requests
Hello,
I want to use std::regex with a nlohmann::json value but I have somme problems.
My C++ file :
Compiler g++ output :
How to avoid this error?
Thank,
Jean-Marc
The text was updated successfully, but these errors were encountered: