Skip to content

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

Open
@nielsvd

Description

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions