
https://svn.lrde.epita.fr/svn/oln/trunk/metalic Index: ChangeLog from Roland Levillain <roland@lrde.epita.fr> Static `if'. * mlc/if.hh: New file. if.hh | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) Index: mlc/if.hh --- mlc/if.hh (revision 0) +++ mlc/if.hh (working copy) @@ -1,4 +1,4 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005 EPITA Research and Development Laboratory +// Copyright (C) 2001, 2002, 2003, 2004, 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 @@ -31,8 +31,19 @@ # include <mlc/bool.hh> -/// Macro mlc_if. -# define mlc_if(Cond, Then, Else) typename mlc::if_<(Cond), (Then), (Else)>::ret +/** \def mlc_if(Cond, Then, Else) + ** \brief Static `if' on types. + ** + ** If \a Cond is true, evaluate to type \a Then, otherwise evaluate to + ** type \a Else. + ** + ** \note \a Then and \a Else must be valid types, since they are both + ** evaluated, whatever the result of \a Cond. + ** + */ +# define mlc_if(Cond, Then, Else) typename mlc::if_<Cond, Then, Else>::ret +/// Likewise, without the leading \c typename keyword. +# define mlc_if_(Cond, Then, Else) mlc::if_<Cond, Then, Else>::ret namespace mlc @@ -41,17 +52,23 @@ namespace internal { + /// \brief Declare a static `if'. + /// \note Internal class, don't use it directly. template <bool b, typename then_type, typename else_type> - struct fun_if_; + struct if_; + /// \brief Specialization of mlc::internal::if_ when condition is true. + /// \note Internal class, don't use it directly. template <typename then_type, typename else_type> - struct fun_if_ <true, then_type, else_type> + struct if_ <true, then_type, else_type> { typedef then_type ret; }; + /// \brief Specialization of mlc::internal::if_ when condition is false. + /// \note Internal class, don't use it directly. template <typename then_type, typename else_type> - struct fun_if_ <false, then_type, else_type> + struct if_ <false, then_type, else_type> { typedef else_type ret; }; @@ -59,14 +76,20 @@ } // end of namespace mlc::internal +/** \brief Static `if' on types. + ** + ** If \a Cond is true, evaluate to type \a Then, otherwise evaluate to + ** type \a Else. The \a ret member holds the result. + ** + ** \note \a Then and \a Else must be valid types, since they are both + ** evaluated, whatever the result of \a Cond. + */ template <typename cond_type, typename then_type, typename else_type> - struct if_ : public internal::fun_if_ < mlc_bool(cond_type), then_type, else_type > + struct if_ : public internal::if_ < mlc_bool(cond_type), then_type, else_type > { }; - } // end of namespace mlc - #endif // ! METALIC_IF_HH