Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r79858 - in sandbox/type_erasure: boost/type_erasure libs/type_erasure/test
From: steven_at_[hidden]
Date: 2012-08-03 14:18:43


Author: steven_watanabe
Date: 2012-08-03 14:18:42 EDT (Fri, 03 Aug 2012)
New Revision: 79858
URL: http://svn.boost.org/trac/boost/changeset/79858

Log:
Require the type to match for the static_binding constructor.
Added:
   sandbox/type_erasure/libs/type_erasure/test/fail_construct_mismatch.cpp (contents, props changed)
   sandbox/type_erasure/libs/type_erasure/test/fail_construct_mismatch_cref.cpp (contents, props changed)
   sandbox/type_erasure/libs/type_erasure/test/fail_construct_mismatch_ref.cpp (contents, props changed)
Text files modified:
   sandbox/type_erasure/boost/type_erasure/any.hpp | 9 ++++++++-
   sandbox/type_erasure/libs/type_erasure/test/Jamfile.jam | 3 +++
   sandbox/type_erasure/libs/type_erasure/test/test_subscript.cpp | 2 +-
   3 files changed, 12 insertions(+), 2 deletions(-)

Modified: sandbox/type_erasure/boost/type_erasure/any.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/any.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/any.hpp 2012-08-03 14:18:42 EDT (Fri, 03 Aug 2012)
@@ -197,7 +197,10 @@
     any(const U& data_arg, const static_binding<Map>& binding_arg)
       : table(binding_arg),
         data(data_arg)
- {}
+ {
+ BOOST_MPL_ASSERT((::boost::is_same<
+ typename ::boost::mpl::at<Map, T>::type, U>));
+ }
     /**
      * Copies an @ref any.
      *
@@ -856,6 +859,8 @@
     any(U& arg, const static_binding<Map>& binding_arg)
       : table(binding_arg)
     {
+ BOOST_MPL_ASSERT((::boost::is_same<
+ typename ::boost::mpl::at<Map, T>::type, U>));
         data.data = ::boost::addressof(arg);
     }
     /**
@@ -1241,6 +1246,8 @@
     any(const U& arg, const static_binding<Map>& binding_arg)
       : table(binding_arg)
     {
+ BOOST_MPL_ASSERT((::boost::is_same<
+ typename ::boost::mpl::at<Map, T>::type, U>));
         data.data = const_cast<void*>(static_cast<const void*>(::boost::addressof(arg)));
     }
     /**

Modified: sandbox/type_erasure/libs/type_erasure/test/Jamfile.jam
==============================================================================
--- sandbox/type_erasure/libs/type_erasure/test/Jamfile.jam (original)
+++ sandbox/type_erasure/libs/type_erasure/test/Jamfile.jam 2012-08-03 14:18:42 EDT (Fri, 03 Aug 2012)
@@ -37,6 +37,9 @@
 run test_null.cpp /boost//unit_test_framework ;
 
 compile-fail fail_default_construct.cpp ;
+compile-fail fail_construct_mismatch.cpp ;
+compile-fail fail_construct_mismatch_ref.cpp ;
+compile-fail fail_construct_mismatch_cref.cpp ;
 compile-fail fail_binding_convert_no_mapping.cpp ;
 compile-fail fail_increment_discard_const.cpp ;
 

Added: sandbox/type_erasure/libs/type_erasure/test/fail_construct_mismatch.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_erasure/libs/type_erasure/test/fail_construct_mismatch.cpp 2012-08-03 14:18:42 EDT (Fri, 03 Aug 2012)
@@ -0,0 +1,21 @@
+// Boost.TypeErasure library
+//
+// Copyright 2012 Steven Watanabe
+//
+// 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)
+//
+// $Id$
+
+#include <boost/type_erasure/any.hpp>
+#include <boost/type_erasure/builtin.hpp>
+#include <boost/mpl/map.hpp>
+
+using namespace boost::type_erasure;
+namespace mpl = boost::mpl;
+
+int main()
+{
+ any<copy_constructible<> > x(1, make_binding<mpl::map<mpl::pair<_self, char> > >());
+}

Added: sandbox/type_erasure/libs/type_erasure/test/fail_construct_mismatch_cref.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_erasure/libs/type_erasure/test/fail_construct_mismatch_cref.cpp 2012-08-03 14:18:42 EDT (Fri, 03 Aug 2012)
@@ -0,0 +1,22 @@
+// Boost.TypeErasure library
+//
+// Copyright 2012 Steven Watanabe
+//
+// 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)
+//
+// $Id$
+
+#include <boost/type_erasure/any.hpp>
+#include <boost/type_erasure/builtin.hpp>
+#include <boost/mpl/map.hpp>
+
+using namespace boost::type_erasure;
+namespace mpl = boost::mpl;
+
+int main()
+{
+ int i;
+ any<copy_constructible<>, _self&> x(i, make_binding<mpl::map<mpl::pair<_self, char> > >());
+}

Added: sandbox/type_erasure/libs/type_erasure/test/fail_construct_mismatch_ref.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_erasure/libs/type_erasure/test/fail_construct_mismatch_ref.cpp 2012-08-03 14:18:42 EDT (Fri, 03 Aug 2012)
@@ -0,0 +1,22 @@
+// Boost.TypeErasure library
+//
+// Copyright 2012 Steven Watanabe
+//
+// 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)
+//
+// $Id$
+
+#include <boost/type_erasure/any.hpp>
+#include <boost/type_erasure/builtin.hpp>
+#include <boost/mpl/map.hpp>
+
+using namespace boost::type_erasure;
+namespace mpl = boost::mpl;
+
+int main()
+{
+ int i;
+ any<copy_constructible<>, _self&> x(i, make_binding<mpl::map<mpl::pair<_self, char> > >());
+}

Modified: sandbox/type_erasure/libs/type_erasure/test/test_subscript.cpp
==============================================================================
--- sandbox/type_erasure/libs/type_erasure/test/test_subscript.cpp (original)
+++ sandbox/type_erasure/libs/type_erasure/test/test_subscript.cpp 2012-08-03 14:18:42 EDT (Fri, 03 Aug 2012)
@@ -58,7 +58,7 @@
 {
     typedef ::boost::mpl::vector<common<>, common<_a>, subscriptable<const _a&, const _self> > test_concept;
     typedef ::boost::mpl::map<
- ::boost::mpl::pair<_self, int*>,
+ ::boost::mpl::pair<_self, const int*>,
         ::boost::mpl::pair<_a, int>
> types;
     const int i[5] = { 0, 0, 0, 0, 0 };


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