capicxx-core-runtime icon indicating copy to clipboard operation
capicxx-core-runtime copied to clipboard

Fix c++11 compilation

Open marques-bruno opened this issue 2 years ago • 2 comments

New to this framework, just followed the "CommonAPI C D-BUS in 10 min" tutorial and ran into this compile issue. I'm a bit surprised I'm the first one reporting this: ptr_fun is a c++03 function deprecated in c++11 and removed in c++17.

marques-bruno avatar Aug 01 '22 18:08 marques-bruno

I was also facing this issue, but it depends on the compiler. Although setting -std=c++17 it compiles successfully. I would suggest the following patch (because std::not1 is going to be removed too):

diff --git a/src/CommonAPI/Utils.cpp b/src/CommonAPI/Utils.cpp
index 8f7f6e7..d1891f6 100644
--- a/src/CommonAPI/Utils.cpp
+++ b/src/CommonAPI/Utils.cpp
@@ -31,7 +31,7 @@ void trim(std::string& toTrim) {
         std::find_if(
             toTrim.begin(),
             toTrim.end(),
-            std::not1(std::ptr_fun(isspace))
+            [](char c) { return !std::isspace(c); }
         )
     );
 
@@ -39,7 +39,7 @@ void trim(std::string& toTrim) {
         std::find_if(
             toTrim.rbegin(),
             toTrim.rend(),
-            std::not1(std::ptr_fun(isspace))).base(),
+            [](char c) { return !std::isspace(c); }).base(),
             toTrim.end()
     );
 }

dprogm avatar Aug 13 '23 18:08 dprogm

@marques-bruno internally we detected the same problem, could you please use an int instead of char please?

@goncaloalmeida - Please take a look at the notes section of isspace (https://en.cppreference.com/w/cpp/string/byte/isspace#Notes). I think char is the preferred type here. Also discussed in this thread: https://stackoverflow.com/questions/44973435/stdptr-fun-replacement-for-c17

pberginkonsult avatar Sep 06 '23 13:09 pberginkonsult