[mpl] and_<true_> returns false

The following snippet fails to compile (tested with 1.54.0 and trunk, several compilers), #include <boost/mpl/and.hpp> #include <boost/mpl/bool.hpp> #include <boost/mpl/or.hpp> int main() { using namespace boost::mpl; static_assert(and_<true_>::value, "U KID?"); //this one fires static_assert(or_<true_>::value, "U KID?"); //this one is ok } This issue actually showed up in a variadic template scenario. Is this a bug? I feel like I'm doing something really wrong... I guess one may not call `and_` with less than two arguments. If that's the case, it would be helpful if it would be impossible to instantiate it with a single argument. Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com

I would go the other way and start support from zero arguments! The "and" operation would default to TRUE while "or" defaults to "FALSE." (Hint: the operations default to their "identity" operand value, and definitely not their "short-circuit" operand value.) Daryle W.

On 09/18/13 22:46, Matt Calabrese wrote:
My reply to Augustin mentioned a variadic and_ and or_ which takes any number of args, including 0. I looked closer at the code and found: http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/mpl/null_uni... which is used, indirectly, by the and_ and or_ metafunctions. The null_unit comments indicates it short-circuits the evaluation based on whether the current argument is the Null argument. In the case of and_, Null would be mpl::false_, In the case of or_, Null would be mpl::true_. At least that's my understanding after a brief review of code. HTH. -regards, Larry

Not to miss the important part, there is a bug. (A single argument for "and" or "or" should return itself.) Have you put it on our Trac system? You should probably mention this thread; search on one of the mailing list archive sites to find the first message so you can add its link to the bug report. Daryle W.

On 19/09/2013 02:03 a.m., Daryle Walker wrote:
Done. #9137 Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com

On 09/18/13 18:33, Agustín K-ballo Bergé wrote:
There's a variadic mpl::and_ and mpl::or_ which I think solves this problem. However, I seriously doubt it would compile as fast because, my impression is that the standard boost mpl spent a lot of effort using the preprocessor to speed compile times, and the variadic versions here: http://svn.boost.org/svn/boost/sandbox/variadic_templates/boost/mpl/ were not coded with compile speed in mind :( -regards Larry
participants (4)
-
Agustín K-ballo Bergé
-
Daryle Walker
-
Larry Evans
-
Matt Calabrese