multiset checkin

[SVN r20683]
This commit is contained in:
Aleksey Gurtovoy
2003-11-05 15:48:24 +00:00
parent e513af9490
commit 44fd2878bf
13 changed files with 484 additions and 32 deletions

View File

@@ -0,0 +1,44 @@
#ifndef BOOST_MPL_AUX_COUNT_IMPL_HPP_INCLUDED
#define BOOST_MPL_AUX_COUNT_IMPL_HPP_INCLUDED
// + file: boost/mpl/aux_/count_impl.hpp
// + last modified: 05/nov/03
// Copyright Aleksey Gurtovoy 2000-03
//
// Use, modification and distribution are subject to 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.
#include "boost/mpl/count_fwd.hpp"
#include "boost/mpl/count_if.hpp"
#include "boost/mpl/same_as.hpp"
#include "boost/mpl/aux_/config/static_constant.hpp"
#include "boost/mpl/aux_/config/workaround.hpp"
#include "boost/mpl/aux_/traits_lambda_spec.hpp"
namespace boost {
namespace mpl {
template< typename Tag > struct count_impl
{
template< typename Sequence, typename T > struct apply
#if BOOST_WORKAROUND(__BORLANDC__,BOOST_TESTED_AT(0x561))
{
typedef typename count_if< Sequence,same_as<T> >::type type;
BOOST_STATIC_CONSTANT(int, value = BOOST_MPL_AUX_VALUE_WKND(type)::value);
#else
: count_if< Sequence,same_as<T> >
{
#endif
};
};
BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC(2,count_impl)
}}
#endif // BOOST_MPL_AUX_COUNT_IMPL_HPP_INCLUDED

View File

@@ -35,7 +35,7 @@ struct value_wknd
#if defined(BOOST_MPL_MSVC_60_ETI_BUG)
template<>
struct value_wknd<int>
: int_<0>
: int_<1>
{
};
#endif

View File

@@ -3,21 +3,20 @@
#define BOOST_MPL_AUX_YES_NO_HPP_INCLUDED
// + file: boost/mpl/aux_/yes_no.hpp
// + last modified: 05/may/03
// + last modified: 05/nov/03
// Copyright (c) 2000-03
// Aleksey Gurtovoy
// Copyright Aleksey Gurtovoy 2000-03
//
// 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.
// Use, modification and distribution are subject to 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.
#include "boost/mpl/aux_/config/workaround.hpp"
#include "boost/mpl/aux_/config/msvc.hpp"
namespace boost { namespace mpl { namespace aux {
typedef char (&no_tag)[1];
@@ -33,6 +32,25 @@ template<> struct yes_no_tag<true>
typedef yes_tag type;
};
}}}
template< long n > struct weighted_tag
{
#if !BOOST_WORKAROUND(BOOST_MSVC, == 1200)
typedef char (&type)[n];
#else
char buf[n];
typedef weighted_tag type;
#endif
};
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x561)) \
|| BOOST_WORKAROUND(BOOST_MSVC, == 1300)
template<> struct weighted_tag<0>
{
typedef char (&type)[1];
};
#endif
}}} // namespace boost::mpl::aux
#endif // BOOST_MPL_AUX_YES_NO_HPP_INCLUDED

View File

@@ -1,24 +1,21 @@
//-----------------------------------------------------------------------------
// boost mpl/count.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2000-02
// Aleksey Gurtovoy
//
// 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_COUNT_HPP_INCLUDED
#define BOOST_MPL_COUNT_HPP_INCLUDED
#include "boost/mpl/count_if.hpp"
#include "boost/mpl/same_as.hpp"
// + file: boost/mpl/count.hpp
// + last modified: 05/nov/03
// Copyright Aleksey Gurtovoy 2000-03
//
// Use, modification and distribution are subject to 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.
#include "boost/mpl/count_fwd.hpp"
#include "boost/mpl/aux_/count_impl.hpp"
#include "boost/mpl/aux_/sequence_tag.hpp"
#include "boost/mpl/aux_/void_spec.hpp"
#include "boost/mpl/aux_/lambda_support.hpp"
@@ -32,7 +29,8 @@ template<
, typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T)
>
struct count
: count_if< Sequence,same_as<T> >
: count_impl< typename BOOST_MPL_AUX_SEQUENCE_TAG(Sequence) >
::template apply<Sequence,T>
{
BOOST_MPL_AUX_LAMBDA_SUPPORT(2,count,(Sequence,T))
};
@@ -41,7 +39,6 @@ BOOST_MPL_AUX_AGLORITHM_NAMESPACE_END
BOOST_MPL_AUX_ALGORITHM_VOID_SPEC(2, count)
} // namespace mpl
} // namespace boost
}}
#endif // BOOST_MPL_COUNT_HPP_INCLUDED

View File

@@ -0,0 +1,29 @@
#ifndef BOOST_MPL_COUNT_FWD_HPP_INCLUDED
#define BOOST_MPL_COUNT_FWD_HPP_INCLUDED
// + file: boost/mpl/count_fwd.hpp
// + last modified: 05/nov/03
// Copyright Aleksey Gurtovoy 2000-03
//
// Use, modification and distribution are subject to 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.
#include "boost/mpl/aux_/algorithm_namespace.hpp"
namespace boost {
namespace mpl {
template< typename Tag > struct count_impl;
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_BEGIN
template< typename Sequence, typename T > struct count;
BOOST_MPL_AUX_AGLORITHM_NAMESPACE_END
}}
#endif // BOOST_MPL_COUNT_FWD_HPP_INCLUDED

View File

@@ -0,0 +1,81 @@
#ifndef BOOST_MPL_MULTISET_AUX_COUNT_IMPL_HPP_INCLUDED
#define BOOST_MPL_MULTISET_AUX_COUNT_IMPL_HPP_INCLUDED
// + file: boost/mpl/multiset/aux_/count_impl.hpp
// + last modified: 05/nov/03
// Copyright Aleksey Gurtovoy 2003
//
// Use, modification and distribution are subject to 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.
#include "boost/mpl/multiset/aux_/tag.hpp"
#include "boost/mpl/count_fwd.hpp"
#include "boost/mpl/int.hpp"
#include "boost/mpl/aux_/type_wrapper.hpp"
#include "boost/mpl/aux_/static_cast.hpp"
#include "boost/mpl/aux_/config/static_constant.hpp"
#include "boost/mpl/aux_/config/workaround.hpp"
#include "boost/mpl/aux_/config/msvc.hpp"
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
# include "boost/mpl/if.hpp"
# include "boost/type_traits/is_reference.hpp"
#endif
namespace boost { namespace mpl {
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
namespace aux {
template< typename S, typename U >
struct multiset_count_impl
: int_< sizeof(S::key_count(BOOST_MPL_AUX_STATIC_CAST(U*,0))) - 1 >
{
};
template< typename S, typename U >
struct multiset_count_ref_impl
{
typedef U (* u_)();
typedef int_< sizeof(S::ref_key_count(BOOST_MPL_AUX_STATIC_CAST(u_,0))) - 1 > type_;
BOOST_STATIC_CONSTANT(int, value = type_::value);
typedef type_ type;
};
}
template<>
struct count_impl< aux::multiset_tag >
{
template< typename Set, typename Key > struct apply
: if_<
is_reference<Key>
, aux::multiset_count_ref_impl<Set,Key>
, aux::multiset_count_impl<Set,Key>
>::type
{
};
};
#else
template<>
struct count_impl< aux::multiset_tag >
{
template< typename Set, typename Key > struct apply
{
enum { msvc71_wknd_ = sizeof(Set::key_count(BOOST_MPL_AUX_STATIC_CAST(aux::type_wrapper<Key>*,0))) - 1 };
typedef int_< msvc71_wknd_ > type;
BOOST_STATIC_CONSTANT(int, value = msvc71_wknd_);
};
};
#endif // BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
}} // namespace boost::mpl
#endif // BOOST_MPL_MULTISET_AUX_COUNT_IMPL_HPP_INCLUDED

View File

@@ -0,0 +1,33 @@
#ifndef BOOST_MPL_MULTISET_AUX_INSERT_IMPL_HPP_INCLUDED
#define BOOST_MPL_MULTISET_AUX_INSERT_IMPL_HPP_INCLUDED
// + file: boost/mpl/multiset/aux_/insert_impl.hpp
// + last modified: 05/nov/03
// Copyright Aleksey Gurtovoy 2003
//
// Use, modification and distribution are subject to 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.
#include "boost/mpl/multiset/aux_/item.hpp"
#include "boost/mpl/multiset/aux_/tag.hpp"
#include "boost/mpl/insert_fwd.hpp"
namespace boost { namespace mpl {
//#error here!
template<>
struct insert_traits< aux::multiset_tag >
{
template< typename Set, typename Key, typename unused_ > struct algorithm
{
typedef ms_item<Key,Set> type;
};
};
}} // namespace boost::mpl
#endif // BOOST_MPL_MULTISET_AUX_INSERT_IMPL_HPP_INCLUDED

View File

@@ -0,0 +1,116 @@
#ifndef BOOST_MPL_MULTISET_AUX_ITEM_HPP_INCLUDED
#define BOOST_MPL_MULTISET_AUX_ITEM_HPP_INCLUDED
// + file: boost/mpl/multiset/aux_/item.hpp
// + last modified: 05/nov/03
// Copyright Aleksey Gurtovoy 2003
//
// Use, modification and distribution are subject to 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.
#include "boost/mpl/multiset/aux_/tag.hpp"
#include "boost/mpl/int.hpp"
#include "boost/mpl/aux_/type_wrapper.hpp"
#include "boost/mpl/aux_/yes_no.hpp"
#include "boost/mpl/aux_/value_wknd.hpp"
#include "boost/mpl/aux_/static_cast.hpp"
#include "boost/mpl/aux_/config/workaround.hpp"
#include "boost/mpl/aux_/config/msvc.hpp"
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
# include "boost/mpl/apply_if.hpp"
# include "boost/mpl/next.hpp"
# include "boost/type_traits/is_same.hpp"
#endif
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x561)) \
|| BOOST_WORKAROUND(BOOST_MSVC, == 1300)
# define BOOST_MPL_CFG_NO_DEPENDENT_ARRAY_TYPES
#endif
namespace boost { namespace mpl {
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
template< typename T, typename Base >
struct ms_item
{
typedef aux::multiset_tag tag;
template< typename U > struct prior_count
{
enum { msvc70_wknd_ = sizeof(Base::key_count(BOOST_MPL_AUX_STATIC_CAST(U*,0))) };
typedef int_< msvc70_wknd_ > count_;
typedef typename apply_if< is_same<T,U>, next<count_>, count_ >::type c_;
#if defined(BOOST_MPL_CFG_NO_DEPENDENT_ARRAY_TYPES)
typedef typename aux::weighted_tag<BOOST_MPL_AUX_MSVC_VALUE_WKND(c_)::value>::type type;
#else
typedef char (&type)[BOOST_MPL_AUX_MSVC_VALUE_WKND(c_)::value];
#endif
};
template< typename U > struct prior_ref_count
{
typedef U (* u_)();
enum { msvc70_wknd_ = sizeof(Base::ref_key_count(BOOST_MPL_AUX_STATIC_CAST(u_,0))) };
typedef int_< msvc70_wknd_ > count_;
typedef typename apply_if< is_same<T,U>, next<count_>, count_ >::type c_;
#if defined(BOOST_MPL_CFG_NO_DEPENDENT_ARRAY_TYPES)
typedef typename aux::weighted_tag<BOOST_MPL_AUX_MSVC_VALUE_WKND(c_)::value>::type type;
#else
typedef char (&type)[BOOST_MPL_AUX_MSVC_VALUE_WKND(c_)::value];
#endif
};
template< typename U >
static typename prior_count<U>::type key_count(U*);
template< typename U >
static typename prior_ref_count<U>::type ref_key_count(U (*)());
};
#else // BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
namespace aux {
template< typename U, typename Base >
struct prior_key_count
{
enum { msvc71_wknd_ = sizeof(Base::key_count(BOOST_MPL_AUX_STATIC_CAST(aux::type_wrapper<U>*,0))) };
typedef int_< msvc71_wknd_ > count_;
#if defined(BOOST_MPL_CFG_NO_DEPENDENT_ARRAY_TYPES)
typedef typename aux::weighted_tag< BOOST_MPL_AUX_VALUE_WKND(count_)::value >::type type;
#else
typedef char (&type)[count_::value];
#endif
};
}
template< typename T, typename Base >
struct ms_item
{
typedef aux::multiset_tag tag;
enum { msvc71_wknd_ = sizeof(Base::key_count(BOOST_MPL_AUX_STATIC_CAST(aux::type_wrapper<T>*,0))) + 1 };
typedef int_< msvc71_wknd_ > count_;
#if defined(BOOST_MPL_CFG_NO_DEPENDENT_ARRAY_TYPES)
static
typename aux::weighted_tag< BOOST_MPL_AUX_VALUE_WKND(count_)::value >::type
key_count(aux::type_wrapper<T>*);
#else
static char (& key_count(aux::type_wrapper<T>*) )[count_::value];
#endif
template< typename U >
static typename aux::prior_key_count<U,Base>::type key_count(aux::type_wrapper<U>*);
};
#endif // BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
}} // namespace boost::mpl
#endif // BOOST_MPL_MULTISET_AUX_ITEM_HPP_INCLUDED

View File

@@ -0,0 +1,33 @@
#ifndef BOOST_MPL_MULTISET_AUX_MULTISET0_HPP_INCLUDED
#define BOOST_MPL_MULTISET_AUX_MULTISET0_HPP_INCLUDED
// + file: boost/mpl/multiset/aux_/multiset0.hpp
// + last modified: 05/nov/03
// Copyright Aleksey Gurtovoy 2003
//
// Use, modification and distribution are subject to 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.
#include "boost/mpl/multiset/aux_/tag.hpp"
#include "boost/mpl/int.hpp"
namespace boost { namespace mpl {
template< int dummy_ = 0 >
struct multiset0
{
typedef aux::multiset_tag tag;
typedef int_<1> count_;
static char (& key_count(...) )[count_::value];
static char (& ref_key_count(...) )[count_::value];
};
}} // namespace boost::mpl
#endif // BOOST_MPL_MULTISET_AUX_MULTISET0_HPP_INCLUDED

View File

@@ -0,0 +1,22 @@
#ifndef BOOST_MPL_MULTISET_AUX_TAG_HPP_INCLUDED
#define BOOST_MPL_MULTISET_AUX_TAG_HPP_INCLUDED
// + file: boost/mpl/multiset/aux_/tag.hpp
// + last modified: 05/nov/03
// Copyright Aleksey Gurtovoy 2003
//
// Use, modification and distribution are subject to 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.
namespace boost { namespace mpl { namespace aux {
struct multiset_tag;
}}}
#endif // BOOST_MPL_MULTISET_AUX_TAG_HPP_INCLUDED

View File

@@ -0,0 +1,35 @@
#ifndef BOOST_MPL_MULTISET_MULTISET0_HPP_INCLUDED
#define BOOST_MPL_MULTISET_MULTISET0_HPP_INCLUDED
// + file: boost/mpl/multiset0.hpp
// + last modified: 27/oct/03
// Copyright (C) Aleksey Gurtovoy 2003
//
// Use, modification and distribution are subject to 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.
//#include "boost/mpl/multiset/aux_/at.hpp"
//#include "boost/mpl/multiset/aux_/front.hpp"
//#include "boost/mpl/multiset/aux_/push_front.hpp"
//#include "boost/mpl/multiset/aux_/pop_front.hpp"
//#include "boost/mpl/multiset/aux_/back.hpp"
//#include "boost/mpl/multiset/aux_/clear.hpp"
//#include "boost/mpl/multiset/aux_/O1_size.hpp"
//#include "boost/mpl/multiset/aux_/size.hpp"
//#include "boost/mpl/multiset/aux_/empty.hpp"
//#include "boost/mpl/multiset/aux_/empty.hpp"
#include "boost/mpl/multiset/aux_/insert_impl.hpp"
#include "boost/mpl/multiset/aux_/count_impl.hpp"
//#include "boost/mpl/multiset/aux_/has_key_impl.hpp"
//#include "boost/mpl/multiset/aux_/begin_end_impl.hpp"
//#include "boost/mpl/multiset/aux_/iterator.hpp"
#include "boost/mpl/multiset/aux_/item.hpp"
#include "boost/mpl/multiset/aux_/multiset0.hpp"
#include "boost/mpl/multiset/aux_/tag.hpp"
#endif // BOOST_MPL_MULTISET_MULTISET0_HPP_INCLUDED

View File

@@ -48,6 +48,7 @@ compile joint_view.cpp ;
compile lambda.cpp ;
compile lambda_args.cpp ;
compile max_element.cpp ;
compile multiset.cpp ;
compile list.cpp ;
compile list_c.cpp ;
compile logical.cpp ;

43
test/multiset.cpp Normal file
View File

@@ -0,0 +1,43 @@
// + file: libs/mpl/test/multiset.cpp
// + last modified: 05/nov/03
// Copyright Aleksey Gurtovoy 2003
//
// Use, modification and distribution are subject to 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.
#include "boost/mpl/multiset/multiset0.hpp"
#include "boost/mpl/insert.hpp"
#include "boost/mpl/count.hpp"
#include "boost/static_assert.hpp"
using namespace boost;
using namespace boost::mpl;
struct abstract
{
virtual ~abstract() = 0;
};
int main()
{
typedef multiset0<> s0;
typedef insert<s0,int>::type s1;
typedef insert<s1,char&>::type s2;
typedef insert<s2,int>::type s3;
typedef insert<s3,abstract>::type s4;
BOOST_STATIC_ASSERT((count<s0,int>::value == 0));
BOOST_STATIC_ASSERT((count<s1,int>::value == 1));
BOOST_STATIC_ASSERT((count<s2,int>::value == 1));
BOOST_STATIC_ASSERT((count<s2,char&>::value == 1));
BOOST_STATIC_ASSERT((count<s3,int>::value == 2));
BOOST_STATIC_ASSERT((count<s3,char&>::value == 1));
BOOST_STATIC_ASSERT((count<s4,abstract>::value == 1));
return 0;
}