unique.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #ifndef BOOST_MPL_UNIQUE_HPP_INCLUDED
  2. #define BOOST_MPL_UNIQUE_HPP_INCLUDED
  3. // Copyright Aleksey Gurtovoy 2000-2004
  4. // Copyright John R. Bandela 2000-2002
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/mpl for documentation.
  11. // $Id$
  12. // $Date$
  13. // $Revision$
  14. #include <boost/mpl/fold.hpp>
  15. #include <boost/mpl/reverse_fold.hpp>
  16. #include <boost/mpl/eval_if.hpp>
  17. #include <boost/mpl/and.hpp>
  18. #include <boost/mpl/identity.hpp>
  19. #include <boost/mpl/pair.hpp>
  20. #include <boost/mpl/apply.hpp>
  21. #include <boost/mpl/aux_/inserter_algorithm.hpp>
  22. #include <boost/mpl/aux_/na.hpp>
  23. #include <boost/mpl/aux_/na_spec.hpp>
  24. #include <boost/mpl/aux_/lambda_spec.hpp>
  25. namespace boost { namespace mpl {
  26. namespace aux {
  27. template< typename Predicate, typename Operation >
  28. struct unique_op
  29. {
  30. template< typename Pair, typename T > struct apply
  31. {
  32. typedef typename Pair::first seq_;
  33. typedef typename Pair::second prior_;
  34. typedef typename eval_if<
  35. and_< is_not_na<prior_>, apply2<Predicate,prior_,T> >
  36. , identity<seq_>
  37. , apply2<Operation,seq_,T>
  38. >::type new_seq_;
  39. typedef pair<new_seq_,T> type;
  40. };
  41. };
  42. template<
  43. typename Sequence
  44. , typename Predicate
  45. , typename Inserter
  46. >
  47. struct unique_impl
  48. : first< typename fold<
  49. Sequence
  50. , pair< typename Inserter::state,na >
  51. , protect< aux::unique_op<Predicate,typename Inserter::operation> >
  52. >::type >
  53. {
  54. };
  55. template<
  56. typename Sequence
  57. , typename Predicate
  58. , typename Inserter
  59. >
  60. struct reverse_unique_impl
  61. : first< typename reverse_fold<
  62. Sequence
  63. , pair< typename Inserter::state,na >
  64. , protect< aux::unique_op<Predicate,typename Inserter::operation> >
  65. >::type >
  66. {
  67. };
  68. } // namespace aux
  69. BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF(3, unique)
  70. }}
  71. #endif // BOOST_MPL_UNIQUE_HPP_INCLUDED