1

I'm using Lemon Graph Library and I want to add an item to a lemon map without copying it or asigning. Here is the code:

#include <iostream>
#include <lemon/list_graph.h>
#include <lemon/maps.h>

using namespace lemon;
using namespace std;

typedef lemon::ListDigraph             LGraph;
typedef lemon::ListDigraph::Arc        LArc;
typedef lemon::ListDigraph::Node       LNode;

class MyNode {
public:
    CrossRefMap<LGraph, LArc, std::string> inputs;

    MyNode(const LGraph& graph) : inputs(graph) { }
};


int main(){
    LGraph graph;
    LGraph::NodeMap<MyNode> nodes(graph);

    LNode n = graph.addNode();
    nodes[n] = MyNode(graph); // error: object of type 'MyNode' cannot be assigned because its copy assignment operator is implicitly deleted

    return 0;
}

The main problem here is the CrossRefMap which needs initialization in constructor and has has no copy consturctor or assignment operator. I could use pointer to this structure instead, but this solution doesn't satisfy me. How can I solve this problem? Any suggestions will be appreciated. ;)

Artem Zankovich
  • 2,319
  • 20
  • 36
remdezx
  • 2,939
  • 28
  • 49
  • 1
    How about providing a _move-constructor_, or possibly define some kind of _swap member function_ and do something like `MyNode(graph).swap(nodes[n])` – Tom Knapen Jun 05 '13 at 17:25
  • It's nice idea, but I just noticed, that when I add move constructor to Node I need to add copy constructor too ;/ Lemon uses coy constuctor in map initialization. So I still don't know how to insert lemon map to a lemon map this way. – remdezx Jun 07 '13 at 13:21
  • What about using any wrapper around `MyNode`? That wrapper would be a smart pointer or `reference_wrapper`. – Gonmator Jul 17 '13 at 11:45
  • And what about using move assignment operator `MyNode& operator=(MyNode&&)`? – Gonmator Jul 17 '13 at 11:49

1 Answers1

1

As far as I know there is no possibility to do it with standard lemon maps, so I implemented my own one based on std::map. I can track changes in the graph and update my map using lemon graph observers.

remdezx
  • 2,939
  • 28
  • 49