为什么 BGL 函数的参数用点而不是逗号分隔?

Why are the arguments to BGL functions separated by dots, instead of commas?

我正在阅读某人的代码。这是来自 boost 图形库的函数。 这是原始函数定义。

 void dijkstra_shortest_paths
      (const Graph& g,
       typename graph_traits<Graph>::vertex_descriptor s, 
       PredecessorMap predecessor, DistanceMap distance, WeightMap weight, 
       VertexIndexMap index_map,
       CompareFunction compare, CombineFunction combine, DistInf inf, DistZero zero,
       DijkstraVisitor vis, ColorMap color = default)

这是我从别人那里挑出来的一段代码。它有效,但我只是不明白为什么他在 predecessor_map weight_mapdistance_map 之间使用点而不是逗号?他传入函数的参数有多少?

dijkstra_shortest_paths(graph, source_vertex,
                          predecessor_map(&predecessors[0])
                          .weight_map(get(&Edge::cost, graph))
                          .distance_map(&distances[0]));

documentation 解释了发生了什么:

Many of the Boost.Graph algorithms have a long list of parameters, most of which have default values. This causes several problems.

[...]

A better solution is provided by bgl_named_params. This class allows users to provide parameters is any order, and matches arguments to parameters based on parameter names.

[...]

Each of the arguments is passed to a function whose name indicates which parameter the argument is for. Each of the named parameters is separated by a period, not a comma.

[...]

Typically the user never needs to deal with the bgl_named_params class directly, since there are functions like boost::weight_map that create an instance of bgl_named_params.

另见 What is the “Named Parameter Idiom”?