Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r78430 - in sandbox/type_erasure: boost/type_erasure boost/type_erasure/detail libs/type_erasure/test
From: steven_at_[hidden]
Date: 2012-05-11 23:56:10


Author: steven_watanabe
Date: 2012-05-11 23:56:07 EDT (Fri, 11 May 2012)
New Revision: 78430
URL: http://svn.boost.org/trac/boost/changeset/78430

Log:
Initial handling for associated types.
Added:
   sandbox/type_erasure/boost/type_erasure/deduced.hpp (contents, props changed)
   sandbox/type_erasure/libs/type_erasure/test/test_deduced.cpp (contents, props changed)
Text files modified:
   sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp | 11 +++++++++++
   sandbox/type_erasure/libs/type_erasure/test/Jamfile.jam | 1 +
   2 files changed, 12 insertions(+), 0 deletions(-)

Added: sandbox/type_erasure/boost/type_erasure/deduced.hpp
==============================================================================
--- (empty file)
+++ sandbox/type_erasure/boost/type_erasure/deduced.hpp 2012-05-11 23:56:07 EDT (Fri, 11 May 2012)
@@ -0,0 +1,54 @@
+// Boost.TypeErasure library
+//
+// Copyright 2011 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$
+
+#ifndef BOOST_TYPE_ERASURE_DEDUCED_HPP_INCLUDED
+#define BOOST_TYPE_ERASURE_DEDUCED_HPP_INCLUDED
+
+#include <boost/mpl/eval_if.hpp>
+#include <boost/mpl/identity.hpp>
+#include <boost/mpl/set.hpp>
+#include <boost/mpl/empty.hpp>
+#include <boost/type_erasure/detail/get_placeholders.hpp>
+#include <boost/type_erasure/placeholder.hpp>
+
+namespace boost {
+namespace type_erasure {
+
+/**
+ * A placeholder for an assocated type. The type corresponding
+ * to this placeholder is deduced by substituting placeholders
+ * in the arguments of the metafunction and then evaluating it.
+ *
+ * When using @ref deduced in a template context, if it is possible for
+ * Metafunction to contain no placeholders, use the nested type,
+ * to automatically evaluate it early as needed.
+ */
+template<class Metafunction>
+struct deduced :
+ ::boost::type_erasure::placeholder<deduced<Metafunction> >
+{
+ typedef typename ::boost::mpl::eval_if<
+ ::boost::mpl::empty<
+ typename ::boost::type_erasure::detail::get_placeholders<
+ Metafunction,
+ ::boost::mpl::set0<>
+ >::type
+ >,
+ Metafunction,
+ ::boost::mpl::identity<
+ ::boost::type_erasure::deduced<Metafunction>
+ >
+ >::type type;
+};
+
+}
+}
+
+#endif

Modified: sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/detail/rebind_placeholders.hpp 2012-05-11 23:56:07 EDT (Fri, 11 May 2012)
@@ -27,6 +27,10 @@
 
 namespace boost {
 namespace type_erasure {
+
+template<class F>
+struct deduced;
+
 namespace detail {
 
 template<class T, class Bindings>
@@ -59,6 +63,13 @@
>::type type;
 };
 
+template<class F, class Bindings>
+struct rebind_placeholders_in_argument<
+ ::boost::type_erasure::deduced<F>,
+ Bindings
+> : ::boost::type_erasure::detail::rebind_placeholders<F, Bindings>::type
+{};
+
 #if !defined(BOOST_NO_VARIADIC_TEMPLATES)
 
 template<template<class...> class T, class... U, class Bindings>

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-05-11 23:56:07 EDT (Fri, 11 May 2012)
@@ -30,6 +30,7 @@
 run test_forward_iterator.cpp /boost//unit_test_framework ;
 run test_tuple.cpp /boost//unit_test_framework ;
 run test_stream.cpp /boost//unit_test_framework ;
+run test_deduced.cpp /boost//unit_test_framework ;
 
 compile-fail fail_increment_discard_const.cpp ;
 

Added: sandbox/type_erasure/libs/type_erasure/test/test_deduced.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_erasure/libs/type_erasure/test/test_deduced.cpp 2012-05-11 23:56:07 EDT (Fri, 11 May 2012)
@@ -0,0 +1,51 @@
+// Boost.TypeErasure library
+//
+// Copyright 2011 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/type_erasure/operators.hpp>
+#include <boost/type_erasure/any_cast.hpp>
+#include <boost/type_erasure/deduced.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/assert.hpp>
+#include <boost/type_traits/remove_pointer.hpp>
+#include <boost/type_traits/is_same.hpp>
+
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp>
+
+using namespace boost::type_erasure;
+
+template<class T = _self>
+struct common : ::boost::mpl::vector<
+ copy_constructible<T>,
+ typeid_<T>
+> {};
+
+BOOST_AUTO_TEST_CASE(test_deduce_dereference)
+{
+ typedef ::boost::mpl::vector<
+ copy_constructible<>,
+ typeid_<deduced<boost::remove_pointer<_self> >::type>,
+ dereferenceable<deduced<boost::remove_pointer<_self> >&>
+ > test_concept;
+ int i;
+ any<test_concept> x(&i);
+ any<test_concept, deduced<boost::remove_pointer<_self> >&> y(*x);
+ BOOST_CHECK_EQUAL(&any_cast<int&>(y), &i);
+}
+
+BOOST_MPL_ASSERT((
+ boost::is_same<
+ deduced<boost::remove_pointer<_self> >::type,
+ deduced<boost::remove_pointer<_self> > >));
+
+BOOST_MPL_ASSERT((
+ boost::is_same<deduced<boost::remove_pointer<int*> >::type, int >));


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