2005-04-06 Thierry GERAUD <theo(a)tegucigalpa.lrde.epita.fr>
* mlc/bool.hh: Make clear that ::ret is not ::val.
* mlc/properties.hh: Likewise.
* mlc/if.hh: Likewise.
* mlc/value.hh: Likewise.
* tests/main/tests/is_a1: Likewise.
Index: tests/main/tests/is_a1
===================================================================
--- tests/main/tests/is_a1 (revision 115)
+++ tests/main/tests/is_a1 (working copy)
@@ -13,21 +13,21 @@
template <class T>
void foo()
{
- is_false<mlc_is_a(int, bool)::ret>::ensure();
- is_true<mlc_is_a(B, A)::ret>::ensure();
- is_true<mlc_is_a(C, A)::ret>::ensure();
- is_false<mlc_is_a(A, B)::ret>::ensure();
+ is_false<mlc_is_a(int, bool)::val>::ensure();
+ is_true<mlc_is_a(B, A)::val>::ensure();
+ is_true<mlc_is_a(C, A)::val>::ensure();
+ is_false<mlc_is_a(A, B)::val>::ensure();
}
int main()
{
- is_false<mlc_is_a_(int, bool)::ret>::ensure();
- is_true<mlc_is_a_(B, A)::ret>::ensure();
- is_true<mlc_is_a_(C, A)::ret>::ensure();
- is_false<mlc_is_a_(A, B)::ret>::ensure();
+ is_false<mlc_is_a_(int, bool)::val>::ensure();
+ is_true<mlc_is_a_(B, A)::val>::ensure();
+ is_true<mlc_is_a_(C, A)::val>::ensure();
+ is_false<mlc_is_a_(A, B)::val>::ensure();
- is_true<mlc_is_a_(T_B<int>, T_A)::ret>::ensure();
- is_false<mlc_is_a_(T_A<int>, T_B)::ret>::ensure();
+ is_true<mlc_is_a_(T_B<int>, T_A)::val>::ensure();
+ is_false<mlc_is_a_(T_A<int>, T_B)::val>::ensure();
foo<int>();
}
Index: mlc/bool.hh
===================================================================
--- mlc/bool.hh (revision 115)
+++ mlc/bool.hh (working copy)
@@ -34,30 +34,62 @@
namespace mlc
{
+ struct Boolean_value
+ {
+ };
- /// Specialization of mlc::value for T = bool and v = true; it provides ::ensure().
+ /// Specializations of mlc::value for T = bool; when v = true, ensure() is provided.
+
template <>
- struct value <bool, true>
+ struct value <bool, true> : public Boolean_value
{
+ static const bool b = true;
+ static const bool val = true;
static void ensure() {}
- static const bool ret = true;
- private:
- value();
+ protected:
+ value() {}
};
+ template <>
+ struct value <bool, false> : public Boolean_value
+ {
+ static const bool b = false;
+ static const bool val = false;
+ protected:
+ value() {}
+ };
+
/// Typedefs of true_type and false_type.
typedef value<bool, true> true_type;
typedef value<bool, false> false_type;
- /// Class is_true<b> (provided for bkd compability).
- template <bool b>
- struct is_true : public value<bool, b>
+ /// Classes is_true<b> and is_false<b> (provided for bkd compability).
+
+ template <bool b> struct is_true {};
+ template <> struct is_true <true> { static void ensure() {} };
+
+ template <bool b> struct is_false {};
+ template <> struct is_false <false> { static void ensure() {} };
+
+
+
+ /// Logical unary not of a Boolean type
+
+ template <typename T>
+ struct not_ : public value<bool, !T::b>
{
+ // FIXME: static assert here and below s.a. ~not_() { mlc_is_a(not_<T>,
Boolean_value); }
};
+ /// Logical binary operators between a couple of Boolean types
+ template <typename L, typename R> struct and_ : public value <bool, (L::b
&& R::b)> {};
+ template <typename L, typename R> struct or_ : public value <bool, (L::b ||
R::b)> {};
+ template <typename L, typename R> struct nand_ : public value <bool, (L::b
&& !R::b)> {};
+ template <typename L, typename R> struct xor_ : public value <bool, ((L::b
&& !R::b) || (!L::b && R::b))> {};
+
} // end of namespace mlc
Index: mlc/properties.hh
===================================================================
--- mlc/properties.hh (revision 115)
+++ mlc/properties.hh (working copy)
@@ -33,6 +33,7 @@
# include <mlc/if.hh>
# include <mlc/cmp.hh>
+# include <mlc/types.hh>
Index: mlc/if.hh
===================================================================
--- mlc/if.hh (revision 115)
+++ mlc/if.hh (working copy)
@@ -38,19 +38,30 @@
namespace mlc
{
- template <typename cond_type, typename then_type, typename else_type>
- struct if_;
-
- template <typename then_type, typename else_type>
- struct if_ <true_type, then_type, else_type>
+ namespace internal
{
- typedef then_type ret;
- };
- template <typename then_type, typename else_type>
- struct if_ <false_type, then_type, else_type>
+ template <bool b, typename then_type, typename else_type>
+ struct if_;
+
+ template <typename then_type, typename else_type>
+ struct if_ <true, then_type, else_type>
+ {
+ typedef then_type ret;
+ };
+
+ template <typename then_type, typename else_type>
+ struct if_ <false, then_type, else_type>
+ {
+ typedef else_type ret;
+ };
+
+ } // end of namespace mlc::internal
+
+
+ template <typename cond_type, typename then_type, typename else_type>
+ struct if_ : public internal::if_ < cond_type::b, then_type, else_type >
{
- typedef else_type ret;
};
Index: mlc/value.hh
===================================================================
--- mlc/value.hh (revision 115)
+++ mlc/value.hh (working copy)
@@ -39,9 +39,9 @@
template <typename T, T v>
struct value
{
- static const T ret = v;
- private:
- value();
+ static const T val = v;
+ value() {}
+ operator T() const { return v; }
};