Skip to content

Commit 2fb6e02

Browse files
committed
examples: C++11: Use using instead of typedef
1 parent 167ac18 commit 2fb6e02

File tree

170 files changed

+894
-994
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+894
-994
lines changed

example/accum-compile-times.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,25 +35,25 @@ BOOST_INSTALL_PROPERTY(vertex, compile_cost);
3535

3636
using namespace boost;
3737

38-
typedef adjacency_list< listS, // Store out-edges of each vertex in a std::list
39-
listS, // Store vertex set in a std::list
40-
directedS, // The file dependency graph is directed
41-
// vertex properties
42-
property< vertex_name_t, std::string,
43-
property< vertex_compile_cost_t, float,
44-
property< vertex_distance_t, float,
45-
property< vertex_color_t, default_color_type > > > >,
46-
// an edge property
47-
property< edge_weight_t, float > >
48-
file_dep_graph2;
38+
using file_dep_graph2
39+
= adjacency_list< listS, // Store out-edges of each vertex in a std::list
40+
listS, // Store vertex set in a std::list
41+
directedS, // The file dependency graph is directed
42+
// vertex properties
43+
property< vertex_name_t, std::string,
44+
property< vertex_compile_cost_t, float,
45+
property< vertex_distance_t, float,
46+
property< vertex_color_t, default_color_type > > > >,
47+
// an edge property
48+
property< edge_weight_t, float > >;
4949

50-
typedef graph_traits< file_dep_graph2 >::vertex_descriptor vertex_t;
51-
typedef graph_traits< file_dep_graph2 >::edge_descriptor edge_t;
50+
using vertex_t = graph_traits< file_dep_graph2 >::vertex_descriptor;
51+
using edge_t = graph_traits< file_dep_graph2 >::edge_descriptor;
5252

5353
int main(int argc, const char** argv)
5454
{
5555
std::ifstream file_in(argc >= 2 ? argv[1] : "makefile-dependencies.dat");
56-
typedef graph_traits< file_dep_graph2 >::vertices_size_type size_type;
56+
using size_type = graph_traits< file_dep_graph2 >::vertices_size_type;
5757
size_type n_vertices;
5858
file_in >> n_vertices; // read in number of vertices
5959
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300

example/actor_clustering.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ struct Actor
3434
int id;
3535
};
3636

37-
typedef adjacency_list< vecS, vecS, undirectedS, Actor,
38-
property< edge_centrality_t, double > >
39-
ActorGraph;
40-
typedef graph_traits< ActorGraph >::vertex_descriptor Vertex;
41-
typedef graph_traits< ActorGraph >::edge_descriptor Edge;
37+
using ActorGraph = adjacency_list< vecS, vecS, undirectedS, Actor,
38+
property< edge_centrality_t, double > >;
39+
using Vertex = graph_traits< ActorGraph >::vertex_descriptor;
40+
using Edge = graph_traits< ActorGraph >::edge_descriptor;
4241

4342
void load_actor_graph(std::istream& in, ActorGraph& g)
4443
{
@@ -50,7 +49,7 @@ void load_actor_graph(std::istream& in, ActorGraph& g)
5049
std::vector< Vertex > actors_in_movie;
5150

5251
// Map from the actor numbers on this line to the actor vertices
53-
typedef tokenizer< char_separator< char > > Tok;
52+
using Tok = tokenizer< char_separator< char > >;
5453
Tok tok(line, char_separator< char >(" "));
5554
for (auto const & id : tok)
5655
{
@@ -101,7 +100,7 @@ std::ostream& write_pajek_graph(std::ostream& out, const Graph& g,
101100

102101
class actor_clustering_threshold : public bc_clustering_threshold< double >
103102
{
104-
typedef bc_clustering_threshold< double > inherited;
103+
using inherited = bc_clustering_threshold< double >;
105104

106105
public:
107106
actor_clustering_threshold(

example/adj_list_ra_edgelist.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@
1414
int main()
1515
{
1616
using namespace boost;
17-
typedef adjacency_list< vecS, vecS, bidirectionalS, no_property,
18-
property< int, edge_weight_t >, no_property, vecS >
19-
Graph;
17+
using Graph = adjacency_list< vecS, vecS, bidirectionalS, no_property,
18+
property< int, edge_weight_t >, no_property, vecS >;
2019

2120
const std::size_t n = 3;
22-
typedef std::pair< std::size_t, std::size_t > E;
21+
using E = std::pair< std::size_t, std::size_t >;
2322
E edge_array[] = { E(0, 1), E(0, 2), E(0, 1) };
2423
const std::size_t m = sizeof(edge_array) / sizeof(E);
2524
Graph g(edge_array, edge_array + m, n);

example/adjacency_list.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ int main(int, char*[])
5454
using namespace boost;
5555
using namespace std;
5656

57-
typedef adjacency_list< vecS, listS, undirectedS, VertexProperties,
58-
EdgeProperties >
59-
Graph;
57+
using Graph = adjacency_list< vecS, listS, undirectedS, VertexProperties,
58+
EdgeProperties >;
6059

6160
const int V = 5;
6261
Graph g(V);

example/adjacency_list_io.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,26 @@ struct n1_t
3737
{
3838
num = 23063
3939
};
40-
typedef vertex_property_tag kind;
40+
using kind = vertex_property_tag;
4141
};
4242
struct n2_t
4343
{
4444
enum
4545
{
4646
num = 23062
4747
};
48-
typedef vertex_property_tag kind;
48+
using kind = vertex_property_tag;
4949
};
5050
struct n3_t
5151
{
5252
enum
5353
{
5454
num = 23061
5555
};
56-
typedef vertex_property_tag kind;
56+
using kind = vertex_property_tag;
5757
};
58-
typedef property< n1_t, int,
59-
property< n2_t, double, property< n3_t, MyStruct > > >
60-
VertexProperty;
58+
using VertexProperty = property< n1_t, int,
59+
property< n2_t, double, property< n3_t, MyStruct > > >;
6160

6261
//====== edge properties
6362
struct e1_t
@@ -66,18 +65,17 @@ struct e1_t
6665
{
6766
num = 23064
6867
};
69-
typedef edge_property_tag kind;
68+
using kind = edge_property_tag;
7069
};
71-
typedef property< e1_t, double > EdgeProperty;
70+
using EdgeProperty = property< e1_t, double >;
7271

7372
//===== graph types
7473

75-
typedef adjacency_list< vecS, listS, directedS, no_property, no_property >
76-
Graph1;
74+
using Graph1
75+
= adjacency_list< vecS, listS, directedS, no_property, no_property >;
7776

78-
typedef adjacency_list< setS, setS, bidirectionalS, VertexProperty,
79-
EdgeProperty >
80-
Graph2;
77+
using Graph2 = adjacency_list< setS, setS, bidirectionalS, VertexProperty,
78+
EdgeProperty >;
8179

8280
int main()
8381
{
@@ -103,7 +101,7 @@ int main()
103101
// read Graph2, incomplete data in a different order. Write it diffently.
104102
Graph2 g31;
105103
std::ifstream readFile31("data3.txt");
106-
typedef property< n3_t, MyStruct, property< n1_t, int > > readNodeProp;
104+
using readNodeProp = property< n3_t, MyStruct, property< n1_t, int > >;
107105
readFile31 >> read(g31, readNodeProp(), EdgeProperty());
108106
std::cout << "graph g31 from file data3.txt:\n"
109107
<< write(g31, property< n3_t, MyStruct >(), EdgeProperty())

example/adjacency_matrix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int main()
2828

2929
// A directed graph
3030

31-
typedef adjacency_matrix< directedS > Graph;
31+
using Graph = adjacency_matrix< directedS >;
3232
Graph g(N);
3333
add_edge(B, C, g);
3434
add_edge(B, F, g);
@@ -52,7 +52,7 @@ int main()
5252

5353
// An undirected graph
5454

55-
typedef adjacency_matrix< undirectedS > UGraph;
55+
using UGraph = adjacency_matrix< undirectedS >;
5656
UGraph ug(N);
5757
add_edge(B, C, ug);
5858
add_edge(B, F, ug);

example/astar-cities.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct location
3030
{
3131
float y, x; // lat, long
3232
};
33-
typedef float cost;
33+
using cost = float;
3434

3535
template < class Name, class LocMap > class city_writer
3636
{
@@ -82,7 +82,7 @@ template < class Graph, class CostType, class LocMap >
8282
class distance_heuristic : public astar_heuristic< Graph, CostType >
8383
{
8484
public:
85-
typedef typename graph_traits< Graph >::vertex_descriptor Vertex;
85+
using Vertex = typename graph_traits< Graph >::vertex_descriptor;
8686
distance_heuristic(LocMap l, Vertex goal) : m_location(l), m_goal(goal) {}
8787
CostType operator()(Vertex u)
8888
{
@@ -120,13 +120,12 @@ int main(int argc, char** argv)
120120
{
121121

122122
// specify some types
123-
typedef adjacency_list< listS, vecS, undirectedS, no_property,
124-
property< edge_weight_t, cost > >
125-
mygraph_t;
126-
typedef property_map< mygraph_t, edge_weight_t >::type WeightMap;
127-
typedef mygraph_t::vertex_descriptor vertex;
128-
typedef mygraph_t::edge_descriptor edge_descriptor;
129-
typedef std::pair< int, int > edge;
123+
using mygraph_t = adjacency_list< listS, vecS, undirectedS, no_property,
124+
property< edge_weight_t, cost > >;
125+
using WeightMap = property_map< mygraph_t, edge_weight_t >::type;
126+
using vertex = mygraph_t::vertex_descriptor;
127+
using edge_descriptor = mygraph_t::edge_descriptor;
128+
using edge = std::pair< int, int >;
130129

131130
// specify data
132131
enum nodes

example/astar_maze.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
boost::mt19937 random_generator;
4646

4747
// Distance traveled in the maze
48-
typedef double distance;
48+
using distance = double;
4949

5050
#define GRID_RANK 2
51-
typedef boost::grid_graph< GRID_RANK > grid;
52-
typedef boost::graph_traits< grid >::vertex_descriptor vertex_descriptor;
53-
typedef boost::graph_traits< grid >::vertices_size_type vertices_size_type;
51+
using grid = boost::grid_graph< GRID_RANK >;
52+
using vertex_descriptor = boost::graph_traits< grid >::vertex_descriptor;
53+
using vertices_size_type = boost::graph_traits< grid >::vertices_size_type;
5454

5555
// A hash function for vertices.
5656
struct vertex_hash
@@ -66,9 +66,9 @@ struct vertex_hash
6666
}
6767
};
6868

69-
typedef boost::unordered_set< vertex_descriptor, vertex_hash > vertex_set;
70-
typedef boost::vertex_subset_complement_filter< grid, vertex_set >::type
71-
filtered_grid;
69+
using vertex_set = boost::unordered_set< vertex_descriptor, vertex_hash >;
70+
using filtered_grid
71+
= boost::vertex_subset_complement_filter< grid, vertex_set >::type;
7272

7373
// A searchable maze
7474
//
@@ -190,14 +190,13 @@ bool maze::solve()
190190
{
191191
boost::static_property_map< distance > weight(1);
192192
// The predecessor map is a vertex-to-vertex mapping.
193-
typedef boost::unordered_map< vertex_descriptor, vertex_descriptor,
194-
vertex_hash >
195-
pred_map;
193+
using pred_map = boost::unordered_map< vertex_descriptor, vertex_descriptor,
194+
vertex_hash >;
196195
pred_map predecessor;
197196
boost::associative_property_map< pred_map > pred_pmap(predecessor);
198197
// The distance map is a vertex-to-distance mapping.
199-
typedef boost::unordered_map< vertex_descriptor, distance, vertex_hash >
200-
dist_map;
198+
using dist_map
199+
= boost::unordered_map< vertex_descriptor, distance, vertex_hash >;
201200
dist_map distance;
202201
boost::associative_property_map< dist_map > dist_pmap(distance);
203202

example/bellman-example.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ int main()
5656
N
5757
};
5858
char name[] = { 'u', 'v', 'x', 'y', 'z' };
59-
typedef std::pair< int, int > E;
59+
using E = std::pair< int, int >;
6060
const int n_edges = 10;
6161
E edge_array[] = { E(u, y), E(u, x), E(u, v), E(v, u), E(x, y), E(x, v),
6262
E(y, v), E(y, z), E(z, u), E(z, x) };
6363
int weight[n_edges] = { -4, 8, 5, -2, 9, -3, 7, 2, 6, 7 };
6464

65-
typedef adjacency_list< vecS, vecS, directedS, no_property, EdgeProperties >
66-
Graph;
65+
using Graph
66+
= adjacency_list< vecS, vecS, directedS, no_property, EdgeProperties >;
6767
#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
6868
// VC++ can't handle the iterator constructor
6969
Graph g(N);

example/bellman-ford-internet.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,16 @@ int main()
2626
n_vertices
2727
};
2828
const int n_edges = 11;
29-
typedef std::pair< int, int > Edge;
29+
using Edge = std::pair< int, int >;
3030

3131
// The list of connections between routers stored in an array.
3232
Edge edges[] = { Edge(A, B), Edge(A, C), Edge(B, D), Edge(B, E), Edge(C, E),
3333
Edge(C, F), Edge(D, H), Edge(D, E), Edge(E, H), Edge(F, G),
3434
Edge(G, H) };
3535

3636
// Specify the graph type and declare a graph object
37-
typedef edge_list< Edge*, Edge, std::ptrdiff_t,
38-
std::random_access_iterator_tag >
39-
Graph;
37+
using Graph = edge_list< Edge*, Edge, std::ptrdiff_t,
38+
std::random_access_iterator_tag >;
4039
Graph g(edges, edges + n_edges);
4140

4241
// The transmission delay values for each edge.

0 commit comments

Comments
 (0)