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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:33:19+00:00 2026-05-23T01:33:19+00:00

From http://www.cplusplus.com/reference/stl/bitset/ : Because no such small elemental type exists in most C++ environments,

  • 0

From http://www.cplusplus.com/reference/stl/bitset/:

Because no such small elemental type exists in most C++ environments, the individual elements are accessed as special references which mimic bool elements.

How, exactly, does this bit reference work?

The only way I could think of would be to use a static array of chars, but then each instance would need to store its index in the array. Since each reference instance would have at least the size of a size_t, that would destroy the compactness of the bitset. Additionally, resizing may be slow, and bit manipulation is expected to be fast.

  • 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-23T01:33:20+00:00Added an answer on May 23, 2026 at 1:33 am

    I think you are confusing two things.

    The bitset class stores the bits in a compact representations, e.g. in a char array, typically 8 bits per char (but YMMV on “exotic” platforms).

    The bitset::reference class is provided to allow users of the bitset class to have reference-like objects to the bits stored in a bitset.

    Because regular pointers and references don’t have enough granularity to point to the single bits stored in the bitset (their minimum granularity is the char), such class mimics the semantic of a reference to fake reference-like lvalue operations on the bits. This is needed, in particular, to allow the value returned by operator[] to work “normally” as an lvalue (and it probably costitutes 99% of its “normal” use). In this case it can be seen as a “proxy-object”.

    This behavior is achieved by overloading the assignment operator and the conversion-to-bool operator; the bitset::reference class will probably encapsulate a reference to the parent bitset object and the offset (bytes+bit) of the referenced bit, that are used by such operators to retrieve and store the value of the bit.

    —EDIT—

    Actually, the g++ implementation makes the bitset::reference store directly a pointer to the memory word in which the byte is stored, and the bit number in such word. This however is just an implementation detail to boost its performance.

    By the way, in the library sources I found a very compact but clear explanation of what bitset::reference is and what it does:

      /**
       *  This encapsulates the concept of a single bit.  An instance of this
       *  class is a proxy for an actual bit; this way the individual bit
       *  operations are done as faster word-size bitwise instructions.
       *
       *  Most users will never need to use this class directly; conversions
       *  to and from bool are automatic and should be transparent.  Overloaded
       *  operators help to preserve the illusion.
       *
       *  (On a typical system, this <em>bit %reference</em> is 64
       *  times the size of an actual bit.  Ha.)
       */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I downloaded the STL source code from http://www.sgi.com/tech/stl/download.html , but it only has the
Js File //Modified from http://www.beyondstandards.com/archives/input-placeholders/ function activatePlaceholders() { var detect = navigator.userAgent.toLowerCase(); if (detect.indexOf(safari)
How to display contents from www directory for http://www.website.com i..e when a user visits
I am trying to run this snippet from http://www.ibm.com/developerworks/linux/library/l-prog3.html on a python 2.6 runtime.
I'm trying to run 'Sencha Command' from http://www.sencha.com/products/touch/ SDK on windows, but i just
i'm doing Android Live Wallpaper programmitically.I tried an example from http://www.codeproject.com/KB/Android/AndroidLiveWallpaper.aspx .WHen i run..i
I am currently using this JQuery datepicker from http://www.eyecon.ro/datepicker/ . I have looked through
I getting this error when retrieve xml request from http://www.cbr.ru/scripts/XML_daily.asp XML code like this:
So I'm attempting to utilize a generic compare functor in my utility class. I
class A {}; class B { public: B (A a) {} }; A a;

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.