Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2006-05-07 10:22:03


Tobias Schwinger wrote:
> Ooops. I just noticed this problem has already been reported...
>

OK, The problem is that e.g. "begin< int_<1> >" doesn't return "void_" (as stated in the documentation) but fails to compile instead.

Here is a tentative patch that straightens this issue.

The code in the modified file seems to assume that "sequence_tag" sorts out non-sequences -- so it /might/ be more elegant to fix the problem there.
Anyway, there is no such guarantee (according to the documentation) and it would require another detection whether "begin_impl" has been specialized, so it might as well be worse.

Regards,

Tobias

Index: boost/mpl/aux_/begin_end_impl.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/mpl/aux_/begin_end_impl.hpp,v
retrieving revision 1.8
diff -u -r1.8 begin_end_impl.hpp
--- boost/mpl/aux_/begin_end_impl.hpp 2 Sep 2004 15:40:43 -0000 1.8
+++ boost/mpl/aux_/begin_end_impl.hpp 7 May 2006 14:12:19 -0000
@@ -17,7 +17,9 @@
 #include <boost/mpl/begin_end_fwd.hpp>
 #include <boost/mpl/sequence_tag_fwd.hpp>
 #include <boost/mpl/void.hpp>
+#include <boost/mpl/eval_if.hpp>
 #include <boost/mpl/aux_/na.hpp>
+#include <boost/mpl/aux_/has_begin.hpp>
 #include <boost/mpl/aux_/traits_lambda_spec.hpp>
 #include <boost/mpl/aux_/config/eti.hpp>
 
@@ -27,12 +29,27 @@
 // specializing either the 'begin_impl/end_impl' or the primary
 // 'begin/end' templates
 
+namespace aux {
+
+template< typename Sequence > struct begin_type
+{
+ typedef typename Sequence::begin type;
+};
+
+template< typename Sequence > struct end_type
+{
+ typedef typename Sequence::end type;
+};
+
+} // namespace aux
+
 template< typename Tag >
 struct begin_impl
 {
     template< typename Sequence > struct apply
     {
- typedef typename Sequence::begin type;
+ typedef typename eval_if<aux::has_begin<Sequence,true_>,
+ aux::begin_type<Sequence>,void_ >::type type;
     };
 };
 
@@ -41,7 +58,8 @@
 {
     template< typename Sequence > struct apply
     {
- typedef typename Sequence::end type;
+ typedef typename eval_if<aux::has_begin<Sequence,true_>,
+ aux::end_type<Sequence>,void_ >::type type;
     };
 };
 
@@ -63,8 +81,7 @@
 AUX778076_IMPL_SPEC(end, nested_begin_end_tag, typename Sequence::end)
 
 // if a type 'T' does not contain 'begin/end' or 'tag' members
-// and doesn't specialize either 'begin/end' or 'begin_impl/end_impl'
-// templates, then we end up here
+// and doesn't specialize 'begin/end' templates, then we end up here
 AUX778076_IMPL_SPEC(begin, non_sequence_tag, void_)
 AUX778076_IMPL_SPEC(end, non_sequence_tag, void_)
 AUX778076_IMPL_SPEC(begin, na, void_)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk