Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80882 - in sandbox/type_erasure: boost/type_erasure libs/type_erasure/test
From: steven_at_[hidden]
Date: 2012-10-05 20:08:27


Author: steven_watanabe
Date: 2012-10-05 20:08:26 EDT (Fri, 05 Oct 2012)
New Revision: 80882
URL: http://svn.boost.org/trac/boost/changeset/80882

Log:
Add metafunction is_subconcept.
Added:
   sandbox/type_erasure/boost/type_erasure/is_subconcept.hpp (contents, props changed)
   sandbox/type_erasure/libs/type_erasure/test/test_is_subconcept.cpp (contents, props changed)
Text files modified:
   sandbox/type_erasure/libs/type_erasure/test/Jamfile.jam | 2 ++
   1 files changed, 2 insertions(+), 0 deletions(-)

Added: sandbox/type_erasure/boost/type_erasure/is_subconcept.hpp
==============================================================================
--- (empty file)
+++ sandbox/type_erasure/boost/type_erasure/is_subconcept.hpp 2012-10-05 20:08:26 EDT (Fri, 05 Oct 2012)
@@ -0,0 +1,100 @@
+// 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$
+
+#ifndef BOOST_TYPE_ERASURE_IS_SUBCONCEPT_HPP_INCLUDED
+#define BOOST_TYPE_ERASURE_IS_SUBCONCEPT_HPP_INCLUDED
+
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/end.hpp>
+#include <boost/mpl/find_if.hpp>
+#include <boost/mpl/has_key.hpp>
+#include <boost/type_traits/is_same.hpp>
+#include <boost/type_erasure/detail/normalize.hpp>
+#include <boost/type_erasure/detail/rebind_placeholders.hpp>
+
+namespace boost {
+namespace type_erasure {
+namespace detail {
+
+template<class Sub, class Super, class PlaceholderMap>
+struct is_subconcept_impl {
+ typedef typename ::boost::type_erasure::detail::normalize_concept<
+ Super>::concept_set super_set;
+ typedef typename ::boost::type_erasure::detail::get_placeholder_normalization_map<
+ Super
+ >::type placeholder_subs_super;
+
+ typedef typename ::boost::type_erasure::detail::normalize_concept<
+ Sub>::type normalized_sub;
+ typedef typename ::boost::type_erasure::detail::get_placeholder_normalization_map<
+ Sub
+ >::type placeholder_subs_sub;
+
+ typedef typename ::boost::mpl::eval_if< ::boost::is_same<PlaceholderMap, void>,
+ boost::mpl::identity<void>,
+ ::boost::type_erasure::detail::convert_deductions<
+ PlaceholderMap,
+ placeholder_subs_sub,
+ placeholder_subs_super
+ >
+ >::type bindings;
+
+ typedef typename ::boost::mpl::if_< ::boost::is_same<PlaceholderMap, void>,
+ ::boost::mpl::_1,
+ ::boost::type_erasure::detail::rebind_placeholders<
+ ::boost::mpl::_1,
+ bindings
+ >
+ >::type transform;
+
+ typedef typename ::boost::is_same<
+ typename ::boost::mpl::find_if<normalized_sub,
+ ::boost::mpl::not_<
+ ::boost::mpl::has_key<
+ super_set,
+ transform
+ >
+ >
+ >::type,
+ typename ::boost::mpl::end<normalized_sub>::type
+ >::type type;
+};
+
+}
+
+/**
+ * @ref is_subconcept is a boolean metafunction that determines whether
+ * one concept is a sub-concept of another.
+ *
+ * \code
+ * is_subconcept<incrementable<>, incrementable<> > -> true
+ * is_subconcept<incrementable<>, addable<> > -> false
+ * is_subconcept<incrementable<_a>, forward_iterator<_iter>,
+ * mpl::map<mpl::pair<_a, _iter> > > -> true
+ * \endcode
+ *
+ * \tparam Sub The sub concept
+ * \tparam Super The super concept
+ * \tparam PlaceholderMap (optional) An MPL map with keys for
+ * every non-deduced placeholder in Sub. The
+ * associated value of each key is the corresponding placeholder
+ * in Super. If @c PlaceholderMap is omitted, @c Super and @c Sub
+ * are presumed to use the same set of placeholders.
+ */
+template<class Sub, class Super, class PlaceholderMap = void>
+struct is_subconcept : ::boost::type_erasure::detail::is_subconcept_impl<Sub, Super, PlaceholderMap>::type {
+};
+
+}
+}
+
+#endif

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-10-05 20:08:26 EDT (Fri, 05 Oct 2012)
@@ -37,6 +37,8 @@
 run test_null.cpp /boost//unit_test_framework ;
 run test_free.cpp /boost//unit_test_framework ;
 
+compile test_is_subconcept.cpp ;
+
 compile-fail fail_default_construct.cpp ;
 compile-fail fail_construct_mismatch.cpp ;
 compile-fail fail_construct_mismatch_ref.cpp ;

Added: sandbox/type_erasure/libs/type_erasure/test/test_is_subconcept.cpp
==============================================================================
--- (empty file)
+++ sandbox/type_erasure/libs/type_erasure/test/test_is_subconcept.cpp 2012-10-05 20:08:26 EDT (Fri, 05 Oct 2012)
@@ -0,0 +1,34 @@
+// 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/is_subconcept.hpp>
+#include <boost/type_erasure/builtin.hpp>
+#include <boost/type_erasure/operators.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/mpl/assert.hpp>
+
+namespace mpl = boost::mpl;
+using namespace boost::type_erasure;
+
+BOOST_MPL_ASSERT((is_subconcept<typeid_<>, typeid_<> >));
+BOOST_MPL_ASSERT_NOT((is_subconcept<typeid_<>, incrementable<> >));
+BOOST_MPL_ASSERT_NOT((is_subconcept<mpl::vector<typeid_<>, incrementable<> >, typeid_<> >));
+BOOST_MPL_ASSERT_NOT((is_subconcept<mpl::vector<typeid_<>, incrementable<> >, incrementable<> >));
+BOOST_MPL_ASSERT((is_subconcept<typeid_<>, mpl::vector<typeid_<>, incrementable<> > >));
+BOOST_MPL_ASSERT((is_subconcept<incrementable<>, mpl::vector<typeid_<>, incrementable<> > >));
+BOOST_MPL_ASSERT((is_subconcept<mpl::vector<typeid_<>, incrementable<> >, mpl::vector<incrementable<>, typeid_<> > >));
+
+BOOST_MPL_ASSERT((is_subconcept<typeid_<_a>, typeid_<_b>, mpl::map<mpl::pair<_a, _b> > >));
+BOOST_MPL_ASSERT_NOT((is_subconcept<typeid_<_a>, incrementable<_b>, mpl::map<mpl::pair<_a, _b> > >));
+BOOST_MPL_ASSERT_NOT((is_subconcept<mpl::vector<typeid_<_a>, incrementable<_a> >, typeid_<_b>, mpl::map<mpl::pair<_a, _b> > >));
+BOOST_MPL_ASSERT_NOT((is_subconcept<mpl::vector<typeid_<_a>, incrementable<_a> >, incrementable<_b>, mpl::map<mpl::pair<_a, _b> > >));
+BOOST_MPL_ASSERT((is_subconcept<typeid_<_a>, mpl::vector<typeid_<_b>, incrementable<_b> >, mpl::map<mpl::pair<_a, _b> > >));
+BOOST_MPL_ASSERT((is_subconcept<incrementable<_a>, mpl::vector<typeid_<_b>, incrementable<_b> >, mpl::map<mpl::pair<_a, _b> > >));
+BOOST_MPL_ASSERT((is_subconcept<mpl::vector<typeid_<_a>, incrementable<_a> >, mpl::vector<incrementable<_b>, typeid_<_b> >, mpl::map<mpl::pair<_a, _b> > >));


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