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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:49:26+00:00 2026-05-26T17:49:26+00:00

From an example [1] in the documentation for boost::iterator_facade: class node_iterator : public boost::iterator_facade<

  • 0

From an example [1] in the documentation for boost::iterator_facade:

class node_iterator : public boost::iterator_facade< /* ... */ >
{
 public:  node_iterator() : m_node(0) { } 
          /* ... */
 private: node_base* m_node;
};

Followed by a footnote:

Technically, the C++ standard places almost no requirements on a default-constructed iterator, so if we were really concerned with efficiency, we could’ve written the default constructor to leave m_node uninitialized.

My question (two parts):

(a) What requirements does the C++ standard place on a default-constructed iterator?

(b) Why would leaving out m_node(0) avoid initializing m_node when instantiating a node_iterator? Wouldn’t m_node then be default-initialized (thus zero-initialized) anyway?

[1] http://www.boost.org/doc/libs/1_47_0/libs/iterator/doc/iterator_facade.html#constructors-and-data-members
(nb: Although this question originated from a boost example, I believe it applies to STL iterators, thus I did not use a “boost” tag.)

  • 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-05-26T17:49:26+00:00Added an answer on May 26, 2026 at 5:49 pm

    Why would leaving out m_node(0) avoid initializing m_node when instantiating a node_iterator?

    Just because the default constructor for a node_iterator is called does not mean that the non-static data-members of the class itself are properly initialized, especially if no initialization is specified for those data-members. This includes omitting those non-static data-members from the constructor initialization list. Furthermore, m_node is a pointer, and therefore a POD-type, thus it does not have a default-constructor that would be called to construct the object before entering the body of the constructor for node_iterator itself. Therefore omitting m_node from the initializer list would avoid specifically initializing the m_node data_member.

    Wouldn’t m_node then be default-initialized (thus zero-initialized) anyway?

    Per the C++03 spec, section 8.5/9, a non-static object (which also includes a non-static data-member of a class) is initialized with an “indeterminant” value if no initializer is specified for that object. A non-static object is only default-initialized if it is a non-POD class type and/or a const-qualified type. In this case m_node is a pointer-type, and is therefore a POD-type, so it is not zero-initialized … it’s just “initialized” with whatever pre-existing value was in memory at the location of the variable, thus making it an “indeterminant” value that it’s initialized with.

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

Sidebar

Related Questions

I couldn't figure out that from SASS documentation. For example I would like to
From the documentation on the boost site for lexical cast it states that when
For example, I tried following example from documentation : =TEXT(WEEKDAY([Column1]), dddd) But it won't
The CreateSpreadsheetWorkbook example method from the OpenXml documentation does translate directly to F#. The
Following example from this link: http://developer.kde.org/documentation/books/kde-2.0-development/ch03lev1sec3.html #include <QObject> #include <QPushButton> #include <iostream> using namespace
Borrowing from the example on the Matplotlib documentation page and slightly modifying the code,
I am trying to implement one of the first examples from boost::random documentation in
I try to use doctest from example from http://docs.python.org/library/doctest.html But when I run python
Provide an example for the pseudo-regex: Match every url except those from example.com and
For example: from datetime import <c-x><c-o>{list of modules inside datetime package}

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.