Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix c++11 compilation #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

marques-bruno
Copy link

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.

@dprogm
Copy link

dprogm commented Aug 13, 2023

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()
     );
 }

Copy link
Contributor

@goncaloalmeida goncaloalmeida left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@pberginkonsult
Copy link

pberginkonsult commented Sep 6, 2023

@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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants