pmem::obj::operator==()

9 views
Skip to first unread message

Supriya Mishra SVNIT

unread,
Jun 28, 2023, 1:40:19 AM6/28/23
to pmem
Hi,

I am trying to check if two persistent_ptr are equal or not using == operator. Here is the sample code-

using namespace pmem;
using namespace pmem::obj;

persistent_ptr<Treenode>child;
persistent_ptr<Treenode>root;

if(operator==(child==root)){
     \\do something..
}

I am getting the following error-

error: no matching function for call to ‘operator==(__gnu_cxx::__alloc_traits<std::allocator<pmem::obj::persistent_ptr<PRnode> >, pmem::obj::persistent_ptr<PRnode> >::value_type&, PRnode*)’
126 |                         if (operator==(parentPtr->childPtrs[i],this)) {
      |                             ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/11/bits/stl_algobase.h:64,


Can somebody help me figure out how to resolve this error?

Best regards,
Supriya

Igor

unread,
Jun 29, 2023, 11:01:15 AM6/29/23
to Supriya Mishra SVNIT, pmem
Hi,

Since persistent_ptr overloads the comparison operator, you should just call:
if (child == root) {
    // do something
}

You can find more information on how operator overloading works here: https://en.cppreference.com/w/cpp/language/operators

Best regards,
Igor

--
You received this message because you are subscribed to the Google Groups "pmem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pmem+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pmem/8a8963d8-1eb7-4c46-b66c-9db790d533dfn%40googlegroups.com.

Supriya Mishra SVNIT

unread,
Jul 11, 2023, 1:16:54 PM7/11/23
to pmem
Hi Igor,

Thanks a lot for the help. I tried it and it worked.

Best regards,
Supriya
Reply all
Reply to author
Forward
0 new messages