643: Enhance xtd traits mechanism so that set of traits can be defined.

2006-10-16 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr> Enhance xtd traits mechanism so that set of traits can be defined. * xtd/optraits.hh (from_set_traits_): New. * xtd/traits.hh (set_traits_): New. (from_set_traits_): New. (set_trait_): New specialization. Index: xtd/optraits.hh =================================================================== --- xtd/optraits.hh (revision 642) +++ xtd/optraits.hh (working copy) @@ -63,7 +63,6 @@ }; - // logic struct land : public abstract::op_tag {}; @@ -112,8 +111,27 @@ + namespace internal + { + // Unary operators (op_lnot and op_uminus) can be fetched from type traits. + template < typename T > + struct from_set_traits_< op_lnot, T > + { + typedef typename xtd::set_traits_<T>::op_lnot_ret ret; + }; + + template < typename T > + struct from_set_traits_< op_uminus, T > + { + typedef typename xtd::set_traits_<T>::op_uminus_ret ret; + }; + + } // end of namespace xtd::internal + + + template < typename name, typename data > struct default_case_ < op_<name>, data > Index: xtd/traits.hh =================================================================== --- xtd/traits.hh (revision 642) +++ xtd/traits.hh (working copy) @@ -42,15 +42,69 @@ + // This class aims at being specialized by the client. + template < typename T > + struct set_traits_ : public mlc::undefined + { + // Unary operators. + typedef mlc::undefined op_lnot_ret; + typedef mlc::undefined op_uminus_ret; + + // Values. + typedef mlc::undefined min_ret; + typedef mlc::undefined max_ret; + typedef mlc::undefined zero_ret; + typedef mlc::undefined one_ret; + + // Quantization. + typedef mlc::undefined nbits; + + // Features. + typedef mlc::undefined is_scalar; + typedef mlc::undefined is_signed; + + // FIXME: ... + }; + + + + namespace internal + { + + // This class should be specialized for each 'subject' so + // that set_trait_ gets related to set_traits_. + template < typename subject, + typename T > + struct from_set_traits_ : public mlc::undefined + { + // FIXME: Add a static check to make sure that this class has + // been specialized. + }; + + } // end of namespace xtd::internal + + + + // This class aims at being specialized by the client. template < typename subject, typename T1, typename T2 = mlc::none > struct set_trait_ : public mlc::undefined { + // A definition, e.g., + // typedef int ret; }; + template < typename subject, + typename T > + struct set_trait_< subject, T, mlc::none > : public internal::from_set_traits_<subject, T> + { + // A definition, e.g., + // typedef int ret; + }; + namespace internal {
participants (1)
-
Thierry GERAUD