1
0
forked from boostorg/mpl

Fix default implementation of has_push_back and has_push_front

[SVN r54948]
This commit is contained in:
Steven Watanabe
2009-07-14 16:49:45 +00:00
parent 78364897a1
commit 1ba6d35b4d
5 changed files with 73 additions and 12 deletions

View File

@@ -25,8 +25,7 @@
namespace boost { namespace mpl { namespace boost { namespace mpl {
template< typename Tag > struct has_push_back_arg;
struct has_push_back_impl;
// agurt 05/feb/04: no default implementation; the stub definition is needed // agurt 05/feb/04: no default implementation; the stub definition is needed
// to enable the default 'has_push_back' implementation below // to enable the default 'has_push_back' implementation below
@@ -39,7 +38,7 @@ struct push_back_impl
// if you've got an assert here, you are requesting a 'push_back' // if you've got an assert here, you are requesting a 'push_back'
// specialization that doesn't exist. // specialization that doesn't exist.
BOOST_MPL_ASSERT_MSG( BOOST_MPL_ASSERT_MSG(
( boost::is_same< T, has_push_back_impl<T> >::value ) ( boost::is_same< T, has_push_back_arg >::value )
, REQUESTED_PUSH_BACK_SPECIALIZATION_FOR_SEQUENCE_DOES_NOT_EXIST , REQUESTED_PUSH_BACK_SPECIALIZATION_FOR_SEQUENCE_DOES_NOT_EXIST
, ( Sequence ) , ( Sequence )
); );
@@ -51,13 +50,13 @@ struct has_push_back_impl
{ {
template< typename Seq > struct apply template< typename Seq > struct apply
#if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING) #if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING)
: aux::has_type< push_back< Seq, has_push_back_impl<Tag> > > : aux::has_type< push_back< Seq, has_push_back_arg > >
{ {
#else #else
{ {
typedef aux::has_type< push_back< Seq, has_push_back_impl<Tag> > > type; typedef aux::has_type< push_back< Seq, has_push_back_arg > > type;
BOOST_STATIC_CONSTANT(bool, value = BOOST_STATIC_CONSTANT(bool, value =
(aux::has_type< push_back< Seq, has_push_back_impl<Tag> > >::value) (aux::has_type< push_back< Seq, has_push_back_arg > >::value)
); );
#endif #endif
}; };

View File

@@ -25,8 +25,7 @@
namespace boost { namespace mpl { namespace boost { namespace mpl {
template< typename Tag > struct has_push_front_arg;
struct has_push_front_impl;
// agurt 05/feb/04: no default implementation; the stub definition is needed // agurt 05/feb/04: no default implementation; the stub definition is needed
// to enable the default 'has_push_front' implementation below // to enable the default 'has_push_front' implementation below
@@ -40,7 +39,7 @@ struct push_front_impl
// if you've got an assert here, you are requesting a 'push_front' // if you've got an assert here, you are requesting a 'push_front'
// specialization that doesn't exist. // specialization that doesn't exist.
BOOST_MPL_ASSERT_MSG( BOOST_MPL_ASSERT_MSG(
( boost::is_same< T, has_push_front_impl<T> >::value ) ( boost::is_same< T, has_push_front_arg >::value )
, REQUESTED_PUSH_FRONT_SPECIALIZATION_FOR_SEQUENCE_DOES_NOT_EXIST , REQUESTED_PUSH_FRONT_SPECIALIZATION_FOR_SEQUENCE_DOES_NOT_EXIST
, ( Sequence ) , ( Sequence )
); );
@@ -52,13 +51,13 @@ struct has_push_front_impl
{ {
template< typename Seq > struct apply template< typename Seq > struct apply
#if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING) #if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING)
: aux::has_type< push_front< Seq, has_push_front_impl<Tag> > > : aux::has_type< push_front< Seq, has_push_front_arg > >
{ {
#else #else
{ {
typedef aux::has_type< push_front< Seq, has_push_front_impl<Tag> > > type; typedef aux::has_type< push_front< Seq, has_push_front_arg > > type;
BOOST_STATIC_CONSTANT(bool, value = BOOST_STATIC_CONSTANT(bool, value =
(aux::has_type< push_front< Seq, has_push_front_impl<Tag> > >::value) (aux::has_type< push_front< Seq, has_push_front_arg > >::value)
); );
#endif #endif
}; };

View File

@@ -66,6 +66,7 @@ compile numeric_ops.cpp ;
compile pair_view.cpp ; compile pair_view.cpp ;
compile partition.cpp ; compile partition.cpp ;
compile pop_front.cpp ; compile pop_front.cpp ;
compile push_back.cpp ;
compile push_front.cpp ; compile push_front.cpp ;
compile quote.cpp ; compile quote.cpp ;
compile range_c.cpp ; compile range_c.cpp ;

52
test/push_back.cpp Normal file
View File

@@ -0,0 +1,52 @@
// Copyright Steven Watanabe 2009
//
// 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.
// $Id$
// $Date: 2008-10-10 02:21:07 -0700 (Fri, 10 Oct 2008) $
// $Revision: 49240 $
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/aux_/test.hpp>
struct no_push_back_tag {};
struct no_push_back
{
typedef no_push_back_tag tag;
};
struct has_push_back_tag {};
struct with_push_back
{
typedef has_push_back_tag tag;
};
namespace boost { namespace mpl {
template<>
struct push_back_impl< has_push_back_tag >
{
template<class Seq, class T> struct apply
{
typedef no_push_back type;
};
};
}}
MPL_TEST_CASE()
{
MPL_ASSERT_NOT(( has_push_back< no_push_back > ));
MPL_ASSERT(( has_push_back< with_push_back > ));
typedef push_back< with_push_back , int >::type test;
MPL_ASSERT(( is_same< test, no_push_back > ));
}

View File

@@ -1,5 +1,6 @@
// Copyright Aleksey Gurtovoy 2000-2004 // Copyright Aleksey Gurtovoy 2000-2004
// Copyright Steven Watanabe 2009
// //
// Distributed under the Boost Software License, Version 1.0. // Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at // (See accompanying file LICENSE_1_0.txt or copy at
@@ -19,6 +20,13 @@
#include <boost/mpl/aux_/test.hpp> #include <boost/mpl/aux_/test.hpp>
struct no_push_front_tag {};
struct no_push_front
{
typedef no_push_front_tag tag;
};
MPL_TEST_CASE() MPL_TEST_CASE()
{ {
typedef push_front<list0<>,long>::type res1; typedef push_front<list0<>,long>::type res1;
@@ -37,4 +45,6 @@ MPL_TEST_CASE()
MPL_ASSERT(( has_push_front< list1<long> > )); MPL_ASSERT(( has_push_front< list1<long> > ));
MPL_ASSERT_NOT(( has_push_back< list0<> > )); MPL_ASSERT_NOT(( has_push_back< list0<> > ));
MPL_ASSERT_NOT(( has_push_front< no_push_front > ));
} }