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