[mpl] and_<true_> returns false
The following snippet fails to compile (tested with 1.54.0 and trunk,
several compilers),
#include
Date: Wed, 18 Sep 2013 20:33:31 -0300 From: kaballo86@hotmail.com
The following snippet fails to compile (tested with 1.54.0 and trunk, several compilers),
#include
#include #include int main() { using namespace boost::mpl; static_assert(and_
::value, "U KID?"); //this one fires static_assert(or_ ::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.
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 Wed, Sep 18, 2013 at 7:14 PM, Daryle Walker
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.)
I agree. Use of that kind of stuff comes up all the time when dealing with variadics. Having sensible 0 argument and 1 argument forms is important. -- -Matt Calabrese
On 09/18/13 22:46, Matt Calabrese wrote:
On Wed, Sep 18, 2013 at 7:14 PM, Daryle Walker
wrote: 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.)
I agree. Use of that kind of stuff comes up all the time when dealing with variadics. Having sensible 0 argument and 1 argument forms is important.
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
Date: Wed, 18 Sep 2013 20:33:31 -0300 From: kaballo86@hotmail.com
The following snippet fails to compile (tested with 1.54.0 and trunk, several compilers),
#include
#include #include int main() { using namespace boost::mpl; static_assert(and_
::value, "U KID?"); //this one fires static_assert(or_ ::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...
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:
Date: Wed, 18 Sep 2013 20:33:31 -0300
From:kaballo86@hotmail.com
The following snippet fails to compile (tested with 1.54.0 and trunk, several compilers),
int main() { using namespace boost::mpl; static_assert(and_
::value, "U KID?"); //this one fires static_assert(or_ ::value, "U KID?"); //this one is ok } 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?
Done. #9137 Regards, -- Agustín K-ballo Bergé.- http://talesofcpp.fusionfenix.com
On 09/18/13 18:33, Agustín K-ballo Bergé wrote:
The following snippet fails to compile (tested with 1.54.0 and trunk, several compilers),
#include
#include #include int main() { using namespace boost::mpl; static_assert(and_
::value, "U KID?"); //this one fires static_assert(or_ ::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,
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