Files
boost_mpl/include/boost/mpl/unique.hpp
T

86 lines
2.0 KiB
C++
Raw Normal View History

2002-09-15 22:13:24 +00:00
#ifndef BOOST_MPL_UNIQUE_HPP_INCLUDED
#define BOOST_MPL_UNIQUE_HPP_INCLUDED
2004-09-02 15:41:37 +00:00
// Copyright Aleksey Gurtovoy 2000-2004
// Copyright John R. Bandela 2000-2002
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/mpl for documentation.
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
// $Source$
// $Date$
// $Revision$
#include <boost/mpl/fold.hpp>
#include <boost/mpl/reverse_fold.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/apply.hpp>
#include <boost/mpl/aux_/inserter_algorithm.hpp>
#include <boost/mpl/aux_/na.hpp>
#include <boost/mpl/aux_/na_spec.hpp>
#include <boost/mpl/aux_/lambda_spec.hpp>
namespace boost { namespace mpl {
2002-09-15 22:13:24 +00:00
namespace aux {
2004-09-02 15:41:37 +00:00
template< typename Predicate, typename Operation >
2002-09-15 22:13:24 +00:00
struct unique_op
{
template< typename Pair, typename T > struct apply
{
typedef typename Pair::first seq_;
typedef typename Pair::second prior_;
2004-09-02 15:41:37 +00:00
typedef typename eval_if<
and_< is_not_na<prior_>, apply2<Predicate,prior_,T> >
2002-09-15 22:13:24 +00:00
, identity<seq_>
2004-09-02 15:41:37 +00:00
, apply2<Operation,seq_,T>
2002-09-15 22:13:24 +00:00
>::type new_seq_;
typedef pair<new_seq_,T> type;
};
};
template<
2004-09-02 15:41:37 +00:00
typename Sequence
, typename Predicate
, typename Inserter
2002-09-15 22:13:24 +00:00
>
2004-09-02 15:41:37 +00:00
struct unique_impl
: first< typename fold<
2002-09-15 22:13:24 +00:00
Sequence
2004-09-02 15:41:37 +00:00
, pair< typename Inserter::state,na >
, protect< aux::unique_op<Predicate,typename Inserter::operation> >
>::type >
{
2002-09-15 22:13:24 +00:00
};
2004-09-02 15:41:37 +00:00
template<
typename Sequence
, typename Predicate
, typename Inserter
>
struct reverse_unique_impl
: first< typename reverse_fold<
Sequence
, pair< typename Inserter::state,na >
, protect< aux::unique_op<Predicate,typename Inserter::operation> >
>::type >
{
};
2003-03-11 11:59:49 +00:00
2004-09-02 15:41:37 +00:00
} // namespace aux
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
BOOST_MPL_AUX_INSERTER_ALGORITHM_DEF(3, unique)
}}
2002-09-15 22:13:24 +00:00
#endif // BOOST_MPL_UNIQUE_HPP_INCLUDED