https://svn.lrde.epita.fr/svn/oln/trunk/static
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Extensible entry points in a class hierarchy (first version).
* stc/entry.hh: New.
* tests/entry.cc: New test.
* stc/Makefile.am (nobase_stc_HEADERS): Add entry.hh.
* tests/Makefile.am (check_PROGRAMS): Add `entry'.
(entry_SOURCES): New.
stc/Makefile.am | 1
stc/entry.hh | 151 ++++++++++++++++++++++++++++++
tests/Makefile.am | 2
tests/entry.cc | 267 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 421 insertions(+)
Index: tests/entry.cc
--- tests/entry.cc (revision 0)
+++ tests/entry.cc (revision 0)
@@ -0,0 +1,267 @@
+/// Test the extensible entry points in a class hierarchy.
+
+#include <stc/entry.hh>
+
+#include <mlc/case.hh>
+#include <mlc/assert.hh>
+#include <mlc/is_a.hh>
+
+// FIXME: Fake. Remove this when mlc::abort_ is added to the project.
+namespace mlc
+{
+ template <typename T>
+ class abort_ {};
+}
+
+
+/*----------.
+| Library. |
+`----------*/
+
+/* Simplified class diagram.
+
+
+ /top/
+ ^
+ |
+ ,------------+------------.
+ | |
+ /property1/ /property2/
+ ^ ^
+ | |
+ ,-----+-----. ,-----+-----.
+ | | | |
+ /property1a/ /property1b/ /property2a/ /property2b/
+ | | | |
+ o o o o
+ o o
+ | |
+ stc::set_entry_node<C,1> stc::set_entry_node<C,1>
+ (first selector) (second selector)
+ ^ ^
+ | |
+
+ `------------+------------'
+ |
+ entry
+ ^
+ |
+ foo
+
+
+ In fact, this is closer to this :
+
+ /top/
+ ^
+ |
+ |
+ /property2/
+ ^
+ |
+ ,-----+-----.
+ | |
+ /property2a/ /property2b/
+ | |
+ o o
+ o
+ |
+ stc::set_entry_node<foo,2>
+ (second selector)
+ ^
+ |
+ /property1/
+ ^
+ |
+ ,-----+-----.
+ | |
+ /property1a/ /property1b/
+ | |
+ o o
+ o
+ |
+ stc::set_entry_node<foo,1>
+ (first selector)
+ ^
+ |
+ entry
+ ^
+ |
+ foo
+
+*/
+
+namespace my_lib
+{
+ // Virtual types.
+ // We don't use all the equipment of stc/properties.hh for
+ // simplicity purpose.
+ template <typename T>
+ struct vtypes
+ {
+ // Nothing.
+ };
+
+ /// Top of the hierachy.
+ struct top {};
+
+ /// Property 1.
+ /// \{
+ struct property1 : virtual public top {};
+ struct property1a : public property1 {};
+ struct property1b : public property1 {};
+ /// \}
+
+ /// Property 2.
+ /// \{
+ struct property2 : virtual public top {};
+ struct property2a : public property2 {};
+ struct property2b : public property2 {};
+ /// \}
+}
+
+mlc_case_equipment_for_namespace(my_lib);
+
+
+// -------------------------- //
+// Equipment for property 1. //
+// -------------------------- //
+
+namespace my_lib
+{
+ // Switch on property 1.
+ /// \{
+ struct prop1_tag;
+
+ template <typename prop1_type>
+ struct case_<prop1_tag, prop1_type, 1> :
+ // Test.
+ public mlc::where_< mlc_is_a(prop1_type, int) >
+ {
+ // Super class if test succeed.
+ typedef property1a ret;
+ };
+
+ template <typename prop1_type>
+ struct case_<prop1_tag, prop1_type, 2> :
+ // Test.
+ public mlc::where_< mlc_is_a(prop1_type, long) >
+ {
+ // Super class if test succeed.
+ typedef property1b ret;
+ };
+
+ template <typename prop1_type>
+ struct default_case_<prop1_tag, prop1_type>
+ {
+ typedef mlc::abort_<prop1_tag> ret;
+ };
+ /// \}
+
+} // End of namespace my_lib
+
+// FIXME: Maybe set/get_entry_node should be moved inside a macro?
+namespace stc
+{
+ /// Property 1.
+ /// E is for Exact.
+ template <typename E>
+ struct set_entry_node<E, 1> :
+ public my_lib::switch_<my_lib::prop1_tag,
+ typename my_lib::vtypes<E>::prop1>::ret
+ {
+ };
+}
+
+// -------------------------- //
+// Equipment for property 2. //
+// -------------------------- //
+
+namespace my_lib
+{
+ // Switch on property 2.
+ /// \{
+ struct prop2_tag;
+
+ template <typename prop2_type>
+ struct case_<prop2_tag, prop2_type, 1> :
+ // Test.
+ public mlc::where_< mlc_is_a(prop2_type, float) >
+ {
+ // Super class if test succeed.
+ typedef property2a ret;
+ };
+
+ template <typename prop2_type>
+ struct case_<prop2_tag, prop2_type, 2> :
+ // Test.
+ public mlc::where_< mlc_is_a(prop2_type, double) >
+ {
+ // Super class if test succeed.
+ typedef property2b ret;
+ };
+
+ template <typename prop2_type>
+ struct default_case_<prop2_tag, prop2_type>
+ {
+ typedef mlc::abort_<prop2_tag> ret;
+ };
+ /// \}
+
+} // End of namespace my_lib
+
+// FIXME: Maybe set/get_entry_node should be moved inside a macro?
+namespace stc
+{
+ /// Property 2.
+ /// E is for Exact.
+ template <typename E>
+ struct set_entry_node<E, 2> :
+ public my_lib::switch_<my_lib::prop2_tag,
+ typename my_lib::vtypes<E>::prop2>::ret
+ {
+ };
+}
+
+
+/*--------------.
+| Client code. |
+`--------------*/
+
+// Fwd decl.
+namespace client
+{
+ struct foo;
+}
+
+// client::foo's vtypes.
+namespace my_lib
+{
+ template <>
+ struct vtypes<client::foo>
+ {
+ typedef int prop1;
+ typedef double prop2;
+ };
+}
+
+namespace client
+{
+ struct foo : public stc::entry<foo>
+ {
+ };
+}
+
+
+int
+main ()
+{
+ mlc::assert_<mlc_is_a_(client::foo, my_lib::top)>::check();
+
+ mlc::assert_<mlc_is_a_(client::foo, my_lib::property1)>::check();
+ mlc::assert_<mlc_is_a_(client::foo, my_lib::property1a)>::check();
+ mlc::assert_<mlc_is_not_a_(client::foo, my_lib::property1b)>::check();
+
+ mlc::assert_<mlc_is_a_(client::foo, my_lib::property2)>::check();
+ mlc::assert_<mlc_is_not_a_(client::foo, my_lib::property2a)>::check();
+ mlc::assert_<mlc_is_a_(client::foo, my_lib::property2b)>::check();
+}
Index: tests/Makefile.am
--- tests/Makefile.am (revision 437)
+++ tests/Makefile.am (working copy)
@@ -8,8 +8,10 @@
# when oln.m4 is available in the distribution.
check_PROGRAMS = \
+ entry \
properties
properties_SOURCES = properties.cc
+entry_SOURCES = entry.cc
TESTS = $(check_PROGRAMS)
Index: stc/entry.hh
--- stc/entry.hh (revision 0)
+++ stc/entry.hh (revision 0)
@@ -0,0 +1,151 @@
+// Copyright (C) 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef STATIC_ENTRY_HH
+# define STATIC_ENTRY_HH
+
+/** \file stc/entry.hh
+ \brief Extensible entry points in a class hierarchy.
+
+ The following simplified diagram shows a typical use of this
+ facility.
+
+ First hierarchy Second hierarchy
+
+
+ /A/ /B/
+ ^ ^
+ | |
+ ,-----+-----. ,-----+-----.
+ | | | |
+ /A1/ /A2/ /B1/ /B2/
+ | | | |
+ o o o o
+ o o
+ | |
+ stc::set_entry_node<C,1> stc::set_entry_node<C,2>
+ (first selector) (second selector)
+ ^ ^
+ | |
+
+ `------------+------------'
+ |
+ stc::entry
+ ^
+ |
+ C
+ (a client class)
+
+
+ Actually, the inheritance tree is (almost) linear, and the real
+ code rather looks like this:
+
+ /B/
+ ^
+ |
+ ,-----+-----.
+ | |
+ /B1/ /B2/
+ | |
+ o o
+ o
+ |
+ stc::set_entry_node<C,2>
+ ^
+ |
+ /A/
+ ^
+ |
+ ,-----+-----.
+ | |
+ /A1/ /A2/
+ | |
+ o o
+ o
+ |
+ stc::set_entry_node<C,1>
+ ^
+ |
+ stc::entry
+ ^
+ |
+ C
+*/
+
+#include <mlc/if.hh>
+#include <mlc/is_a.hh>
+#include <mlc/comma.hh>
+
+namespace stc
+{
+ namespace internal
+ {
+ // End of the recurring inheritance.
+ struct none {};
+ // No user class should derive from this class.
+ struct not_user_defined {};
+ }
+
+ /** \brief Entry point of a hierarchy.
+ To be possibly specialized by the user.
+
+ This class is use as selector ``plugging'' itself (inheriting)
+ to (from) a bottom class in one of the multiple hierarchies. */
+ template <typename exact, unsigned num>
+ struct set_entry_node : public internal::not_user_defined
+ {
+ // Nothing.
+ };
+
+ namespace internal
+ {
+ // Not to be defined by the user.
+ // FIXME: Use a lock?
+ template <typename exact, unsigned num>
+ struct get_entry_node :
+ public set_entry_node<exact, num>,
+ public mlc::if_< mlc_is_a( mlc_comma_1( set_entry_node<exact, num + 1> ),
+ internal::not_user_defined ),
+ internal::none,
+ internal::get_entry_node<exact, num + 1> >::ret
+ {
+ };
+ }
+
+ /** \brief Bottom entry point.
+
+ This class must not to be specialized by the user. However,
+ this class is meant to be super class of classes below the
+ multiple hierarchies. */
+ template <typename exact>
+ struct entry : public internal::get_entry_node<exact, 1>
+ {
+ };
+
+} // end of namespace stc
+
+#endif // ! STATIC_ENTRY_HH
Index: stc/Makefile.am
--- stc/Makefile.am (revision 437)
+++ stc/Makefile.am (working copy)
@@ -2,4 +2,5 @@
stcdir = $(includedir)/stc
nobase_stc_HEADERS = \
+ entry.hh \
properties.hh
https://svn.lrde.epita.fr/svn/oln/trunk/extended
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
First draft of extended functions.
* xtd/math.hh: New file.
* xtd/res.hh: New file.
* xtd/cast.hh: New file.
* xtd/math: New file.
* xtd/math/trigo.hh: New file.
* xtd/math/arith.hh: New file.
* xtd/math/id.hh: New file.
* xtd/mexpr.hh: New file.
* xtd/args.hh: New file.
* xtd/literal.hh: New file.
* xtd/ops_expr.hh: New file.
* xtd/abstract: New file.
* xtd/abstract/nary_fun.hh: New file.
* xtd/abstract/exact.hh: New file.
* xtd/abstract/fun_expr.hh: New file.
* xtd/abstract/any.hh: New file.
* xtd/abstract/fun.hh: New file.
* xtd/abstract/plain_fun.hh: New file.
* xtd/abstract/meta_fun.hh: New file.
* xtd/mfun.hh: New file.
* xtd/traits.hh: New file.
* xtd/builtin: New file.
* xtd/builtin/traits.hh: New file.
* xtd/arg.hh: New file.
* xtd/case.hh: New file.
* tests/id.cc: New file.
* tests/cos.cc: New file.
* tests/cast.cc: New file.
* tests/Makefile.am: Update.
tests/Makefile.am | 13 +
tests/cast.cc | 37 ++++
tests/cos.cc | 52 +++++
tests/id.cc | 43 ++++
xtd/abstract/any.hh | 67 +++++++
xtd/abstract/exact.hh | 93 ++++++++++
xtd/abstract/fun.hh | 58 ++++++
xtd/abstract/fun_expr.hh | 225 +++++++++++++++++++++++++
xtd/abstract/meta_fun.hh | 290 ++++++++++++++++++++++++++++++++
xtd/abstract/nary_fun.hh | 53 +++++
xtd/abstract/plain_fun.hh | 271 ++++++++++++++++++++++++++++++
xtd/arg.hh | 152 ++++++++++++++++
xtd/args.hh | 179 +++++++++++++++++++
xtd/builtin/traits.hh | 90 ++++++++++
xtd/case.hh | 37 ++++
xtd/cast.hh | 126 ++++++++++++++
xtd/literal.hh | 113 ++++++++++++
xtd/math.hh | 45 +++++
xtd/math/arith.hh | 104 +++++++++++
xtd/math/id.hh | 68 +++++++
xtd/math/trigo.hh | 154 +++++++++++++++++
xtd/mexpr.hh | 413 ++++++++++++++++++++++++++++++++++++++++++++++
xtd/mfun.hh | 195 +++++++++++++++++++++
xtd/ops_expr.hh | 84 +++++++++
xtd/res.hh | 292 ++++++++++++++++++++++++++++++++
xtd/traits.hh | 55 ++++++
26 files changed, 3308 insertions(+), 1 deletion(-)
Index: xtd/math.hh
--- xtd/math.hh (revision 0)
+++ xtd/math.hh (revision 0)
@@ -0,0 +1,45 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MATH_HH
+# define EXTENDED_MATH_HH
+
+# include <cmath>
+
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/mfun.hh>
+# include <xtd/arg.hh>
+# include <xtd/ops_expr.hh>
+
+# include <xtd/math/id.hh>
+# include <xtd/math/trigo.hh>
+# include <xtd/math/arith.hh>
+// # include <xtd/math/logic.hh>
+
+
+
+#endif // ! EXTENDED_MATH_HH
Index: xtd/res.hh
--- xtd/res.hh (revision 0)
+++ xtd/res.hh (revision 0)
@@ -0,0 +1,292 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_RES_HH
+# define EXTENDED_RES_HH
+
+# include <mlc/flags.hh>
+# include <mlc/bool.hh> // FIXME: should be assert.hh
+# include <mlc/if.hh>
+# include <mlc/is_a.hh>
+# include <mlc/comma.hh>
+# include <mlc/cmp.hh>
+# include <mlc/ret.hh>
+
+# include <xtd/abstract/nary_fun.hh>
+
+
+
+// forward declarations ...............................
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+ template <typename E>
+ class meta_fun_;
+
+ template <unsigned n, typename E>
+ class meta_nary_fun_;
+
+ template <typename E>
+ class fun_expr_;
+
+ } // end of namespace xtd::abstract
+
+ template <typename F,
+ typename Expr>
+ struct m1expr;
+
+ template <typename F,
+ typename Expr1, typename Expr2>
+ struct m2expr;
+
+ template <typename F,
+ typename Expr1, typename Expr2, typename Expr3>
+ struct m3expr;
+
+} // end of namespace xtd
+
+
+// end of forward declarations ........................
+
+
+
+
+// macros
+
+# define xtd_res_0(F) typename xtd::internal::get_res_<F>::ret
+# define xtd_res_1(F, A1) typename xtd::internal::get_res_<F, A1>::ret
+# define xtd_res_2(F, A1, A2) typename xtd::internal::get_res_<F, A1, A2>::ret
+# define xtd_res_3(F, A1, A2, A3) typename xtd::internal::get_res_<F, A1, A2, A3>::ret
+
+# define xtd_expr_res(F, Args) typename xtd::internal::get_expr_res_<F, Args>::ret
+
+
+namespace xtd
+{
+
+ namespace ERROR
+ {
+ struct THE_MACRO_xtd_res_0_IS_FOR_USE_ON_AN_xtd_meta_fun;
+ struct THE_MACRO_xtd_res_1_IS_FOR_USE_ON_AN_xtd_meta_fun;
+ struct THE_MACRO_xtd_res_2_IS_FOR_USE_ON_AN_xtd_meta_fun;
+ struct THE_MACRO_xtd_res_3_IS_FOR_USE_ON_AN_xtd_meta_fun;
+
+ struct THE_MACRO_xtd_expr_res_IS_FOR_USE_ON_AN_xtd_fun_expr;
+ struct THE_MACRO_xtd_expr_res_IS_FOR_USE_WITH_AN_xtd_args;
+
+ struct THE_MACRO_xtd_res_0_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_0;
+ struct THE_MACRO_xtd_res_1_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_1;
+ struct THE_MACRO_xtd_res_2_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_2;
+ struct THE_MACRO_xtd_res_3_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_3;
+
+ struct SPECIALIZATION_OF_xtd_res_NOT_FOUND;
+ struct SPECIALIZATION_OF_xtd_expr_res_NOT_FOUND;
+
+ struct NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_res;
+ struct NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_expr_res;
+
+ struct YOU_SHOULD_NOT_DERIVE_DIRECTLY_FROM_xtd_meta_fun_BUT_FROM_xtd_meta_nary_fun_;
+
+ struct FIXME_NAME_THIS_ERROR ;
+
+ } // end of namespace xtd::ERROR
+
+
+
+
+ // FIXME: doc
+
+ template <typename F,
+ typename A1 = mlc::none,
+ typename A2 = mlc::none,
+ typename A3 = mlc::none>
+ struct res_ : public mlc::undefined
+ {
+ };
+
+
+ template <typename F,
+ typename Args>
+ struct expr_res_ : public mlc::undefined
+ {
+ };
+
+
+
+ namespace internal
+ {
+ // FIXME: doc...
+
+
+ // for meta_fun that are *not* fun_expr
+ // ------------------------------------
+
+
+ // three args
+
+ template <typename F,
+ typename A1 = mlc::none,
+ typename A2 = mlc::none,
+ typename A3 = mlc::none>
+ struct do_get_res_
+
+ : private mlc::assert_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ xtd::ERROR::THE_MACRO_xtd_res_3_IS_FOR_USE_ON_AN_xtd_meta_fun >,
+
+ private mlc::assert_< mlc::and_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ mlc_is_a(F, xtd::abstract::nary_fun_<3>) >,
+ xtd::ERROR::THE_MACRO_xtd_res_3_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_3 >,
+
+ private mlc::assert_< mlc_is_not_a(mlc_comma_3(xtd::res_<F,A1,A2,A3>), mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_res_NOT_FOUND >,
+
+ private mlc::assert_< mlc::neq_< mlc_ret(mlc_comma_3(xtd::res_<F,A1,A2,A3>)), mlc::not_found >,
+ xtd::ERROR::NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_res >
+ {
+ typedef mlc_ret(mlc_comma_3(xtd::res_<F,A1,A2,A3>)) ret;
+ };
+
+
+
+ // no arg
+
+ template <typename F>
+ struct do_get_res_< F >
+
+ : private mlc::assert_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ xtd::ERROR::THE_MACRO_xtd_res_0_IS_FOR_USE_ON_AN_xtd_meta_fun >,
+
+ private mlc::assert_< mlc::and_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ mlc_is_a(F, xtd::abstract::nary_fun_<0>) >,
+ xtd::ERROR::THE_MACRO_xtd_res_0_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_0 >,
+
+ private mlc::assert_< mlc_is_not_a(xtd::res_<F>, mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_res_NOT_FOUND >,
+
+ private mlc::assert_< mlc::neq_< mlc_ret(xtd::res_<F>), mlc::not_found >,
+ xtd::ERROR::NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_res >
+ {
+ typedef mlc_ret(xtd::res_<F>) ret;
+ };
+
+
+ // a single arg
+
+ template <typename F, typename A1>
+ struct do_get_res_< F, A1 >
+
+ : private mlc::assert_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ xtd::ERROR::THE_MACRO_xtd_res_1_IS_FOR_USE_ON_AN_xtd_meta_fun >,
+
+ private mlc::assert_< mlc::and_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ mlc_is_a(F, xtd::abstract::nary_fun_<1>) >,
+ xtd::ERROR::THE_MACRO_xtd_res_1_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_1 >,
+
+ private mlc::assert_< mlc_is_not_a(mlc_comma_1(xtd::res_<F,A1>), mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_res_NOT_FOUND >,
+
+ private mlc::assert_< mlc::neq_< mlc_ret(mlc_comma_1(xtd::res_<F,A1>)), mlc::not_found >,
+ xtd::ERROR::NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_res >
+ {
+ typedef mlc_ret(mlc_comma_1(xtd::res_<F,A1>)) ret;
+ };
+
+
+ // a couple of args
+
+ template <typename F, typename A1, typename A2>
+ struct do_get_res_< F, A1, A2 >
+
+ : private mlc::assert_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ xtd::ERROR::THE_MACRO_xtd_res_2_IS_FOR_USE_ON_AN_xtd_meta_fun >,
+
+ private mlc::assert_< mlc::and_< mlc_is_a(F, xtd::abstract::meta_fun_),
+ mlc_is_a(F, xtd::abstract::nary_fun_<2>) >,
+ xtd::ERROR::THE_MACRO_xtd_res_2_IS_FOR_USE_ON_AN_xtd_meta_nary_fun_WITH_n_BEING_2 >,
+
+ private mlc::assert_< mlc_is_not_a(mlc_comma_2(xtd::res_<F,A1,A2>), mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_res_NOT_FOUND >,
+
+ private mlc::assert_< mlc::neq_< mlc_ret(mlc_comma_2(xtd::res_<F,A1,A2>)), mlc::not_found >,
+ xtd::ERROR::NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_res >
+ {
+ typedef mlc_ret(mlc_comma_2(xtd::res_<F,A1,A2>)) ret;
+ };
+
+
+
+ // for meta_fun that *are* fun_expr
+ // ------------------------------------
+
+ template <typename F,
+ typename Args>
+ struct get_expr_res_
+
+ : private mlc::assert_< mlc_is_a(F, xtd::abstract::fun_expr_),
+ xtd::ERROR::THE_MACRO_xtd_expr_res_IS_FOR_USE_ON_AN_xtd_fun_expr >,
+
+ private mlc::assert_< mlc_is_a(Args, xtd::abstract::args),
+ xtd::ERROR::THE_MACRO_xtd_expr_res_IS_FOR_USE_WITH_AN_xtd_args >,
+
+ private mlc::assert_< mlc_is_not_a(mlc_comma_1(xtd::expr_res_<F,Args>), mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_expr_res_NOT_FOUND >,
+
+ private mlc::assert_< mlc::neq_< mlc_ret(mlc_comma_1(xtd::expr_res_<F,Args>)), mlc::not_found >,
+ xtd::ERROR::NO_ret_FOUND_IN_THE_SPECIALIZATION_OF_xtd_expr_res >
+ {
+ typedef mlc_ret(mlc_comma_1(xtd::expr_res_<F,Args>)) ret;
+ };
+
+
+
+ // get_res_ is the entry point
+ // ------------------------------------
+
+ template <typename F,
+ typename A1 = mlc::none,
+ typename A2 = mlc::none,
+ typename A3 = mlc::none>
+ struct get_res_ : public mlc::if_< mlc_is_a(F, xtd::abstract::fun_expr_),
+ get_expr_res_<F, xtd::args_<A1, A2, A3> >,
+ do_get_res_<F, A1, A2, A3> >::ret
+ {};
+
+ // FIXME: add extra assertions here(?)
+
+
+
+ } // end of namespace xtd::internal
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_RES_HH
Index: xtd/cast.hh
--- xtd/cast.hh (revision 0)
+++ xtd/cast.hh (revision 0)
@@ -0,0 +1,126 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_CAST_HH
+# define EXTENDED_CAST_HH
+
+# include <mlc/pair.hh>
+
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/abstract/meta_fun.hh>
+# include <xtd/mexpr.hh>
+
+
+
+namespace xtd
+{
+
+ /*! \class xtd::plain_cast_<Dest>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename Dest, typename Src> struct plain_cast_; // fwd decl
+
+ template <typename Dest, typename Src>
+ struct fun_traits_< plain_cast_<Dest, Src> >
+ {
+ typedef Src arg_type;
+ typedef Dest res_type;
+ };
+
+ template <typename Dest, typename Src>
+ struct plain_cast_ : public abstract::plain_nary_fun_< 1, plain_cast_<Dest, Src> >
+ {
+ Dest impl_op(const Src& arg) const
+ {
+ return Dest(arg);
+ }
+ };
+
+
+
+
+ // equipment for xtd::meta_cast_<Dest>
+
+ template <typename Dest> struct meta_cast_; // fwd decl
+
+ template <typename Dest, typename A>
+ struct res_< meta_cast_<Dest>, A >
+ {
+ typedef Dest ret;
+ };
+
+
+ /*! \class xtd::meta_cast_<Dest>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename Dest>
+ struct meta_cast_ : public abstract::meta_nary_fun_< 1, meta_cast_<Dest> >
+ {
+ template <typename A>
+ Dest impl_calc(const A& a) const
+ // ---------
+ {
+ return Dest(a);
+ }
+ };
+
+
+
+ /*! \function xtd::cast_<Dest>(arg)
+ **
+ ** This function mimics the behavior of the method:
+ **
+ ** xtd::meta_nary_fun_<1, E>::operator(const A& a)
+ **
+ ** The method is thus turned into a function where E, the
+ ** unary meta function actually is meta_cast_<Dest>.
+ */
+
+ template <typename Dest, typename A>
+ typename xtd::case_< xtd::tag::meta_1ary_fun_operator,
+ mlc::pair_< meta_cast_<Dest>,
+ A >
+ >::ret::res
+ cast_(const A& a)
+ {
+ typedef typename xtd::case_< xtd::tag::meta_1ary_fun_operator,
+ mlc::pair_< meta_cast_<Dest>, A> >::ret case_t;
+ static const meta_cast_<Dest> the_;
+ return case_t::impl(&the_, a);
+ }
+
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_CAST_HH
Index: xtd/math/trigo.hh
--- xtd/math/trigo.hh (revision 0)
+++ xtd/math/trigo.hh (revision 0)
@@ -0,0 +1,154 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MATH_TRIGO_HH
+# define EXTENDED_MATH_TRIGO_HH
+
+# include <cmath>
+
+# include <mlc/assert.hh>
+# include <mlc/logic.hh>
+# include <mlc/cmp.hh>
+
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/mfun.hh>
+
+
+
+
+
+// FIXME: macro doc!
+
+# define xtd_decl_trigo_fun(FunName) \
+ \
+ template <typename T> struct FunName##_; \
+ \
+ template <typename T> \
+ struct fun_traits_< FunName##_<T> > \
+ \
+ : private mlc::assert_< mlc::or_list_< mlc::eq_<T, float>, \
+ mlc::eq_<T, double>, \
+ mlc::eq_<T, long double> >, \
+ xtd::ERROR::TRIGONOMETRY_ONLY_RUNS_ON_float_OR_double_OR_long_double > \
+ { \
+ typedef mlc::dummy arg_type; \
+ typedef mlc::dummy res_type; \
+ }; \
+ \
+ template <> \
+ struct fun_traits_< FunName##_<float> > \
+ { \
+ typedef float arg_type; \
+ typedef float res_type; \
+ }; \
+ \
+ template <> \
+ struct fun_traits_< FunName##_<double> > \
+ { \
+ typedef double arg_type; \
+ typedef double res_type; \
+ }; \
+ \
+ template <> \
+ struct fun_traits_< FunName##_<long double> > \
+ { \
+ typedef long double arg_type; \
+ typedef long double res_type; \
+ }; \
+ \
+ template <typename T> \
+ struct FunName##_ : public abstract::trigo_< T, FunName##_<T> > \
+ { \
+ typedef FunName##_<T> self; \
+ \
+ xtd_res(self) impl_op(const T& arg) const \
+ { \
+ return std::FunName(arg); \
+ } \
+ }; \
+ \
+ const FunName##_<float> f##FunName; \
+ const FunName##_<double> d##FunName; \
+ const FunName##_<long double> ld##FunName; \
+ \
+ typedef m1fun_<FunName##_> FunName##_type; \
+ const FunName##_type FunName; \
+ \
+ struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
+
+
+
+namespace xtd
+{
+
+ namespace ERROR
+ {
+
+ struct TRIGONOMETRY_ONLY_RUNS_ON_float_OR_double_OR_long_double;
+
+ } // end of namespace xtd::ERROR
+
+
+ namespace abstract
+ {
+
+ template <typename T, typename E>
+ struct trigo_ :
+
+ private mlc::assert_< mlc::or_list_< mlc::eq_<T, float>,
+ mlc::eq_<T, double>,
+ mlc::eq_<T, long double> >,
+ xtd::ERROR::TRIGONOMETRY_ONLY_RUNS_ON_float_OR_double_OR_long_double >,
+
+ public abstract::plain_nary_fun_< 1, E >
+ {
+ protected:
+ trigo_() {}
+ };
+
+
+ } // end of namespace xtd::abstract
+
+
+ xtd_decl_trigo_fun(cos);
+ xtd_decl_trigo_fun(sin);
+ xtd_decl_trigo_fun(tan);
+
+ xtd_decl_trigo_fun(acos);
+ xtd_decl_trigo_fun(asin);
+ xtd_decl_trigo_fun(atan);
+
+ xtd_decl_trigo_fun(cosh);
+ xtd_decl_trigo_fun(sinh);
+ xtd_decl_trigo_fun(tanh);
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_MATH_COS_HH
Index: xtd/math/arith.hh
--- xtd/math/arith.hh (revision 0)
+++ xtd/math/arith.hh (revision 0)
@@ -0,0 +1,104 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MATH_ARITH_HH
+# define EXTENDED_MATH_ARITH_HH
+
+# include <xtd/builtin/traits.hh>
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/mfun.hh>
+
+
+
+namespace xtd
+{
+
+
+ /*! \class xtd::plain_plus_<T>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename T1, typename T2> struct plain_plus_; // fwd decl
+
+ template <typename T1, typename T2>
+ struct fun_traits_< plain_plus_<T1, T2> >
+ {
+ typedef T1 arg1_type;
+ typedef T2 arg2_type;
+ typedef xtd_plus(T1, T2) res_type;
+ };
+
+ template <typename T1, typename T2>
+ struct plain_plus_ : public abstract::plain_nary_fun_< 2, plain_plus_<T1, T2> >
+ {
+ typedef plain_plus_<T1, T2> self;
+ xtd_res(self) impl_op(const T1& arg1, const T2& arg2) const
+ {
+ return arg1 + arg2;
+ }
+ };
+
+ typedef m2fun_<plain_plus_> plus_type;
+ const plus_type plus;
+
+
+
+ /*! \class xtd::plain_mult_<T>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename T1, typename T2> struct plain_mult_; // fwd decl
+
+ template <typename T1, typename T2>
+ struct fun_traits_< plain_mult_<T1, T2> >
+ {
+ typedef T1 arg1_type;
+ typedef T2 arg2_type;
+ typedef xtd_mult(T1, T2) res_type;
+ };
+
+ template <typename T1, typename T2>
+ struct plain_mult_ : public abstract::plain_nary_fun_< 2, plain_mult_<T1, T2> >
+ {
+ typedef plain_mult_<T1, T2> self;
+ xtd_res(self) impl_op(const T1& arg1, const T2& arg2) const
+ {
+ return arg1 * arg2;
+ }
+ };
+
+ typedef m2fun_<plain_mult_> mult_type;
+ const mult_type mult;
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_MATH_ARITH_HH
Index: xtd/math/id.hh
--- xtd/math/id.hh (revision 0)
+++ xtd/math/id.hh (revision 0)
@@ -0,0 +1,68 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MATH_ID_HH
+# define EXTENDED_MATH_ID_HH
+
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/mfun.hh>
+
+
+namespace xtd
+{
+
+ /*! \class xtd::plain_id_<T>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename T> struct plain_id_; // fwd decl
+
+ template <typename T>
+ struct fun_traits_< plain_id_<T> >
+ {
+ typedef T arg_type;
+ typedef T res_type;
+ };
+
+ template <typename T>
+ struct plain_id_ : public abstract::plain_nary_fun_< 1, plain_id_<T> >
+ {
+ T impl_op(const T& arg) const
+ {
+ return arg;
+ }
+ };
+
+ // id
+ const m1fun_<plain_id_> id;
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_MATH_ID_HH
Index: xtd/mexpr.hh
--- xtd/mexpr.hh (revision 0)
+++ xtd/mexpr.hh (revision 0)
@@ -0,0 +1,413 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MEXPR_HH
+# define EXTENDED_MEXPR_HH
+
+# include <mlc/case.hh>
+# include <mlc/assert.hh>
+# include <mlc/is_a.hh>
+
+# include <xtd/args.hh>
+# include <xtd/res.hh>
+# include <xtd/abstract/nary_fun.hh>
+# include <xtd/abstract/fun_expr.hh>
+
+
+
+
+
+namespace xtd
+{
+
+ namespace ERROR
+ {
+
+ struct FIXME;
+
+ } // end of namespace xtd::ERROR
+
+
+
+ // FIXME: temporary code; move it elsewhere!
+
+ template <unsigned n1, unsigned n2>
+ struct n_max {
+ static const unsigned ret = (n1 > n2 ? n1 : n2);
+ };
+
+
+
+ // m0expr_
+
+ template <typename F>
+ struct m0expr_;
+
+
+ template <typename F>
+ struct nargs_< m0expr_<F> >
+ {
+ static const unsigned ret = 0;
+ };
+
+
+ template <typename F, typename Args>
+ struct expr_res_< m0expr_<F>, Args >
+ {
+ // f()
+ typedef xtd_res_0(F) ret;
+ };
+
+
+ template <typename F>
+ struct m0expr_
+
+ : public abstract::nary_fun_expr_< 0, m0expr_<F> >
+ {
+ const F f;
+
+ m0expr_() :
+ f()
+ {}
+
+ m0expr_(const F& f) :
+ f(f)
+ {
+ mlc::assert_< mlc_is_a(F, abstract::nary_fun_<0>),
+ ERROR::FIXME >::check();
+ }
+
+ template <typename Args>
+ xtd_res_0(F) impl_eval(const Args& as) const
+ {
+ return f();
+ }
+ };
+
+
+
+ // m1expr_
+
+ template <typename F,
+ typename Expr>
+ struct m1expr_;
+
+
+ template <typename F,
+ typename Expr>
+ struct nargs_< m1expr_<F, Expr> >
+ {
+ static const unsigned ret = xtd_nargs(Expr);
+ };
+
+
+ template <typename F,
+ typename Expr,
+ typename Args>
+ struct expr_res_< m1expr_<F, Expr>,
+ Args >
+ {
+ // f(expr.eval(as))
+ typedef xtd_expr_res(Expr, Args) eval_t;
+ typedef xtd_res_1(F, eval_t) ret;
+ };
+
+
+ template <typename F,
+ typename Expr>
+ struct m1expr_
+
+ : public abstract::nary_fun_expr_< xtd_nargs(Expr),
+ m1expr_<F, Expr> >
+ {
+ typedef m1expr_<F, Expr> self;
+
+ const F f;
+ const Expr expr;
+
+ m1expr_() :
+ f(),
+ expr()
+ {}
+
+ m1expr_(const abstract::fun_expr_<Expr>& expr) :
+ f(),
+ expr(exact_of(expr))
+ {}
+
+ m1expr_(const F& f,
+ const abstract::fun_expr_<Expr>& expr) :
+ f(f),
+ expr(exact_of(expr))
+ {
+ mlc::assert_< mlc_is_a(F, abstract::nary_fun_<1>),
+ ERROR::FIXME >::check();
+ }
+
+ template <typename Args>
+ xtd_expr_res(self, Args) impl_eval(const Args& as) const
+ {
+ return f(expr.eval(as));
+ }
+ };
+
+
+
+
+ // m2expr_
+
+
+ template <typename F,
+ typename Expr1, typename Expr2>
+ struct m2expr_;
+
+
+ template <typename F,
+ typename Expr1, typename Expr2>
+ struct nargs_< m2expr_<F, Expr1, Expr2> >
+ {
+ static const unsigned ret = n_max< xtd_nargs(Expr1),
+ xtd_nargs(Expr2) >::ret;
+ };
+
+
+ template <typename F,
+ typename Expr1, typename Expr2,
+ typename Args>
+ struct expr_res_< m2expr_<F, Expr1, Expr2>,
+ Args >
+ {
+ // f(expr1.eval(as), expr2.eval(as))
+ typedef xtd_expr_res(Expr1, Args) eval1_t;
+ typedef xtd_expr_res(Expr2, Args) eval2_t;
+ typedef xtd_res_2(F, eval1_t, eval2_t) ret;
+ };
+
+
+ template <typename F,
+ typename Expr1, typename Expr2>
+ struct m2expr_
+
+ : public abstract::nary_fun_expr_< xtd_nargs(mlc_comma_2(m2expr_<F, Expr1, Expr2>)),
+ m2expr_<F, Expr1, Expr2> >
+ {
+ typedef m2expr_<F, Expr1, Expr2> self;
+
+ const F f;
+ const Expr1 expr1;
+ const Expr2 expr2;
+
+ m2expr_() :
+ f(),
+ expr1(),
+ expr2()
+ {}
+
+ m2expr_(const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2) :
+ f(),
+ expr1(exact_of(expr1)),
+ expr2(exact_of(expr2))
+ {}
+
+ m2expr_(const F& f,
+ const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2) :
+ f(f),
+ expr1(exact_of(expr1)),
+ expr2(exact_of(expr2))
+ {
+ mlc::assert_< mlc_is_a(F, abstract::nary_fun_<2>),
+ ERROR::FIXME >::check();
+ }
+
+ template <typename Args>
+ xtd_expr_res(self, Args) impl_eval(const Args& as) const
+ {
+ return f(expr1.eval(as), expr2.eval(as));
+ }
+ };
+
+
+
+ // m3expr_
+
+ template <typename F,
+ typename Expr1, typename Expr2, typename Expr3>
+ struct m3expr_;
+
+
+ template <typename F,
+ typename Expr1, typename Expr2, typename Expr3>
+ struct nargs_< m3expr_<F, Expr1, Expr2, Expr3> >
+ {
+ static const unsigned ret = n_max< xtd_nargs(Expr1),
+ n_max< xtd_nargs(Expr2),
+ xtd_nargs(Expr3) >::ret >::ret;
+ };
+
+
+ template <typename F,
+ typename Expr1, typename Expr2, typename Expr3,
+ typename Args>
+ struct expr_res_< m3expr_<F, Expr1, Expr2, Expr3>,
+ Args >
+ {
+ // f(expr1.eval(as), expr2.eval(as), expr3.eval(as))
+ typedef xtd_expr_res(Expr1, Args) eval1_t;
+ typedef xtd_expr_res(Expr2, Args) eval2_t;
+ typedef xtd_expr_res(Expr3, Args) eval3_t;
+ typedef xtd_res_3(F, eval1_t, eval2_t, eval3_t) ret;
+ };
+
+
+ template <typename F,
+ typename Expr1, typename Expr2, typename Expr3>
+ struct m3expr_
+
+ : public abstract::nary_fun_expr_< xtd_nargs(mlc_comma_3(m3expr_<F, Expr1, Expr2, Expr3>)),
+ m3expr_<F, Expr1, Expr2, Expr3> >
+ {
+ typedef m3expr_<F, Expr1, Expr2, Expr3> self;
+
+ const F f;
+ const Expr1 expr1;
+ const Expr2 expr2;
+ const Expr3 expr3;
+
+ m3expr_() :
+ f(),
+ expr1(),
+ expr2(),
+ expr3()
+ {}
+
+ m3expr_(const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2,
+ const abstract::fun_expr_<Expr3>& expr3) :
+ f(),
+ expr1(exact_of(expr1)),
+ expr2(exact_of(expr2)),
+ expr3(exact_of(expr3))
+ {}
+
+ m3expr_(const F& f,
+ const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2,
+ const abstract::fun_expr_<Expr3>& expr3) :
+ f(f),
+ expr1(exact_of(expr1)),
+ expr2(exact_of(expr2)),
+ expr3(exact_of(expr3))
+ {
+ mlc::assert_< mlc_is_a(F, abstract::nary_fun_<3>),
+ ERROR::FIXME >::check();
+ }
+
+ template <typename Args>
+ xtd_expr_res(self, Args) impl_eval(const Args& as) const
+ {
+ return f(expr1.eval(as), expr2.eval(as), expr3.eval(as));
+ }
+ };
+
+
+
+
+
+ // meta_nary_fun_<1, F>::operator()(abstract::fun_expr_<Expr>& expr) const
+
+ template <typename F, typename Expr>
+ struct case_< tag::meta_1ary_fun_operator,
+ mlc::pair_<F, Expr>,
+ 1 >
+ : public mlc::where_< mlc_is_a(Expr, abstract::fun_expr_) >
+ {
+ typedef m1expr_<F, Expr> res;
+
+ static res impl(const abstract::meta_nary_fun_<1, F>* this_,
+ const abstract::fun_expr_<Expr>& expr)
+ {
+ res tmp(exact_of(*this_), expr);
+ return tmp;
+ }
+ };
+
+
+ // meta_nary_fun_<2, F>::operator()(const fun_expr_<Expr1>& expr1,
+ // const fun_expr_<Expr2>& expr2) const
+
+ template <typename F, typename Expr1, typename Expr2>
+ struct case_< tag::meta_2ary_fun_operator,
+ mlc::valist_<F, Expr1, Expr2>,
+ 1 >
+ : public mlc::where_< mlc::and_< mlc_is_a(Expr1, abstract::fun_expr_),
+ mlc_is_a(Expr2, abstract::fun_expr_) > >
+ {
+ typedef m2expr_<F, Expr1, Expr2> res;
+
+ static res impl(const abstract::meta_nary_fun_<2, F>* this_,
+ const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2)
+ {
+ res tmp(exact_of(*this_), expr1, expr2);
+ return tmp;
+ }
+ };
+
+
+ // meta_nary_fun_<3, F>::operator()(const fun_expr_<Expr1>& expr1,
+ // const fun_expr_<Expr2>& expr2,
+ // const fun_expr_<Expr3>& expr3) const
+
+ template <typename F, typename Expr1, typename Expr2, typename Expr3>
+ struct case_< tag::meta_3ary_fun_operator,
+ mlc::valist_<F, Expr1, Expr2, Expr3>,
+ 1 >
+ : public mlc::where_< mlc::and_< mlc_is_a(Expr1, abstract::fun_expr_),
+ mlc::and_< mlc_is_a(Expr2, abstract::fun_expr_),
+ mlc_is_a(Expr3, abstract::fun_expr_) > > >
+ {
+ typedef m3expr_<F, Expr1, Expr2, Expr3> res;
+
+ static res impl(const abstract::meta_nary_fun_<3, F>* this_,
+ const abstract::fun_expr_<Expr1>& expr1,
+ const abstract::fun_expr_<Expr2>& expr2,
+ const abstract::fun_expr_<Expr3>& expr3)
+ {
+ res tmp(exact_of(*this_), expr1, expr2, expr3);
+ return tmp;
+ }
+ };
+
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_MEXPR_HH
Index: xtd/args.hh
--- xtd/args.hh (revision 0)
+++ xtd/args.hh (revision 0)
@@ -0,0 +1,179 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ARGS_HH
+# define EXTENDED_ARGS_HH
+
+# include <mlc/flags.hh>
+
+
+
+// FIXME: doc
+// FIXME: this code should be rewritten to check that
+// FIXME: xtd::nargs_<F>::ret is properly defined; see for
+// FIXME: instance, the code of xtd_res or xtd_arg1...
+
+# define xtd_nargs(F) xtd::nargs_<F>::ret
+
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+ /*! \class xtd::abstract::args
+ **
+ ** FIXME: Abstract base class for args_<..>
+ */
+
+ struct args
+ {
+ protected:
+ args() {}
+ };
+
+ } // end of namespace xtd::abstract
+
+
+
+
+ /*! \class xtd::nargs_<F>
+ **
+ ** FIXME: doc
+ ** FIXME: and add a mechanism so that the type of F is checked
+ ** FIXME: Cf. get_res0_ in xtd/abstract/meta_fun.hh
+ */
+
+ template <typename F>
+ struct nargs_;
+
+
+
+
+ /*! \class xtd::args_<A1, ..>
+ **
+ ** FIXME: to pack arguments
+ */
+
+ // three args
+
+ template <typename A1 = mlc::none,
+ typename A2 = mlc::none,
+ typename A3 = mlc::none>
+ struct args_ : public abstract::args
+ {
+ args_(const A1& arg1, const A2& arg2, const A3& arg3)
+ : arg1(arg1),
+ arg2(arg2),
+ arg3(arg3)
+ {}
+ const A1 arg1;
+ const A2 arg2;
+ const A3 arg3;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef A3 arg3_type;
+ };
+
+ template <typename A1, typename A2, typename A3>
+ args_<A1,A2,A3> mk_args(const A1& arg1, const A2& arg2, const A3& arg3)
+ {
+ args_<A1,A2,A3> tmp(arg1, arg2, arg3);
+ return tmp;
+ }
+
+
+ // no arg
+
+ template <>
+ struct args_<> : public abstract::args
+ {
+ args_()
+ {}
+ typedef mlc::none arg1_type;
+ typedef mlc::none arg2_type;
+ typedef mlc::none arg3_type;
+ };
+
+ args_<> mk_args()
+ {
+ args_<> tmp;
+ return tmp;
+ }
+
+
+ // a single arg
+
+ template <typename A1>
+ struct args_< A1 > : public abstract::args
+ {
+ args_(const A1& arg1)
+ : arg1(arg1)
+ {}
+ const A1 arg1;
+ typedef A1 arg1_type;
+ typedef mlc::none arg2_type;
+ typedef mlc::none arg3_type;
+ };
+
+ template <typename A1>
+ args_<A1> mk_args(const A1& arg1)
+ {
+ args_<A1> tmp(arg1);
+ return tmp;
+ }
+
+
+ // a couple of args
+
+ template <typename A1, typename A2>
+ struct args_< A1, A2 > : public abstract::args
+ {
+ args_(const A1& arg1, const A2& arg2)
+ : arg1(arg1),
+ arg2(arg2)
+ {}
+ const A1 arg1;
+ const A2 arg2;
+ typedef A1 arg1_type;
+ typedef A2 arg2_type;
+ typedef mlc::none arg3_type;
+ };
+
+ template <typename A1, typename A2>
+ args_<A1,A2> mk_args(const A1& arg1, const A2& arg2)
+ {
+ args_<A1,A2> tmp(arg1, arg2);
+ return tmp;
+ }
+
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_ARGS_HH
Index: xtd/literal.hh
--- xtd/literal.hh (revision 0)
+++ xtd/literal.hh (revision 0)
@@ -0,0 +1,113 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_LITERAL_HH
+# define EXTENDED_LITERAL_HH
+
+# include <xtd/abstract/plain_fun.hh>
+
+
+
+namespace xtd
+{
+
+ /*! \class xtd::literal_<T>
+ **
+ ** FIXME: doc
+ */
+
+ template <typename T> struct literal_; // fwd decl
+
+ template <typename T>
+ struct fun_traits_< literal_<T> >
+ {
+ typedef T res_type;
+ };
+
+ template <typename T>
+ struct literal_ : public abstract::plain_nary_fun_< 0, literal_<T> >
+ {
+ const T value;
+
+ literal_(const T& value)
+ : value(value)
+ {}
+
+ T impl_op() const
+ {
+ return this->value;
+ }
+ };
+
+
+
+ // literal as fun expression
+ // FIXME: this should be the only version (?)
+ // FIXME: we should remove the plain version (?)
+
+ template <typename T>
+ struct literal_expr_;
+
+
+ template <typename T>
+ struct nargs_< literal_expr_<T> >
+ {
+ static const unsigned ret = 0;
+ };
+
+
+ template <typename T, typename Args>
+ struct expr_res_< literal_expr_<T>, Args >
+ {
+ typedef T ret;
+ };
+
+
+ template <typename T>
+ struct literal_expr_
+
+ : public abstract::nary_fun_expr_< 0, literal_expr_<T> >
+ {
+ const T value;
+
+ literal_expr_(const T& value) :
+ value(value)
+ {}
+
+ template <typename Args>
+ T impl_eval(const Args&) const
+ {
+ return this->value;
+ }
+ };
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_LITERAL_HH
Index: xtd/ops_expr.hh
--- xtd/ops_expr.hh (revision 0)
+++ xtd/ops_expr.hh (revision 0)
@@ -0,0 +1,84 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_OPS_EXPR_HH
+# define EXTENDED_OPS_EXPR_HH
+
+# include <mlc/case.hh>
+
+# include <xtd/abstract/fun_expr.hh>
+# include <xtd/mexpr.hh>
+# include <xtd/math/arith.hh>
+
+
+namespace xtd
+{
+
+// namespace abstract
+// {
+
+
+ // +
+
+ template <typename L, typename R>
+ xtd::m2expr_<xtd::plus_type, L, R>
+ operator + (const xtd::abstract::fun_expr_<L>& lexpr,
+ const xtd::abstract::fun_expr_<R>& rexpr)
+ {
+ xtd::m2expr_<xtd::plus_type, L, R> tmp(lexpr, rexpr);
+ return tmp;
+ }
+
+ // HERE
+
+// template <typename R>
+// xtd::m2expr_<xtd::plus_type, m0expr<literal_<int> >, R>
+// operator + (int i,
+// const xtd::abstract::fun_expr_<R>& rexpr)
+// {
+// xtd::m2expr<xtd::plus_type, L, R> tmp;
+// return tmp;
+// }
+
+
+ // *
+
+ template <typename L, typename R>
+ xtd::m2expr_<xtd::mult_type, L, R>
+ operator * (const xtd::abstract::fun_expr_<L>& lexpr,
+ const xtd::abstract::fun_expr_<R>& rexpr)
+ {
+ xtd::m2expr_<xtd::mult_type, L, R> tmp(lexpr, rexpr);
+ return tmp;
+ }
+
+// } // end of namespace xtd::abstract
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_OPS_EXPR_HH
Index: xtd/abstract/nary_fun.hh
--- xtd/abstract/nary_fun.hh (revision 0)
+++ xtd/abstract/nary_fun.hh (revision 0)
@@ -0,0 +1,53 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_NARY_FUN_HH
+# define EXTENDED_ABSTRACT_NARY_FUN_HH
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+ // FIXME: doc!
+
+ template <unsigned n>
+ class nary_fun_
+ {
+ protected:
+ nary_fun_()
+ {}
+ };
+
+ } // end of namespace xtd::abstract
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_ABSTRACT_NARY_FUN_HH
Index: xtd/abstract/exact.hh
--- xtd/abstract/exact.hh (revision 0)
+++ xtd/abstract/exact.hh (revision 0)
@@ -0,0 +1,93 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_EXACT_HH
+# define EXTENDED_ABSTRACT_EXACT_HH
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+ template <typename E> class plain_fun_;
+ template <typename E> class meta_fun_;
+ template <typename E> class fun_expr_;
+
+ } // end of namespace xtd::abstract
+
+
+ // plain_fun_
+
+ template <typename E>
+ const E* exact_of(const abstract::plain_fun_<E>* f)
+ {
+ return (const E*)(const void*)(f);
+ }
+
+ template <typename E>
+ const E& exact_of(const abstract::plain_fun_<E>& f)
+ {
+ return *exact_of(&f);
+ }
+
+
+ // meta_fun_
+
+ template <typename E>
+ const E* exact_of(const abstract::meta_fun_<E>* f)
+ {
+ return (const E*)(const void*)(f);
+ }
+
+ template <typename E>
+ const E& exact_of(const abstract::meta_fun_<E>& f)
+ {
+ return *exact_of(&f);
+ }
+
+
+ // fun_expr_
+
+ template <typename E>
+ const E* exact_of(const abstract::fun_expr_<E>* f)
+ {
+ return (const E*)(const void*)(f);
+ }
+
+ template <typename E>
+ const E& exact_of(const abstract::fun_expr_<E>& f)
+ {
+ return *exact_of(&f);
+ }
+
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_ABSTRACT_EXACT_HH
Index: xtd/abstract/fun_expr.hh
--- xtd/abstract/fun_expr.hh (revision 0)
+++ xtd/abstract/fun_expr.hh (revision 0)
@@ -0,0 +1,225 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_FUN_EXPR_HH
+# define EXTENDED_ABSTRACT_FUN_EXPR_HH
+
+# include <mlc/bool.hh>
+# include <mlc/is_a.hh>
+# include <mlc/comma.hh>
+
+# include <xtd/args.hh>
+# include <xtd/res.hh>
+# include <xtd/abstract/exact.hh>
+# include <xtd/abstract/meta_fun.hh>
+
+
+
+
+namespace xtd
+{
+
+ namespace ERROR
+ {
+
+ struct INTERNAL_ILL_FORMED_CALL_TO_xtd_fun_expr_eval;
+
+ } // end of namespace xtd::ERROR
+
+
+
+ namespace abstract
+ {
+
+ /*! \class xtd::abstract::fun_expr_<E>
+ **
+ ** Abstract base class for function expressions. Parameter E is
+ ** the exact type of the function expression.
+ **
+ ** Design note: this class does not derive from xtd::abstract::any
+ ** to avoid diamond inheritance since fun_expr classes are also
+ ** meta_fun classes.
+ */
+
+ template <typename E>
+ class fun_expr_
+
+ // FIXME: at that point, we should verify that nargs_<E> is user-defined...
+
+ : public fun_<E>
+ {
+ public:
+
+ // evaluation:
+
+ template <typename Args>
+ xtd_expr_res(E, Args)
+ eval(const Args& as) const
+ {
+ mlc::assert_< mlc_is_a(Args, xtd::abstract::args),
+ xtd::ERROR::INTERNAL_ILL_FORMED_CALL_TO_xtd_fun_expr_eval >::check();
+ return exact_of(this)->impl_eval(as);
+ }
+
+ // FIXME: the get_nargs method is obsolete; remove it!
+ unsigned nargs() const { return xtd_nargs(E); }
+
+ protected:
+ fun_expr_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::nary_fun_expr_<n, E>
+ **
+ ** Abstract base class for function expressions with an explicit
+ ** number of arguments.
+ **
+ ** Parameter n is the number of arguments with n being 0, 1, 2, or
+ ** 3.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <unsigned n, typename E>
+ class nary_fun_expr_;
+
+
+
+ /*! \class xtd::abstract::nary_fun_expr_<0, E>
+ **
+ ** Abstract base class for function expressions taking no
+ ** argument.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class nary_fun_expr_< 0, E >
+
+ : public fun_expr_<E>,
+ public meta_nary_fun_<0, E>
+ {
+ public:
+ xtd_res_0(E) impl_calc() const
+ {
+ return this->eval(mk_args());
+ }
+ protected:
+ nary_fun_expr_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::nary_fun_expr_<1, E>
+ **
+ ** Abstract base class for function expressions taking one
+ ** argument.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class nary_fun_expr_< 1, E >
+
+ : public fun_expr_<E>,
+ public meta_nary_fun_<1, E>
+ {
+ public:
+ template <typename A>
+ xtd_res_1(E, A)
+ impl_calc(const A& a) const
+ {
+ return this->eval(mk_args(a));
+ }
+ protected:
+ nary_fun_expr_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::nary_fun_expr_<2, E>
+ **
+ ** Abstract base class for function expressions taking two
+ ** arguments.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class nary_fun_expr_< 2, E >
+
+ : public fun_expr_<E>,
+ public meta_nary_fun_<2, E>
+ {
+ public:
+ template <typename A1, typename A2>
+ xtd_res_2(E, A1, A2)
+ impl_calc(const A1& a1, const A2& a2) const
+ {
+ return this->eval(mk_args(a1, a2));
+ }
+ protected:
+ nary_fun_expr_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::nary_fun_expr_<3, E>
+ **
+ ** Abstract base class for function expressions taking three
+ ** arguments.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class nary_fun_expr_< 3, E >
+
+ : public fun_expr_<E>,
+ public meta_nary_fun_<3, E>
+ {
+ public:
+ template <typename A1, typename A2, typename A3>
+ xtd_res_3(E, A1, A2, A3)
+ impl_calc(const A1& a1, const A2& a2, const A3& a3) const
+ {
+ return this->eval(mk_args(a1, a2, a3));
+ }
+ protected:
+ nary_fun_expr_() {}
+ };
+
+
+ } // end of namespace xtd::abstract
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_ABSTRACT_FUN_EXPR_HH
Index: xtd/abstract/any.hh
--- xtd/abstract/any.hh (revision 0)
+++ xtd/abstract/any.hh (revision 0)
@@ -0,0 +1,67 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_ANY_HH
+# define EXTENDED_ABSTRACT_ANY_HH
+
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+ /*! \class xtd::abstract::any
+ **
+ ** Abstract base class for static hierarchies in xtd. Parameter E
+ ** is the exact type.
+ */
+
+ template <class E>
+ class any
+ {
+ public:
+
+ typedef E exact_type;
+
+ // exact is not provided by stc::any so that xtd is independant
+ // from the stc lib.
+ E& exact() { return *(E*)(void*)(this); }
+ const E& exact() const { return *(const E*)(const void*)(this); }
+
+ protected:
+ any() {}
+ };
+
+
+ } // end of namespace abstract::xtd
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_ABSTRACT_ANY_HH
Index: xtd/abstract/fun.hh
--- xtd/abstract/fun.hh (revision 0)
+++ xtd/abstract/fun.hh (revision 0)
@@ -0,0 +1,58 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_FUN_HH
+# define EXTENDED_ABSTRACT_FUN_HH
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+ /*! \class xtd::abstract::fun_
+ **
+ ** Abstract base class for xtd functions. Parameter E is the
+ ** exact type of the function.
+ */
+
+ template <typename E>
+ class fun_
+ {
+ protected:
+ fun_() {}
+ };
+
+
+ } // end of namespace xtd::abstract
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_ABSTRACT_FUN_HH
Index: xtd/abstract/plain_fun.hh
--- xtd/abstract/plain_fun.hh (revision 0)
+++ xtd/abstract/plain_fun.hh (revision 0)
@@ -0,0 +1,271 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_PLAIN_FUN_HH
+# define EXTENDED_ABSTRACT_PLAIN_FUN_HH
+
+# include <mlc/flags.hh>
+# include <mlc/bool.hh> // FIXME: should be assert.hh
+# include <mlc/is_a.hh>
+# include <mlc/typedef.hh>
+
+# include <xtd/abstract/exact.hh>
+# include <xtd/abstract/fun.hh>
+# include <xtd/abstract/nary_fun.hh>
+
+
+// macros
+
+# define xtd_arg(F) typename xtd::typedef_::arg_type::from_<xtd::fun_traits_<F> >::ret
+
+# define xtd_arg1(F) typename xtd::typedef_::arg1_type::from_<xtd::fun_traits_<F> >::ret
+# define xtd_arg2(F) typename xtd::typedef_::arg2_type::from_<xtd::fun_traits_<F> >::ret
+# define xtd_arg3(F) typename xtd::typedef_::arg3_type::from_<xtd::fun_traits_<F> >::ret
+
+# define xtd_res(F) typename xtd::typedef_::res_type::from_<xtd::fun_traits_<F> >::ret
+
+
+
+
+namespace xtd
+{
+
+ namespace ERROR
+ {
+ struct SPECIALIZATION_OF_xtd_fun_traits_NOT_FOUND_FOR_AN_xtd_plain_fun;
+ struct xtd_fun_traits_SHOULD_DEFINE_res_type_FOR_AN_xtd_plain_fun;
+
+ struct xtd_fun_traits_SHOULD_DEFINE_arg_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_1;
+
+ struct xtd_fun_traits_SHOULD_DEFINE_arg1_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_2;
+ struct xtd_fun_traits_SHOULD_DEFINE_arg2_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_2;
+
+ struct xtd_fun_traits_SHOULD_DEFINE_arg1_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3;
+ struct xtd_fun_traits_SHOULD_DEFINE_arg2_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3;
+ struct xtd_fun_traits_SHOULD_DEFINE_arg3_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3;
+
+ struct YOU_SHOULD_NOT_DERIVE_FROM_xtd_plain_fun_BUT_FROM_xtd_plain_nary_fun;
+
+ // FIXME: add error messages corresponding to definitions without sense
+ // FIXME: such as having arg2 when the plain function is unary
+
+ } // end of namespace xtd::ERROR
+
+
+ template <typename F>
+ struct fun_traits_ : public mlc::undefined
+ {
+ // nothing
+ };
+
+ mlc_decl_typedef(arg_type);
+
+ mlc_decl_typedef(arg1_type);
+ mlc_decl_typedef(arg2_type);
+ mlc_decl_typedef(arg3_type);
+
+ mlc_decl_typedef(res_type);
+
+
+ namespace abstract
+ {
+
+ // fwd decl
+ template <unsigned n, typename E> class plain_nary_fun_;
+
+
+
+ /*! \class xtd::abstract::plain_fun_
+ **
+ ** Abstract base class for plain functions. Parameter E is the
+ ** exact type of the function.
+ */
+
+ template <typename E>
+ class plain_fun_
+
+ : private mlc::assert_< mlc_is_not_a(xtd::fun_traits_<E>, mlc::undefined),
+ xtd::ERROR::SPECIALIZATION_OF_xtd_fun_traits_NOT_FOUND_FOR_AN_xtd_plain_fun >,
+
+ private mlc::assert_< mlc::neq_<xtd_res(E), mlc::not_found>,
+ xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_res_type_FOR_AN_xtd_plain_fun >,
+
+ public fun_<E>
+ {
+ protected:
+ plain_fun_(){
+ // FIXME: unsigned is parameter so mlc_is_a does not work
+// mlc::assert_< mlc_is_a(E, plain_nary_fun_),
+// xtd::ERROR::YOU_SHOULD_NOT_DERIVE_FROM_xtd_plain_fun_BUT_FROM_xtd_plain_nary_fun
+// >::check();
+ }
+ };
+
+
+ /*! \class xtd::abstract::plain_nary_fun_<n, E>
+ **
+ ** Abstract base class for plain functions with an explicit number
+ ** of arguments.
+ **
+ ** Parameter n is the number of arguments with n being 0, 1, 2, or
+ ** 3.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <unsigned n, typename E>
+ class plain_nary_fun_;
+
+
+
+ /*! \class xtd::abstract::plain_nary_fun_<0, E>
+ **
+ ** Abstract base class for plain functions taking no argument.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class plain_nary_fun_< 0, E >
+
+ : public plain_fun_<E>,
+ public nary_fun_<0>
+ {
+ public:
+ xtd_res(E) operator()() const
+ {
+ return exact_of(this)->impl_op();
+ }
+ protected:
+ plain_nary_fun_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::plain_nary_fun_<1, E>
+ **
+ ** Abstract base class for plain functions taking one argument.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class plain_nary_fun_< 1, E >
+
+ : public plain_fun_<E>,
+ public nary_fun_<1>,
+
+ private mlc::assert_< mlc::neq_<xtd_arg(E), mlc::not_found>,
+ xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_1 >
+ {
+ public:
+ xtd_res(E) operator()(const xtd_arg(E)& arg) const
+ {
+ return exact_of(this)->impl_op(arg);
+ }
+ protected:
+ plain_nary_fun_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::plain_nary_fun_<2, E>
+ **
+ ** Abstract base class for plain functions taking two arguments.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class plain_nary_fun_< 2, E >
+
+ : public plain_fun_<E>,
+ public nary_fun_<2>,
+
+ private mlc::assert_< mlc::neq_<xtd_arg1(E), mlc::not_found>,
+ xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg1_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_2 >,
+
+ private mlc::assert_< mlc::neq_<xtd_arg2(E), mlc::not_found>,
+ xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg2_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_2 >
+ {
+ public:
+ xtd_res(E) operator()(const xtd_arg1(E)& arg1,
+ const xtd_arg2(E)& arg2) const
+ {
+ return exact_of(this)->impl_op(arg1, arg2);
+ }
+ protected:
+ plain_nary_fun_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::plain_nary_fun_<3, E>
+ **
+ ** Abstract base class for plain functions taking three arguments.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class plain_nary_fun_< 3, E >
+
+ : public plain_fun_<E>,
+ public nary_fun_<3>,
+
+ private mlc::assert_< mlc::neq_<xtd_arg1(E), mlc::not_found>,
+ xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg1_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3 >,
+
+ private mlc::assert_< mlc::neq_<xtd_arg2(E), mlc::not_found>,
+ xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg2_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3 >,
+
+ private mlc::assert_< mlc::neq_<xtd_arg3(E), mlc::not_found>,
+ xtd::ERROR::xtd_fun_traits_SHOULD_DEFINE_arg3_type_FOR_AN_xtd_plain_nary_fun_WITH_n_BEING_3 >
+ {
+ public:
+ xtd_res(E) operator()(const xtd_arg1(E)& arg1,
+ const xtd_arg2(E)& arg2,
+ const xtd_arg3(E)& arg3) const
+ {
+ return exact_of(this)->impl_op(arg1, arg2, arg3);
+ }
+ protected:
+ plain_nary_fun_() {}
+ };
+
+
+ } // end of namespace xtd::abstract
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_ABSTRACT_PLAIN_FUN_HH
Index: xtd/abstract/meta_fun.hh
--- xtd/abstract/meta_fun.hh (revision 0)
+++ xtd/abstract/meta_fun.hh (revision 0)
@@ -0,0 +1,290 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ABSTRACT_META_FUN_HH
+# define EXTENDED_ABSTRACT_META_FUN_HH
+
+# include <mlc/pair.hh>
+# include <mlc/valist.hh>
+
+# include <xtd/abstract/exact.hh>
+# include <xtd/abstract/fun.hh>
+# include <xtd/abstract/nary_fun.hh>
+# include <xtd/args.hh>
+# include <xtd/res.hh>
+# include <xtd/case.hh>
+
+
+
+
+// macros
+
+namespace xtd
+{
+
+ // FIXME: document case stuff...
+
+ namespace tag
+ {
+
+ struct meta_1ary_fun_operator;
+ struct meta_2ary_fun_operator;
+ struct meta_3ary_fun_operator;
+
+ } // end of namespace xtd::tag
+
+
+ // meta_nary_fun_<1, E>::operator()(const A& a) const
+
+ template <typename E, typename A>
+ struct default_case_ < tag::meta_1ary_fun_operator,
+ mlc::pair_<E, A> >
+ {
+ typedef xtd_res_1(E, A) res;
+
+ static res impl(const abstract::meta_nary_fun_<1, E>* this_,
+ const A& a)
+ {
+ return exact_of(this_)->impl_calc(a);
+ }
+ };
+
+
+ // meta_nary_fun_<2, E>::operator()(const A1& a1, const A2& a2) const
+
+ template <typename E, typename A1, typename A2>
+ struct default_case_ < tag::meta_2ary_fun_operator,
+ mlc::valist_<E, A1, A2> >
+ {
+ typedef xtd_res_2(E, A1, A2) res;
+
+ static res impl(const abstract::meta_nary_fun_<2, E>* this_,
+ const A1& a1, const A2& a2)
+ {
+ return exact_of(this_)->impl_calc(a1, a2);
+ }
+ };
+
+
+ // meta_nary_fun_<3, E>::operator()(const A1& a1, const A2& a2, const A3& a3) const
+
+ template <typename E, typename A1, typename A2, typename A3>
+ struct default_case_ < tag::meta_3ary_fun_operator,
+ mlc::valist_<E, A1, A2, A3> >
+ {
+ typedef xtd_res_3(E, A1, A2, A3) res;
+
+ static res impl(const abstract::meta_nary_fun_<3, E>* this_,
+ const A1& a1, const A2& a2, const A3& a3)
+ {
+ return exact_of(this_)->impl_calc(a1, a2, a3);
+ }
+ };
+
+
+} // end of namespace xtd
+
+
+namespace xtd
+{
+
+ namespace abstract
+ {
+
+
+ /*! \class xtd::abstract::meta_fun_<E>
+ **
+ ** Abstract base class for meta functions. Parameter E is the
+ ** exact type of the function.
+ */
+
+ template <typename E>
+ class meta_fun_
+
+ : public fun_<E>
+ {
+ protected:
+ meta_fun_()
+ {
+ // FIXME: mlc_is_a does not work with unsigned parameter...
+// mlc::assert_< mlc_is_a(E, xtd::abstract::meta_nary_fun_),
+// xtd::ERROR::YOU_SHOULD_NOT_DERIVE_DIRECTLY_FROM_xtd_meta_fun_BUT_FROM_xtd_meta_nary_fun_
+// >::check();
+ }
+ };
+
+
+ /*! \class xtd::abstract::meta_nary_fun_<n, E>
+ **
+ ** Abstract base class for meta functions with an explicit number
+ ** of arguments.
+ **
+ ** Parameter n is the number of arguments with n being 1, 2, or 3.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <unsigned n, typename E>
+ class meta_nary_fun_;
+
+
+
+ /*! \class xtd::abstract::meta_nary_fun_<0, E>
+ **
+ ** Abstract base class for meta functions taking no argument.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class meta_nary_fun_< 0, E >
+
+ : public meta_fun_<E>,
+ public nary_fun_<0>
+ {
+ public:
+
+ xtd_res_0(E)
+ operator()() const
+ {
+ return exact_of(this)->impl_calc();
+ }
+
+ protected:
+ meta_nary_fun_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::meta_nary_fun_<1, E>
+ **
+ ** Abstract base class for meta functions taking one argument.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class meta_nary_fun_< 1, E >
+
+ : public meta_fun_<E>,
+ public nary_fun_<1>
+ {
+ public:
+
+ template <typename A>
+ struct case_ : public xtd::case_< xtd::tag::meta_1ary_fun_operator,
+ mlc::pair_<E, A> >::ret
+ {};
+
+ template <typename A>
+ typename case_<A>::res
+ operator()(const A& a) const
+ {
+ return case_<A>::impl(this, a);
+ }
+
+ protected:
+ meta_nary_fun_() {}
+ };
+
+
+
+ /*! \class xtd::abstract::meta_nary_fun_<2, E>
+ **
+ ** Abstract base class for meta functions taking two arguments.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class meta_nary_fun_< 2, E >
+
+ : public meta_fun_<E>,
+ public nary_fun_<2>
+ {
+ public:
+
+ template <typename A1, typename A2>
+ struct case_ : public xtd::case_< xtd::tag::meta_2ary_fun_operator,
+ mlc::valist_<E, A1, A2> >::ret
+ {};
+
+ template <typename A1, typename A2>
+ typename case_<A1, A2>::res
+ operator()(const A1& a1, const A2& a2) const
+ {
+ return case_<A1, A2>::impl(this, a1, a2);
+ }
+
+ protected:
+ meta_nary_fun_() {}
+ };
+
+
+ /*! \class xtd::abstract::meta_nary_fun_<3, E>
+ **
+ ** Abstract base class for meta functions taking three arguments.
+ ** This class is defined as a specialization.
+ **
+ ** Parameter E is the exact type of the function.
+ */
+
+ template <typename E>
+ class meta_nary_fun_< 3, E >
+
+ : public meta_fun_<E>,
+ public nary_fun_<3>
+ {
+ public:
+
+ template <typename A1, typename A2, typename A3>
+ struct case_ : public xtd::case_< xtd::tag::meta_3ary_fun_operator,
+ mlc::valist_<E, A1, A2, A3> >::ret
+ {};
+
+ template <typename A1, typename A2, typename A3>
+ typename case_<A1, A2, A3>::res
+ operator()(const A1& a1, const A2& a2, const A3& a3) const
+ {
+ return case_<A1, A2, A3>::impl(this, a1, a2, a3);
+ }
+
+ protected:
+ meta_nary_fun_() {}
+ };
+
+
+ } // end of namespace xtd::abstract
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_ABSTRACT_META_FUN_HH
Index: xtd/mfun.hh
--- xtd/mfun.hh (revision 0)
+++ xtd/mfun.hh (revision 0)
@@ -0,0 +1,195 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_MFUN_HH
+# define EXTENDED_MFUN_HH
+
+# include <mlc/assert.hh>
+# include <mlc/logic.hh>
+# include <mlc/is_a.hh>
+
+# include <xtd/abstract/plain_fun.hh>
+# include <xtd/abstract/meta_fun.hh>
+
+
+
+// FIXME: in this file replace impl_calc by impl_op
+
+
+namespace xtd
+{
+
+
+ namespace ERROR
+ {
+
+ struct AN_xtd_m1fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_1;
+ struct AN_xtd_m2fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_2;
+ struct AN_xtd_m3fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_3;
+
+ } // end of namespace xtd::ERROR
+
+
+
+
+ // equipment for xtd::m1fun_<F>
+
+ template <template <typename> class F>
+ struct m1fun_;
+
+ template <template <typename> class F, typename A>
+ struct res_< m1fun_<F>, A >
+
+ : private mlc::assert_< mlc::and_< mlc_is_a(F<A>, abstract::plain_fun_),
+ mlc_is_a(F<A>, abstract::nary_fun_<1>) >,
+ xtd::ERROR::AN_xtd_m1fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_1 >
+
+ {
+ typedef xtd_res(F<A>) ret;
+ };
+
+
+ /*! \class xtd::m1fun_<F>
+ **
+ ** FIXME: doc
+ */
+
+ template <template <typename> class F>
+ struct m1fun_ : public abstract::meta_nary_fun_< 1, m1fun_<F> >
+ {
+ template <typename A>
+ xtd_res(F<A>) impl_calc(const A& a) const
+ // ---------
+ {
+ typedef F<A> F_;
+ mlc::assert_< mlc::and_< mlc_is_a(F_, abstract::plain_fun_),
+ mlc_is_a(F_, abstract::nary_fun_<1>) >,
+ xtd::ERROR::AN_xtd_m1fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_1
+ >::check();
+ static const F_ f_;
+ return f_(a);
+ }
+ };
+
+
+
+
+
+ // equipment for xtd::m2fun_<F>
+
+ template <template <typename, typename> class F>
+ struct m2fun_;
+
+
+ template <template <typename, typename> class F,
+ typename A1, typename A2>
+
+ struct res_< m2fun_<F>, A1, A2 >
+
+ : private mlc::assert_< mlc::and_< mlc_is_a(mlc_comma_1(F<A1,A2>), abstract::plain_fun_),
+ mlc_is_a(mlc_comma_1(F<A1,A2>), abstract::nary_fun_<2>) >,
+ xtd::ERROR::AN_xtd_m2fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_2 >
+ {
+ typedef F<A1,A2> F_;
+ typedef xtd_res(F_) ret;
+ };
+
+
+ /*! \class xtd::m2fun_<F>
+ **
+ ** FIXME: doc
+ */
+
+ template <template <typename, typename> class F>
+ struct m2fun_ : public abstract::meta_nary_fun_< 2, m2fun_<F> >
+ {
+ template <typename A1, typename A2>
+ xtd_res(mlc_comma_1(F<A1,A2>)) impl_calc(const A1& a1, const A2& a2) const
+ // ---------
+ {
+ typedef F<A1,A2> F_;
+ mlc::assert_< mlc::and_< mlc_is_a(F_, abstract::plain_fun_),
+ mlc_is_a(F_, abstract::nary_fun_<2>) >,
+ xtd::ERROR::AN_xtd_m2fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_2 >::check();
+ static const F_ f_;
+ return f_(a1, a2);
+ }
+ };
+
+
+
+
+
+
+ // equipment for xtd::m3fun_<F>
+
+ template <template <typename, typename, typename> class F>
+ struct m3fun_;
+
+
+ template <template <typename, typename, typename> class F,
+ typename A1, typename A2, typename A3>
+
+ struct res_< m3fun_<F>, A1, A2, A3 >
+
+ : private mlc::assert_< mlc::and_< mlc_is_a(mlc_comma_2(F<A1,A2,A3>), abstract::plain_fun_),
+ mlc_is_a(mlc_comma_2(F<A1,A2,A3>), abstract::nary_fun_<3>) >,
+ xtd::ERROR::AN_xtd_m3fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_3 >
+ {
+ typedef F<A1,A2,A3> F_;
+ typedef xtd_res(F_) ret;
+ };
+
+
+ /*! \class xtd::m3fun_<F>
+ **
+ ** FIXME: doc
+ */
+
+ template <template <typename, typename, typename> class F>
+ struct m3fun_ : public abstract::meta_nary_fun_< 3, m3fun_<F> >
+ {
+ template <typename A1, typename A2, typename A3>
+ xtd_res(mlc_comma_2(F<A1,A2,A3>)) impl_calc(const A1& a1, const A2& a2, const A3& a3) const
+ // ---------
+ {
+ typedef F<A1,A2,A3> F_;
+ mlc::assert_< mlc::and_< mlc_is_a(F_, abstract::plain_fun_),
+ mlc_is_a(F_, abstract::nary_fun_<3>) >,
+ xtd::ERROR::AN_xtd_m3fun_SHOULD_TAKE_AS_PARAMETER_AN_xtd_plain_nary_fun_WITH_n_BEING_3 >::check();
+ static const F_ f_;
+ return f_(a1, a2, a3);
+ }
+ };
+
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_MFUN_HH
Index: xtd/traits.hh
--- xtd/traits.hh (revision 0)
+++ xtd/traits.hh (revision 0)
@@ -0,0 +1,55 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_TRAITS_HH
+# define EXTENDED_TRAITS_HH
+
+# include <mlc/flags.hh>
+
+
+# define xtd_plus(L, R) typename xtd::plus_trait_< L, R >::ret
+# define xtd_mult(L, R) typename xtd::mult_trait_< L, R >::ret
+
+
+namespace xtd
+{
+
+ template <typename L, typename R>
+ struct plus_trait_ : public mlc::undefined
+ {
+ };
+
+ template <typename L, typename R>
+ struct mult_trait_ : public mlc::undefined
+ {
+ };
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_TRAITS_HH
Index: xtd/builtin/traits.hh
--- xtd/builtin/traits.hh (revision 0)
+++ xtd/builtin/traits.hh (revision 0)
@@ -0,0 +1,90 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_BUILTIN_TRAITS_HH
+# define EXTENDED_BUILTIN_TRAITS_HH
+
+# include <xtd/traits.hh>
+
+
+namespace xtd
+{
+
+ // FIXME: this is dummy and incomplete code!
+
+
+ // plus
+
+ template <typename T>
+ struct plus_trait_ < T, T >
+ {
+ typedef T ret;
+ };
+
+ template <> struct plus_trait_ < float, int > { typedef float ret; };
+ template <> struct plus_trait_ < int, float > { typedef float ret; };
+ template <> struct plus_trait_ < double, int > { typedef double ret; };
+ template <> struct plus_trait_ < int, double > { typedef double ret; };
+ template <> struct plus_trait_ < double, float > { typedef double ret; };
+ template <> struct plus_trait_ < float, double > { typedef double ret; };
+
+ template <> struct plus_trait_ < long double, int > { typedef long double ret; };
+ template <> struct plus_trait_ < int, long double > { typedef long double ret; };
+ template <> struct plus_trait_ < long double, float > { typedef long double ret; };
+ template <> struct plus_trait_ < float, long double > { typedef long double ret; };
+ template <> struct plus_trait_ < long double, double > { typedef long double ret; };
+ template <> struct plus_trait_ < double, long double > { typedef long double ret; };
+
+
+ // mult
+
+ template <typename T>
+ struct mult_trait_ < T, T >
+ {
+ typedef T ret;
+ };
+
+ template <> struct mult_trait_ < float, int > { typedef float ret; };
+ template <> struct mult_trait_ < int, float > { typedef float ret; };
+ template <> struct mult_trait_ < double, int > { typedef double ret; };
+ template <> struct mult_trait_ < int, double > { typedef double ret; };
+ template <> struct mult_trait_ < double, float > { typedef double ret; };
+ template <> struct mult_trait_ < float, double > { typedef double ret; };
+
+ template <> struct mult_trait_ < long double, int > { typedef long double ret; };
+ template <> struct mult_trait_ < int, long double > { typedef long double ret; };
+ template <> struct mult_trait_ < long double, float > { typedef long double ret; };
+ template <> struct mult_trait_ < float, long double > { typedef long double ret; };
+ template <> struct mult_trait_ < long double, double > { typedef long double ret; };
+ template <> struct mult_trait_ < double, long double > { typedef long double ret; };
+
+
+} // end of namespace xtd
+
+
+
+#endif // ! EXTENDED_BUILTIN_TRAITS_HH
Index: xtd/arg.hh
--- xtd/arg.hh (revision 0)
+++ xtd/arg.hh (revision 0)
@@ -0,0 +1,152 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_ARG_HH
+# define EXTENDED_ARG_HH
+
+# include <mlc/assert.hh>
+# include <mlc/is_a.hh>
+
+# include <xtd/args.hh>
+# include <xtd/mexpr.hh>
+
+
+
+
+# define xtd_nargs(F) xtd::nargs_<F>::ret
+
+
+
+namespace xtd
+{
+
+
+
+ namespace internal
+ {
+
+ // FIXME: doc
+
+ template <unsigned i> struct impl_arg_;
+
+ template <>
+ struct impl_arg_<1>
+ {
+ template <typename Args>
+ typename Args::arg1_type impl_eval(const Args& args) const
+ {
+ mlc::assert_< mlc_is_a(Args, xtd::abstract::args) >::check();
+ return args.arg1;
+ }
+ };
+
+ template <>
+ struct impl_arg_<2>
+ {
+ template <typename Args>
+ typename Args::arg2_type impl_eval(const Args& args) const
+ {
+ mlc::assert_< mlc_is_a(Args, xtd::abstract::args) >::check();
+ return args.arg2;
+ }
+ };
+
+ template <>
+ struct impl_arg_<3>
+ {
+ template <typename Args>
+ typename Args::arg3_type impl_eval(const Args& args) const
+ {
+ mlc::assert_< mlc_is_a(Args, xtd::abstract::args) >::check();
+ return args.arg3;
+ }
+ };
+
+ } // end of namespace xtd::internal
+
+
+
+
+ /*! \class xtd::arg_<i>
+ **
+ ** FIXME: placeholder for the ith argument
+ */
+
+
+ template <unsigned i> struct arg_;
+
+ template <unsigned i>
+ struct nargs_< arg_<i> >
+ {
+ static const unsigned ret = i;
+ };
+
+
+ template <typename Args>
+ struct expr_res_< arg_<1>, Args >
+ {
+ typedef typename Args::arg1_type ret;
+ };
+
+ template <typename Args>
+ struct expr_res_< arg_<2>, Args >
+ {
+ typedef typename Args::arg2_type ret;
+ };
+
+ template <typename Args>
+ struct expr_res_< arg_<3>, Args >
+ {
+ typedef typename Args::arg3_type ret;
+ };
+
+
+ template <unsigned i>
+ struct arg_
+
+ : public abstract::nary_fun_expr_< i, arg_<i> >,
+
+ public internal::impl_arg_<i>
+
+ // FIXME: add something like ": private mlc::assert_< (i > 1 and i <= 3) >"
+ {
+ typedef internal::impl_arg_<i> super;
+ using super::impl_eval;
+ };
+
+
+ // placeholders:
+
+ const arg_<1> _1 = arg_<1>();
+ const arg_<2> _2 = arg_<2>();
+ const arg_<3> _3 = arg_<3>();
+
+
+} // end of namespace xtd
+
+
+#endif // ! EXTENDED_ARG_HH
Index: xtd/case.hh
--- xtd/case.hh (revision 0)
+++ xtd/case.hh (revision 0)
@@ -0,0 +1,37 @@
+// Copyright (C) 2002, 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef EXTENDED_CASE_HH
+# define EXTENDED_CASE_HH
+
+# include <mlc/case.hh>
+
+
+mlc_case_equipment_for_namespace(xtd);
+
+
+#endif // ! EXTENDED_CASE_HH
Index: tests/id.cc
--- tests/id.cc (revision 0)
+++ tests/id.cc (revision 0)
@@ -0,0 +1,43 @@
+#include <iostream>
+
+
+#include <xtd/math/id.hh>
+
+
+
+// namespace xtd
+// {
+// struct xfail;
+
+// template <>
+// struct fun_traits_< xfail >
+// {
+// typedef int res_type;
+// };
+// struct xfail : public xtd::abstract::plain_fun_< xfail >
+// {
+// };
+
+// }
+
+
+
+int main()
+{
+
+// {
+// xtd::xfail test;
+// }
+
+
+ {
+ xtd::plain_id_<int> id_int;
+ std::cout << id_int(51) << std::endl;
+
+ xtd::plain_id_<float> id_float;
+ std::cout << id_float(5.1f) << std::endl;
+
+ }
+
+
+}
Index: tests/cos.cc
--- tests/cos.cc (revision 0)
+++ tests/cos.cc (revision 0)
@@ -0,0 +1,52 @@
+#include <iostream>
+
+#include <xtd/math.hh>
+
+
+int main()
+{
+
+// {
+// using xtd::cos;
+// std::cout << cos(5.1f) << std::endl;
+// }
+
+// {
+// using xtd::cos;
+// using xtd::sin;
+// using xtd::_1;
+// using xtd::_2;
+
+// std::cout << cos(_1)(5.1f) << std::endl;
+// std::cout << (cos(_1) + sin(_2))(5.f, 1.f) << std::endl;
+// std::cout << (cos(_1) + sin(_2)).nargs() << std::endl;
+// }
+
+// {
+// using xtd::cos;
+// using xtd::_1;
+// using xtd::_2;
+// std::cout << (cos(_1)(_2)).nargs() << std::endl; // gives: 2
+// }
+
+ {
+ using xtd::cos;
+ using xtd::sin;
+ using xtd::_1;
+ using xtd::_2;
+
+// std::cout << (cos(_1) * cos(_1) + sin(_2) * sin(_2))(5.f, 5.f) << std::endl;
+
+// std::cout << (_1)(_1)(51.f) << std::endl;
+// std::cout << (_1 + _1)(51.f) << std::endl;
+// std::cout << (_1 + _2)(5.f, 1.f) << std::endl;
+
+// (cos(_1) + sin(_1))(_1);
+// std::cout << (cos(_1) * cos(_1) + sin(_1) * sin(_1))(_1)(51.f) << std::endl;
+
+ std::cout << (_1 * _1 + _2 * _2)(cos(_1), sin(_1))(51.f) << std::endl;
+
+// std::cout << ((cos(_1) + sin(_2))(_1, _1)).nargs() << std::endl;
+ }
+
+}
Index: tests/Makefile.am
--- tests/Makefile.am (revision 433)
+++ tests/Makefile.am (working copy)
@@ -1,8 +1,19 @@
## Process this file through Automake to create Makefile.in -*- Makefile -*-
-AM_CPPFLAGS = -I$(top_srcdir)/extended -I$(top_srcdir)/metalic
+AM_CPPFLAGS = -I$(top_srcdir)/extended
# FIXME: Add
#
# AM_CXXFLAGS = $(CXXFLAGS_STRICT) $(CXXFLAGS_OPTIMIZE) -ggdb
#
# when oln.m4 is available in the distribution.
+
+check_PROGRAMS = \
+ id \
+ cast \
+ cos
+
+id_SOURCES = id.cc
+cast_SOURCES = cast.cc
+cos_SOURCES = cos.cc
+
+TESTS = $(check_PROGRAMS)
Index: tests/cast.cc
--- tests/cast.cc (revision 0)
+++ tests/cast.cc (revision 0)
@@ -0,0 +1,37 @@
+#include <iostream>
+#include <xtd/cast.hh>
+#include <xtd/arg.hh>
+#include <xtd/math/trigo.hh>
+
+
+int main()
+{
+
+ {
+ xtd::plain_cast_<int, float> fun;
+ std::cout << fun(3.14) << std::endl;
+ }
+
+ {
+ xtd::meta_cast_<int> fun;
+ std::cout << fun(3.14) << std::endl;
+ }
+
+ {
+ using xtd::cast_;
+ using xtd::cos;
+ using xtd::_1;
+ std::cout << (cast_<int>(cos(_1)))(3.14) << std::endl;
+ std::cout << cos(cast_<float>(_1))(3) << std::endl;
+ }
+
+// {
+// xtd::cos_<int> c;
+// }
+
+// {
+// using xtd::cos;
+// cos(1);
+// }
+
+}
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
Disambiguate Boolean value types and Boolean expression types.
* tests/ret.cc: Update.
* mlc/ret.hh: Fix missing include.
The Boolean value classes are re-written and internal::value_ is
removed; this class was too ambiguous since precise types, e.g.,
int_<i>, are provided and it was weirdly located in the value class
hierarchy.
* mlc/bool.hh (bool_<true>, bool_<false>): Merge those
specializations into the single and once for all written class
bool_<b>.
(bool_<true>::is_true): Remove since this mark is now factored
in the base class bexpr_is_<b>.
(bool_<b>): Add inheritance so that a Boolean value can be
considered as a Boolean expression type.
(internal::value_<bool, b>): Remove this specialization since
the class internal::value_ is also removed.
(logic.hh): Remove inclusion.
(mlc_bool): Move to...
The Boolean expression types are now handled by special classes.
Yet mlc::true_ and mlc::false_ remain expression types in addition
of value types.
* mlc/bexpr.hh: ...this file. This macro only applies on Boolean
expression types.
(bexpr_): Remove this obsolete wrapper.
(bexpr_is_<b>): New base class with its couple of specializations
which act as a replacement for bool_<b> for expression types.
(internal::bool_of_): Replace the meta-code for mlc_bool.
Those changes induce a lot of updates described below.
* mlc/pair.hh: Update includes.
* mlc/logic.hh: Update. Instead of deriving from bool_<b>
Boolean expression types now derive from bexpr_is_<b>.
(and_list_, or_list_): Comment to postpone updating while keeping
code compile.
* mlc/implies.hh: Update inheritance.
* mlc/if.hh: Update includes and add assertion.
* mlc/assert.hh: Update includes.
* mlc/valist.hh: Likewise.
* mlc/wrap.hh: Remove obsolete code.
* mlc/is_a.hh: Update inheritance.
(bexpr_): Replace by wrap_.
* mlc/case.hh: Update. Now use mlc_bool instead of ::value.
* mlc/cmp.hh: Update inheritance.
(eq_::ensure): Remove this obsolete feature.
* mlc/value.hh: Move sub-classes of value to...
* mlc/int.hh, mlc/char.hh: ...these new files.
* mlc/values.hh: New file that includes the whole value types material.
mlc/assert.hh | 7
mlc/bexpr.hh | 139 ++++++++++++++++++-
mlc/bool.hh | 168 ++---------------------
mlc/case.hh | 33 ++--
mlc/char.hh | 51 +++++++
mlc/cmp.hh | 20 +-
mlc/if.hh | 9 -
mlc/implies.hh | 6
mlc/int.hh | 88 ++++++++++++
mlc/is_a.hh | 13 -
mlc/logic.hh | 403 ++++++++++++++++++++++++++++-----------------------------
mlc/pair.hh | 3
mlc/ret.hh | 1
mlc/valist.hh | 2
mlc/value.hh | 133 ++----------------
mlc/values.hh | 49 ++++++
mlc/wrap.hh | 55 -------
tests/ret.cc | 4
18 files changed, 610 insertions(+), 574 deletions(-)
Index: tests/ret.cc
--- tests/ret.cc (revision 428)
+++ tests/ret.cc (working copy)
@@ -12,6 +12,6 @@
int main()
{
- std::cout << mlc::ret_found_in_<yes>::value << std::endl;
- std::cout << mlc::ret_found_in_<no>::value << std::endl;
+ std::cout << mlc_bool( mlc::ret_found_in_<yes> ) << std::endl;
+ std::cout << mlc_bool( mlc::ret_found_in_<no> ) << std::endl;
}
Index: mlc/ret.hh
--- mlc/ret.hh (revision 428)
+++ mlc/ret.hh (working copy)
@@ -29,6 +29,7 @@
# define METALIC_RET_HH
# include <mlc/typedef.hh>
+# include <mlc/cmp.hh>
Index: mlc/int.hh
--- mlc/int.hh (revision 0)
+++ mlc/int.hh (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef METALIC_INT_HH
+# define METALIC_INT_HH
+
+# include <mlc/value.hh>
+
+
+
+/// Internal macros.
+
+# define mlc_internal_decl_unsigned_integer(Type, TypeName) \
+template <Type val> \
+struct TypeName : public abstract::unsigned_integer \
+{ \
+ typedef Type type; \
+ static const Type value = val; \
+}
+
+
+# define mlc_internal_decl_signed_integer(Type, TypeName) \
+template <Type val> \
+struct TypeName : public abstract::signed_integer \
+{ \
+ typedef Type type; \
+ static const Type value = val; \
+}
+
+
+
+namespace mlc {
+
+
+ namespace abstract {
+
+ /// Abstractions for integer values as types.
+
+ struct integer : public value {};
+ struct unsigned_integer : public integer {};
+ struct signed_integer : public integer {};
+
+ } // end of namespace mlc::abstract
+
+
+
+ // Dedicated sub-classes for builtin types.
+
+ mlc_internal_decl_unsigned_integer( unsigned char, uchar_ );
+ mlc_internal_decl_unsigned_integer( unsigned short, ushort_ );
+ mlc_internal_decl_unsigned_integer( unsigned int, uint_ );
+ mlc_internal_decl_unsigned_integer( unsigned long, ulong_ );
+
+ mlc_internal_decl_signed_integer( signed char, schar_ );
+ mlc_internal_decl_signed_integer( signed short, short_ );
+ mlc_internal_decl_signed_integer( signed int, int_ );
+ mlc_internal_decl_signed_integer( signed long, long_ );
+
+
+} // end of namespace mlc
+
+
+
+#endif // ! METALIC_INT_HH
Index: mlc/bool.hh
--- mlc/bool.hh (revision 428)
+++ mlc/bool.hh (working copy)
@@ -29,17 +29,7 @@
# define METALIC_BOOL_HH
# include <mlc/value.hh>
-# include <mlc/flags.hh>
-
-
-/*! \def mlc_bool(Bexpr)
-**
-** Macro that retrieves a Boolean value from a Boolean expression type.
-** Its result is either true or false.
-*/
-# define mlc_bool(Bexpr) mlc::internal::get_bool<Bexpr>::value
-
-
+# include <mlc/bexpr.hh>
namespace mlc
@@ -49,12 +39,10 @@
/*! \class mlc::abstract::boolean
**
- ** Abstract base class for Booleans represented as types. This
- ** class has two important sub-classes: mlc::true_ and
- ** mlc::false_.
- **
- ** Any mlc Boolean expression type derives from either mlc::true_
- ** or mlc::false_ so derives from mlc::abstract::boolean.
+ ** Abstract base class for Boolean values represented as types.
+ ** This class has exactly one sub-class: mlc::bool_<b> where b is
+ ** either true or false. Thanks to aliases, mlc::bool_<true> and
+ ** mlc::bool_<false> are respectively mlc::true_ and mlc::false_.
*/
struct boolean : public value {};
@@ -62,40 +50,16 @@
} // end of mlc::abstract
- // fwd decl
- template <bool> struct bool_;
-
-
- namespace internal
- {
-
- /*! \class mlc::get_bool<T>
- **
- ** Internal class so do not use it. This class gives access to a
- ** Boolean value from a Boolean expression type; it is used in the
- ** mlc_bool(T) macro.
- **
- ** \see mlc_bool(T)
- */
- template <typename T>
- struct get_bool
- {
- static const bool value = T::bool_value_;
- };
-
- /*! \class mlc::value_<bool, b>
- **
- ** Specialization of value_<T, val> for the Boolean case.
+ /*! \class mlc::bool_<b>
**
- ** Design notes: 1) This specialization is defined so that mlc
- ** Booleans derive from mlc::abstract::boolean. 2) This
- ** specialization conforms to the interface of the generic version
- ** of mlc::internal::value_.
+ ** Value type corresponding to bool.
*/
template <bool b>
- struct value_ <bool, b> : public abstract::boolean
+ struct bool_ : public bexpr_is_<b>,
+ public abstract::boolean
+
{
/*! \typedef type
**
@@ -112,129 +76,29 @@
** This member is provided for any mlc value class such as
** mlc::int_<51> and mlc::char_<'c'>. However, to access the
** regular value of a type T that you know to be a mlc Boolean
- ** expression, you should prefer to use the macro mlc_bool(T).
- ** This macro also ensures that T really is an expression.
+ ** expression, you should prefer to use the macro mlc_value(T).
+ ** This macro also ensures that T is a mlc value type.
**
*/
static const bool value = b;
-
- /*! \typedef eval
- **
- ** Returns mlc::true_ or mlc::false_.
- **
- ** Since Boolean expression types derive from either mlc::true_
- ** or mlc::false_, these expression types are never exactly
- ** mlc::true_ nor mlc::false_. This typedef thus allows for the
- ** expression evaluation.
- **
- ** Please note that, however, we usually do not need expression
- ** evaluation. The most common use of a Boolean expression is
- ** to check that it is verified (true) and, for that, we provide
- ** "assert_<bexpr, errmsg>::check()". For instance:
- ** assert_< or_<mlc_is_a(T, int), mlc_is_a(T, unsigned)> >::check();
- ** ensures that T is int or unsigned without using ::eval.
- **
- ** \see mlc::true_, mlc::false_, mlc::assert_<bexpr, errmsg>.
- */
- typedef bool_<b> eval;
-
- private:
-
- /*! \member bool_value_
- **
- ** This member is redundant with the member 'value'. It is used
- ** by the mlc_bool(T) macro to ensure that T actually derives
- ** from mlc::true_ or mlc::false_.
- */
- static const bool bool_value_ = b;
-
- template <typename T> friend class get_bool;
};
- } // end of namespace mlc::internal
-
-
-
- /*! \class mlc::bool_<true>
- **
- ** Specialization of mlc::bool_<b> for b set to true. This type
- ** is also known as mlc::true_. Every Boolean expression types
- ** derive either from this type or from mlc::false_.
- **
- ** Design notes: 1) This specialization is defined so that mlc
- ** Booleans derive from mlc::abstract::boolean. 2) This
- ** specialization conforms to the interface of the generic version
- ** of mlc::internal::value_.
+ /*! \def mlc::true_
**
- ** \see mlc::bool_<false>
+ ** This is an alias (typedef) for mlc::bool_<true>.
*/
-
- template <>
- struct bool_<true> : public internal::value_<bool, true>
- {
-
- // FIXME: doc
- using internal::value_<bool, true>::value;
- using internal::value_<bool, true>::eval;
-
- /*! \typedef is_true
- **
- ** You should not use this typedef.
- **
- ** This typedef is inherited in every Boolean expression types
- ** that derive from mlc::true_. This typedef is not provided in
- ** mlc::false_. The type returned by this typedef has no meaning
- ** (and thus no significant value). Static checks via
- ** "mlc::assert_<bexpr, err>" rely on the presence or absence of
- ** this typedef.
- **
- ** \see mlc::assert_<bexpr, err>
- */
- typedef dummy is_true;
-
- };
-
typedef bool_<true> true_;
- /*! \class mlc::bool_<false>
- **
- ** Specialization of mlc::bool_<b> for b set to false. This type
- ** is also known as mlc::false_. Every Boolean expression types
- ** derive either from this type or from mlc::true_.
- **
- ** Conversely to mlc::true_, this class does not feature the typedef
- ** "is_true". So, when a Boolean expression type, say Expr, is
- ** evaluated to false, the static checks via "assert_<Expr>"
- ** do not compile.
- **
- ** Design notes: 1) This specialization is defined so that mlc
- ** Booleans derive from mlc::abstract::boolean. 2) This
- ** specialization conforms to the interface of the generic version
- ** of mlc::internal::value_.
+ /*! \def mlc::false_
**
- ** \see mlc::bool_<true>, mlc::assert_<bexpr, errmsg>
+ ** This is an alias (typedef) for mlc::bool_<false>.
*/
-
- template <>
- struct bool_<false> : public internal::value_<bool, false>
- {
- // FIXME: doc
- private:
- typedef internal::value_<bool, false> super_type;
- public:
- using super_type::value;
- using super_type::eval;
- };
-
typedef bool_<false> false_;
} // end of namespace mlc
-# include <mlc/logic.hh>
-
-
#endif // ! METALIC_BOOL_HH
Index: mlc/pair.hh
--- mlc/pair.hh (revision 428)
+++ mlc/pair.hh (working copy)
@@ -28,7 +28,8 @@
#ifndef METALIC_PAIR_HH
# define METALIC_PAIR_HH
-# include <mlc/bool.hh>
+# include <mlc/assert.hh>
+# include <mlc/logic.hh>
# include <mlc/uint.hh>
Index: mlc/logic.hh
--- mlc/logic.hh (revision 428)
+++ mlc/logic.hh (working copy)
@@ -28,9 +28,8 @@
#ifndef METALIC_LOGIC_HH
# define METALIC_LOGIC_HH
-# include <mlc/bool.hh>
+# include <mlc/bexpr.hh>
# include <mlc/assert.hh>
-# include <mlc/flags.hh>
@@ -44,7 +43,7 @@
*/
template <typename T>
struct not_
- : public bool_<( !mlc_bool(T) )>
+ : public bexpr_is_<( !mlc_bool(T) )>
{};
@@ -57,7 +56,7 @@
*/
template <typename L, typename R>
struct and_
- : public bool_<( mlc_bool(L) && mlc_bool(R) )>
+ : public bexpr_is_<( mlc_bool(L) && mlc_bool(R) )>
{};
@@ -70,7 +69,7 @@
*/
template <typename L, typename R>
struct nand_
- : public bool_<( !(mlc_bool(L) && mlc_bool(R)) )>
+ : public bexpr_is_<( !(mlc_bool(L) && mlc_bool(R)) )>
{};
@@ -83,7 +82,7 @@
*/
template <typename L, typename R>
struct or_
- : public bool_<( mlc_bool(L) || mlc_bool(R) )>
+ : public bexpr_is_<( mlc_bool(L) || mlc_bool(R) )>
{};
@@ -96,7 +95,7 @@
*/
template <typename L, typename R>
struct nor_
- : public bool_<( !(mlc_bool(L) || mlc_bool(R)) )>
+ : public bexpr_is_<( !(mlc_bool(L) || mlc_bool(R)) )>
{};
@@ -107,7 +106,7 @@
*/
template <typename L, typename R>
struct xor_
- : public bool_<( mlc_bool(L) != mlc_bool(R) )>
+ : public bexpr_is_<( mlc_bool(L) != mlc_bool(R) )>
{};
@@ -118,204 +117,204 @@
*/
template <typename L, typename R>
struct xnor_
- : public bool_<( !(mlc_bool(L) != mlc_bool(R)) )>
+ : public bexpr_is_<( !(mlc_bool(L) != mlc_bool(R)) )>
{};
- /// Internal helpers for logical operators between several Boolean types
+// /// Internal helpers for logical operators between several Boolean types
- namespace internal
- {
- // FIXME: doc
-
- template <typename A>
- struct is_bexpr_or_none_ : public true_ // FIXME: pb using mlc_is_a because of circular deps
- {
- };
-
-
- // va_eval_
-
- template <typename A>
- struct va_eval_
- {
- typedef typename A::eval ret;
- };
-
- template <>
- struct va_eval_ <none>
- {
- typedef none ret;
- };
-
-
- // or_list_2_
-
- template <typename A1, typename A2>
- struct or_list_2_
- : public or_<A1, A2>::eval
- {};
-
- template <>
- struct or_list_2_ <none, none>
- : public true_
- {};
-
- template <typename A1>
- struct or_list_2_ <A1, none>
- : public A1
- {};
-
- template <typename A2>
- struct or_list_2_ <none, A2>; // forbidden
-
- // or_list_4_
-
- template <typename A1, typename A2, typename A3, typename A4>
- struct or_list_4_
- : public or_list_2_< typename or_list_2_<A1, A2>::eval,
- typename or_list_2_<A3, A4>::eval >::eval
- {};
-
- template <>
- struct or_list_4_ <none, none, none, none>
- : public true_
- {};
-
- // or_list_
-
- template <typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7, typename A8>
- struct or_list_
- : public or_list_2_< typename or_list_4_<A1, A2, A3, A4>::eval,
- typename or_list_4_<A5, A6, A7, A8>::eval >::eval
- {};
-
-
- // and_list_2_
-
- template <typename A1, typename A2>
- struct and_list_2_
- : public and_<A1, A2>::eval
- {};
-
- template <>
- struct and_list_2_ <none, none>
- : public true_
- {};
-
- template <typename A1>
- struct and_list_2_ <A1, none>
- : public A1
- {};
-
- template <typename A2>
- struct and_list_2_ <none, A2>; // forbidden
-
- // and_list_4_
-
- template <typename A1, typename A2, typename A3, typename A4>
- struct and_list_4_
- : public and_list_2_< typename and_list_2_<A1, A2>::eval,
- typename and_list_2_<A3, A4>::eval >::eval
- {};
-
- template <>
- struct and_list_4_ <none, none, none, none>
- : public true_
- {};
-
- // and_list_
-
- template <typename A1, typename A2, typename A3, typename A4,
- typename A5, typename A6, typename A7, typename A8>
- struct and_list_
- : public and_list_2_< typename and_list_4_<A1, A2, A3, A4>::eval,
- typename and_list_4_<A5, A6, A7, A8>::eval >::eval
- {};
-
- } // end of mlc::internal
-
-
-
- /*! \class mlc::or_list_<..>
- **
- ** Logical n-ary 'or' operator on a set of Boolean expression types.
- ** The number of arguments (parameters) should be at least 3 and at
- ** most 8. This class is also a Boolean expression type.
- **
- ** Sample use:
- ** mlc::or_list_< mlc::eq_<T, int>,
- ** mlc_is_a(T, mlc::int_),
- ** mlc_is_a(T, my::integer) >
- **
- ** \see mlc::or_<L,R> mlc::and_list_<..>
- */
-
- template <typename A1,
- typename A2,
- typename A3,
- typename A4 = none,
- typename A5 = none,
- typename A6 = none,
- typename A7 = none,
- typename A8 = none>
- struct or_list_ : private multiple_assert_< internal::is_bexpr_or_none_<A1>,
- internal::is_bexpr_or_none_<A2>,
- internal::is_bexpr_or_none_<A3>,
- internal::is_bexpr_or_none_<A4>,
- internal::is_bexpr_or_none_<A5>,
- internal::is_bexpr_or_none_<A6>,
- internal::is_bexpr_or_none_<A7>,
- internal::is_bexpr_or_none_<A8> >,
- public internal::or_list_< typename internal::va_eval_<A1>::ret,
- typename internal::va_eval_<A2>::ret,
- typename internal::va_eval_<A3>::ret,
- typename internal::va_eval_<A4>::ret,
- typename internal::va_eval_<A5>::ret,
- typename internal::va_eval_<A6>::ret,
- typename internal::va_eval_<A7>::ret,
- typename internal::va_eval_<A8>::ret >
- {
- };
-
-
-
- /*! \class mlc::and_list_<..>
- **
- ** Logical n-ary 'and' operator on a set of Boolean expression types.
- ** The number of arguments (parameters) should be at least 3 and at
- ** most 8. This class is also a Boolean expression type.
- **
- ** \see mlc::and_<L,R> mlc::or_list_<..>
- */
-
- template <typename A1,
- typename A2,
- typename A3,
- typename A4 = none,
- typename A5 = none,
- typename A6 = none,
- typename A7 = none,
- typename A8 = none>
- struct and_list_ : private multiple_assert_< internal::is_bexpr_or_none_<A1>,
- internal::is_bexpr_or_none_<A2>,
- internal::is_bexpr_or_none_<A3>,
- internal::is_bexpr_or_none_<A4>,
- internal::is_bexpr_or_none_<A5>,
- internal::is_bexpr_or_none_<A6>,
- internal::is_bexpr_or_none_<A7>,
- internal::is_bexpr_or_none_<A8> >,
- public internal::and_list_< typename internal::va_eval_<A1>::ret,
- typename internal::va_eval_<A2>::ret,
- typename internal::va_eval_<A3>::ret,
- typename internal::va_eval_<A4>::ret,
- typename internal::va_eval_<A5>::ret,
- typename internal::va_eval_<A6>::ret,
- typename internal::va_eval_<A7>::ret,
- typename internal::va_eval_<A8>::ret >
- {
- };
+// namespace internal
+// {
+// // FIXME: doc
+
+// template <typename A>
+// struct is_bexpr_or_none_ : public true_ // FIXME: pb using mlc_is_a because of circular deps
+// {
+// };
+
+
+// // va_eval_
+
+// template <typename A>
+// struct va_eval_
+// {
+// typedef typename A::eval ret;
+// };
+
+// template <>
+// struct va_eval_ <none>
+// {
+// typedef none ret;
+// };
+
+
+// // or_list_2_
+
+// template <typename A1, typename A2>
+// struct or_list_2_
+// : public or_<A1, A2>::eval
+// {};
+
+// template <>
+// struct or_list_2_ <none, none>
+// : public true_
+// {};
+
+// template <typename A1>
+// struct or_list_2_ <A1, none>
+// : public A1
+// {};
+
+// template <typename A2>
+// struct or_list_2_ <none, A2>; // forbidden
+
+// // or_list_4_
+
+// template <typename A1, typename A2, typename A3, typename A4>
+// struct or_list_4_
+// : public or_list_2_< typename or_list_2_<A1, A2>::eval,
+// typename or_list_2_<A3, A4>::eval >::eval
+// {};
+
+// template <>
+// struct or_list_4_ <none, none, none, none>
+// : public true_
+// {};
+
+// // or_list_
+
+// template <typename A1, typename A2, typename A3, typename A4,
+// typename A5, typename A6, typename A7, typename A8>
+// struct or_list_
+// : public or_list_2_< typename or_list_4_<A1, A2, A3, A4>::eval,
+// typename or_list_4_<A5, A6, A7, A8>::eval >::eval
+// {};
+
+
+// // and_list_2_
+
+// template <typename A1, typename A2>
+// struct and_list_2_
+// : public and_<A1, A2>::eval
+// {};
+
+// template <>
+// struct and_list_2_ <none, none>
+// : public true_
+// {};
+
+// template <typename A1>
+// struct and_list_2_ <A1, none>
+// : public A1
+// {};
+
+// template <typename A2>
+// struct and_list_2_ <none, A2>; // forbidden
+
+// // and_list_4_
+
+// template <typename A1, typename A2, typename A3, typename A4>
+// struct and_list_4_
+// : public and_list_2_< typename and_list_2_<A1, A2>::eval,
+// typename and_list_2_<A3, A4>::eval >::eval
+// {};
+
+// template <>
+// struct and_list_4_ <none, none, none, none>
+// : public true_
+// {};
+
+// // and_list_
+
+// template <typename A1, typename A2, typename A3, typename A4,
+// typename A5, typename A6, typename A7, typename A8>
+// struct and_list_
+// : public and_list_2_< typename and_list_4_<A1, A2, A3, A4>::eval,
+// typename and_list_4_<A5, A6, A7, A8>::eval >::eval
+// {};
+
+// } // end of mlc::internal
+
+
+
+// /*! \class mlc::or_list_<..>
+// **
+// ** Logical n-ary 'or' operator on a set of Boolean expression types.
+// ** The number of arguments (parameters) should be at least 3 and at
+// ** most 8. This class is also a Boolean expression type.
+// **
+// ** Sample use:
+// ** mlc::or_list_< mlc::eq_<T, int>,
+// ** mlc_is_a(T, mlc::int_),
+// ** mlc_is_a(T, my::integer) >
+// **
+// ** \see mlc::or_<L,R> mlc::and_list_<..>
+// */
+
+// template <typename A1,
+// typename A2,
+// typename A3,
+// typename A4 = none,
+// typename A5 = none,
+// typename A6 = none,
+// typename A7 = none,
+// typename A8 = none>
+// struct or_list_ : private multiple_assert_< internal::is_bexpr_or_none_<A1>,
+// internal::is_bexpr_or_none_<A2>,
+// internal::is_bexpr_or_none_<A3>,
+// internal::is_bexpr_or_none_<A4>,
+// internal::is_bexpr_or_none_<A5>,
+// internal::is_bexpr_or_none_<A6>,
+// internal::is_bexpr_or_none_<A7>,
+// internal::is_bexpr_or_none_<A8> >,
+// public internal::or_list_< typename internal::va_eval_<A1>::ret,
+// typename internal::va_eval_<A2>::ret,
+// typename internal::va_eval_<A3>::ret,
+// typename internal::va_eval_<A4>::ret,
+// typename internal::va_eval_<A5>::ret,
+// typename internal::va_eval_<A6>::ret,
+// typename internal::va_eval_<A7>::ret,
+// typename internal::va_eval_<A8>::ret >
+// {
+// };
+
+
+
+// /*! \class mlc::and_list_<..>
+// **
+// ** Logical n-ary 'and' operator on a set of Boolean expression types.
+// ** The number of arguments (parameters) should be at least 3 and at
+// ** most 8. This class is also a Boolean expression type.
+// **
+// ** \see mlc::and_<L,R> mlc::or_list_<..>
+// */
+
+// template <typename A1,
+// typename A2,
+// typename A3,
+// typename A4 = none,
+// typename A5 = none,
+// typename A6 = none,
+// typename A7 = none,
+// typename A8 = none>
+// struct and_list_ : private multiple_assert_< internal::is_bexpr_or_none_<A1>,
+// internal::is_bexpr_or_none_<A2>,
+// internal::is_bexpr_or_none_<A3>,
+// internal::is_bexpr_or_none_<A4>,
+// internal::is_bexpr_or_none_<A5>,
+// internal::is_bexpr_or_none_<A6>,
+// internal::is_bexpr_or_none_<A7>,
+// internal::is_bexpr_or_none_<A8> >,
+// public internal::and_list_< typename internal::va_eval_<A1>::ret,
+// typename internal::va_eval_<A2>::ret,
+// typename internal::va_eval_<A3>::ret,
+// typename internal::va_eval_<A4>::ret,
+// typename internal::va_eval_<A5>::ret,
+// typename internal::va_eval_<A6>::ret,
+// typename internal::va_eval_<A7>::ret,
+// typename internal::va_eval_<A8>::ret >
+// {
+// };
} // end of namespace mlc
Index: mlc/if.hh
--- mlc/if.hh (revision 428)
+++ mlc/if.hh (working copy)
@@ -28,7 +28,9 @@
#ifndef METALIC_IF_HH
# define METALIC_IF_HH
-# include <mlc/bool.hh>
+# include <mlc/bexpr.hh>
+# include <mlc/assert.hh>
+# include <mlc/is_a.hh>
/** \def mlc_if(Cond, Then, Else)
@@ -85,7 +87,10 @@
** evaluated, whatever the result of \a Cond.
*/
template <typename cond_type, typename then_type, typename else_type>
- struct if_ : public internal::if_ < mlc_bool(cond_type), then_type, else_type >
+ struct if_ :
+ // FIXME: enable the static assertion below!!!
+ private assert_< mlc_is_a(cond_type, mlc::abstract::bexpr) >,
+ public internal::if_ < mlc_bool(cond_type), then_type, else_type >
{
};
Index: mlc/values.hh
--- mlc/values.hh (revision 0)
+++ mlc/values.hh (revision 0)
@@ -0,0 +1,49 @@
+// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef METALIC_VALUES_HH
+# define METALIC_VALUES_HH
+
+
+
+/*!
+**
+** This file is provided to group all value types.
+*/
+
+# include <mlc/value.hh>
+# include <mlc/bool.hh>
+# include <mlc/char.hh>
+# include <mlc/int.hh>
+# include <mlc/uint.hh>
+
+
+// ...
+
+
+
+#endif // ! METALIC_VALUES_HH
Index: mlc/assert.hh
--- mlc/assert.hh (revision 428)
+++ mlc/assert.hh (working copy)
@@ -28,8 +28,6 @@
#ifndef METALIC_ASSERT_HH
# define METALIC_ASSERT_HH
-# include <mlc/bool.hh>
-
namespace mlc
@@ -228,7 +226,4 @@
} // end of namespace mlc
-# include <mlc/logic.hh>
-
-
-#endif // ! METALIC_BOOL_HH
+#endif // ! METALIC_ASSERT_HH
Index: mlc/valist.hh
--- mlc/valist.hh (revision 428)
+++ mlc/valist.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef METALIC_VALIST_HH
# define METALIC_VALIST_HH
-# include <mlc/bool.hh>
+# include <mlc/assert.hh>
# include <mlc/cmp.hh>
# include <mlc/uint.hh>
Index: mlc/implies.hh
--- mlc/implies.hh (revision 428)
+++ mlc/implies.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef METALIC_IMPLIES_HH
# define METALIC_IMPLIES_HH
-# include <mlc/bool.hh>
+# include <mlc/bexpr.hh>
/*! \def mlc_implies(Left_BExpr, Right_BExpr)
@@ -40,7 +40,7 @@
*/
# define mlc_implies(Left_BExpr, Right_BExpr) \
- typename mlc::implies_<Left_BExpr, Right_BExpr>::ret
+ mlc::bexpr_< typename mlc::implies_<Left_BExpr, Right_BExpr>::ret >
# define mlc_implies_(Left_BExpr, Right_BExpr) \
mlc::implies_<Left_BExpr, Right_BExpr>::ret
@@ -61,7 +61,7 @@
template <typename L, typename R>
struct implies_
- : public bool_<( !mlc_bool(L) || mlc_bool(R) )>
+ : public mlc::bexpr_is_<( !mlc_bool(L) || mlc_bool(R) )>
{};
} // end of namespace mlc
Index: mlc/wrap.hh
--- mlc/wrap.hh (revision 428)
+++ mlc/wrap.hh (working copy)
@@ -28,23 +28,10 @@
#ifndef METALIC_WRAP_HH
# define METALIC_WRAP_HH
-# include <mlc/is_a.hh>
-
namespace mlc
{
- /// Forward declarations of types used in specific version of wrap_.
- /// \{
- namespace abstract
- {
- struct value;
- struct boolean;
- }
- /// \}
-
-
-
/*! \class mlc::wrap_<T>
**
** This class is a workaround to the problem of implicit typename
@@ -69,48 +56,6 @@
template <class T>
struct wrap_ : public T
{
- // FIXME: there's no use to unwrap so disabled(?)
- // typedef T unwrap;
- };
-
-
-
- /*! \class mlc::value_wrap_<T>
- **
- ** This class acts like mlc::wrap_<T> but is dedicated to
- ** value types. The parameter \a T should be a value type.
- **
- ** \see mlc::wrap_<T>
- */
-
- template <class T>
- struct value_wrap_ : private assert_< mlc_is_a(T, mlc::abstract::value) >,
- public T
- {
- typedef typename T::type type;
- static const T value = T::value;
- };
-
-
-
- /*! \class mlc::boolean_wrap_<T>
- **
- ** This class acts like mlc::wrap_<T> but is dedicated to Boolean.
- ** The parameter \a T should be a Boolean expression type. FIXME:
- ** there is a confusion between the Boolean value type and Boolean
- ** expression types!!!
- **
- ** \see mlc::wrap_<T>
- */
-
- template <class T>
- struct boolean_wrap_ : private assert_< mlc_is_a(T, mlc::abstract::boolean) >,
- public T
- {
- typedef typename T::type type;
- static const T value = T::value;
-
- typedef typename T::eval eval;
};
Index: mlc/is_a.hh
--- mlc/is_a.hh (revision 428)
+++ mlc/is_a.hh (working copy)
@@ -30,6 +30,7 @@
# include <mlc/bool.hh>
# include <mlc/bexpr.hh>
+# include <mlc/wrap.hh>
// private macro so do _not_ use it
@@ -107,7 +108,7 @@
template<class T, class U>
struct ret
- : public bool_<( mlc_internal_is_a_result_ )>
+ : public mlc::bexpr_is_<( mlc_internal_is_a_result_ )>
{
};
};
@@ -130,7 +131,7 @@
template<class T, template < class > class U>
struct ret
- : public bool_<( mlc_internal_is_a_result_ )>
+ : public mlc::bexpr_is_<( mlc_internal_is_a_result_ )>
{
};
};
@@ -153,7 +154,7 @@
template<class T, template < class,class > class U>
struct ret
- : public bool_<( mlc_internal_is_a_result_ )>
+ : public mlc::bexpr_is_<( mlc_internal_is_a_result_ )>
{};
};
@@ -175,7 +176,7 @@
template<class T, template < template < class > class > class U>
struct ret
- : public bool_<( mlc_internal_is_a_result_ )>
+ : public mlc::bexpr_is_<( mlc_internal_is_a_result_ )>
{};
};
@@ -197,7 +198,7 @@
template<class T, template < template < class,class > class > class U>
struct ret
- : public bool_<( mlc_internal_is_a_result_ )>
+ : public mlc::bexpr_is_<( mlc_internal_is_a_result_ )>
{};
};
@@ -238,7 +239,7 @@
*/
# define mlc_is_a(T, U) \
-mlc::bexpr_< typename mlc::is_a_< sizeof(mlc::form::of< U >()) >::ret< T, U > >
+mlc::wrap_< typename mlc::is_a_< sizeof(mlc::form::of< U >()) >::ret< T, U > >
# define mlc_is_a_(T, U) \
mlc::is_a_< sizeof(mlc::form::of< U >()) >::ret< T, U >
Index: mlc/case.hh
--- mlc/case.hh (revision 428)
+++ mlc/case.hh (working copy)
@@ -198,14 +198,16 @@
mlc::ret_found_in_< NAMESPACE::case_<context, data, i> > >, \
mlc::ERROR::A_case_STATEMENT_IN_A_switch_SHOULD_HAVE_A_ret > \
{ \
- typedef handle_case_ < \
- use, \
+ typedef mlc_is_a(mlc_comma_2(NAMESPACE::case_<context, data, i+1>), \
+ mlc::case_selected) next_case_is_selected; \
+ typedef mlc_is_a(mlc_comma_2(NAMESPACE::case_<context, data, i+1>), \
+ mlc::case_not_selected) next_case_is_not_selected; \
+ \
+ typedef handle_case_ < use, \
context, data, i+1, \
- mlc_is_a(mlc_comma_2(NAMESPACE::case_<context, data, i+1>), \
- mlc::case_selected)::value, \
- mlc_is_a(mlc_comma_2(NAMESPACE::case_<context, data, i+1>), \
- mlc::case_not_selected)::value > next_t; \
- typedef typename next_t::ret ret; \
+ mlc_bool(next_case_is_selected), mlc_bool(next_case_is_not_selected) \
+ > handle_next_case_t; \
+ typedef typename handle_next_case_t::ret ret; \
}; \
\
\
@@ -217,14 +219,15 @@
mlc::locked >, \
mlc::ERROR::A_case_STATEMENT_SHOULD_NOT_START_AT_INDEX_0_BUT_1 > \
{ \
- typedef handle_case_ < \
- use, \
+ typedef mlc_is_a(mlc_comma_2(NAMESPACE::case_<context, data, 1>), \
+ mlc::case_selected) first_case_is_selected; \
+ typedef mlc_is_a(mlc_comma_2(NAMESPACE::case_<context, data, 1>), \
+ mlc::case_not_selected) first_case_is_not_selected; \
+ typedef handle_case_ < use, \
context, data, 1, \
- mlc_is_a(mlc_comma_2(NAMESPACE::case_<context, data, 1>), \
- mlc::case_selected)::value, \
- mlc_is_a(mlc_comma_2(NAMESPACE::case_<context, data, 1>), \
- mlc::case_not_selected)::value > handle_t; \
- typedef typename handle_t::ret ret; \
+ mlc_bool(first_case_is_selected), mlc_bool(first_case_is_not_selected) \
+ > handle_first_case_t; \
+ typedef typename handle_first_case_t::ret ret; \
}; \
\
\
@@ -260,7 +263,7 @@
\
} \
\
-struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n \
+struct e_n_d__w_i_t_h__s_e_m_i_c_o_l_o_n
Index: mlc/value.hh
--- mlc/value.hh (revision 428)
+++ mlc/value.hh (working copy)
@@ -29,56 +29,8 @@
# define METALIC_VALUE_HH
# include <mlc/type.hh>
-// # include <mlc/wrap.hh>
-
-
-
-/** \def mlc_value(T)
- ** \brief Returns the value of a value type.
- **
- ** Only works when \a T is a value type such as mlc::bool_<b> or
- ** mlc::int_<i>. The result is respectively a bool value and an int
- ** value. Please prefer using this macro to a direct call to
- ** T::value because such a direct call may not compile (read the
- ** design notes below for details).
- **
- ** Design notes: FIXME: doc
- */
-
-// # define mlc_value(T) mlc::wrap_<T>::value
-
-
-
-/// Internal macros.
-
-
-# define mlc_internal_decl_unsigned_(Type, TypeName) \
-namespace internal \
-{ \
- template <Type val> \
- struct value_ <Type, val> : public abstract::unsigned_integer \
- { \
- typedef Type type; \
- static const Type value = val; \
- }; \
-} \
-template <Type val> \
-struct TypeName : public internal::value_<Type, val> {}
-
-
-# define mlc_internal_decl_signed_(Type, TypeName) \
-namespace internal \
-{ \
- template <Type val> \
- struct value_ <Type, val> : public abstract::signed_integer \
- { \
- typedef Type type; \
- static const Type value = val; \
- }; \
-} \
-template <Type val> \
-struct TypeName : public internal::value_<Type, val> {}
-
+// # include <mlc/assert.hh>
+// # include <mlc/is_a.hh>
@@ -99,86 +51,43 @@
{
};
- /// Abstractions for integer values as types.
-
- struct integer : public value {};
- struct unsigned_integer : public integer {};
- struct signed_integer : public integer {};
-
} // end of namespace mlc::abstract
namespace internal
{
- /*! \class mlc::internal::value_<T, val>
- **
- ** Base class for values to be represented by types. This class
- ** is in the internal namespace so you should not use it. Its
- ** purpose is only to factor code for derived classes that are not
- ** internal (for instance, mlc::true_ or mlc::int_<51>).
- **
- ** Design note: this class can only be used for values that can be
- ** a parameter (mlc::internal::value_<float, 3.14f> is incorrect).
- **
- ** Parameter T is the type of the value. Parameter val is the
- ** value itself.
- **
- ** \see mlc/bool.hh
- */
-
- template <typename T, T val>
- struct value_ : public abstract::value
+ template <typename T>
+ struct value_of_
+ // FIXME: commented below to avoid circular dependances
+ // : private assert_< mlc_is_a(T, mlc::abstract::value) >
{
- /*! \typedef type
- **
- ** Gives the regular type of the value. For instance,
- ** mlc::true_::type is bool and mlc::int_<51>::type is int.
- */
- typedef T type;
-
- /*! \member value
- **
- ** Gives the regular value. For instance,
- ** mlc::true_::value is true and mlc::int_<51>::value is 51.
- */
- static const T value = val;
+ static const typename T::type ret = T::value;
};
} // end of namespace mlc::internal
+} // end of namespace mlc
- // Dedicated sub-classes for builtin types.
-
- mlc_internal_decl_unsigned_( unsigned char, uchar_ );
- mlc_internal_decl_unsigned_( unsigned short, ushort_ );
- mlc_internal_decl_unsigned_( unsigned int, uint_ );
- mlc_internal_decl_unsigned_( unsigned long, ulong_ );
-
- mlc_internal_decl_signed_( signed char, schar_ );
- mlc_internal_decl_signed_( signed short, short_ );
- mlc_internal_decl_signed_( signed int, int_ );
- mlc_internal_decl_signed_( signed long, long_ );
-
-
- // char
-
- template <char c>
- struct char_ : public internal::value_<char, c>
- {
- };
-
-
- // Boolean values as types are defined elsewhere
- // see: mlc/bool.hh
+/** \def mlc_value(T)
+ ** \brief Returns the value of a value type.
+ **
+ ** Only works when \a T is a value type such as mlc::bool_<b> or
+ ** mlc::int_<i>. The result is respectively a bool value and an int
+ ** value; for instance mlc_value(mlc::int_<51>) gives 51. Please
+ ** prefer using this macro to a direct call to T::value because such
+ ** a direct call may not compile (read the design notes below for
+ ** details).
+ **
+ ** Design notes: FIXME: doc
+ */
-} // end of namespace mlc
+# define mlc_value(T) mlc::internal::value_of_<T>::ret
-# include <mlc/bool.hh>
#endif // ! METALIC_VALUE_HH
Index: mlc/char.hh
--- mlc/char.hh (revision 0)
+++ mlc/char.hh (revision 0)
@@ -0,0 +1,51 @@
+// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef METALIC_CHAR_HH
+# define METALIC_CHAR_HH
+
+# include <mlc/value.hh>
+
+
+
+namespace mlc
+{
+
+ // char
+
+ template <char c>
+ struct char_ : public abstract::value
+ {
+ typedef char type;
+ static const char value = c;
+ };
+
+
+} // end of namespace mlc
+
+
+#endif // ! METALIC_CHAR_HH
Index: mlc/cmp.hh
--- mlc/cmp.hh (revision 428)
+++ mlc/cmp.hh (working copy)
@@ -28,8 +28,9 @@
#ifndef METALIC_CMP_HH
# define METALIC_CMP_HH
-# include <mlc/bool.hh>
+# include <mlc/bexpr.hh>
# include <mlc/is_a.hh>
+# include <mlc/logic.hh>
/// Macros mlc_eq and mlc_neq.
@@ -59,17 +60,14 @@
template <typename T1, typename T2>
struct eq_ : private multiple_assert_< is_not_value<T1>,
is_not_value<T2> >,
- public false_
+ public bexpr_is_<false>
{
};
template <typename T>
struct eq_ <T, T> : private assert_< is_not_value<T> >,
- public true_
+ public bexpr_is_<true>
{
- // Solve the ambiguity on ensure(), a static member function
- // inherited both from true_ and assert_.
- using true_::ensure;
};
/// \}
@@ -78,13 +76,13 @@
template <typename T1, typename T2>
struct neq_ : private multiple_assert_< is_not_value<T1>,
is_not_value<T2> >,
- public true_
+ public bexpr_is_<true>
{
};
template <typename T>
struct neq_ <T, T> : private assert_< is_not_value<T> >,
- public false_
+ public bexpr_is_<false>
{
};
/// \}
@@ -110,9 +108,9 @@
/// Check whether a type is a sound (supposedly before using it).
template <typename T>
- struct is_ok : public and_list_< neq_<T, not_found>,
- neq_<T, not_ok>,
- neq_<T, undefined > >
+ struct is_ok : public and_< neq_<T, not_found>,
+ and_< neq_<T, not_ok>,
+ neq_<T, undefined > > >
{
};
Index: mlc/bexpr.hh
--- mlc/bexpr.hh (revision 428)
+++ mlc/bexpr.hh (working copy)
@@ -28,25 +28,152 @@
#ifndef METALIC_BEXPR_HH
# define METALIC_BEXPR_HH
+# include <mlc/type.hh>
+# include <mlc/flags.hh>
+
+
namespace mlc
{
- /*! \class mlc::bexpr_<T>
+
+ /// Forward declarations for Booleans value type and their aliases.
+ /// \{
+ template <bool b> struct bool_;
+ typedef bool_<true> true_;
+ typedef bool_<false> false_;
+ /// \}
+
+
+
+ namespace abstract {
+
+ /*! \class mlc::abstract::bexpr
+ **
+ ** Abstract base class for mlc Boolean expression types.
**
- ** This class is a wrapper for Boolean expression types. FIXME: doc
+ ** When you define a new class for a Boolean expression type, you
+ ** should not directly derive from this class from fom its
+ ** subclass: bexpr_is_<b>.
**
- ** \see mlc::wrap_<T>
+ ** \see bexpr_is_<b>
*/
- template <class T>
- struct bexpr_ : public T
+ struct bexpr : public type
{
- typedef typename T::eval eval;
+ // typedef void eval;
};
+ } // end of namespace mlc::abstract
+
+
+
+ /*! \class mlc::bexpr_is_<b>
+ **
+ ** Base class for any class of mlc Boolean expression types.
+ ** When you define a new class for a Boolean expression type, you
+ ** should directly derive from this class.
+ **
+ ** This class provides the typedef 'eval' which evaluates to either
+ ** mlc::true_ or mlc::false_ the expression.
+ **
+ ** \see mlc::bexpr_is_<true>, mlc::bexpr_is_<false>
+ */
+
+ template <bool b> struct bexpr_is_;
+
+
+ /*! \class mlc::bexpr_is_<true>
+ **
+ ** Specialization of mlc::bexpr_is_<b> when b is 'true'. This class
+ ** provides the typedef member 'is_true' to every Boolean expression
+ ** type that evaluates to true_.
+ **
+ ** \see mlc::bexpr_is_<b>, mlc::bexpr_is_<false>
+ */
+
+ template <>
+ struct bexpr_is_ < true > : public abstract::bexpr
+ {
+ typedef mlc::true_ eval;
+
+ /*! \typedef is_true
+ **
+ ** This member is inherited in every Boolean expression type that
+ ** evaluates to true_. Conversely, such member does not appear in
+ ** bexpr_is_<false> so it does not exist in every Boolean
+ ** expression type that evaluates to false_.
+ */
+ typedef mlc::dummy is_true;
+ };
+
+
+ /*! \class mlc::bexpr_is_<false>
+ **
+ ** Specialization of mlc::bexpr_is_<b> when b is 'false'. This class
+ ** does not provide the typedef member 'is_true' to every Boolean expression
+ ** type that evaluates to false_.
+ **
+ ** \see mlc::bexpr_is_<b>, mlc::bexpr_is_<true>
+ */
+
+ template <>
+ struct bexpr_is_ < false > : public abstract::bexpr
+ {
+ typedef mlc::false_ eval;
+ };
+
+
+
+
+ namespace internal
+ {
+
+ /// \class mlc::internal::bool_of_<bexpr>
+ /// \brief Returns the bool value corresponding to a Boolean expression type.
+ /// \note Internal class, don't use it directly.
+
+ template <typename bexpr>
+ struct bool_of_
+ // FIXME: commented below to avoid circular dependances
+ // : private assert_< mlc_is_a(bexpr, mlc::abstract::bexpr) >
+ {
+ // 1) the bexpr evaluates to either mlc::true_ or mlc::false_
+ // so the expected result comes from the value of b in
+ // mlc::bool_<b>
+ // 2) retrieving b is performed by the specialization of
+ // internal::bool_of_ provided few lines below
+ static const bool ret = internal::bool_of_<typename bexpr::eval>::ret;
+ };
+
+ /// \class mlc::internal::bool_of_< mlc::bool_<b> >
+ /// \brief Specialization of mlc::internal::bool_of_<bexpr>
+ /// \note Internal class, don't use it directly.
+ /// \see mlc::internal::bool_of_<bexpr>
+ template <bool b>
+ struct bool_of_ < mlc::bool_<b> >
+ {
+ static const bool ret = b;
+ };
+
+ } // end of namespace mlc::internal
+
} // end of namespace mlc
+
+
+/** \def mlc_bool(Bexpr)
+ **
+ ** Returns the bool value corresponding to a Boolean expression type.
+ **
+ ** \note Value retrieval is performed by
+ ** mlc::internal::bool_of_<Bexpr>
+ */
+
+# define mlc_bool(Bexpr) mlc::internal::bool_of_<Bexpr>::ret
+
+
+
#endif // ! METALIC_BEXPR_HH
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
First step towards explicit bexpr.
* mlc/bool.hh: Fix doc typo.
* mlc/TODO: Update.
* mlc/wrap.hh (unwrap): Remove cause useless.
(value_wrap_, boolean_wrap_): New dedicated wrappers.
* mlc/bexpr.hh: New file. It provides an explicit wrapper for Boolean
expression types; it is a first step towards the disambiguation between
the Boolean value type and the many Boolean expression types.
* mlc/is_a.hh (mlc_is_a): Update; now use bexpr_ instead of wrap_.
* mlc/value.hh (mlc_value): Suggest this macro.
TODO | 34 +++++++++++++++++++++++++++++++++-
bexpr.hh | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++
bool.hh | 2 +-
is_a.hh | 4 ++--
value.hh | 17 +++++++++++++++++
wrap.hh | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
6 files changed, 166 insertions(+), 5 deletions(-)
Index: mlc/bool.hh
--- mlc/bool.hh (revision 427)
+++ mlc/bool.hh (working copy)
@@ -32,7 +32,7 @@
# include <mlc/flags.hh>
-/*! \def mlc_bool(&Bexpr)
+/*! \def mlc_bool(Bexpr)
**
** Macro that retrieves a Boolean value from a Boolean expression type.
** Its result is either true or false.
Index: mlc/TODO
--- mlc/TODO (revision 427)
+++ mlc/TODO (working copy)
@@ -2,4 +2,36 @@
* files
-create assert.hh from bool.hh
+** bool.hh
+
+create assert.hh from parts of bool.hh
+
+** boolean and bexpr
+
+there is a confusion between mlc::abstract::boolean and the notion of
+bexpr (Boolean expression type)!
+
+** value.hh
+
+This file mixes bool_, int_, etc. so I should be split into several
+parts and all value-related files should be re-organized. The current
+situation is weird: internal::value is not in value.hh; uint.hh does
+not define mlc::uint_; etc.
+
+
+* renaming
+
+** cmp.hh
+
+eq_ -> equal_ etc.
+
+** comma.hh
+
+mlc_comma_N -> mlc_cmN (the shorter the better)
+
+
+* design
+
+** mlc_is_a
+
+It uses wrap_; though, is it really useful?
Index: mlc/wrap.hh
--- mlc/wrap.hh (revision 427)
+++ mlc/wrap.hh (working copy)
@@ -28,9 +28,23 @@
#ifndef METALIC_WRAP_HH
# define METALIC_WRAP_HH
+# include <mlc/is_a.hh>
+
namespace mlc
{
+
+ /// Forward declarations of types used in specific version of wrap_.
+ /// \{
+ namespace abstract
+ {
+ struct value;
+ struct boolean;
+ }
+ /// \}
+
+
+
/*! \class mlc::wrap_<T>
**
** This class is a workaround to the problem of implicit typename
@@ -47,14 +61,60 @@
**
** Design note: a detailed example can be read at the end of
** the file mlc/wrap.hh
+ **
+ **
+ ** \see mlc::value_wrap_<T>, mlc::bexpr_wrap_<T>
*/
template <class T>
struct wrap_ : public T
{
- typedef T unwrap;
+ // FIXME: there's no use to unwrap so disabled(?)
+ // typedef T unwrap;
+ };
+
+
+
+ /*! \class mlc::value_wrap_<T>
+ **
+ ** This class acts like mlc::wrap_<T> but is dedicated to
+ ** value types. The parameter \a T should be a value type.
+ **
+ ** \see mlc::wrap_<T>
+ */
+
+ template <class T>
+ struct value_wrap_ : private assert_< mlc_is_a(T, mlc::abstract::value) >,
+ public T
+ {
+ typedef typename T::type type;
+ static const T value = T::value;
+ };
+
+
+
+ /*! \class mlc::boolean_wrap_<T>
+ **
+ ** This class acts like mlc::wrap_<T> but is dedicated to Boolean.
+ ** The parameter \a T should be a Boolean expression type. FIXME:
+ ** there is a confusion between the Boolean value type and Boolean
+ ** expression types!!!
+ **
+ ** \see mlc::wrap_<T>
+ */
+
+ template <class T>
+ struct boolean_wrap_ : private assert_< mlc_is_a(T, mlc::abstract::boolean) >,
+ public T
+ {
+ typedef typename T::type type;
+ static const T value = T::value;
+
+ typedef typename T::eval eval;
};
+
+
} // end of namespace mlc
Index: mlc/is_a.hh
--- mlc/is_a.hh (revision 427)
+++ mlc/is_a.hh (working copy)
@@ -29,7 +29,7 @@
# define METALIC_IS_A_HH
# include <mlc/bool.hh>
-# include <mlc/wrap.hh>
+# include <mlc/bexpr.hh>
// private macro so do _not_ use it
@@ -238,7 +238,7 @@
*/
# define mlc_is_a(T, U) \
-mlc::wrap_< typename mlc::is_a_<sizeof(mlc::form::of<U >())>::ret<T,U > >
+mlc::bexpr_< typename mlc::is_a_< sizeof(mlc::form::of< U >()) >::ret< T, U > >
# define mlc_is_a_(T, U) \
mlc::is_a_< sizeof(mlc::form::of<U >())>::ret<T,U >
Index: mlc/value.hh
--- mlc/value.hh (revision 427)
+++ mlc/value.hh (working copy)
@@ -29,6 +29,23 @@
# define METALIC_VALUE_HH
# include <mlc/type.hh>
+// # include <mlc/wrap.hh>
+
+
+
+/** \def mlc_value(T)
+ ** \brief Returns the value of a value type.
+ **
+ ** Only works when \a T is a value type such as mlc::bool_<b> or
+ ** mlc::int_<i>. The result is respectively a bool value and an int
+ ** value. Please prefer using this macro to a direct call to
+ ** T::value because such a direct call may not compile (read the
+ ** design notes below for details).
+ **
+ ** Design notes: FIXME: doc
+ */
+
+// # define mlc_value(T) mlc::wrap_<T>::value
Index: mlc/bexpr.hh
--- mlc/bexpr.hh (revision 0)
+++ mlc/bexpr.hh (revision 0)
@@ -0,0 +1,52 @@
+// Copyright (C) 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef METALIC_BEXPR_HH
+# define METALIC_BEXPR_HH
+
+
+namespace mlc
+{
+
+ /*! \class mlc::bexpr_<T>
+ **
+ ** This class is a wrapper for Boolean expression types. FIXME: doc
+ **
+ ** \see mlc::wrap_<T>
+ */
+
+ template <class T>
+ struct bexpr_ : public T
+ {
+ typedef typename T::eval eval;
+ };
+
+
+} // end of namespace mlc
+
+
+#endif // ! METALIC_BEXPR_HH
https://svn.lrde.epita.fr/svn/oln/trunk/metalic
Index: ChangeLog
from Thierry Geraud <theo(a)lrde.epita.fr>
Create assert.hh from bool.hh contents.
* mlc/bool.hh (mlc_type_iff, mlc::type_iff_): Remove cause soon obsolete.
(bool_<true>::ensure()): Remove to force the client to use assert_.
(bool_): Add using clauses to make contents explicit.
(internal::check_, internal::check_item_): Move to...
(literal_, no_error_message, no_bexpr): Move to...
(assert_, multiple_assert_): Move to...
* mlc/assert.hh: ... this new file.
* tests/is_a.cc: Update.
* tests/if.cc: Update.
* tests/typedef.cc: Update.
* mlc/logic.hh: Update.
mlc/assert.hh | 234 ++++++++++++++++++++++++++++++++++++++++++++++++
mlc/bool.hh | 267 ++++---------------------------------------------------
mlc/logic.hh | 1
tests/if.cc | 5 -
tests/is_a.cc | 5 -
tests/typedef.cc | 7 +
6 files changed, 267 insertions(+), 252 deletions(-)
Index: tests/is_a.cc
--- tests/is_a.cc (revision 426)
+++ tests/is_a.cc (working copy)
@@ -1,4 +1,5 @@
#include <mlc/is_a.hh>
+#include <mlc/assert.hh>
struct A {};
struct B : public A {};
@@ -9,6 +10,6 @@
int
main ()
{
- mlc_is_a_(B, A)::ensure();
- mlc_is_a_(D<int>, C<int>)::ensure();
+ mlc::assert_< mlc_is_a_(B, A) >::check();
+ mlc::assert_< mlc_is_a_(D<int>, C<int>) >::check();
}
Index: tests/if.cc
--- tests/if.cc (revision 426)
+++ tests/if.cc (working copy)
@@ -1,5 +1,6 @@
#include <mlc/if.hh>
#include <mlc/cmp.hh>
+#include <mlc/assert.hh>
struct alpha;
struct beta;
@@ -10,8 +11,8 @@
main()
{
typedef mlc_if_(mlc::true_, alpha, beta) x;
- mlc_eq(x, alpha)::ensure();
+ mlc::assert_< mlc_eq(x, alpha) >::check();
typedef mlc_if_(mlc::false_, gamma, delta) y;
- mlc_eq(y, delta)::ensure();
+ mlc::assert_< mlc_eq(y, delta) >::check();
}
Index: tests/typedef.cc
--- tests/typedef.cc (revision 426)
+++ tests/typedef.cc (working copy)
@@ -1,5 +1,6 @@
#include <mlc/typedef.hh>
#include <mlc/cmp.hh>
+#include <mlc/assert.hh>
struct foo
{
@@ -12,6 +13,8 @@
int
main ()
{
- mlc_eq(mlc_typedef_(foo, good_type), foo::good_type)::ensure();
- mlc_eq(mlc_typedef_(foo, bad_type), mlc::not_found)::ensure();
+ mlc::assert_< mlc_eq(mlc_typedef_(foo, good_type),
+ foo::good_type) >::check();
+ mlc::assert_< mlc_eq(mlc_typedef_(foo, bad_type),
+ mlc::not_found) >::check();
}
Index: mlc/bool.hh
--- mlc/bool.hh (revision 426)
+++ mlc/bool.hh (working copy)
@@ -30,25 +30,14 @@
# include <mlc/value.hh>
# include <mlc/flags.hh>
-# include <mlc/wrap.hh>
-/*! \def mlc_bool(BExpr)
+/*! \def mlc_bool(&Bexpr)
**
** Macro that retrieves a Boolean value from a Boolean expression type.
** Its result is either true or false.
*/
-# define mlc_bool(BExpr) mlc::internal::get_bool<BExpr>::value
-
-
-
-/*! \def mlc_type_iff(Type, BExpr)
-**
-** FIXME: doc
-*/
-# define mlc_type_iff(Type, BExpr) typename mlc::type_iff_<Type, BExpr>::ret
-# define mlc_type_iff_(Type, BExpr) mlc::type_iff_<Type, BExpr>::ret
-
+# define mlc_bool(Bexpr) mlc::internal::get_bool<Bexpr>::value
@@ -141,11 +130,11 @@
** Please note that, however, we usually do not need expression
** evaluation. The most common use of a Boolean expression is
** to check that it is verified (true) and, for that, we provide
- ** "expr::ensure();" and "assert_<expr..>". For instance:
- ** or_<mlc_is_a(T, int), mlc_is_a(T, unsigned)>::ensure();
+ ** "assert_<bexpr, errmsg>::check()". For instance:
+ ** assert_< or_<mlc_is_a(T, int), mlc_is_a(T, unsigned)> >::check();
** ensures that T is int or unsigned without using ::eval.
**
- ** \see mlc::true_, mlc::false_, mlc::assert_<expr..>.
+ ** \see mlc::true_, mlc::false_, mlc::assert_<bexpr, errmsg>.
*/
typedef bool_<b> eval;
@@ -163,214 +152,10 @@
};
- /*! \class mlc::internal::check_<bexpr, result>
- **
- ** Internal so do not use it. This class is for use in the
- ** definition of mlc::assert_<bexpr, err>.
- **
- ** Design note: this class does not derive from abstract::type
- ** because it is used in inheritance so a ctor should exist.
- **
- ** \see mlc::assert_<bexpr, err>
- */
-
- template <typename bexpr, typename result>
- struct check_
- {
- };
-
-
- /*! \class mlc::internal::check_item_<i, bexpr, result>
- **
- ** Internal so do not use it. This class is for use in the
- ** definition of mlc::multiple_assert_<..>.
- **
- ** Design note: this class does not derive from abstract::type
- ** because it is used in inheritance so a ctor should exist.
- **
- ** \see mlc::multiple_assert_<..>
- */
-
- template <unsigned i, typename bexpr, typename result>
- struct check_item_
- {
- };
-
} // end of namespace mlc::internal
- /*! \class mlc::no_error_message
- **
- ** FIXME: doc
- */
-
- struct no_error_message;
-
-
- /*! \class mlc::no_bexpr
- **
- ** Internal class for use in mlc::multiple_assert_<..>.
- */
-
- struct no_bexpr
- {
- typedef dummy is_true;
- };
-
-
- /*! \class mlc::assert_<bexpr, err>
- **
- ** FIXME: this doc is partially obsolete!
- **
- ** This class is a replacement for the instruction "expr::ensure();"
- ** when there is no room for having instruction. The typical use
- ** is to express a constraint (or several constraints) upon a
- ** parameter (or several parameters) of a templated class.
- **
- ** assert_<expr> only accepts one parameter, which has to be a
- ** Boolean expression type. An equivalent version for a variadic
- ** list of parameters is multiple_assert_<expr1,..>
- **
- ** Sample use:
- **
- ** template <class T>
- ** struct foo : private virtual assert_< neq_<T, int> >
- ** { ...
- ** };
- ** means that T can be any type but int.
- **
- **
- ** Please avoid the following code:
- ** template <class T1, class T2>
- ** struct bar : private virtual assert_< neq_<T1, int> >,
- ** private virtual assert_< neq_<T2, int> >
- ** { ...
- ** };
- ** a better replacement is:
- ** template <class T1, class T2>
- ** struct bar : private virtual multiple_assert_< neq_<T1, int>,
- ** neq_<T2, int> >
- ** { ...
- ** };
- ** see the design notes below for details.
- **
- ** Also prefer the use of multiple_assert_<expr1, expr2> than the
- ** equivalent assert_< and_<expr1, expr2> >. Actually, the former
- ** provides better error messages since the compiler is able to
- ** say which expr is not verified, whereas the latter cannot.
- **
- **
- ** Design notes: 1) This class does not derive from abstract::type
- ** because it is used in inheritance so a ctor should exist. 2)
- ** This class relies on mlc::internal::assert_item_ to check that
- ** the expression is true. 3) When several contrains such as
- ** "private assert_<..>" appear through a hierarchy of classes or
- ** for a given class, the program may not compile because of
- ** multiple inheritance of the same base class; the solution is to
- ** systematically write "private virtual assert_<..>".
- **
- ** \see multiple_assert_<bexpr1,..>
- **
- */
-
- template <typename bexpr, typename err = no_error_message>
- struct assert_ :
- public virtual internal::check_<bexpr, typename bexpr::is_true>
- {
- public:
- static void ensure() {}
- protected:
- assert_() {}
- };
-
-
- /*! \class mlc::type_iff_<T, bexpr>
- **
- ** FIXME: doc
- ** returns type T iff bexpr
- */
- template <typename T, typename bexpr>
- struct type_iff_ :
- private assert_<bexpr>
- {
- typedef T ret;
- };
-
-
- /*! \class mlc::literal_<T>
- **
- ** FIXME: doc
- */
-
- template <typename T>
- struct literal_
- {
- typedef T ret;
- };
-
-
- /*! \class mlc::multiple_assert_<bexpr1..>
- **
- ** FIXME: this doc is partially obsolete!
- **
- ** This class is a replacement for a sequence of instructions:
- ** "expr1::ensure(); .." when there is no room for having
- ** instructions. The typical use is to express a constraint (or
- ** several constraints) upon a parameter (or several parameters)
- ** of a templated class.
- **
- ** multiple_assert_<..> has a variadic list of parameters. It expects
- ** at least 2 parameters and handles up to 9 parameters. Each
- ** parameter has to be a Boolean expression type. To check only a
- ** single expression, the appropriate tool is assert_<expr>.
- **
- **
- ** Sample use:
- **
- ** template <class T1, class T2>
- ** struct foo : private virtual multiple_assert_< neq_<T1, int>,
- ** neq_<T2, int> >
- ** { ...
- ** };
- **
- ** Design notes: 1) This class does not derive from abstract::type
- ** because it is used in inheritance so a ctor should exist. 2)
- ** This class relies on mlc::internal::assert_item_ to check that
- ** each expression is true. 3) using "virtual" allow to encompass
- ** the multiple base class problem.
- **
- ** Limitation: no error message can be provided with this present
- ** version of multiple_assert_ so prefer using several assert_.
- **
- ** \see assert_<bexpr, err>
- */
-
- template <typename bexpr1,
- typename bexpr2,
- typename bexpr3 = no_bexpr,
- typename bexpr4 = no_bexpr,
- typename bexpr5 = no_bexpr,
- typename bexpr6 = no_bexpr,
- typename bexpr7 = no_bexpr,
- typename bexpr8 = no_bexpr,
- typename bexpr9 = no_bexpr>
- struct multiple_assert_ :
- private virtual internal::check_item_<1, bexpr1, typename bexpr1::is_true>,
- private virtual internal::check_item_<2, bexpr2, typename bexpr2::is_true>,
- private virtual internal::check_item_<3, bexpr3, typename bexpr3::is_true>,
- private virtual internal::check_item_<4, bexpr4, typename bexpr4::is_true>,
- private virtual internal::check_item_<5, bexpr5, typename bexpr5::is_true>,
- private virtual internal::check_item_<6, bexpr6, typename bexpr6::is_true>,
- private virtual internal::check_item_<7, bexpr7, typename bexpr7::is_true>,
- private virtual internal::check_item_<8, bexpr8, typename bexpr8::is_true>,
- private virtual internal::check_item_<9, bexpr9, typename bexpr9::is_true>
- {
- protected:
- multiple_assert_() {}
- };
-
-
/*! \class mlc::bool_<true>
**
** Specialization of mlc::bool_<b> for b set to true. This type
@@ -388,25 +173,10 @@
template <>
struct bool_<true> : public internal::value_<bool, true>
{
- /*! \member ensure()
- **
- ** This member is inherited in every Boolean expression types that
- ** derive from mlc::true_. This member is not provided in
- ** mlc::false_.
- **
- ** A static check to ensure that a Boolean expression type, say
- ** Expr, is verified can thus be written as an instruction:
- ** "Expr::ensure();"
- **
- ** When there is no room in code for an instruction, use
- ** mlc::assert_<bexpr> instead.
- **
- ** Design note: This member is a no-op (it has no cost at
- ** run-time).
- **
- ** \see: mlc::assert_<expr>
- */
- static void ensure() {}
+
+ // FIXME: doc
+ using internal::value_<bool, true>::value;
+ using internal::value_<bool, true>::eval;
/*! \typedef is_true
**
@@ -434,23 +204,28 @@
** is also known as mlc::false_. Every Boolean expression types
** derive either from this type or from mlc::true_.
**
- ** Conversely to mlc::true_, this class does not feature ensure()
- ** nor assert_. So, when a Boolean expression type, say Expr,
- ** is evaluated to false, the static checks "Expr::ensure();" and
- ** "Expr::assert_" do not compile.
+ ** Conversely to mlc::true_, this class does not feature the typedef
+ ** "is_true". So, when a Boolean expression type, say Expr, is
+ ** evaluated to false, the static checks via "assert_<Expr>"
+ ** do not compile.
**
** Design notes: 1) This specialization is defined so that mlc
** Booleans derive from mlc::abstract::boolean. 2) This
** specialization conforms to the interface of the generic version
- ** of mlc::internal::value_. 3) Conversely to "mlc::bool_<true>"
- ** no typedef "is_true" is provided.
+ ** of mlc::internal::value_.
**
- ** \see mlc::bool_<true>
+ ** \see mlc::bool_<true>, mlc::assert_<bexpr, errmsg>
*/
template <>
struct bool_<false> : public internal::value_<bool, false>
{
+ // FIXME: doc
+ private:
+ typedef internal::value_<bool, false> super_type;
+ public:
+ using super_type::value;
+ using super_type::eval;
};
typedef bool_<false> false_;
Index: mlc/logic.hh
--- mlc/logic.hh (revision 426)
+++ mlc/logic.hh (working copy)
@@ -29,6 +29,7 @@
# define METALIC_LOGIC_HH
# include <mlc/bool.hh>
+# include <mlc/assert.hh>
# include <mlc/flags.hh>
Index: mlc/assert.hh
--- mlc/assert.hh (revision 0)
+++ mlc/assert.hh (revision 0)
@@ -0,0 +1,234 @@
+// Copyright (C) 2006 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
+// MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef METALIC_ASSERT_HH
+# define METALIC_ASSERT_HH
+
+# include <mlc/bool.hh>
+
+
+
+namespace mlc
+{
+
+
+ namespace internal
+ {
+
+ /*! \class mlc::internal::check_<bexpr, result>
+ **
+ ** Internal so do not use it. This class is for use in the
+ ** definition of mlc::assert_<bexpr, err>.
+ **
+ ** Design note: this class does not derive from abstract::type
+ ** because it is used in inheritance so a ctor should exist.
+ **
+ ** \see mlc::assert_<bexpr, err>
+ */
+
+ template <typename bexpr, typename result>
+ struct check_
+ {
+ };
+
+
+ /*! \class mlc::internal::check_item_<i, bexpr, result>
+ **
+ ** Internal so do not use it. This class is for use in the
+ ** definition of mlc::multiple_assert_<..>.
+ **
+ ** Design note: this class does not derive from abstract::type
+ ** because it is used in inheritance so a ctor should exist.
+ **
+ ** \see mlc::multiple_assert_<..>
+ */
+
+ template <unsigned i, typename bexpr, typename result>
+ struct check_item_
+ {
+ };
+
+ } // end of namespace mlc::internal
+
+
+
+ /*! \class mlc::no_error_message
+ **
+ ** FIXME: doc
+ */
+
+ struct no_error_message;
+
+
+ /*! \class mlc::no_bexpr
+ **
+ ** Internal class for use in mlc::multiple_assert_<..>.
+ */
+
+ struct no_bexpr
+ {
+ typedef dummy is_true;
+ };
+
+
+ /*! \class mlc::assert_<bexpr, err>
+ **
+ ** FIXME: this doc is partially obsolete!
+ **
+ ** This class is a replacement for the instruction "expr::ensure();"
+ ** when there is no room for having instruction. The typical use
+ ** is to express a constraint (or several constraints) upon a
+ ** parameter (or several parameters) of a templated class.
+ **
+ ** assert_<expr> only accepts one parameter, which has to be a
+ ** Boolean expression type. An equivalent version for a variadic
+ ** list of parameters is multiple_assert_<expr1,..>
+ **
+ ** Sample use:
+ **
+ ** template <class T>
+ ** struct foo : private virtual assert_< neq_<T, int> >
+ ** { ...
+ ** };
+ ** means that T can be any type but int.
+ **
+ **
+ ** Please avoid the following code:
+ ** template <class T1, class T2>
+ ** struct bar : private virtual assert_< neq_<T1, int> >,
+ ** private virtual assert_< neq_<T2, int> >
+ ** { ...
+ ** };
+ ** a better replacement is:
+ ** template <class T1, class T2>
+ ** struct bar : private virtual multiple_assert_< neq_<T1, int>,
+ ** neq_<T2, int> >
+ ** { ...
+ ** };
+ ** see the design notes below for details.
+ **
+ ** Also prefer the use of multiple_assert_<expr1, expr2> than the
+ ** equivalent assert_< and_<expr1, expr2> >. Actually, the former
+ ** provides better error messages since the compiler is able to
+ ** say which expr is not verified, whereas the latter cannot.
+ **
+ **
+ ** Design notes: 1) This class does not derive from abstract::type
+ ** because it is used in inheritance so a ctor should exist. 2)
+ ** This class relies on mlc::internal::assert_item_ to check that
+ ** the expression is true. 3) When several contrains such as
+ ** "private assert_<..>" appear through a hierarchy of classes or
+ ** for a given class, the program may not compile because of
+ ** multiple inheritance of the same base class; the solution is to
+ ** systematically write "private virtual assert_<..>".
+ **
+ ** \see multiple_assert_<bexpr1,..>
+ **
+ */
+
+ template <typename bexpr, typename err = no_error_message>
+ struct assert_ :
+ public virtual internal::check_<bexpr, typename bexpr::is_true>
+ {
+ public:
+ static void check() {}
+ protected:
+ assert_() {}
+ };
+
+
+
+ /*! \class mlc::multiple_assert_<bexpr1..>
+ **
+ ** FIXME: this doc is partially obsolete!
+ **
+ ** This class is a replacement for a sequence of instructions:
+ ** "expr1::ensure(); .." when there is no room for having
+ ** instructions. The typical use is to express a constraint (or
+ ** several constraints) upon a parameter (or several parameters)
+ ** of a templated class.
+ **
+ ** multiple_assert_<..> has a variadic list of parameters. It expects
+ ** at least 2 parameters and handles up to 9 parameters. Each
+ ** parameter has to be a Boolean expression type. To check only a
+ ** single expression, the appropriate tool is assert_<expr>.
+ **
+ **
+ ** Sample use:
+ **
+ ** template <class T1, class T2>
+ ** struct foo : private virtual multiple_assert_< neq_<T1, int>,
+ ** neq_<T2, int> >
+ ** { ...
+ ** };
+ **
+ ** Design notes: 1) This class does not derive from abstract::type
+ ** because it is used in inheritance so a ctor should exist. 2)
+ ** This class relies on mlc::internal::assert_item_ to check that
+ ** each expression is true. 3) using "virtual" allow to encompass
+ ** the multiple base class problem.
+ **
+ ** Limitation: no error message can be provided with this present
+ ** version of multiple_assert_ so prefer using several assert_.
+ **
+ ** \see assert_<bexpr, err>
+ */
+
+ template <typename bexpr1,
+ typename bexpr2,
+ typename bexpr3 = no_bexpr,
+ typename bexpr4 = no_bexpr,
+ typename bexpr5 = no_bexpr,
+ typename bexpr6 = no_bexpr,
+ typename bexpr7 = no_bexpr,
+ typename bexpr8 = no_bexpr,
+ typename bexpr9 = no_bexpr>
+ struct multiple_assert_ :
+ private virtual internal::check_item_<1, bexpr1, typename bexpr1::is_true>,
+ private virtual internal::check_item_<2, bexpr2, typename bexpr2::is_true>,
+ private virtual internal::check_item_<3, bexpr3, typename bexpr3::is_true>,
+ private virtual internal::check_item_<4, bexpr4, typename bexpr4::is_true>,
+ private virtual internal::check_item_<5, bexpr5, typename bexpr5::is_true>,
+ private virtual internal::check_item_<6, bexpr6, typename bexpr6::is_true>,
+ private virtual internal::check_item_<7, bexpr7, typename bexpr7::is_true>,
+ private virtual internal::check_item_<8, bexpr8, typename bexpr8::is_true>,
+ private virtual internal::check_item_<9, bexpr9, typename bexpr9::is_true>
+ {
+ public:
+ static void check() {}
+ protected:
+ multiple_assert_() {}
+ };
+
+
+} // end of namespace mlc
+
+
+# include <mlc/logic.hh>
+
+
+#endif // ! METALIC_BOOL_HH