Search code examples
c++lemon-graph-library

Making a vector of graphs in Lemon Graph Library


I created a graph and added nodes and transitions to it in Lemon Graph Library

typedef ListDigraph Graph;
vector<Graph> Process;
for(temp = temp.child("role");temp;temp = temp.next_sibling("role"))
{
    Graph proc;
    for(xml_node temp1 = temp.child("states").child("state");temp1;temp1 = temp1.next_sibling())
    {
        string state = temp1.child_value();
        state = role + "_" + state;
        vertex = process.addNode();
        state_name[vertex] = state;
    }
    Process.push_back(proc);
}

If I don't push it in vector everything works fine, but when I try to push it in Process I get error. Error is 70-80 lines long, but the main point I found is:

/usr/local/include/lemon/list_graph.h:336:5: error:
lemon::ListDigraph::ListDigraph(const lemon::ListDigraph&) is private 

After doing what @Magtheridon96 suggested getting the following error:

    In file included from /usr/include/c++/4.6/i686-linux-gnu/./bits/c++allocator.h:34:0,
                 from /usr/include/c++/4.6/bits/allocator.h:48,
                 from /usr/include/c++/4.6/string:43,
                 from /usr/include/c++/4.6/bits/locale_classes.h:42,
                 from /usr/include/c++/4.6/bits/ios_base.h:43,
                 from /usr/include/c++/4.6/ios:43,
                 from /usr/include/c++/4.6/ostream:40,
                 from /usr/include/c++/4.6/iostream:40,
                 from usingleda.cpp:1:
/usr/include/c++/4.6/ext/new_allocator.h: In member function ‘void __gnu_cxx::new_allocator<_Tp>::construct(__gnu_cxx::new_allocator<_Tp>::pointer, _Args&& ...) [with _Args = {std::unique_ptr<lemon::ListDigraph>&}, _Tp = std::unique_ptr<lemon::ListDigraph>, __gnu_cxx::new_allocator<_Tp>::pointer = std::unique_ptr<lemon::ListDigraph>*]’:
/usr/include/c++/4.6/bits/vector.tcc:97:6:   instantiated from ‘void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {std::unique_ptr<lemon::ListDigraph>&}, _Tp = std::unique_ptr<lemon::ListDigraph>, _Alloc = std::allocator<std::unique_ptr<lemon::ListDigraph> >]’
usingleda.cpp:134:43:   instantiated from here
/usr/include/c++/4.6/ext/new_allocator.h:114:4: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = lemon::ListDigraph, _Dp = std::default_delete<lemon::ListDigraph>, std::unique_ptr<_Tp, _Dp> = std::unique_ptr<lemon::ListDigraph>]’
/usr/include/c++/4.6/bits/unique_ptr.h:256:7: error: declared here
In file included from /usr/include/c++/4.6/vector:70:0,
                 from /usr/local/include/lemon/core.h:22,
                 from /usr/local/include/lemon/list_graph.h:26,
                 from usingleda.cpp:3:
/usr/include/c++/4.6/bits/vector.tcc: In member function ‘void std::vector<_Tp, _Alloc>::_M_insert_aux(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {std::unique_ptr<lemon::ListDigraph>&}, _Tp = std::unique_ptr<lemon::ListDigraph>, _Alloc = std::allocator<std::unique_ptr<lemon::ListDigraph> >, std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::unique_ptr<lemon::ListDigraph>*, std::vector<std::unique_ptr<lemon::ListDigraph> > >, typename std::_Vector_base<_Tp, _Alloc>::_Tp_alloc_type::pointer = std::unique_ptr<lemon::ListDigraph>*]’:
/usr/include/c++/4.6/bits/vector.tcc:102:4:   instantiated from ‘void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {std::unique_ptr<lemon::ListDigraph>&}, _Tp = std::unique_ptr<lemon::ListDigraph>, _Alloc = std::allocator<std::unique_ptr<lemon::ListDigraph> >]’
usingleda.cpp:134:43:   instantiated from here
/usr/include/c++/4.6/bits/vector.tcc:319:4: error: use of deleted function ‘std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = lemon::ListDigraph, _Dp = std::default_delete<lemon::ListDigraph>, std::unique_ptr<_Tp, _Dp> = std::unique_ptr<lemon::ListDigraph>]’
/usr/include/c++/4.6/bits/unique_ptr.h:256:7: error: declared here

Solution

  • You are not permitted to make copies of this object (This is what the author wants). The author of the library made the copy constructor private to ensure that you can't do this.

    The solution is to change std::vector<Graph> to std::vector<std::unique_ptr<Graph>>

    That way, you don't need to make copies of the object as the author intended.

    You would then allocate and insert like this:

    std::unique_ptr<Graph> graph(new Graph);
    // ...
    vec.emplace_back(graph);