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

  • Home
  • SEARCH
  • 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 67421
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:15:26+00:00 2026-05-10T19:15:26+00:00

Several times, while perusing the Boost library’s documentation, I’ve run across return values that

  • 0

Several times, while perusing the Boost library’s documentation, I’ve run across return values that are marked ‘convertible to bool‘ (search that page for the phrase ‘convertible to bool’, it’s about a third of the way down). I once stumbled across an oblique reference to a paper explaining the reason for that, but have never been able to find said paper (and I can no longer find the page I saw the reference on either).

Can anyone explain why (and when) you should return something that’s ‘convertible to bool‘ rather than simply returning a bool?

  • 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. 2026-05-10T19:15:26+00:00Added an answer on May 10, 2026 at 7:15 pm

    “convertible to bool” simply means anything which can meaningfully be used in a boolean context (e.g. in an if condition). This makes sense in implicit conversions. Imagine an object which you want to use in a boolean context, e.g. std::fstream:

    ifstream ifs('filename'); while (ifs >> token)     cout 'token ' << token << ' read.' << endl; 

    Here, ifs is convertible to boolean. Well, actually, it isn’t. Rather, it is convertible to something that, in turn, is convertible to bool. This is to prevent such statements:

    int b = ifs; 

    The reasoning is that such a statement is most probably not intended and the compiler should therefore prevent it. By returning a “convertible to bool” rather than a bool, this is achieved because two user-defined implicit conversions can’t be chained in one expression.

    In this context, you might want to look up the safe bool idiom. Chris has already alluded to one possible implementation, using void* as a return type. Usually, the this pointer is then used to represent true. This is what gets used by the STL. However, this is unfortunately still flawed. Several alternatives have been proposed (neatly wrapped up in the article I’ve linked above) and as far as I know, have also been included into C++0x for consideration. I’m not aware of the current status of these proposals, though.

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

Sidebar

Ask A Question

Stats

  • Questions 63k
  • Answers 63k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer On the storyboard there is a SpeedRatio setting which is… May 11, 2026 at 10:38 am
  • added an answer If what you really are looking for is the wp_title… May 11, 2026 at 10:38 am
  • added an answer If you already have extensive C code that was used… May 11, 2026 at 10:38 am

Related Questions

Several times, while perusing the Boost library's documentation, I've run across return values that
Several times now I've been faced with plans from a team that wants to
Several times in my career, I have worked in a software group that determined
I've tried to do this several times with no luck. After reading this post
I have heard the 'shard' technique mentioned several times with regard to solving scaling
I have had to do this several times, usually when trying to find in
I'm seeing this error several times an hour on my production site and am
I have implemented authentication systems for webapps several times over the years, but before
I tried to install Delphi 7 on Vista several times and Vista prevented me
I'm getting the error: wintypes.dcu not found several times a day in the Delphi

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.