Skip to content

Commit f872370

Browse files
committed
Use C++11 for-loop
1 parent 60dde1f commit f872370

File tree

3 files changed

+16
-36
lines changed

3 files changed

+16
-36
lines changed

Commands/nib/nib.mm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ @interface TMDWindowCommand : TMDCommand
4141
candidates.push_back(nibName);
4242
}
4343

44-
iterate(it, candidates)
44+
for(std::string const& path : candidates)
4545
{
4646
struct stat sb;
47-
if(stat(it->c_str(), &sb) == 0)
48-
return *it;
47+
if(stat(path.c_str(), &sb) == 0)
48+
return path;
4949
}
5050

5151
fprintf(stderr, "nib could not be loaded: %s (does not exist)\n", nibName.c_str());

Dialog2.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,10 @@
1111
#define enumerate(container,var) for(NSEnumerator* _enumerator = [container objectEnumerator]; var = [_enumerator nextObject]; )
1212
#endif
1313

14-
inline char const* beginof (char const* cStr) { return cStr; }
15-
inline char const* endof (char const* cStr) { return cStr + strlen(cStr); }
16-
template <typename T, int N> T* beginof (T (&a)[N]) { return a; }
17-
template <typename T, int N> T* endof (T (&a)[N]) { return a + N; }
18-
template <typename T, int N, int M> T (*beginof(T (&m)[N][M]))[M] { return m; }
19-
template <typename T, int N, int M> T (*endof(T (&m)[N][M]))[M] { return m + N; }
20-
template <class T> typename T::const_iterator beginof (T const& c) { return c.begin(); }
21-
template <class T> typename T::const_iterator endof (T const& c) { return c.end(); }
22-
template <class T> typename T::iterator beginof (T& c) { return c.begin(); }
23-
template <class T> typename T::iterator endof (T& c) { return c.end(); }
24-
25-
#ifndef foreach
26-
#define foreach(v,f,l) for(decltype(f) v = (f), _end = (l); v != _end; ++v)
27-
#endif
28-
29-
#ifndef iterate
30-
#define iterate(v,c) foreach(v, beginof(c), endof(c))
31-
#endif
32-
3314
#ifndef sizeofA
3415
#define sizeofA(a) (sizeof(a)/sizeof(a[0]))
3516
#endif
3617

37-
3818
#define ErrorAndReturn(message) while(1){[proxy writeStringToError:@"Error: " message "\n"];return;};
3919

4020
#endif /* _DIALOG_H_ */

tm_dialog2.mm

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ int main (int argc, char const* argv[])
121121
FD_ZERO(&readfds); FD_ZERO(&writefds);
122122

123123
int num_fds = 0;
124-
iterate(it, fd_map)
124+
for(auto const& pair : fd_map)
125125
{
126-
FD_SET(it->first, &readfds);
127-
num_fds = std::max(num_fds, it->first + 1);
126+
FD_SET(pair.first, &readfds);
127+
num_fds = std::max(num_fds, pair.first + 1);
128128
}
129129

130130
int i = select(num_fds, &readfds, &writefds, NULL, NULL);
@@ -134,25 +134,25 @@ int main (int argc, char const* argv[])
134134
continue;
135135
}
136136

137-
std::vector<std::map<int, int>::iterator> to_remove;
138-
iterate(it, fd_map)
137+
std::vector<int> to_remove;
138+
for(auto const& pair : fd_map)
139139
{
140-
if(FD_ISSET(it->first, &readfds))
140+
if(FD_ISSET(pair.first, &readfds))
141141
{
142142
char buf[1024];
143-
ssize_t len = read(it->first, buf, sizeof(buf));
143+
ssize_t len = read(pair.first, buf, sizeof(buf));
144144

145145
if(len == 0)
146-
to_remove.push_back(it); // we can’t remove as long as we need the iterator for the ++
147-
else write(it->second, buf, len);
146+
to_remove.push_back(pair.first); // we can’t remove as long as we need the iterator for the ++
147+
else write(pair.second, buf, len);
148148
}
149149
}
150150

151-
iterate(it, to_remove)
151+
for(int key : to_remove)
152152
{
153-
if((*it)->second == stdin_fd)
154-
close((*it)->second);
155-
fd_map.erase(*it);
153+
if(fd_map[key] == stdin_fd)
154+
close(stdin_fd);
155+
fd_map.erase(key);
156156
}
157157
}
158158

0 commit comments

Comments
 (0)