https://svn.lrde.epita.fr/svn/oln/trunk/static
Now, the task is to find where the use of `stc_direct_type_of' (instead of
`stc_type_of') is really mandatory. My guess is that we should use it
systematically inside the definition of generic (image or morpher) classes,
as long as we know its exact type from a template parameter.
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Provide two versions of type_of_: one working on `from_type'
directly (new behavior), the other working on its exact type (old
behavior).
* stc/vtypes.hh (type_of_): Don't perform the virtual type
retrieval on the exact type of `from_type', use it directly.
(exact_type_of_): New.
Perform a virtual type retrieval using the exact type of
`from_type' (i.e., implement the previous behavior of type_of_).
(stc_type_of): Adjust macro.
(stc_direct_type_of, stc_direct_type_of_): New macros.
(stc_local_type_of, stc_local_type_of_): Remove these macros, as
they are used nowhere (but in tests), and are just (useless) sugar
for `stc_type_of' and `stc_type_of_'.
* tests/vtypes.cc (my_type_of_)
* tests/vtypes-and-exact.cc (my_type_of_)
* tests/vtypes-multiple-supers.cc (my_type_of_): Adjust.
stc/vtypes.hh | 58 ++++++++++++++++++++++------------------
tests/vtypes-and-exact.cc | 2 -
tests/vtypes-multiple-supers.cc | 2 -
tests/vtypes.cc | 2 -
4 files changed, 36 insertions, 28 deletions
Index: tests/vtypes-and-exact.cc
--- tests/vtypes-and-exact.cc (revision 556)
+++ tests/vtypes-and-exact.cc (working copy)
@@ -40,7 +40,7 @@
typename my_type_of_(FromType, Typedef)
#define my_type_of_(FromType, Typedef) \
- stc_local_type_of_(my::category::my_cat, FromType, Typedef)
+ stc_type_of_(my, my::category::my_cat, FromType, Typedef)
namespace my
{
Index: tests/vtypes-multiple-supers.cc
--- tests/vtypes-multiple-supers.cc (revision 556)
+++ tests/vtypes-multiple-supers.cc (working copy)
@@ -41,7 +41,7 @@
typename my_type_of_(FromType, Typedef)
#define my_type_of_(FromType, Typedef) \
- stc_local_type_of_(my::category::my_cat, FromType, Typedef)
+ stc_type_of_(my, my::category::my_cat, FromType, Typedef)
/// \}
Index: tests/vtypes.cc
--- tests/vtypes.cc (revision 556)
+++ tests/vtypes.cc (working copy)
@@ -38,7 +38,7 @@
typename my_type_of_(FromType, Typedef)
#define my_type_of_(FromType, Typedef) \
- stc_local_type_of_(my::category::my_cat, FromType, Typedef)
+ stc_type_of_(my, my::category::my_cat, FromType, Typedef)
namespace my
{
Index: stc/vtypes.hh
--- stc/vtypes.hh (revision 556)
+++ stc/vtypes.hh (working copy)
@@ -775,23 +775,20 @@
template <typename category, typename from_type, typename typedef_type> \
struct type_of_ \
{ \
- /* Get the exact type of \a from_type. */ \
- typedef stc_to_exact(from_type) from_exact_type; \
- \
/* Look for the typedef in internal vtypes. */ \
typedef typename \
internal::rec_get_vtype<internal::tag::internal, category, \
- from_exact_type, typedef_type>::ret \
+ from_type, typedef_type>::ret \
internal_vtype_candidate; \
/* Look for the typedef as a single vtype definition. */ \
typedef typename \
internal::rec_get_vtype<internal::tag::single, category, \
- from_exact_type, typedef_type>::ret \
+ from_type, typedef_type>::ret \
single_vtype_candidate; \
/* Look for the typedef as an extended vtype. */ \
typedef typename \
internal::rec_get_vtype<internal::tag::extended, category, \
- from_exact_type, typedef_type>::ret \
+ from_type, typedef_type>::ret \
extended_vtype_candidate; \
\
/* Did we found the virtual type in any of the vtypes structures? */ \
@@ -811,6 +808,18 @@
::ret ret; \
}; \
\
+ /** Entry point of the vtype retrieval algorithm (working on the */ \
+ /** exact version of \a from_type). */ \
+ template <typename category, typename from_type, typename typedef_type> \
+ struct exact_type_of_ \
+ { \
+ /* Get the exact type of \a from_type. */ \
+ typedef stc_to_exact(from_type) from_exact_type; \
+ /* ``Run'' type_of_. */ \
+ typedef typename \
+ type_of_<category, from_exact_type, typedef_type>::ret ret; \
+ }; \
+ \
struct e_n_d__w_i_t_h___s_e_m_i_c_o_l_o_n
@@ -928,31 +937,30 @@
// Virtual types access. //
// ---------------------- //
-// FIXME: Perhaps only ``external'' (i.e., non local) versions of
-// stc_type_of are really useful (since they are more precise), and we
-// could get rid of local versions (stc_local_type_of and
-// stc_local_type_of_).
-
-/// Get the vtype \a Typedef, declared in the current namespace,
-/// from \a FromType (version to be used inside a template).
-#define stc_local_type_of(Category, FromType, Typedef) \
- typename stc_type_of_(Category, FromType, Typedef)
-
-/// Get the vtype \a Typedef, declared in the current namespace,
-/// from \a FromType (version to be used outside a template).
-#define stc_local_type_of_(Category, FromType, Typedef) \
- type_of_<Category, FromType, typedef_:: Typedef##_type >::ret
-
-/// Get the vtype \a Typedef, declared in \a Namespace, from \a
-/// FromType (version to be used inside a template).
+/// Get the vtype \a Typedef, declared in \a Namespace, from the
+/// exact type of \a FromType (version to be used inside a template).
#define stc_type_of(Namespace, Category, FromType, Typedef) \
typename stc_type_of_(Namespace, Category, FromType, Typedef)
-/// Get the vtype \a Typedef, declared in \a Namespace, from \a
-/// FromType (version to be used outside a template).
+/// Get the vtype \a Typedef, declared in \a Namespace, from the
+/// exact type of \a FromType (version to be used outside a template).
#define stc_type_of_(Namespace, Category, FromType, Typedef) \
+ Namespace::exact_type_of_< Category, FromType, \
+ Namespace::typedef_:: Typedef##_type >::ret
+
+
+/// Get the vtype \a Typedef, declared in \a Namespace, from \a
+/// FromType directly. (version to be used inside a template).
+#define stc_direct_type_of(Namespace, Category, FromType, Typedef) \
+ typename stc_direct_type_of_(Namespace, Category, FromType, Typedef)
+
+/// Get the vtype \a Typedef, declared in \a Namespace, from \a
+/// FromType directly (version to be used outside a template).
+#define stc_direct_type_of_(Namespace, Category, FromType, Typedef) \
Namespace::type_of_<Category, FromType, \
Namespace::typedef_:: Typedef##_type >::ret
+
+
/// Declare the vtype \a Typedef in an abstract class (see sample code
/// for details). Warning: this macro assumes that the exact type