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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:22:09+00:00 2026-06-05T09:22:09+00:00

Boost.Optional uses a dummy type to allow constructing uninitialized instances of boost::optional<T> . This

  • 0

Boost.Optional uses a dummy type to allow constructing uninitialized instances of boost::optional<T>. This type is called none_t, and an instance none is already defined in a header for convenience, allowing us to write code such as the following:

boost::optional<int> uninitialized(boost::none);

Looking at the definition of none_t, I noticed that it is in fact a typedef corresponding to a pointer-to-member to some dummy struct:

namespace boost {

namespace detail { struct none_helper{}; }

typedef int detail::none_helper::*none_t ;

none_t const none = (static_cast<none_t>(0)) ;

} // namespace boost

What are the advantages of using such a convoluted typedef over a simple empty struct like this?

namespace boost {

struct none_t {};

none_t const none;

} // namespace boost
  • 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-05T09:22:10+00:00Added an answer on June 5, 2026 at 9:22 am

    Ah, I had never thought to dig deeper.

    One (more or less obvious) advantage to a regular struct, is that now none evaluates to false in boolean contexts.

    One advantage over another “evaluates to false” is that pointer to member are prevented from harmful promotion to integral types.

    So, I guess that it offers a safe and concise way of having a object that evaluates to false.

    EDIT: One should recognize here (hum…) the structure of the Safe Bool Idiom.

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

Sidebar

Related Questions

I have a container class which uses boost::optional to hold the value. Here is
How I can prevent the last line of this code from compiling? #include <boost/optional.hpp>
Boost Network I am trying out this code in a small console app on
Are boost ptime instances always UTC? I can't see any time zone info on
In boost 1.48.0 I find this in the regex code (boost/regex/v4/ w32_regex_traits.hpp ): w32_regex_traits()
How can I reset/unset a boost::optional ? optional<int> x; if( x ) { //
In this new episode of the saga Me vs Boost, libconfig, protocol buffers and
Boost lambda allows to overwrite deduced return type using ret<T> template. I have tried
Currently, I am using a type-safe enum class from Boost Vault : Which Typesafe
The boost ptr_list documentation states that the container uses an underlying std::list<void*> . Why

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.