Debian Codegraph @

3rd_party/range-v3/range/v3/range_for.hpp

raw
1 /// \file
2 // Range v3 library
3 //
4 // Copyright Eric Niebler 2014-present
5 //
6 // Use, modification and distribution is subject to the
7 // Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 //
11 // Project home: https://github.com/ericniebler/range-v3
12 //
13
14 #ifndef RANGES_V3_RANGE_FOR_HPP
15 #define RANGES_V3_RANGE_FOR_HPP
16
17 #include <range/v3/range_fwd.hpp>
18
19 #include <range/v3/range/access.hpp>
20
21 #if RANGES_CXX_RANGE_BASED_FOR < RANGES_CXX_RANGE_BASED_FOR_17
22 /// A range-based for macro, basically a hack until the built-in range-for can handle
23 /// Ranges that have a different type for begin and end. \ingroup range-core
24 #define RANGES_FOR(VAR_DECL, ...) \
25 if(bool CPP_PP_CAT(_range_v3_done, __LINE__) = false) {} \
26 else \
27 for(auto && CPP_PP_CAT(_range_v3_rng, __LINE__) = (__VA_ARGS__); \
28 !CPP_PP_CAT(_range_v3_done, __LINE__);) \
29 for(auto CPP_PP_CAT(_range_v3_begin, __LINE__) = \
30 ranges::begin(CPP_PP_CAT(_range_v3_rng, __LINE__)); \
31 !CPP_PP_CAT(_range_v3_done, __LINE__); \
32 CPP_PP_CAT(_range_v3_done, __LINE__) = true) \
33 for(auto CPP_PP_CAT(_range_v3_end, __LINE__) = \
34 ranges::end(CPP_PP_CAT(_range_v3_rng, __LINE__)); \
35 !CPP_PP_CAT(_range_v3_done, __LINE__) && \
36 CPP_PP_CAT(_range_v3_begin, __LINE__) != \
37 CPP_PP_CAT(_range_v3_end, __LINE__); \
38 ++CPP_PP_CAT(_range_v3_begin, __LINE__)) \
39 if(!(CPP_PP_CAT(_range_v3_done, __LINE__) = true)) {} \
40 else \
41 for(VAR_DECL = *CPP_PP_CAT(_range_v3_begin, __LINE__); \
42 CPP_PP_CAT(_range_v3_done, __LINE__); \
43 CPP_PP_CAT(_range_v3_done, __LINE__) = false) \
44 /**/
45
46 #else
47 #define RANGES_FOR(VAR_DECL, ...) for(VAR_DECL : (__VA_ARGS__))
48 #endif
49
50 #endif