duff.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // Copyright (c) 2000-2002
  3. // Joerg Walter, Mathias Koch
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // The authors gratefully acknowledge the support of
  10. // GeNeSys mbH & Co. KG in producing this work.
  11. //
  12. #ifndef _BOOST_UBLAS_DUFF_
  13. #define _BOOST_UBLAS_DUFF_
  14. #define DD_SWITCH(n, d, r, expr) \
  15. { \
  16. unsigned r = ((n) + (d) - 1) / (d); \
  17. switch ((n) % (d)) { \
  18. case 0: do { expr;
  19. #define DD_CASE_I(i, expr) \
  20. case (i): expr;
  21. #define DD_WHILE(r) \
  22. } while (-- (r) > 0); \
  23. } \
  24. }
  25. #define DD_1T(n, d, r, expr) \
  26. DD_WHILE(r)
  27. #define DD_2T(n, d, r, expr) \
  28. DD_CASE_I(1, expr) \
  29. DD_1T(n, d, r, expr)
  30. #define DD_3T(n, d, r, expr) \
  31. DD_CASE_I(2, expr) \
  32. DD_2T(n, d, r, expr)
  33. #define DD_4T(n, d, r, expr) \
  34. DD_CASE_I(3, expr) \
  35. DD_3T(n, d, r, expr)
  36. #define DD_5T(n, d, r, expr) \
  37. DD_CASE_I(4, expr) \
  38. DD_4T(n, d, r, expr)
  39. #define DD_6T(n, d, r, expr) \
  40. DD_CASE_I(5, expr) \
  41. DD_5T(n, d, r, expr)
  42. #define DD_7T(n, d, r, expr) \
  43. DD_CASE_I(6, expr) \
  44. DD_6T(n, d, r, expr)
  45. #define DD_8T(n, d, r, expr) \
  46. DD_CASE_I(7, expr) \
  47. DD_7T(n, d, r, expr)
  48. #define DD(n, d, r, expr) \
  49. DD_SWITCH(n, d, r, expr) \
  50. DD_##d##T(n, d, r, expr)
  51. #endif