remove.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // (C) Copyright Edward Diener 2015
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. #if !defined(BOOST_VMD_TUPLE_REMOVE_HPP)
  6. #define BOOST_VMD_TUPLE_REMOVE_HPP
  7. #include <boost/vmd/detail/setup.hpp>
  8. #if BOOST_PP_VARIADICS
  9. #include <boost/preprocessor/comparison/equal.hpp>
  10. #include <boost/preprocessor/control/iif.hpp>
  11. #include <boost/preprocessor/logical/bitand.hpp>
  12. #include <boost/preprocessor/tuple/remove.hpp>
  13. #include <boost/preprocessor/tuple/size.hpp>
  14. #include <boost/vmd/empty.hpp>
  15. /*
  16. The succeeding comments in this file are in doxygen format.
  17. */
  18. /** \file
  19. */
  20. /** \def BOOST_VMD_TUPLE_REMOVE(tuple,index)
  21. \brief removes an element from a tuple.
  22. tuple = tuple from which an element is to be removed.
  23. index = The zero-based position in tuple of the element to be removed.
  24. If index is greater or equal to the tuple size the result is undefined.
  25. If the tuple is a single element and the index is 0 the result is an empty tuple.
  26. Otherwise the result is a tuple after removing the index element.
  27. */
  28. #define BOOST_VMD_TUPLE_REMOVE(tuple,index) \
  29. BOOST_PP_IIF \
  30. ( \
  31. BOOST_PP_BITAND \
  32. ( \
  33. BOOST_PP_EQUAL(index,0), \
  34. BOOST_PP_EQUAL(BOOST_PP_TUPLE_SIZE(tuple),1) \
  35. ), \
  36. BOOST_VMD_EMPTY, \
  37. BOOST_PP_TUPLE_REMOVE \
  38. ) \
  39. (tuple,index) \
  40. /**/
  41. /** \def BOOST_VMD_TUPLE_REMOVE_D(d,tuple,index)
  42. \brief removes an element from a tuple. It reenters BOOST_PP_WHILE with maximum efficiency.
  43. d = The next available BOOST_PP_WHILE iteration.
  44. tuple = tuple from which an element is to be removed.
  45. index = The zero-based position in tuple of the element to be removed.
  46. If index is greater or equal to the tuple size the result is undefined.
  47. If the tuple is a single element and the index is 0 the result is an empty tuple.
  48. Otherwise the result is a tuple after removing the index element.
  49. */
  50. #define BOOST_VMD_TUPLE_REMOVE_D(d,tuple,index) \
  51. BOOST_PP_IIF \
  52. ( \
  53. BOOST_PP_BITAND \
  54. ( \
  55. BOOST_PP_EQUAL_D(d,index,0), \
  56. BOOST_PP_EQUAL_D(d,BOOST_PP_TUPLE_SIZE(tuple),1) \
  57. ), \
  58. BOOST_VMD_EMPTY, \
  59. BOOST_PP_TUPLE_REMOVE_D \
  60. ) \
  61. (d,tuple,index) \
  62. /**/
  63. #endif /* BOOST_PP_VARIADICS */
  64. #endif /* BOOST_VMD_TUPLE_REMOVE_HPP */