Discussion:
Looking for std::map::erase_if
Willem Jan Withagen via freebsd-hackers
2021-03-20 14:39:34 UTC
Permalink
Hi,

[ Trying this on FBSD 12.2 ]

In the Ceph code new code uses std::map::erase_if.
Which is in Linux imported from <experimental/map>

Anybody suggestions on libraries to get something matching??

Thanx,
--WjW
Alan Somers
2021-03-20 14:46:42 UTC
Permalink
It looks like it's in there. What code are you trying that doesn't work?
grep erase_if /usr/include/c++/v1/map
void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); //
C++20
void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);
// C++20
void erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
void erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate
__pred)
{ __libcpp_erase_if_container(__c, __pred); }

On Sat, Mar 20, 2021 at 8:39 AM Willem Jan Withagen via freebsd-hackers <
Hi,
[ Trying this on FBSD 12.2 ]
In the Ceph code new code uses std::map::erase_if.
Which is in Linux imported from <experimental/map>
Anybody suggestions on libraries to get something matching??
Thanx,
--WjW
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
Willem Jan Withagen via freebsd-hackers
2021-03-20 15:06:54 UTC
Permalink
It looks like it's in there.  What code are you trying that doesn't work?
Hi Alan,

I thought so too, but all tries last 2 weeks did not result into
anything that got it compiling...
But could be that I did not try hard enough, real work is pulling a lot atm.

Code is at:
https://github.com/dillaman/ceph/blob/138d71fb0635682510cadda8e4ad5aaab3f39e44/src/librbd/api/Trash.cc#L299

Thanx,
--WjW
grep erase_if  /usr/include/c++/v1/map
  void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred);
 // C++20
  void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate
pred);  // C++20
void erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
void erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c,
_Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
On Sat, Mar 20, 2021 at 8:39 AM Willem Jan Withagen via
Hi,
[ Trying this on FBSD 12.2 ]
In the Ceph code new code uses std::map::erase_if.
Which is in Linux imported from <experimental/map>
Anybody suggestions on libraries to get something matching??
Thanx,
--WjW
_______________________________________________
mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to
Alan Somers
2021-03-20 15:22:30 UTC
Permalink
I'm just guessing, but I think you should remove the "experimental" and
build with -std=c++17 .
-Alan
Post by Alan Somers
It looks like it's in there. What code are you trying that doesn't work?
Hi Alan,
I thought so too, but all tries last 2 weeks did not result into anything
that got it compiling...
But could be that I did not try hard enough, real work is pulling a lot atm.
https://github.com/dillaman/ceph/blob/138d71fb0635682510cadda8e4ad5aaab3f39e44/src/librbd/api/Trash.cc#L299
Thanx,
--WjW
grep erase_if /usr/include/c++/v1/map
void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); //
C++20
void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);
// C++20
void erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
void erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate
__pred)
{ __libcpp_erase_if_container(__c, __pred); }
On Sat, Mar 20, 2021 at 8:39 AM Willem Jan Withagen via freebsd-hackers <
Hi,
[ Trying this on FBSD 12.2 ]
In the Ceph code new code uses std::map::erase_if.
Which is in Linux imported from <experimental/map>
Anybody suggestions on libraries to get something matching??
Thanx,
--WjW
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
"
Dimitry Andric
2021-03-20 17:48:33 UTC
Permalink
Well, -std=c++20 even, it is that new. :)

That said, it's always hazardous to rely on experimental features, they are effectively unsupported.

As shown on e.g. cppreference.com, you can use an equivalent function that looks like:

auto old_size = c.size();
for (auto i = c.begin(), last = c.end(); i != last; ) {
if (pred(*i)) {
i = c.erase(i);
} else {
++i;
}
}

-Dimitry
Post by Alan Somers
I'm just guessing, but I think you should remove the "experimental" and
build with -std=c++17 .
-Alan
Post by Alan Somers
It looks like it's in there. What code are you trying that doesn't work?
Hi Alan,
I thought so too, but all tries last 2 weeks did not result into anything
that got it compiling...
But could be that I did not try hard enough, real work is pulling a lot atm.
https://github.com/dillaman/ceph/blob/138d71fb0635682510cadda8e4ad5aaab3f39e44/src/librbd/api/Trash.cc#L299
Thanx,
--WjW
grep erase_if /usr/include/c++/v1/map
void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); //
C++20
void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);
// C++20
void erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
void erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate
__pred)
{ __libcpp_erase_if_container(__c, __pred); }
On Sat, Mar 20, 2021 at 8:39 AM Willem Jan Withagen via freebsd-hackers <
Hi,
[ Trying this on FBSD 12.2 ]
In the Ceph code new code uses std::map::erase_if.
Which is in Linux imported from <experimental/map>
Anybody suggestions on libraries to get something matching??
Thanx,
--WjW
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
"
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain
Russell L. Carter
2021-03-20 18:13:23 UTC
Permalink
Post by Dimitry Andric
Well, -std=c++20 even, it is that new. :)
That said, it's always hazardous to rely on experimental features, they are effectively unsupported.
auto old_size = c.size();
for (auto i = c.begin(), last = c.end(); i != last; ) {
if (pred(*i)) {
i = c.erase(i);
} else {
++i;
}
}
-std=c++20 is the way I would go to future proof, as then eg
erase_if(std::map) is no longer experimental. The potential
downside is then dealing with other oddball usages that are
deprecated in c++20 (or c++17, c++14). If you fix these
upstream might be receptive to patches.

One other detail is the switch for slightly older clang++
or g++ is -std=c++2a, not -std=c++20.

Dimitry is right, cppreference.com is your friend for this.
Very easy to google your problem method/class and get to exactly
what you need in terms of std compatibility.

Russell
Post by Dimitry Andric
-Dimitry
Post by Alan Somers
I'm just guessing, but I think you should remove the "experimental" and
build with -std=c++17 .
-Alan
Post by Alan Somers
It looks like it's in there. What code are you trying that doesn't work?
Hi Alan,
I thought so too, but all tries last 2 weeks did not result into anything
that got it compiling...
But could be that I did not try hard enough, real work is pulling a lot atm.
https://github.com/dillaman/ceph/blob/138d71fb0635682510cadda8e4ad5aaab3f39e44/src/librbd/api/Trash.cc#L299
Thanx,
--WjW
grep erase_if /usr/include/c++/v1/map
void erase_if(map<Key, T, Compare, Allocator>& c, Predicate pred); //
C++20
void erase_if(multimap<Key, T, Compare, Allocator>& c, Predicate pred);
// C++20
void erase_if(map<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate __pred)
{ __libcpp_erase_if_container(__c, __pred); }
void erase_if(multimap<_Key, _Tp, _Compare, _Allocator>& __c, _Predicate
__pred)
{ __libcpp_erase_if_container(__c, __pred); }
On Sat, Mar 20, 2021 at 8:39 AM Willem Jan Withagen via freebsd-hackers <
Hi,
[ Trying this on FBSD 12.2 ]
In the Ceph code new code uses std::map::erase_if.
Which is in Linux imported from <experimental/map>
Anybody suggestions on libraries to get something matching??
Thanx,
--WjW
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-hackers
"
_______________________________________________
https://lists.freebsd.org/mailman/listinfo/freebsd-toolchain
Continue reading on narkive:
Loading...