Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Exercise 1: dispatching a function to C++

Authors: Tiago P. Peixoto1
Affiliations: 1Inverse Complexity Lab
License: CC-BY

Take a look at the template below (available from the manual repo; no need to copy and paste.)

The first file defines a C++ function that receives a graph and a property map, and just prints its values.

example.hh
#include "graph_tool.hh"

#include <iostream>

using namespace graph_tool;
using namespace boost;
using namespace std;

template <typename Graph, typename VMap>
void example(Graph& g, VMap vmap)
{
    cout << "Running on a graph with " << num_vertices(g)
         << " vertices and " << num_edges(g)
         << " edges, with vertex properties given by:" << endl;

    for (auto v : vertices_range(g))
        cout <<  vmap[v] << " ";
    cout << endl;
}

The second file is a compilation unit that dispatches the function above to the appropriate type, depending on what has been received from the Python interpreter.

example.cc
#include <boost/python.hpp>
#include "example.hh"

BOOST_PYTHON_MODULE(libexample)
{
    using namespace boost::python;
    def("example",
        +[](GraphInterface& gi, std::any avmap)
        {
            gt_dispatch<>()
                ([&](auto& g, auto vmap){ example(g, vmap); },
                 all_graph_views, vertex_scalar_properties)
                (gi.get_graph_view(), avmap);
        });
}

The third file is a Python file that binds a function to the its C++ implementation defined above:

example.py
import graph_tool

import libexample

def example(g, vmap=None):
    if vmap is None:
        vmap = g.new_vertex_property("int")
    libexample.example(g._Graph__graph, vmap._get_any())
    return vmap

Finally, the Makefile below facilitates the compilation:

Makefile
CXX=g++
CXXFLAGS=-O3 -fopenmp -std=gnu++17 -Wall -fPIC `pkg-config --cflags --libs graph-tool-py` -shared -DBOOST_ALLOW_DEPRECATED_HEADERS -DNDEBUG
ALL: libexample.so

libexample.so: example.hh example.cc
	${CXX} ${CXXFLAGS} example.cc -o libexample.so

We need to compile the C++ code by typing make:

$ make
g++ -O3 -fopenmp -std=gnu++17 -Wall -fPIC `pkg-config --cflags --libs graph-tool-py` -shared -DBOOST_ALLOW_DEPRECATED_HEADERS -DNDEBUG example.cc -o libexample.so
In file included from /usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph.hh:41,
                 from /usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_tool.hh:21,
                 from example.hh:1,
                 from example.cc:2:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:281:1: warning: identifier ‘concept’ is a keyword in C++20 []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-compat-Wc++20-compat]8;;]
  281 | concept CheckedPMap =
      | ^~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:282:5: warning: identifier ‘requires’ is a keyword in C++20 []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-compat-Wc++20-compat]8;;]
  282 |     requires(T a)
      |     ^~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:281:1: error: concept’ does not name a type; did you mean ‘const’?
  281 | concept CheckedPMap =
      | ^~~~~~~
      | const
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:281:1: note: concept’ only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:288:1: error: concept’ does not name a type; did you mean ‘const’?
  288 | concept UncheckedPMap =
      | ^~~~~~~
      | const
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:288:1: note: concept’ only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:299:31: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  299 |     decltype(auto) operator()(auto&& a)
      |                               ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:305:11: error: CheckedPMap’ has not been declared
  305 | template <CheckedPMap T>
      |           ^~~~~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:306:16: error: T’ was not declared in this scope
  306 | struct uncheck<T>
      |                ^
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:306:17: error: template argument 1 is invalid
  306 | struct uncheck<T>
      |                 ^
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:321:31: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  321 |     decltype(auto) operator()(auto&& a)
      |                               ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:327:11: error: UncheckedPMap’ has not been declared
  327 | template <UncheckedPMap T>
      |           ^~~~~~~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:328:14: error: T’ was not declared in this scope
  328 | struct check<T>
      |              ^
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/fast_vector_property_map.hh:328:15: error: template argument 1 is invalid
  328 | struct check<T>
      |               ^
In file included from /usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph.hh:45:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_properties.hh:809:31: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  809 |     decltype(auto) operator[](auto&& k)
      |                               ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_properties.hh:837:25: error: need ‘typename’ before ‘graph_tool::promote_value<T>::type’ because ‘graph_tool::promote_value<T>’ is a dependent scope
  837 | using promote_value_t = promote_value<T>::type;
      |                         ^~~~~~~~~~~~~~~~
      |                         typename 
In file included from /usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:44,
                 from /usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_filtering.hh:31,
                 from /usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_tool.hh:22:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:147:16: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  147 | auto in_degree(auto v, const auto& g, const auto& ew)
      |                ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:147:30: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  147 | auto in_degree(auto v, const auto& g, const auto& ew)
      |                              ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:147:45: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  147 | auto in_degree(auto v, const auto& g, const auto& ew)
      |                                             ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:208:17: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  208 | auto out_degree(auto v, const auto& g, const auto& ew)
      |                 ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:208:31: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  208 | auto out_degree(auto v, const auto& g, const auto& ew)
      |                               ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:208:46: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  208 | auto out_degree(auto v, const auto& g, const auto& ew)
      |                                              ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:253:19: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  253 | auto total_degree(auto v, const auto& g, const auto& ew)
      |                   ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:253:33: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  253 | auto total_degree(auto v, const auto& g, const auto& ew)
      |                                 ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:253:48: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  253 | auto total_degree(auto v, const auto& g, const auto& ew)
      |                                                ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:258:19: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  258 | auto total_degree(auto v, const auto& g)
      |                   ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:258:33: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  258 | auto total_degree(auto v, const auto& g)
      |                                 ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:263:23: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  263 | auto in_or_out_degree(auto v, const auto& g, auto&&... w)
      |                       ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:263:37: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  263 | auto in_or_out_degree(auto v, const auto& g, auto&&... w)
      |                                     ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:263:46: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  263 | auto in_or_out_degree(auto v, const auto& g, auto&&... w)
      |                                              ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:574:19: error: std::ranges’ has not been declared []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  574 |     : public std::ranges::view_interface<IterRange<Iter>>
      |                   ^~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_selectors.hh:574:27: error: expected ‘{’ before ‘view_interface’
  574 |     : public std::ranges::view_interface<IterRange<Iter>>
      |                           ^~~~~~~~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:288:12: error: std::views’ has not been declared
  288 | using std::views::enumerate;
      |            ^~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh: In function ‘void graph_tool::parallel_loop(Range&&, F&&, size_t, Except*)’:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:338:35: error: std::ranges’ has not been declared []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  338 |     #pragma omp parallel if (std::ranges::size(vals) > thres)
      |                                   ^~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh: At global scope:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:348:32: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  348 | bool quiet_cmp(T1&& x, T2&& y, auto&& f_int, auto&& f)
      |                                ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:348:46: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  348 | bool quiet_cmp(T1&& x, T2&& y, auto&& f_int, auto&& f)
      |                                              ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh: In lambda function:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:361:57: error: cmp_equal’ is not a member of ‘std’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  361 |                      [](auto&& x, auto&& y){return std::cmp_equal(x, y);},
      |                                                         ^~~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:361:57: note: std::cmp_equal’ is only available from C++20 onwards
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh: In lambda function:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:369:57: error: cmp_not_equal’ is not a member of ‘std’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  369 |                      [](auto&& x, auto&& y){return std::cmp_not_equal(x, y);},
      |                                                         ^~~~~~~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:369:57: note: std::cmp_not_equal’ is only available from C++20 onwards
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh: In lambda function:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:377:57: error: cmp_less’ is not a member of ‘std’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  377 |                      [](auto&& x, auto&& y){return std::cmp_less(x, y);},
      |                                                         ^~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:377:57: note: std::cmp_less’ is only available from C++20 onwards
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh: In lambda function:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:385:57: error: cmp_greater’ is not a member of ‘std’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  385 |                      [](auto&& x, auto&& y){return std::cmp_greater(x, y);},
      |                                                         ^~~~~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:385:57: note: std::cmp_greater’ is only available from C++20 onwards
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh: In lambda function:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:393:57: error: cmp_less_equal’ is not a member of ‘std’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  393 |                      [](auto&& x, auto&& y){return std::cmp_less_equal(x, y);},
      |                                                         ^~~~~~~~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:393:57: note: std::cmp_less_equal’ is only available from C++20 onwards
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh: In lambda function:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:401:57: error: cmp_greater_equal’ is not a member of ‘std’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  401 |                      [](auto&& x, auto&& y){return std::cmp_greater_equal(x, y);},
      |                                                         ^~~~~~~~~~~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:401:57: note: std::cmp_greater_equal’ is only available from C++20 onwards
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh: At global scope:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:668:10: error: iter_reference_t’ in namespace ‘std’ does not name a template type; did you mean ‘is_reference_v’? []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  668 |     std::iter_reference_t<random_access_adaptor<Iter>>
      |          ^~~~~~~~~~~~~~~~
      |          is_reference_v
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh: In function ‘auto make_random_access_adaptor(Iter)’:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:678:24: error: random_access_iterator’ is not a member of ‘std’; did you mean ‘random_access_iterator_tag’? []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  678 |     static_assert(std::random_access_iterator<random_access_adaptor<Iter>>);
      |                        ^~~~~~~~~~~~~~~~~~~~~~
      |                        random_access_iterator_tag
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:678:73: error: expected primary-expression before ‘>’ token []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  678 | tatic_assert(std::random_access_iterator<random_access_adaptor<Iter>>);
      |                                                                    ^~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:678:75: error: expected primary-expression before ‘)’ token []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  678 | tatic_assert(std::random_access_iterator<random_access_adaptor<Iter>>);
      |                                                                      ^
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh: In function ‘auto make_random_access_adaptor_range(Range&&)’:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:685:50: error: std::ranges’ has not been declared []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  685 |     auto begin = make_random_access_adaptor(std::ranges::begin(range));
      |                                                  ^~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:686:48: error: std::ranges’ has not been declared []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  686 |     auto end = make_random_access_adaptor(std::ranges::end(range));
      |                                                ^~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:688:24: error: std::ranges’ has not been declared []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  688 |     static_assert(std::ranges::random_access_range<decltype(rg)>);
      |                        ^~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:688:52: error: expected primary-expression before ‘decltype’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  688 |     static_assert(std::ranges::random_access_range<decltype(rg)>);
      |                                                    ^~~~~~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:688:52: error: expected ‘,’ before ‘decltype’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  688 |     static_assert(std::ranges::random_access_range<decltype(rg)>);
      |                                                    ^~~~~~~~~~~~
      |                                                    ,
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:688:52: warning: static_assert’ with non-string message only available with ‘-std=c++2c’ or ‘-std=gnu++2c’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b26-extensions-Wc++26-extensions]8;;]
  688 |     static_assert(std::ranges::random_access_range<decltype(rg)>);
      |                                                    ^~~~~~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:688:52: error: expected primary-expression before ‘decltype’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_util.hh:688:52: error: expected ‘)’ before ‘decltype’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  688 |     static_assert(std::ranges::random_access_range<decltype(rg)>);
      |                  ~                                 ^~~~~~~~~~~~
      |                                                    )
In file included from /usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_filtering.hh:33:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh: In constructor ‘graph_tool::DispatchNotFound::DispatchNotFound(const std::string&, size_t, const std::vector<std::__cxx11::basic_string<char> >&, const std::string&)’:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh:92:24: error: format’ is not a member of ‘std’
   92 |         _error += std::format("Cannot extract argument number {} of desired types {} from value: {}",
      |                        ^~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh:92:24: note: std::format’ is only available from C++20 onwards
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh: At global scope:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh:128:35: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘]8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-fconcepts-fconcepts]8;;’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b20-extensions-Wc++20-extensions]8;;]
  128 | std::vector<std::string> print_tr(auto tr)
      |                                   ^~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh:155:37: error: non-type template parameters of class type only available with ‘-std=c++20’ or ‘-std=gnu++20’
  155 | template <gt_dispatch_args dargs = {}>
      |                                     ^
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh:159:17: warning: static auto graph_tool::gt_dispatch<dargs>::operator()(Dispatch&&, TRS ...)’ may be a static member function only with ‘-std=c++23’ or ‘-std=gnu++23’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/Warning-Options.html#index-Wc_002b_002b23-extensions-Wc++23-extensions]8;;]
  159 |     static auto operator()(Dispatch&& d, TRS... trs)
      |                 ^~~~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh: In member function ‘T graph_tool::extract_param_base<T>::operator()(std::any&)’:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh:439:44: error: format’ is not a member of ‘std’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  439 |                     throw bad_extract(std::format("cannot extract C++ object of type '{}' from std::any, has type: {} ",
      |                                            ^~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh:439:44: note: std::format’ is only available from C++20 onwards
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh: In member function ‘void graph_tool::extract_param_base<T>::throw_err(boost::python::api::object, std::string)’:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh:448:32: error: format’ is not a member of ‘std’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  448 |         throw bad_extract(std::format("cannot extract C++ object of type '{}' from python object: {}{}",
      |                                ^~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh:448:32: note: std::format’ is only available from C++20 onwards
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh: In member function ‘auto graph_tool::extract_param<boost::multi_array_ref<T, NumDims> >::operator()(boost::python::api::object)’:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh:470:39: error: format’ is not a member of ‘std’ []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  470 |             this->throw_err(obj, std::format(", reason: {}", e.what()));
      |                                       ^~~~~~
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/dispatch.hh:470:39: note: std::format’ is only available from C++20 onwards
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_filtering.hh: At global scope:
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_filtering.hh:189:36: error: non-type template parameters of deduced class type only available with ‘-std=c++20’ or ‘-std=gnu++20’
  189 | template <run_action_args rargs = {}>
      |                                    ^
/usr/lib/python3.14/site-packages/graph_tool/include/src/graph/graph_filtering.hh:191:37: error: template argument 1 is invalid []8;;https://gcc.gnu.org/onlinedocs/gcc-16.1.0/gcc/C_002b_002b-Dialect-Options.html#index-Wno-template-body-Wtemplate-body]8;;]
  191 |     : public gt_dispatch<rargs.dargs>
      |                                     ^
example.cc: In lambda function:
example.cc:10:25: note: invalid template non-type parameter
   10 |             gt_dispatch<>()
      |                         ^
example.cc:12:35: error: vertex_scalar_properties’ was not declared in this scope
   12 |                  all_graph_views, vertex_scalar_properties)
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~~
make: *** [Makefile:6: libexample.so] Error 1

Now we are ready to call the function above from Python:

from graph_tool.all import *
from example import example

g = collection.data["dolphins"]

example(g, g.vertex_index);
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 2
      1 from graph_tool.all import *
----> 2 from example import example
      3 
      4 g = collection.data["dolphins"]
      5 

File ~/builds/qLnTWJPqx/0/invcomplexity/lab-manual/gt-workbench/exercise1/example.py:3
      1 import graph_tool
----> 3 import libexample
      5 def example(g, vmap=None):
      6     if vmap is None:

ModuleNotFoundError: No module named 'libexample'

Task 1: Modify the code above to store the number of second neighbors to the property map.

Solutions

Add a link here to your solution as a gitlab repository.

Task 2: Modify the code above to store for each vertex a vector with the 10 closest neighbors.

Solutions

Add a link here to your solution as a gitlab repository.

Task 3: Modify the code above to store the PageRank to the property map.

Solutions

Add a link here to your solution as a gitlab repository.

Task 4: Modify the code above so that the function returns true if the graph is bipartite.

Solutions

Add a link here to your solution as a gitlab repository.

Task 5: Modify the code above so that the function returns performs some computation if the graph is undirected and another if it is directed.

Solutions

Add a link here to your solution as a gitlab repository.