|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r78458 - in sandbox/type_erasure: boost/type_erasure/detail libs/type_erasure/test
From: steven_at_[hidden]
Date: 2012-05-13 13:48:07
Author: steven_watanabe
Date: 2012-05-13 13:48:06 EDT (Sun, 13 May 2012)
New Revision: 78458
URL: http://svn.boost.org/trac/boost/changeset/78458
Log:
Handle duplicate uses of same_type.
Text files modified:
sandbox/type_erasure/boost/type_erasure/detail/normalize.hpp | 33 +++++++++++++++++++++------------
sandbox/type_erasure/libs/type_erasure/test/test_same_type.cpp | 16 ++++++++++++++++
2 files changed, 37 insertions(+), 12 deletions(-)
Modified: sandbox/type_erasure/boost/type_erasure/detail/normalize.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/detail/normalize.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/detail/normalize.hpp 2012-05-13 13:48:06 EDT (Sun, 13 May 2012)
@@ -11,6 +11,7 @@
#ifndef BOOST_TYPE_ERASURE_DETAIL_NORMALIZE_HPP_INCLUDED
#define BOOST_TYPE_ERASURE_DETAIL_NORMALIZE_HPP_INCLUDED
+#include <boost/mpl/assert.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/is_sequence.hpp>
@@ -24,6 +25,7 @@
#include <boost/mpl/fold.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/copy.hpp>
+#include <boost/type_traits/is_same.hpp>
#include <boost/type_erasure/detail/get_placeholders.hpp>
#include <boost/type_erasure/detail/rebind_placeholders.hpp>
#include <boost/type_erasure/detail/normalize_deduced.hpp>
@@ -65,7 +67,8 @@
template<class T, class U>
struct select_pair
{
- // error: cannot resolve conflict
+ BOOST_MPL_ASSERT((::boost::is_same<T, U>));
+ typedef void type;
};
template<class T, class U>
@@ -165,20 +168,26 @@
template<class Out, class T, class U>
struct insert_concept<Out, ::boost::type_erasure::same_type<T, U> >
{
+ typedef typename ::boost::type_erasure::detail::resolve_same_type<
+ typename Out::second,
+ T
+ >::type t1;
+ typedef typename ::boost::type_erasure::detail::resolve_same_type<
+ typename Out::second,
+ U
+ >::type t2;
typedef ::boost::mpl::pair<
typename Out::first,
- typename ::boost::mpl::insert<
- typename Out::second,
- typename ::boost::type_erasure::detail::select_pair<
- typename ::boost::type_erasure::detail::resolve_same_type<
- typename Out::second,
- T
- >::type,
- typename ::boost::type_erasure::detail::resolve_same_type<
- typename Out::second,
- U
+ typename ::boost::mpl::eval_if<
+ ::boost::is_same<t1, t2>,
+ ::boost::mpl::identity<typename Out::second>,
+ ::boost::mpl::insert<
+ typename Out::second,
+ typename ::boost::type_erasure::detail::select_pair<
+ t1,
+ t2
>::type
- >::type
+ >
>::type
> type;
};
Modified: sandbox/type_erasure/libs/type_erasure/test/test_same_type.cpp
==============================================================================
--- sandbox/type_erasure/libs/type_erasure/test/test_same_type.cpp (original)
+++ sandbox/type_erasure/libs/type_erasure/test/test_same_type.cpp 2012-05-13 13:48:06 EDT (Sun, 13 May 2012)
@@ -46,3 +46,19 @@
BOOST_MPL_ASSERT((
boost::is_same<deduced<boost::remove_pointer<int*> >::type, int >));
+
+BOOST_AUTO_TEST_CASE(test_duplicate)
+{
+ typedef ::boost::mpl::vector<
+ copy_constructible<>,
+ typeid_<_a>,
+ dereferenceable<deduced<boost::remove_pointer<_self> >&>,
+ same_type<deduced<boost::remove_pointer<_self> >, _a>,
+ same_type<deduced<boost::remove_pointer<_self> >, _a>
+ > test_concept;
+ int i;
+
+ any<test_concept> x(&i);
+ any<test_concept, _a&> y(*x);
+ BOOST_CHECK_EQUAL(&any_cast<int&>(y), &i);
+}
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