Skip to content
New issue

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

no match for ‘operator==’ #1672

Closed
thiagotps opened this issue Jun 18, 2020 · 3 comments
Closed

no match for ‘operator==’ #1672

thiagotps opened this issue Jun 18, 2020 · 3 comments

Comments

@thiagotps
Copy link

Hi everyone. The following code

#include <bits/stdc++.h>
#include <symengine/expression.h>
#include <symengine/functions.h>
#include <symengine/symbol.h>
#include <symengine/add.h>
#include <symengine/mul.h>

using namespace SymEngine;
using namespace std;




int main() {
  const RCP<const Basic> i1 = integer(10);
  const RCP<const Basic> i2 = i1;

  assert(i1 == i2);
  return 0;
}

results in the error:

/home/thiago/research/lmscpp/sym.cpp:18:13: error: no match foroperator==’ (operand types are ‘const SymEngine::RCP<const SymEngine::Basic>’ andconst SymEngine::RCP<const SymEngine::Basic>’)

The following code compiles fine:

#include <bits/stdc++.h>
#include <symengine/expression.h>
#include <symengine/functions.h>
#include <symengine/symbol.h>
#include <symengine/add.h>
#include <symengine/mul.h>

using namespace SymEngine;
using namespace std;

int main() {
  RCP<const Basic> i1 = integer(10);
  RCP<const Basic> i2 = i1;

  assert(i1 == i2);
  return 0;
}

I think the cause for this is the lack of a const in the end of bool operator==(const RCP<T2> &p2) in line 172, file symengine_rcp.h:

    template <class T2>
    bool operator==(const RCP<T2> &p2)
    {
        return ptr_ == p2.ptr_;
    }

That is, i think it should be:

    template <class T2>
    bool operator==(const RCP<T2> &p2) const
    {
        return ptr_ == p2.ptr_;
    }

Is this a bug ? Or its me using RCP wrongly ? Thanks in advance.

@thiagotps thiagotps changed the title no match for ‘operator==’ (operand types are ‘const SymEngine::RCP<const SymEngine::Basic>’ and ‘const SymEngine::RCP<const SymEngine::Basic>’) no match for ‘operator==’ Jun 18, 2020
@isuruf
Copy link
Member

isuruf commented Jun 18, 2020

Yes, it should be marked const. Btw, == will compare pointer equality and not that the two objects are equal. i.e. i1 == integer(10) will return False as they are two different Integer objects with the same value 10. You should use eq(*i1, *i2) if you want to check that the objects are equal.

@naveensaigit
Copy link
Contributor

Yes, it should be marked const.

Is this change required? I can add it

@lkeegan
Copy link
Member

lkeegan commented May 18, 2021

fixed in #1756

@lkeegan lkeegan closed this as completed May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants