Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/graph/doc/bgl_named_params.html @ 14

Last change on this file since 14 was 12, checked in by landauf, 17 years ago

added boost

File size: 3.5 KB
Line 
1<HTML>
2<!--
3  -- Copyright (c) Jeremy Siek 2000
4  --
5  -- Permission to use, copy, modify, distribute and sell this software
6  -- and its documentation for any purpose is hereby granted without fee,
7  -- provided that the above copyright notice appears in all copies and
8  -- that both that copyright notice and this permission notice appear
9  -- in supporting documentation.  Jeremy Siek makes no
10  -- representations about the suitability of this software for any
11  -- purpose.  It is provided "as is" without express or implied warranty.
12  -->
13<Head>
14<Title>Boost Graph Library: Named Parameters</Title>
15<BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" 
16        ALINK="#ff0000"> 
17<IMG SRC="../../../boost.png" 
18     ALT="C++ Boost" width="277" height="86"> 
19
20<BR Clear>
21
22<H1><A NAME="sec:bgl-named-params"></A>
23<pre>
24bgl_named_params&lt;Param, Type, Rest&gt;
25</pre>
26</H1>
27
28<p>
29Many of the Boost.Graph algorithms have a long list of parameters,
30most of which have default values. This causes several problems.
31First, C++ does not provide a mechanism for handling default
32parameters of template functions. However, this can be overcome by
33creating multiply version of an algorithm with different numbers of
34parameters with each version providing defaults for some subset of
35the parameters. This is the approach used in previous versions of
36Boost.Graph. This solution is still unsatisfactory for several
37reasons:
38
39<ul>
40  <li>The defaults for parameters can only been used in a particular
41  order. If the ordering of the defaults does not fit the users situation
42  he or she has to resort to providing all the parameters.
43
44  <li>Since the list of parameters is long, it is easy to forget
45   the ordering.
46</ul>
47
48<p>
49A better solution is provided by <tt>bgl_named_params</tt>. This class
50allows users to provide parameters is any order, and matches
51arguments to parameters based on parameter names.
52
53<p>
54The following code shows an example of calling
55<tt>bellman_ford_shortest_paths</tt> using the named parameter
56technique. Each of the arguments is passed to a function whose name
57indicates which parameter the argument is for. Each of the named
58parameters is separated by a <b>period</b>, not a comma.
59
60<pre>
61  bool r = boost::bellman_ford_shortest_paths(g, int(N),
62     boost::weight_map(weight).
63     distance_map(&amp;distance[0]).
64     predecessor_map(&amp;parent[0]));
65</pre>
66
67<p>The order in which the arguments are provided does not matter as
68long as they are matched with the correct parameter function.  Here is
69an call to <tt>bellman_ford_shortest_paths</tt> that is equivalent to
70the one above.
71
72<pre>
73  bool r = boost::bellman_ford_shortest_paths(g, int(N),
74     boost::predecessor_map(&amp;parent[0]).
75     distance_map(&amp;distance[0]).
76     weight_map(weight));
77</pre>
78
79<p>Typically the user never needs to deal with the
80<tt>bgl_named_params</tt> class directly, since there are functions
81like <tt>boost::weight_map</tt> that create an instance of
82<tt>bgl_named_params</tt>.
83
84
85<br>
86<HR>
87<TABLE>
88<TR valign=top>
89<TD nowrap>Copyright &copy 2000-2001</TD><TD>
90<A HREF="../../../people/jeremy_siek.htm">Jeremy Siek</A>,
91Indiana University (<A
92HREF="mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</A>)<br>
93<A HREF="../../../people/liequan_lee.htm">Lie-Quan Lee</A>, Indiana University (<A HREF="mailto:llee@cs.indiana.edu">llee@cs.indiana.edu</A>)<br>
94<A HREF=http://www.osl.iu.edu/~lums>Andrew Lumsdaine</A>,
95Indiana University (<A
96HREF="mailto:lums@osl.iu.edu">lums@osl.iu.edu</A>)
97</TD></TR></TABLE>
98
99</BODY>
100</HTML>
Note: See TracBrowser for help on using the repository browser.