flexiblesusy is hosted by Hepforge, IPPP Durham
FlexibleSUSY
pp_map.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012 William Swanson
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Except as contained in this notice, the names of the authors or
24 * their institutions shall not be used in advertising or otherwise to
25 * promote the sale, use or other dealings in this Software without
26 * prior written authorization from the authors.
27 */
28
29#ifndef PP_MAP_H
30#define PP_MAP_H
31
32#define EVAL0(...) __VA_ARGS__
33#define EVAL1(...) EVAL0(EVAL0(EVAL0(__VA_ARGS__)))
34#define EVAL2(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__)))
35#define EVAL3(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__)))
36#define EVAL4(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__)))
37#define EVAL(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__)))
38
39#define MAP_END(...)
40#define MAP_OUT
41#define MAP_COMMA ,
42
43#define MAP_GET_END2() 0, MAP_END
44#define MAP_GET_END1(...) MAP_GET_END2
45#define MAP_GET_END(...) MAP_GET_END1
46#define MAP_NEXT0(test, next, ...) next MAP_OUT
47#define MAP_NEXT1(test, next) MAP_NEXT0(test, next, 0)
48#define MAP_NEXT(test, next) MAP_NEXT1(MAP_GET_END test, next)
49
50#define MAP0(f, x, peek, ...) f(x) MAP_NEXT(peek, MAP1)(f, peek, __VA_ARGS__)
51#define MAP1(f, x, peek, ...) f(x) MAP_NEXT(peek, MAP0)(f, peek, __VA_ARGS__)
52
53#define MAP_LIST_NEXT1(test, next) MAP_NEXT0(test, MAP_COMMA next, 0)
54#define MAP_LIST_NEXT(test, next) MAP_LIST_NEXT1(MAP_GET_END test, next)
55
56#define MAP_LIST0(f, x, peek, ...) f(x) MAP_LIST_NEXT(peek, MAP_LIST1)(f, peek, __VA_ARGS__)
57#define MAP_LIST1(f, x, peek, ...) f(x) MAP_LIST_NEXT(peek, MAP_LIST0)(f, peek, __VA_ARGS__)
58
62#define MAP(f, ...) EVAL(MAP1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
63
68#define MAP_LIST(f, ...) EVAL(MAP_LIST1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
69
70#endif