517: Add a wrapper around mlc::assert_ returning a given type.

https://svn.lrde.epita.fr/svn/oln/trunk/metalic Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Add a wrapper around mlc::assert_ returning a given type. * mlc/assert.hh (assert_and_return_): New class. assert.hh | 27 +++++++++++++++++++++++++++ contract.hh | 1 + 2 files changed, 28 insertions(+) Index: mlc/assert.hh --- mlc/assert.hh (revision 516) +++ mlc/assert.hh (working copy) @@ -226,6 +226,33 @@ }; + + /*! \class mlc::assert_and_return_<bexpr, ret_type, err> + ** + ** Check a static property over \a bexpr, and return \a ret_type as \a ret + ** in case of success. Otherwise, raise a compile-time error. + ** \a err can be used to report a meaningful error message to the + ** programmer. + ** + ** This is a convenient class used to improve the readability of meta + ** programs. + */ + + template <typename bexpr, typename ret_type, typename err = no_error_message> + struct assert_and_return_ : + public virtual internal::check_<bexpr, typename bexpr::is_true> + { + public: + /// The return type of this assert_and_return_ statement. + typedef ret_type ret; + + virtual ~assert_and_return_() {} + + protected: + assert_and_return_() {} + }; + + } // end of namespace mlc Index: mlc/contract.hh --- mlc/contract.hh (revision 516) +++ mlc/contract.hh (working copy) @@ -41,6 +41,7 @@ # define precondition(expr) assert(expr) # define postcondition(expr) assert(expr) +// FIXME: Shouln't we move these macros into Static? # define mlc_check_method_impl(WHERE, RETURN, NAME, ARG, CONST) \ { \
participants (1)
-
Roland Levillain