Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8531879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:35:08+00:00 2026-06-11T09:35:08+00:00

The code below tries to test the short circuit behavior of boost::mpl::or_ and boost::mpl::and_

  • 0

The code below tries to test the short circuit behavior of boost::mpl::or_ and boost::mpl::and_:

#include <vector>
#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/and.hpp>
#include <boost/type_traits/is_scalar.hpp>

// Dummy is forward declared and never defined
template <class T> class dummy;

// If T is a scalar evaluates to T without trying to compute the result of 
// boost::mpl::is_scalar< dummy<T>, otherwise it fails at compile time.
template <class T> 
class testOr 
: public boost::mpl::eval_if< 
    boost::mpl::or_< boost::is_scalar<T>, boost::is_scalar< dummy<T> > >,
    boost::mpl::identity<T>,
    dummy<T>        
>
{};

// If T is not a scalar evaluates to T without trying to compute the result of 
// boost::mpl::is_scalar< dummy<T>, otherwise it should fail at compile time.
template <class T> 
class testAnd
: public boost::mpl::eval_if< 
    // It appears that is_scalar< dummy<T> > is not instantiated and the operation
    // evaluates to false
    boost::mpl::and_< boost::is_scalar<T>, boost::is_scalar< dummy<T> > >,
    dummy<T>,
    boost::mpl::identity<T>
>
{};

int main() {    

  static_assert(boost::is_same< testOr< double >::type, double>::type::value,"Fails at compile time");
  // The following line causes failures at compile time due to incomplete type definition
  //static_assert(boost::is_same< testOr< std::vector<double> >::type, double>::type::value,"Fails at compile time");

  static_assert(boost::is_same< testAnd< std::vector<double> >::type, std::vector<double> >::type::value,"Fails at compile time");
  // The following should cause failure at compile time due to incomplete type definition, but works instead!
  static_assert(boost::is_same< testAnd< double >::type , double >::type::value,"Fails at compile time");

return 0;
}

While I expect this code to fail at compile time due to an incomplete type definition, it actually works:

>icpc --version
icpc (ICC) 12.1.3 20120212
Copyright (C) 1985-2012 Intel Corporation.  All rights reserved.

>icpc -gcc-name=gcc-4.5 -std=c++0x -o ex-4.0.x ex-4.0.cc

So, the point I would like to understand is:

Is there an inconsistency in the way boost::mpl::or_ and boost::mpl::and_ evaluate their arguments or, most likely, is there an error in the code I am not able to catch?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:35:09+00:00Added an answer on June 11, 2026 at 9:35 am

    Why you think, that second argument of or_ will not be evaluated? is_scalar can be used with undefined types.

    For example in this case, you get your error as well.

    // If T is not a scalar evaluates to T without trying to compute the result of 
    // boost::mpl::is_scalar< dummy<T>, otherwise it should fail at compile time.
    template <class T> 
    class testAnd
    : public boost::mpl::eval_if< 
        // It appears that is_scalar< dummy<T> > is not instantiated and the operation
        // evaluates to false
        boost::mpl::and_< boost::is_scalar<T>, boost::is_scalar< dummy<T> > >,
        boost::mpl::identity<T>,
        dummy<T>
    >
    {};
    

    Since boost::is_scalar<T> is true, but boost::is_scalar<dummy<T>> is false in your case, so.

    Look. http://liveworkspace.org/code/a792e18ca16a0410a67a6eee8c550bd9

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Below I have some code that that I cannot Unit test because it tries
The code below tries to parse a file containing these 3 lines: 0 2
I am using the below test code to toggle a div based on a
so guys, if u test the code below, u can see that everything is
The program’s code is like below: using System.Diagnostics; class Test { static void Main()
I tried below code but as I run it gives a black screen image
I tried the below code to check whether my mobile is connected to a
I have tried using the code below but it only display results in Chrome
I have tried rectifying the code below. But I am not able to find
I tried accessing web for xml parsing using the code below: System.Uri proxy =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.