macros.H 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // (c) Daniel Llorens - 2005, 2012
  2. // This library is free software; you can redistribute it and/or modify it under
  3. // the terms of the GNU Lesser General Public License as published by the Free
  4. // Software Foundation; either version 3 of the License, or (at your option) any
  5. // later version.
  6. /// @file macros.H
  7. /// @brief Fundamental macros and types.
  8. #pragma once
  9. #include <cstddef>
  10. #include <type_traits>
  11. #include <utility>
  12. #define X_STRINGIZE(s) STRINGIZE_1(s)
  13. #define STRINGIZE_1(x) #x
  14. #define STRINGIZE(x) STRINGIZE_1(x)
  15. #define JOIN( X, Y ) DO_JOIN( X, Y )
  16. #define DO_JOIN( X, Y ) X##Y
  17. // by G. Pakosz @ http://stackoverflow.com/a/1872506
  18. // FIXME broken for 1 arg
  19. #define FOR_EACH_1(what, x, ...) what(x)
  20. #define FOR_EACH_2(what, x, ...) what(x) FOR_EACH_1(what, __VA_ARGS__)
  21. #define FOR_EACH_3(what, x, ...) what(x) FOR_EACH_2(what, __VA_ARGS__)
  22. #define FOR_EACH_4(what, x, ...) what(x) FOR_EACH_3(what, __VA_ARGS__)
  23. #define FOR_EACH_5(what, x, ...) what(x) FOR_EACH_4(what, __VA_ARGS__)
  24. #define FOR_EACH_6(what, x, ...) what(x) FOR_EACH_5(what, __VA_ARGS__)
  25. #define FOR_EACH_7(what, x, ...) what(x) FOR_EACH_6(what, __VA_ARGS__)
  26. #define FOR_EACH_8(what, x, ...) what(x) FOR_EACH_7(what, __VA_ARGS__)
  27. #define FOR_EACH_9(what, x, ...) what(x) FOR_EACH_8(what, __VA_ARGS__)
  28. #define FOR_EACH_NARG(...) FOR_EACH_NARG_(__VA_ARGS__, FOR_EACH_RSEQ_N())
  29. #define FOR_EACH_NARG_(...) FOR_EACH_ARG_N(__VA_ARGS__)
  30. #define FOR_EACH_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, N, ...) N
  31. #define FOR_EACH_RSEQ_N() 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
  32. #define FOR_EACH_(N, what, x, ...) JOIN(FOR_EACH_, N)(what, x, __VA_ARGS__)
  33. #define FOR_EACH(what, x, ...) FOR_EACH_(FOR_EACH_NARG(x, __VA_ARGS__), what, x, __VA_ARGS__)
  34. namespace mp {
  35. template <class B> constexpr bool exists = true;
  36. struct identity
  37. {
  38. template<class T>
  39. constexpr decltype(auto) operator()(T && t) const noexcept
  40. {
  41. return std::forward<T>(t);
  42. }
  43. };
  44. } // namespace mp