Go to the documentation of this file.
13 #ifndef __STOUT_FOREACH_HPP__
14 #define __STOUT_FOREACH_HPP__
21 #define STOUT_FOREACH_PREFIX CAT(__foreach_, __LINE__)
22 #define STOUT_FOREACH_BODY CAT(STOUT_FOREACH_PREFIX, _body__)
23 #define STOUT_FOREACH_BREAK CAT(STOUT_FOREACH_PREFIX, _break__)
24 #define STOUT_FOREACH_CONTINUE CAT(STOUT_FOREACH_PREFIX, _continue__)
25 #define STOUT_FOREACH_ELEM CAT(STOUT_FOREACH_PREFIX, _elem__)
26 #define STOUT_FOREACH_ONCE CAT(STOUT_FOREACH_PREFIX, _once__)
30 #define foreach(ELEM, ELEMS) for (ELEM : ELEMS)
51 #define foreachpair(KEY, VALUE, ELEMS) \
52 foreach (auto&& STOUT_FOREACH_ELEM, ELEMS) \
53 if (false) STOUT_FOREACH_BREAK: break; \
54 else if (bool STOUT_FOREACH_CONTINUE = false) {} \
55 else if (true) goto STOUT_FOREACH_BODY; \
57 if (!STOUT_FOREACH_CONTINUE) goto STOUT_FOREACH_BREAK; \
58 else if (true) break; \
61 if (bool STOUT_FOREACH_ONCE = false) {} \
62 else for (KEY = std::get<0>( \
63 std::forward<decltype(STOUT_FOREACH_ELEM)>( \
64 STOUT_FOREACH_ELEM)); \
65 !STOUT_FOREACH_ONCE; \
66 STOUT_FOREACH_ONCE = true) \
67 for (VALUE = std::get<1>( \
68 std::forward<decltype(STOUT_FOREACH_ELEM)>( \
69 STOUT_FOREACH_ELEM)); \
70 !STOUT_FOREACH_CONTINUE; \
71 STOUT_FOREACH_CONTINUE = true)
74 #define foreachkey(KEY, ELEMS) foreachpair (KEY, std::ignore, ELEMS)
77 #define foreachvalue(VALUE, ELEMS) foreachpair (std::ignore, VALUE, ELEMS)
79 #endif // __STOUT_FOREACH_HPP__