Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r80880 - in sandbox/type_erasure: boost/type_erasure boost/type_erasure/detail libs/type_erasure/doc
From: steven_at_[hidden]
Date: 2012-10-05 19:14:58


Author: steven_watanabe
Date: 2012-10-05 19:14:57 EDT (Fri, 05 Oct 2012)
New Revision: 80880
URL: http://svn.boost.org/trac/boost/changeset/80880

Log:
Improve error messages when the arguments do not model the correct concept.
Text files modified:
   sandbox/type_erasure/boost/type_erasure/any.hpp | 23 +++++----
   sandbox/type_erasure/boost/type_erasure/binding.hpp | 8 +-
   sandbox/type_erasure/boost/type_erasure/detail/instantiate.hpp | 89 +++++++++++++++++++--------------------
   sandbox/type_erasure/boost/type_erasure/detail/normalize.hpp | 11 ++--
   sandbox/type_erasure/libs/type_erasure/doc/Jamfile.jam | 2
   5 files changed, 68 insertions(+), 65 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-10-05 19:14:57 EDT (Fri, 05 Oct 2012)
@@ -171,12 +171,11 @@
      * constructor of @c U throws.
      */
     template<class U>
- explicit any(const U& data_arg)
- : table((::boost::type_erasure::detail::make_instantiate_concept<
- Concept, ::boost::mpl::map< ::boost::mpl::pair<T, U> > >::type::apply(),
+ explicit any(const U& data_arg, BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U))
+ : table(
             ::boost::type_erasure::make_binding<
                 ::boost::mpl::map< ::boost::mpl::pair<T, U> >
- >())
+ >()
         ),
         data(data_arg)
     {}
@@ -390,17 +389,17 @@
 
     // disambiguating overloads
     template<class U, class Map>
- any(U& data_arg, static_binding<Map>& binding_arg)
+ any(U& data_arg, static_binding<Map>& binding_arg, BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map))
       : table(binding_arg),
         data(data_arg)
     {}
     template<class U, class Map>
- any(const U& data_arg, static_binding<Map>& binding_arg)
+ any(const U& data_arg, static_binding<Map>& binding_arg, BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map))
       : table(binding_arg),
         data(data_arg)
     {}
     template<class U, class Map>
- any(U& data_arg, const static_binding<Map>& binding_arg)
+ any(U& data_arg, const static_binding<Map>& binding_arg, BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map))
       : table(binding_arg),
         data(data_arg)
     {}
@@ -833,7 +832,8 @@
                 ::boost::is_const<U>,
                 ::boost::type_erasure::detail::is_any<U>
>
- >::type* = 0
+ >::type* = 0,
+ BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U)
 #endif
         )
       : table(
@@ -858,7 +858,8 @@
      * \throws Nothing.
      */
     template<class U, class Map>
- any(U& arg, const static_binding<Map>& binding_arg)
+ any(U& arg, const static_binding<Map>& binding_arg,
+ BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map))
       : table(binding_arg)
     {
         BOOST_MPL_ASSERT((::boost::is_same<
@@ -1222,7 +1223,7 @@
      * \throws Nothing.
      */
     template<class U>
- explicit any(const U& arg)
+ explicit any(const U& arg, BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U))
       : table(
             ::boost::type_erasure::make_binding<
                 ::boost::mpl::map< ::boost::mpl::pair<T, U> >
@@ -1245,7 +1246,7 @@
      * \throws Nothing.
      */
     template<class U, class Map>
- any(const U& arg, const static_binding<Map>& binding_arg)
+ any(const U& arg, const static_binding<Map>& binding_arg, BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map))
       : table(binding_arg)
     {
         BOOST_MPL_ASSERT((::boost::is_same<

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-10-05 19:14:57 EDT (Fri, 05 Oct 2012)
@@ -88,8 +88,8 @@
      * \throws Nothing.
      */
     template<class Map>
- explicit binding(const Map&)
- : impl((::boost::type_erasure::detail::make_instantiate_concept<Concept, Map>::type::apply(), static_binding<Map>()))
+ explicit binding(const Map&, BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map))
+ : impl(static_binding<Map>())
     {}
     
     /**
@@ -99,8 +99,8 @@
      * \throws Nothing.
      */
     template<class Map>
- binding(const static_binding<Map>&)
- : impl((::boost::type_erasure::detail::make_instantiate_concept<Concept, Map>::type::apply(), static_binding<Map>()))
+ binding(const static_binding<Map>&, BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map))
+ : impl(static_binding<Map>())
     {}
 
     /**

Modified: sandbox/type_erasure/boost/type_erasure/detail/instantiate.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/detail/instantiate.hpp (original)
+++ sandbox/type_erasure/boost/type_erasure/detail/instantiate.hpp 2012-10-05 19:14:57 EDT (Fri, 05 Oct 2012)
@@ -31,29 +31,33 @@
 template<int N>
 struct make_instantiate_concept_impl;
 
-template<class Concept, class Map>
+template<class Concept>
 struct make_instantiate_concept {
     typedef typename ::boost::type_erasure::detail::normalize_concept<
         Concept>::type normalized;
- typedef typename ::boost::type_erasure::detail::get_placeholder_normalization_map<
- Concept
- >::type placeholder_subs;
-
- typedef typename ::boost::mpl::transform<
- normalized,
- ::boost::type_erasure::detail::rebind_placeholders<
- ::boost::mpl::_1,
- typename ::boost::type_erasure::detail::add_deductions<
- Map,
- placeholder_subs
- >::type
- >
- >::type bound_concept;
     typedef typename ::boost::type_erasure::detail::make_instantiate_concept_impl<
- (::boost::mpl::size<bound_concept>::value)
- >::template apply<bound_concept>::type type;
+ (::boost::mpl::size<normalized>::value)
+ >::type type;
 };
 
+struct instantiate_arg {};
+
+#define BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map) \
+ ::boost::type_erasure::detail::instantiate_arg = \
+ (::boost::type_erasure::detail::make_instantiate_concept< \
+ Concept \
+ >::type::apply((Concept*)0, (Map*)0), \
+ ::boost::type_erasure::detail::instantiate_arg())
+
+#define BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, P0, T0) \
+ ::boost::type_erasure::detail::instantiate_arg = \
+ (::boost::type_erasure::detail::make_instantiate_concept< \
+ Concept \
+ >::type::apply( \
+ (Concept*)0, \
+ (::boost::mpl::map1< ::boost::mpl::pair<P0, T0> >*)0), \
+ ::boost::type_erasure::detail::instantiate_arg())
+
 #define BOOST_PP_FILENAME_1 <boost/type_erasure/detail/instantiate.hpp>
 #define BOOST_PP_ITERATION_LIMITS (0, BOOST_TYPE_ERASURE_MAX_FUNCTIONS)
 #include BOOST_PP_ITERATE()
@@ -68,44 +72,39 @@
 
 #define N BOOST_PP_ITERATION()
 
-#define BOOST_TYPE_ERASURE_INSTANTIATE(z, n, data)\
- (void)&BOOST_PP_CAT(T, n)::apply;
-
-#define BOOST_TYPE_ERASURE_AT(z, n, data) \
- typename ::boost::mpl::at_c<data, n>::type
+#define BOOST_TYPE_ERASURE_INSTANTIATE_IMPL(z, n, data)\
+ (void)&::boost::mpl::at_c<data, n>::type::apply;
 
-#if N
-
-template<BOOST_PP_ENUM_PARAMS(N, class T)>
 struct BOOST_PP_CAT(instantiate_concept, N) {
- static void apply() {
- BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_INSTANTIATE, ~)
+ template<class Concept, class Map>
+ static void apply(Concept *, Map *) {
+ typedef typename ::boost::type_erasure::detail::normalize_concept<
+ Concept>::type normalized;
+ typedef typename ::boost::type_erasure::detail::get_placeholder_normalization_map<
+ Concept
+ >::type placeholder_subs;
+
+ typedef typename ::boost::mpl::transform<
+ normalized,
+ ::boost::type_erasure::detail::rebind_placeholders<
+ ::boost::mpl::_1,
+ typename ::boost::type_erasure::detail::add_deductions<
+ Map,
+ placeholder_subs
+ >::type
+ >
+ >::type concept_sequence;
+ BOOST_PP_REPEAT(N, BOOST_TYPE_ERASURE_INSTANTIATE_IMPL, concept_sequence)
     }
 };
 
-#else
-
-template<class T = void>
-struct instantiate_concept0 {
- static void apply() {}
-};
-
-#endif
-
 template<>
 struct make_instantiate_concept_impl<N>
 {
- template<class Seq>
- struct apply
- {
- typedef ::boost::type_erasure::detail::BOOST_PP_CAT(instantiate_concept, N)<
- BOOST_PP_ENUM(N, BOOST_TYPE_ERASURE_AT, Seq)
- > type;
- };
+ typedef ::boost::type_erasure::detail::BOOST_PP_CAT(instantiate_concept, N) type;
 };
 
-#undef BOOST_TYPE_ERASURE_AT
-#undef BOOST_TYPE_ERASURE_INSTANTIATE
+#undef BOOST_TYPE_ERASURE_INSTANTIATE_IMPL
 
 #undef N
 

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-10-05 19:14:57 EDT (Fri, 05 Oct 2012)
@@ -348,12 +348,13 @@
>
>
>::type basic;
+ typedef typename ::boost::mpl::eval_if<
+ ::boost::type_erasure::is_relaxed<Concept>,
+ ::boost::type_erasure::detail::add_typeinfo<basic>,
+ ::boost::mpl::identity<basic>
+ >::type concept_set;
     typedef typename ::boost::mpl::copy<
- typename ::boost::mpl::eval_if<
- ::boost::type_erasure::is_relaxed<Concept>,
- ::boost::type_erasure::detail::add_typeinfo<basic>,
- ::boost::mpl::identity<basic>
- >::type,
+ concept_set,
         ::boost::mpl::back_inserter< ::boost::mpl::vector0<> >
>::type type;
 };

Modified: sandbox/type_erasure/libs/type_erasure/doc/Jamfile.jam
==============================================================================
--- sandbox/type_erasure/libs/type_erasure/doc/Jamfile.jam (original)
+++ sandbox/type_erasure/libs/type_erasure/doc/Jamfile.jam 2012-10-05 19:14:57 EDT (Fri, 05 Oct 2012)
@@ -37,6 +37,8 @@
         \"BOOST_TYPE_ERASURE_UNARY_OPERATOR(name, op)=template<class T = _self, class R = T> struct name { static R apply(const T&); };\" \\
         \"BOOST_TYPE_ERASURE_BINARY_OPERATOR(name, op)=template<class T = _self, class U = T, class R = T> struct name { static R apply(const T&, const U&); };\" \\
         \"BOOST_TYPE_ERASURE_ASSIGNMENT_OPERATOR(name, op)=template<class T = _self, class U = T> struct name { static void apply(T&, const U&); };\" \\
+ \"BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map)=\" \\
+ \"BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U)=\" \\
         \"table_arg=table\" \\
         \"binding_arg=binding\" \\
         \"data_arg=data\""


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