@@ -137,31 +137,25 @@ Face::Face(Node& p1, Node& p2, Node& p3, Node& p4){
137
137
Node * set_default_node (node_map_t & nodes, int_t x, int_t y, int_t z,
138
138
double *xs, double *ys, double *zs){
139
139
int_t key = key_func (x, y, z);
140
- Node * point ;
141
- if (nodes. count (key) == 0 ){
142
- point = new Node (x, y, z, xs, ys, zs);
143
- nodes[key] = point ;
140
+ auto [it, inserted] = nodes. try_emplace (key, nullptr ) ;
141
+ if (inserted ){
142
+ // construct a new item at the emplaced location
143
+ it-> second = new Node (x, y, z, xs, ys, zs) ;
144
144
}
145
- else {
146
- point = nodes[key];
147
- }
148
- return point;
145
+ return it->second ;
149
146
}
150
147
151
148
Edge * set_default_edge (edge_map_t & edges, Node& p1, Node& p2){
152
149
int_t xC = (p1.location_ind [0 ]+p2.location_ind [0 ])/2 ;
153
150
int_t yC = (p1.location_ind [1 ]+p2.location_ind [1 ])/2 ;
154
151
int_t zC = (p1.location_ind [2 ]+p2.location_ind [2 ])/2 ;
155
152
int_t key = key_func (xC, yC, zC);
156
- Edge * edge;
157
- if (edges.count (key) == 0 ){
158
- edge = new Edge (p1, p2);
159
- edges[key] = edge;
160
- }
161
- else {
162
- edge = edges[key];
153
+ auto [it, inserted] = edges.try_emplace (key, nullptr );
154
+ if (inserted){
155
+ // construct a new item at the emplaced location
156
+ it->second = new Edge (p1, p2);
163
157
}
164
- return edge ;
158
+ return it-> second ;
165
159
};
166
160
167
161
Face * set_default_face (face_map_t & faces, Node& p1, Node& p2, Node& p3, Node& p4){
@@ -170,15 +164,12 @@ Face * set_default_face(face_map_t& faces, Node& p1, Node& p2, Node& p3, Node& p
170
164
y = (p1.location_ind [1 ]+p2.location_ind [1 ]+p3.location_ind [1 ]+p4.location_ind [1 ])/4 ;
171
165
z = (p1.location_ind [2 ]+p2.location_ind [2 ]+p3.location_ind [2 ]+p4.location_ind [2 ])/4 ;
172
166
key = key_func (x, y, z);
173
- Face * face;
174
- if (faces.count (key) == 0 ){
175
- face = new Face (p1, p2, p3, p4);
176
- faces[key] = face;
177
- }
178
- else {
179
- face = faces[key];
167
+ auto [it, inserted] = faces.try_emplace (key, nullptr );
168
+ if (inserted){
169
+ // construct a new item at the emplaced location
170
+ it->second = new Face (p1, p2, p3, p4);
180
171
}
181
- return face ;
172
+ return it-> second ;
182
173
}
183
174
184
175
Cell::Cell (Node *pts[8 ], int_t ndim, int_t maxlevel){
0 commit comments