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 8631433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:13:07+00:00 2026-06-12T09:13:07+00:00

In the C++ standard, std::ios::openmode , std::ios::fmtflags and std::ios::iostate are implementation defined. But std::ios::goodbit

  • 0

In the C++ standard, std::ios::openmode, std::ios::fmtflags and std::ios::iostate are implementation defined. But std::ios::goodbit is standardized to be equal to zero. My question is : can these bitmask be casted to boolean values according to the standard. In other words, to test if an error flag is set, can we type :

inline void myFunction(std::ios::iostate x = std::ios::goodbit) 
{
    if (x) { // <- is it ok or do I have to type "if (x != std::ios::goodbit)" ?
        /* SOMETHING */    
    }
}
  • 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-12T09:13:08+00:00Added an answer on June 12, 2026 at 9:13 am

    No this is not portable code. std::ios::iostate is a Bitmask type which, according to the C++ standard (17.5.2.1.3):

    Each bitmask type can be implemented as an enumerated type that overloads certain operators, as an integer type, or as a bitset

    If iostate is implemented in terms of the latter case, then your code will fail to compile as std::bitset has neither an operator bool nor is it implicitly convertible to an integral type (as in your case).

    Note:
    The following fails to compile:

      std::bitset<8> b;
      return (b) ? 1 : 0;
    

    while this works:

      std::bitset<8> b;
      return (b != 0) ? 1 : 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The C++ standard library offers std::mutex (lock, unlock, try_lock) functionality, that can work within
Standard containers with an std::allocator have their size_type defined as std::size_t . However, is
The standard ios class overrides the void * operator such that it can be
The standard library provides std::advance , but that only advances an iterator to a
I am trying to convert a standard std::string into an NSString but I'm not
In standard library, I found that namespace std is declared as a macro. #define
If all of the members of std::tuple are of standard layout types , is
I am reading the IEEE Standard Verilog Hardware Description Language (specifically IEEE Std 1364-2001)
Why definition of std::function<>::operator() in the C++ standard is: R operator()(ArgTypes...) const; and not
I'm looking for a standard dual-map structure - is there one implemented in std/boost/another

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.