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

Ill-defined copy/move constructors/operators for DefaultSolver #49

Open
nielsvd opened this issue Oct 4, 2024 · 0 comments
Open

Ill-defined copy/move constructors/operators for DefaultSolver #49

nielsvd opened this issue Oct 4, 2024 · 0 comments

Comments

@nielsvd
Copy link

nielsvd commented Oct 4, 2024

The C++ class DefaultSolver currently doesn't behave well when copied or moved.

Based on a quick scan of the C bindings, I don't think it's foreseen to be possible to copy a solver object. Hence, the copy constructor and operator should be deleted.

Moving a solver object is quite straightforward however, but the definition thereof is missing.

Tested implementation (nothing but standard boilerplate code):

template<typename T = double>
class DefaultSolver
{
   ...
    DefaultSolver(const DefaultSolver &) = delete;
    DefaultSolver(DefaultSolver &&other);
    DefaultSolver &operator=(const DefaultSolver &) = delete;
    DefaultSolver &operator=(DefaultSolver &&other);
    ...
};

template<typename T>
DefaultSolver<T>::DefaultSolver(DefaultSolver &&other) : handle(other.handle)
{
    other.handle = nullptr;
}

template<typename T>
DefaultSolver<T> &DefaultSolver<T>::operator=(DefaultSolver &&other)
{
    if (this != &other){
        handle = other.handle;
        other.handle = nullptr;
    }
    return *this;
}
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

1 participant