mirror of
https://github.com/boostorg/mpl.git
synced 2025-08-03 23:04:33 +02:00
Migrated from sandbox.
[SVN r20450]
This commit is contained in:
65
include/boost/mpl/aux_/partition_op.hpp
Normal file
65
include/boost/mpl/aux_/partition_op.hpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// boost mpl/aux_/partition_op.hpp header file
|
||||||
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2003
|
||||||
|
// Eric Friedman
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, distribute and sell this software
|
||||||
|
// and its documentation for any purpose is hereby granted without fee,
|
||||||
|
// provided that the above copyright notice appears in all copies and
|
||||||
|
// that both the copyright notice and this permission notice appear in
|
||||||
|
// supporting documentation. No representations are made about the
|
||||||
|
// suitability of this software for any purpose. It is provided "as is"
|
||||||
|
// without express or implied warranty.
|
||||||
|
|
||||||
|
#ifndef BOOST_MPL_AUX_PARTITION_OP_HPP_INCLUDED
|
||||||
|
#define BOOST_MPL_AUX_PARTITION_OP_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "boost/mpl/apply.hpp"
|
||||||
|
#include "boost/mpl/apply_if.hpp"
|
||||||
|
#include "boost/mpl/if.hpp"
|
||||||
|
#include "boost/mpl/pair.hpp"
|
||||||
|
#include "boost/mpl/push_front.hpp"
|
||||||
|
#include "boost/mpl/aux_/lambda_spec.hpp"
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace mpl {
|
||||||
|
namespace aux {
|
||||||
|
|
||||||
|
template <typename Predicate>
|
||||||
|
struct partition_op
|
||||||
|
{
|
||||||
|
template <typename State, typename Iter>
|
||||||
|
struct apply
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
typedef typename State::first first_;
|
||||||
|
typedef typename State::second second_;
|
||||||
|
typedef typename Iter::type t_;
|
||||||
|
typedef typename apply1< Predicate,t_ >::type pred_;
|
||||||
|
|
||||||
|
typedef typename apply_if<
|
||||||
|
pred_
|
||||||
|
, push_front< first_, t_ >
|
||||||
|
, push_front< second_, t_ >
|
||||||
|
>::type result_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef typename if_<
|
||||||
|
pred_
|
||||||
|
, pair< result_,second_ >
|
||||||
|
, pair< first_,result_ >
|
||||||
|
>::type type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace aux
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_PASS_THROUGH_LAMBDA_SPEC(1,aux::partition_op)
|
||||||
|
|
||||||
|
} // namespace mpl
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_MPL_AUX_PARTITION_OP_HPP_INCLUDED
|
98
include/boost/mpl/aux_/sort_impl.hpp
Normal file
98
include/boost/mpl/aux_/sort_impl.hpp
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// boost mpl/aux_/sort_impl.hpp header file
|
||||||
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2002-2003
|
||||||
|
// Eric Friedman
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, distribute and sell this software
|
||||||
|
// and its documentation for any purpose is hereby granted without fee,
|
||||||
|
// provided that the above copyright notice appears in all copies and
|
||||||
|
// that both the copyright notice and this permission notice appear in
|
||||||
|
// supporting documentation. No representations are made about the
|
||||||
|
// suitability of this software for any purpose. It is provided "as is"
|
||||||
|
// without express or implied warranty.
|
||||||
|
|
||||||
|
#ifndef BOOST_MPL_AUX_SORT_IMPL_HPP_INCLUDED
|
||||||
|
#define BOOST_MPL_AUX_SORT_IMPL_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "boost/mpl/apply.hpp"
|
||||||
|
#include "boost/mpl/apply_if.hpp"
|
||||||
|
#include "boost/mpl/bind.hpp" // for bind2nd
|
||||||
|
#include "boost/mpl/copy_backward.hpp"
|
||||||
|
#include "boost/mpl/empty.hpp"
|
||||||
|
#include "boost/mpl/front.hpp"
|
||||||
|
#include "boost/mpl/identity.hpp"
|
||||||
|
#include "boost/mpl/partition.hpp"
|
||||||
|
#include "boost/mpl/pop_front.hpp"
|
||||||
|
#include "boost/mpl/push_front.hpp"
|
||||||
|
#include "boost/mpl/aux_/traits_lambda_spec.hpp"
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace mpl {
|
||||||
|
|
||||||
|
namespace aux {
|
||||||
|
|
||||||
|
template < typename Sequence, typename Predicate > struct quick_sort;
|
||||||
|
|
||||||
|
template <typename Sequence, typename Predicate>
|
||||||
|
struct quick_sort_impl
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
|
||||||
|
typedef typename front<Sequence>::type pivot_;
|
||||||
|
typedef typename pop_front<Sequence>::type seq_;
|
||||||
|
|
||||||
|
typedef typename partition<
|
||||||
|
seq_
|
||||||
|
, bind2nd< Predicate,pivot_ >
|
||||||
|
>::type partitioned;
|
||||||
|
|
||||||
|
typedef typename quick_sort<
|
||||||
|
typename partitioned::first, Predicate
|
||||||
|
>::type first_part;
|
||||||
|
typedef typename quick_sort<
|
||||||
|
typename partitioned::second, Predicate
|
||||||
|
>::type second_part;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
typedef typename copy_backward<
|
||||||
|
first_part
|
||||||
|
, typename push_front<
|
||||||
|
second_part,pivot_
|
||||||
|
>::type
|
||||||
|
, push_front<_,_>
|
||||||
|
>::type type;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Sequence, typename Predicate>
|
||||||
|
struct quick_sort
|
||||||
|
: apply_if<
|
||||||
|
empty<Sequence>
|
||||||
|
, identity< Sequence >
|
||||||
|
, quick_sort_impl< Sequence,Predicate >
|
||||||
|
>
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace aux
|
||||||
|
|
||||||
|
template< typename Tag >
|
||||||
|
struct sort_traits
|
||||||
|
{
|
||||||
|
template< typename Sequence, typename Predicate >
|
||||||
|
struct algorithm
|
||||||
|
: aux::quick_sort< Sequence,Predicate >
|
||||||
|
{
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC(2,sort_traits)
|
||||||
|
|
||||||
|
} // namespace mpl
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_MPL_AUX_SORT_IMPL_HPP_INCLUDED
|
61
include/boost/mpl/partition.hpp
Normal file
61
include/boost/mpl/partition.hpp
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// boost mpl/partition.hpp header file
|
||||||
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2002-2003
|
||||||
|
// Eric Friedman
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, distribute and sell this software
|
||||||
|
// and its documentation for any purpose is hereby granted without fee,
|
||||||
|
// provided that the above copyright notice appears in all copies and
|
||||||
|
// that both the copyright notice and this permission notice appear in
|
||||||
|
// supporting documentation. No representations are made about the
|
||||||
|
// suitability of this software for any purpose. It is provided "as is"
|
||||||
|
// without express or implied warranty.
|
||||||
|
|
||||||
|
#ifndef BOOST_MPL_PARTITION_HPP_INCLUDED
|
||||||
|
#define BOOST_MPL_PARTITION_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "boost/mpl/aux_/partition_op.hpp"
|
||||||
|
#include "boost/mpl/clear.hpp"
|
||||||
|
#include "boost/mpl/iter_fold.hpp"
|
||||||
|
#include "boost/mpl/lambda.hpp"
|
||||||
|
#include "boost/mpl/pair.hpp"
|
||||||
|
#include "boost/mpl/protect.hpp"
|
||||||
|
#include "boost/mpl/aux_/void_spec.hpp"
|
||||||
|
#include "boost/mpl/aux_/lambda_support.hpp"
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace mpl {
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
template <
|
||||||
|
typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence)
|
||||||
|
, typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Predicate)
|
||||||
|
>
|
||||||
|
struct partition
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
typedef typename lambda<Predicate>::type pred_;
|
||||||
|
typedef typename clear<Sequence>::type cleared_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef typename iter_fold<
|
||||||
|
Sequence
|
||||||
|
, pair< cleared_,cleared_ >
|
||||||
|
, protect< aux::partition_op<pred_> >
|
||||||
|
>::type type;
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_LAMBDA_SUPPORT(2,partition,(Sequence,Predicate))
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_END
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_ALGORITHM_VOID_SPEC(2, partition)
|
||||||
|
|
||||||
|
} // namespace mpl
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_MPL_PARTITION_HPP_INCLUDED
|
53
include/boost/mpl/sort.hpp
Normal file
53
include/boost/mpl/sort.hpp
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// boost mpl/sort.hpp header file
|
||||||
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2002-2003
|
||||||
|
// Eric Friedman
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, distribute and sell this software
|
||||||
|
// and its documentation for any purpose is hereby granted without fee,
|
||||||
|
// provided that the above copyright notice appears in all copies and
|
||||||
|
// that both the copyright notice and this permission notice appear in
|
||||||
|
// supporting documentation. No representations are made about the
|
||||||
|
// suitability of this software for any purpose. It is provided "as is"
|
||||||
|
// without express or implied warranty.
|
||||||
|
|
||||||
|
#ifndef BOOST_MPL_SORT_HPP_INCLUDED
|
||||||
|
#define BOOST_MPL_SORT_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "boost/mpl/sort_fwd.hpp"
|
||||||
|
#include "boost/mpl/aux_/sort_impl.hpp"
|
||||||
|
#include "boost/mpl/lambda.hpp"
|
||||||
|
#include "boost/mpl/aux_/sequence_tag.hpp"
|
||||||
|
#include "boost/mpl/aux_/void_spec.hpp"
|
||||||
|
#include "boost/mpl/aux_/lambda_support.hpp"
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace mpl {
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
template < typename Sequence, typename Predicate > // see sort_fwd.hpp
|
||||||
|
struct sort
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
typedef typename lambda<Predicate>::type pred_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef typename sort_traits<
|
||||||
|
typename BOOST_MPL_AUX_SEQUENCE_TAG(Sequence)
|
||||||
|
>::template algorithm<
|
||||||
|
Sequence, pred_
|
||||||
|
>::type type;
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_LAMBDA_SUPPORT(2,sort,(Sequence,Predicate))
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_END
|
||||||
|
|
||||||
|
} // namespace mpl
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_MPL_SORT_HPP_INCLUDED
|
44
include/boost/mpl/sort_fwd.hpp
Normal file
44
include/boost/mpl/sort_fwd.hpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// boost mpl/sort_fwd.hpp header file
|
||||||
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2002-2003
|
||||||
|
// Eric Friedman
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, distribute and sell this software
|
||||||
|
// and its documentation for any purpose is hereby granted without fee,
|
||||||
|
// provided that the above copyright notice appears in all copies and
|
||||||
|
// that both the copyright notice and this permission notice appear in
|
||||||
|
// supporting documentation. No representations are made about the
|
||||||
|
// suitability of this software for any purpose. It is provided "as is"
|
||||||
|
// without express or implied warranty.
|
||||||
|
|
||||||
|
#ifndef BOOST_MPL_SORT_FWD_HPP_INCLUDED
|
||||||
|
#define BOOST_MPL_SORT_FWD_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "boost/mpl/less.hpp"
|
||||||
|
#include "boost/mpl/placeholders.hpp"
|
||||||
|
#include "boost/mpl/aux_/void_spec.hpp"
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace mpl {
|
||||||
|
|
||||||
|
template< typename Tag > struct sort_traits;
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
template <
|
||||||
|
typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence)
|
||||||
|
, typename Predicate = less<_,_>
|
||||||
|
>
|
||||||
|
struct sort;
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_END
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_ALGORITHM_VOID_SPEC(1, sort)
|
||||||
|
|
||||||
|
} // namespace mpl
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_MPL_SORT_FWD_HPP_INCLUDED
|
61
include/boost/mpl/stable_partition.hpp
Normal file
61
include/boost/mpl/stable_partition.hpp
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// boost mpl/stable_partition.hpp header file
|
||||||
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2002-2003
|
||||||
|
// Eric Friedman
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, distribute and sell this software
|
||||||
|
// and its documentation for any purpose is hereby granted without fee,
|
||||||
|
// provided that the above copyright notice appears in all copies and
|
||||||
|
// that both the copyright notice and this permission notice appear in
|
||||||
|
// supporting documentation. No representations are made about the
|
||||||
|
// suitability of this software for any purpose. It is provided "as is"
|
||||||
|
// without express or implied warranty.
|
||||||
|
|
||||||
|
#ifndef BOOST_MPL_STABLE_PARTITION_HPP_INCLUDED
|
||||||
|
#define BOOST_MPL_STABLE_PARTITION_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "boost/mpl/aux_/partition_op.hpp"
|
||||||
|
#include "boost/mpl/clear.hpp"
|
||||||
|
#include "boost/mpl/iter_fold_backward.hpp"
|
||||||
|
#include "boost/mpl/lambda.hpp"
|
||||||
|
#include "boost/mpl/pair.hpp"
|
||||||
|
#include "boost/mpl/protect.hpp"
|
||||||
|
#include "boost/mpl/aux_/void_spec.hpp"
|
||||||
|
#include "boost/mpl/aux_/lambda_support.hpp"
|
||||||
|
|
||||||
|
namespace boost {
|
||||||
|
namespace mpl {
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
template <
|
||||||
|
typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Sequence)
|
||||||
|
, typename BOOST_MPL_AUX_VOID_SPEC_PARAM(Predicate)
|
||||||
|
>
|
||||||
|
struct stable_partition
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
typedef typename lambda<Predicate>::type pred_;
|
||||||
|
typedef typename clear<Sequence>::type cleared_;
|
||||||
|
|
||||||
|
public:
|
||||||
|
typedef typename iter_fold_backward<
|
||||||
|
Sequence
|
||||||
|
, pair< cleared_,cleared_ >
|
||||||
|
, protect< aux::partition_op<pred_> >
|
||||||
|
>::type type;
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_LAMBDA_SUPPORT(2,stable_partition,(Sequence,Predicate))
|
||||||
|
};
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_END
|
||||||
|
|
||||||
|
BOOST_MPL_AUX_ALGORITHM_VOID_SPEC(2, stable_partition)
|
||||||
|
|
||||||
|
} // namespace mpl
|
||||||
|
} // namespace boost
|
||||||
|
|
||||||
|
#endif // BOOST_MPL_STABLE_PARTITION_HPP_INCLUDED
|
33
test/max_element.cpp
Normal file
33
test/max_element.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// libs mpl/test/max_element.cpp source file
|
||||||
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2002-2003
|
||||||
|
// Eric Friedman
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, distribute and sell this software
|
||||||
|
// and its documentation for any purpose is hereby granted without fee,
|
||||||
|
// provided that the above copyright notice appears in all copies and
|
||||||
|
// that both the copyright notice and this permission notice appear in
|
||||||
|
// supporting documentation. No representations are made about the
|
||||||
|
// suitability of this software for any purpose. It is provided "as is"
|
||||||
|
// without express or implied warranty.
|
||||||
|
|
||||||
|
#include "boost/mpl/max_element.hpp"
|
||||||
|
|
||||||
|
#include "boost/static_assert.hpp"
|
||||||
|
#include "boost/mpl/list_c.hpp"
|
||||||
|
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
typedef mpl::list_c<int, 3, 4, 2, 0, -5, 8, -1, 7>::type numbers;
|
||||||
|
|
||||||
|
typedef mpl::max_element< numbers >::type max_it;
|
||||||
|
typedef max_it::type max_value;
|
||||||
|
BOOST_STATIC_ASSERT((max_value::value == 8));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
35
test/sort.cpp
Normal file
35
test/sort.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// libs mpl/test/sort.cpp source file
|
||||||
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2002-2003
|
||||||
|
// Eric Friedman
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, distribute and sell this software
|
||||||
|
// and its documentation for any purpose is hereby granted without fee,
|
||||||
|
// provided that the above copyright notice appears in all copies and
|
||||||
|
// that both the copyright notice and this permission notice appear in
|
||||||
|
// supporting documentation. No representations are made about the
|
||||||
|
// suitability of this software for any purpose. It is provided "as is"
|
||||||
|
// without express or implied warranty.
|
||||||
|
|
||||||
|
#include "boost/mpl/sort.hpp"
|
||||||
|
|
||||||
|
#include "boost/static_assert.hpp"
|
||||||
|
#include "boost/mpl/list_c.hpp"
|
||||||
|
#include "boost/mpl/equal.hpp"
|
||||||
|
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
typedef mpl::list_c<int, 3, 4, 0, -5, 8, -1, 7>::type numbers;
|
||||||
|
typedef mpl::list_c<int, -5, -1, 0, 3, 4, 7, 8>::type manual_result;
|
||||||
|
|
||||||
|
typedef mpl::sort< numbers >::type result;
|
||||||
|
|
||||||
|
BOOST_STATIC_ASSERT((mpl::equal< result,manual_result >::type::value));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
60
test/stable_partition.cpp
Normal file
60
test/stable_partition.cpp
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// libs mpl/test/stable_partition.cpp source file
|
||||||
|
// See http://www.boost.org for updates, documentation, and revision history.
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// Copyright (c) 2003
|
||||||
|
// Eric Friedman
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, distribute and sell this software
|
||||||
|
// and its documentation for any purpose is hereby granted without fee,
|
||||||
|
// provided that the above copyright notice appears in all copies and
|
||||||
|
// that both the copyright notice and this permission notice appear in
|
||||||
|
// supporting documentation. No representations are made about the
|
||||||
|
// suitability of this software for any purpose. It is provided "as is"
|
||||||
|
// without express or implied warranty.
|
||||||
|
|
||||||
|
#include "boost/mpl/stable_partition.hpp"
|
||||||
|
|
||||||
|
#include "boost/static_assert.hpp"
|
||||||
|
#include "boost/mpl/list_c.hpp"
|
||||||
|
#include "boost/mpl/equal.hpp"
|
||||||
|
|
||||||
|
#include "boost/mpl/less.hpp"
|
||||||
|
#include "boost/mpl/placeholders.hpp"
|
||||||
|
#include "boost/mpl/int.hpp"
|
||||||
|
|
||||||
|
namespace mpl = boost::mpl;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
typedef mpl::list_c<int, 3, 4, 0, -5, 8, -1, 7>::type numbers;
|
||||||
|
typedef mpl::list_c<int, 0, -5, -1>::type manual_first;
|
||||||
|
typedef mpl::list_c<int, 3, 4, 8, 7>::type manual_second;
|
||||||
|
|
||||||
|
//////
|
||||||
|
|
||||||
|
typedef mpl::stable_partition<
|
||||||
|
numbers
|
||||||
|
, mpl::less< mpl::_, mpl::int_<3> >
|
||||||
|
>::type result1;
|
||||||
|
|
||||||
|
typedef result1::first first1;
|
||||||
|
BOOST_STATIC_ASSERT((mpl::equal< first1,manual_first >::type::value));
|
||||||
|
typedef result1::second second1;
|
||||||
|
BOOST_STATIC_ASSERT((mpl::equal< second1,manual_second >::type::value));
|
||||||
|
|
||||||
|
//////
|
||||||
|
|
||||||
|
typedef mpl::stable_partition<
|
||||||
|
numbers
|
||||||
|
, mpl::lt< 3 >
|
||||||
|
>::type result2;
|
||||||
|
|
||||||
|
typedef result2::first first2;
|
||||||
|
BOOST_STATIC_ASSERT((mpl::equal< first2,manual_first >::type::value));
|
||||||
|
typedef result2::second second2;
|
||||||
|
BOOST_STATIC_ASSERT((mpl::equal< second2,manual_second >::type::value));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in New Issue
Block a user