Skip to content

Make std::map pickable #5266

Discussion options

You must be logged in to vote

Hi @alvaro-diaz-valenzuela you need to manually cast to desired pair in a loop. Automatic iteration over py::tuple is simply catching py::handle instances -- thus the translation to std::pair is simply unknown, you probably would need type_caster for it. However, there is a simpler way, written below.

Here is what you need to do (I have simplified the QCData):

class QCDate;  // forward declarations

PYBIND11_MAKE_OPAQUE(std::map<QCDate, double>);

namespace py = pybind11;

class QCDate {
public:
	QCDate() {}
	QCDate(int v) : value{v} {}

    bool operator<(const QCDate& other) const
    {
        return value < other.value;
    }

	int value;
};

PYBIND11_MODULE(mymodule, m)
{
    m.doc() = 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@alvaro-diaz-valenzuela
Comment options

Answer selected by alvaro-diaz-valenzuela
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants