|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r78459 - in sandbox/type_erasure: boost/type_erasure boost/type_erasure/detail libs/type_erasure/test
From: steven_at_[hidden]
Date: 2012-05-13 14:20:32
Author: steven_watanabe
Date: 2012-05-13 14:20:31 EDT (Sun, 13 May 2012)
New Revision: 78459
URL: http://svn.boost.org/trac/boost/changeset/78459
Log:
Handle same_type in conversions.
Text files modified:
sandbox/type_erasure/boost/type_erasure/binding.hpp | 32 ++++++++++++++++++++++++++++----
sandbox/type_erasure/boost/type_erasure/detail/normalize.hpp | 28 ++++++++++++++++++++++++++++
sandbox/type_erasure/libs/type_erasure/test/test_same_type.cpp | 23 +++++++++++++++++++++++
3 files changed, 79 insertions(+), 4 deletions(-)
Modified: sandbox/type_erasure/boost/type_erasure/binding.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/binding.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/binding.hpp 2012-05-13 14:20:31 EDT (Sun, 13 May 2012)
@@ -80,7 +80,13 @@
binding(const binding<Concept2>& other, const Map&)
: manager(new table_type)
{
- manager->template convert_from<Map>(*other.table);
+ manager->template convert_from<
+ typename ::boost::type_erasure::detail::convert_deductions<
+ Map,
+ placeholder_subs,
+ typename binding<Concept2>::placeholder_subs
+ >::type
+ >(*other.table);
table = manager.get();
}
@@ -97,7 +103,13 @@
binding(const binding<Concept2>& other, const static_binding<Map>&)
: manager(new table_type)
{
- manager->template convert_from<Map>(*other.table);
+ manager->template convert_from<
+ typename ::boost::type_erasure::detail::convert_deductions<
+ Map,
+ placeholder_subs,
+ typename binding<Concept2>::placeholder_subs
+ >::type
+ >(*other.table);
table = manager.get();
}
@@ -109,7 +121,13 @@
: table(other.table)
{
table_type t;
- t.template convert_from<Map>(*other.table);
+ t.template convert_from<
+ typename ::boost::type_erasure::detail::convert_deductions<
+ Map,
+ placeholder_subs,
+ placeholder_subs
+ >::type
+ >(*other.table);
}
/** Special case optimization. */
@@ -118,7 +136,13 @@
: table(other.table)
{
table_type t;
- t.template convert_from<Map>(*other.table);
+ t.template convert_from<
+ typename ::boost::type_erasure::detail::convert_deductions<
+ Map,
+ placeholder_subs,
+ placeholder_subs
+ >::type
+ >(*other.table);
}
#endif
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 14:20:31 EDT (Sun, 13 May 2012)
@@ -138,6 +138,34 @@
>::type type;
};
+template<class Bindings, class P, class Out, class Sub>
+struct convert_deduced
+{
+ typedef typename ::boost::type_erasure::detail::rebind_placeholders_in_argument<
+ typename P::first,
+ Bindings
+ >::type result1;
+ typedef typename ::boost::mpl::at<Sub, result1>::type result;
+ typedef typename ::boost::mpl::eval_if<
+ ::boost::mpl::has_key<Out, typename P::second>,
+ ::boost::mpl::identity<Out>,
+ ::boost::mpl::insert<Out, ::boost::mpl::pair<typename P::second, result> >
+ >::type type;
+ BOOST_MPL_ASSERT((boost::is_same<typename ::boost::mpl::at<type, typename P::second>::type, result>));
+};
+
+template<class Bindings, class M, class Sub>
+struct convert_deductions
+{
+ typedef typename ::boost::mpl::fold<
+ M,
+ Bindings,
+ ::boost::type_erasure::detail::convert_deduced<
+ Bindings, ::boost::mpl::_2, ::boost::mpl::_1, Sub
+ >
+ >::type type;
+};
+
template<class Bindings, class P, class Out>
struct add_deduced
{
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 14:20:31 EDT (Sun, 13 May 2012)
@@ -62,3 +62,26 @@
any<test_concept, _a&> y(*x);
BOOST_CHECK_EQUAL(&any_cast<int&>(y), &i);
}
+
+BOOST_AUTO_TEST_CASE(test_convert)
+{
+ typedef ::boost::mpl::vector<
+ copy_constructible<>,
+ typeid_<_a>,
+ dereferenceable<deduced<boost::remove_pointer<_self> >&>,
+ same_type<deduced<boost::remove_pointer<_self> >, _a>
+ > test_concept_src;
+ typedef ::boost::mpl::vector<
+ copy_constructible<_b>,
+ typeid_<_c>,
+ dereferenceable<deduced<boost::remove_pointer<_b> >&, _b>,
+ same_type<deduced<boost::remove_pointer<_b> >, _c>
+ > test_concept_dest;
+ int i;
+
+ any<test_concept_src> x1(&i);
+ any<test_concept_src, _a&> y1(*x1);
+ any<test_concept_dest, _b> x2(x1);
+ any<test_concept_dest, _c&> y2(*x2);
+ BOOST_CHECK_EQUAL(&any_cast<int&>(y2), &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