Boost logo

Boost-Commit :

From: agurtovoy_at_[hidden]
Date: 2008-06-20 00:43:42


Author: agurtovoy
Date: 2008-06-20 00:43:41 EDT (Fri, 20 Jun 2008)
New Revision: 46546
URL: http://svn.boost.org/trac/boost/changeset/46546

Log:
Proper (well, better) diagnostics for passing non-sequence types to sequence algoritms/metafunctions, see http://thread.gmane.org/gmane.comp.lib.boost.user/36876
Text files modified:
   trunk/boost/mpl/aux_/begin_end_impl.hpp | 4 ++--
   trunk/boost/mpl/aux_/push_back_impl.hpp | 26 +++++++++++++++++++++-----
   trunk/boost/mpl/aux_/push_front_impl.hpp | 26 +++++++++++++++++++++-----
   trunk/boost/mpl/aux_/traits_lambda_spec.hpp | 15 +++++++++++----
   trunk/boost/mpl/for_each.hpp | 6 +++++-
   5 files changed, 60 insertions(+), 17 deletions(-)

Modified: trunk/boost/mpl/aux_/begin_end_impl.hpp
==============================================================================
--- trunk/boost/mpl/aux_/begin_end_impl.hpp (original)
+++ trunk/boost/mpl/aux_/begin_end_impl.hpp 2008-06-20 00:43:41 EDT (Fri, 20 Jun 2008)
@@ -93,8 +93,8 @@
 # undef AUX778076_IMPL_SPEC
 
 
-BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC(1,begin_impl)
-BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC(1,end_impl)
+BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC_IMPL(1,begin_impl)
+BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC_IMPL(1,end_impl)
 
 }}
 

Modified: trunk/boost/mpl/aux_/push_back_impl.hpp
==============================================================================
--- trunk/boost/mpl/aux_/push_back_impl.hpp (original)
+++ trunk/boost/mpl/aux_/push_back_impl.hpp 2008-06-20 00:43:41 EDT (Fri, 20 Jun 2008)
@@ -2,7 +2,7 @@
 #ifndef BOOST_MPL_AUX_PUSH_BACK_IMPL_HPP_INCLUDED
 #define BOOST_MPL_AUX_PUSH_BACK_IMPL_HPP_INCLUDED
 
-// Copyright Aleksey Gurtovoy 2000-2004
+// Copyright Aleksey Gurtovoy 2000-2008
 //
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt or copy at
@@ -15,19 +15,35 @@
 // $Revision$
 
 #include <boost/mpl/push_back_fwd.hpp>
+#include <boost/mpl/assert.hpp>
 #include <boost/mpl/aux_/has_type.hpp>
 #include <boost/mpl/aux_/traits_lambda_spec.hpp>
 #include <boost/mpl/aux_/config/forwarding.hpp>
 #include <boost/mpl/aux_/config/static_constant.hpp>
 
+#include <boost/type_traits/is_same.hpp>
+
 namespace boost { namespace mpl {
 
+template< typename Tag >
+struct has_push_back_impl;
+
 // agurt 05/feb/04: no default implementation; the stub definition is needed
 // to enable the default 'has_push_back' implementation below
 template< typename Tag >
 struct push_back_impl
 {
- template< typename Sequence, typename T > struct apply {};
+ template< typename Sequence, typename T > struct apply
+ {
+ // should be instantiated only in the context of 'has_push_back_impl';
+ // if you've got an assert here, you are requesting a 'push_back'
+ // specialization that doesn't exist.
+ BOOST_MPL_ASSERT_MSG(
+ ( boost::is_same< T, has_push_back_impl<T> >::value )
+ , REQUESTED_PUSH_BACK_SPECIALIZATION_FOR_SEQUENCE_DOES_NOT_EXIST
+ , ( Sequence )
+ );
+ };
 };
 
 template< typename Tag >
@@ -35,13 +51,13 @@
 {
     template< typename Seq > struct apply
 #if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING)
- : aux::has_type< push_back<Seq,int> >
+ : aux::has_type< push_back< Seq, has_push_back_impl<Tag> > >
     {
 #else
     {
- typedef aux::has_type< push_back<Seq,int> > type;
+ typedef aux::has_type< push_back< Seq, has_push_back_impl<Tag> > > type;
         BOOST_STATIC_CONSTANT(bool, value =
- (aux::has_type< push_back<Seq,int> >::value)
+ (aux::has_type< push_back< Seq, has_push_back_impl<Tag> > >::value)
             );
 #endif
     };

Modified: trunk/boost/mpl/aux_/push_front_impl.hpp
==============================================================================
--- trunk/boost/mpl/aux_/push_front_impl.hpp (original)
+++ trunk/boost/mpl/aux_/push_front_impl.hpp 2008-06-20 00:43:41 EDT (Fri, 20 Jun 2008)
@@ -2,7 +2,7 @@
 #ifndef BOOST_MPL_AUX_PUSH_FRONT_IMPL_HPP_INCLUDED
 #define BOOST_MPL_AUX_PUSH_FRONT_IMPL_HPP_INCLUDED
 
-// Copyright Aleksey Gurtovoy 2000-2004
+// Copyright Aleksey Gurtovoy 2000-2008
 //
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt or copy at
@@ -15,20 +15,36 @@
 // $Revision$
 
 #include <boost/mpl/push_front_fwd.hpp>
+#include <boost/mpl/assert.hpp>
 #include <boost/mpl/aux_/has_type.hpp>
 #include <boost/mpl/aux_/traits_lambda_spec.hpp>
 #include <boost/mpl/aux_/config/forwarding.hpp>
 #include <boost/mpl/aux_/config/static_constant.hpp>
 
+#include <boost/type_traits/is_same.hpp>
+
 namespace boost { namespace mpl {
 
+template< typename Tag >
+struct has_push_front_impl;
+
 // agurt 05/feb/04: no default implementation; the stub definition is needed
 // to enable the default 'has_push_front' implementation below
 
 template< typename Tag >
 struct push_front_impl
 {
- template< typename Sequence, typename T > struct apply {};
+ template< typename Sequence, typename T > struct apply
+ {
+ // should be instantiated only in the context of 'has_push_front_impl';
+ // if you've got an assert here, you are requesting a 'push_front'
+ // specialization that doesn't exist.
+ BOOST_MPL_ASSERT_MSG(
+ ( boost::is_same< T, has_push_front_impl<T> >::value )
+ , REQUESTED_PUSH_FRONT_SPECIALIZATION_FOR_SEQUENCE_DOES_NOT_EXIST
+ , ( Sequence )
+ );
+ };
 };
 
 template< typename Tag >
@@ -36,13 +52,13 @@
 {
     template< typename Seq > struct apply
 #if !defined(BOOST_MPL_CFG_NO_NESTED_FORWARDING)
- : aux::has_type< push_front<Seq,int> >
+ : aux::has_type< push_front< Seq, has_push_front_impl<Tag> > >
     {
 #else
     {
- typedef aux::has_type< push_front<Seq,int> > type;
+ typedef aux::has_type< push_front< Seq, has_push_front_impl<Tag> > > type;
         BOOST_STATIC_CONSTANT(bool, value =
- (aux::has_type< push_front<Seq,int> >::value)
+ (aux::has_type< push_front< Seq, has_push_front_impl<Tag> > >::value)
             );
 #endif
     };

Modified: trunk/boost/mpl/aux_/traits_lambda_spec.hpp
==============================================================================
--- trunk/boost/mpl/aux_/traits_lambda_spec.hpp (original)
+++ trunk/boost/mpl/aux_/traits_lambda_spec.hpp 2008-06-20 00:43:41 EDT (Fri, 20 Jun 2008)
@@ -2,7 +2,7 @@
 #ifndef BOOST_MPL_AUX_TRAITS_LAMBDA_SPEC_HPP_INCLUDED
 #define BOOST_MPL_AUX_TRAITS_LAMBDA_SPEC_HPP_INCLUDED
 
-// Copyright Aleksey Gurtovoy 2000-2004
+// Copyright Aleksey Gurtovoy 2000-2008
 //
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt or copy at
@@ -14,17 +14,18 @@
 // $Date$
 // $Revision$
 
+#include <boost/mpl/sequence_tag_fwd.hpp>
 #include <boost/mpl/void.hpp>
 #include <boost/mpl/aux_/preprocessor/params.hpp>
 #include <boost/mpl/aux_/config/lambda.hpp>
 
 #if !defined(BOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT)
 
-# define BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC(i, trait) /**/
+# define BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC_IMPL(i, trait) /**/
 
 #elif !defined(BOOST_MPL_CFG_MSVC_ETI_BUG)
 
-# define BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC(i, trait) \
+# define BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC_IMPL(i, trait) \
 template<> struct trait<void_> \
 { \
     template< BOOST_MPL_PP_PARAMS(i, typename T) > struct apply \
@@ -35,7 +36,7 @@
 
 #else
 
-# define BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC(i, trait) \
+# define BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC_IMPL(i, trait) \
 template<> struct trait<void_> \
 { \
     template< BOOST_MPL_PP_PARAMS(i, typename T) > struct apply \
@@ -53,4 +54,10 @@
 
 #endif // BOOST_MPL_CFG_NO_FULL_LAMBDA_SUPPORT
 
+
+#define BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC(i, trait) \
+ BOOST_MPL_ALGORITM_TRAITS_LAMBDA_SPEC_IMPL(i, trait) \
+ template<> struct trait<non_sequence_tag> {}; \
+/**/
+
 #endif // BOOST_MPL_AUX_TRAITS_LAMBDA_SPEC_HPP_INCLUDED

Modified: trunk/boost/mpl/for_each.hpp
==============================================================================
--- trunk/boost/mpl/for_each.hpp (original)
+++ trunk/boost/mpl/for_each.hpp 2008-06-20 00:43:41 EDT (Fri, 20 Jun 2008)
@@ -2,7 +2,7 @@
 #ifndef BOOST_MPL_FOR_EACH_HPP_INCLUDED
 #define BOOST_MPL_FOR_EACH_HPP_INCLUDED
 
-// Copyright Aleksey Gurtovoy 2000-2004
+// Copyright Aleksey Gurtovoy 2000-2008
 //
 // Distributed under the Boost Software License, Version 1.0.
 // (See accompanying file LICENSE_1_0.txt or copy at
@@ -14,12 +14,14 @@
 // $Date$
 // $Revision$
 
+#include <boost/mpl/is_sequence.hpp>
 #include <boost/mpl/begin_end.hpp>
 #include <boost/mpl/apply.hpp>
 #include <boost/mpl/bool.hpp>
 #include <boost/mpl/next_prior.hpp>
 #include <boost/mpl/deref.hpp>
 #include <boost/mpl/identity.hpp>
+#include <boost/mpl/assert.hpp>
 #include <boost/mpl/aux_/unwrap.hpp>
 
 #include <boost/type_traits/is_same.hpp>
@@ -90,6 +92,8 @@
 inline
 void for_each(F f, Sequence* = 0, TransformOp* = 0)
 {
+ BOOST_MPL_ASSERT(( is_sequence<Sequence> ));
+
     typedef typename begin<Sequence>::type first;
     typedef typename end<Sequence>::type last;
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk