Namespaces
Variants

cpp/utility/bitset/operator at: Difference between revisions

From cppreference.com
adding header
Space Mission (talk | contribs)
m {{p}} (for “paragraph”) gives lesser V offset.
 
(23 intermediate revisions by 10 users not shown)
Line 1: Line 1:
{{cpp/utility/bitset/title | operator[]}}
{{cpp/utility/bitset/title|operator[]}}
{{cpp/utility/bitset/sidebar}}
{{cpp/utility/bitset/}}
{{ddcl list begin}}
{{begin}}
{{ddcl list item | num=1 |
{{|num=1|
bool operator[]( size_t pos ) const;
bool operator[]( size_t pos ) const;
}}
}}
{{ddcl list item | num=2 |
{{|num=2|
reference operator[]( size_t pos );
reference operator[]( size_t pos );
}}
}}
{{ddcl list end}}
{{end}}


Accesses the bit at position {{tt|pos}}. The first version returns the value of the bit, the second version returns an object of type {{ltt|todo|reference}} that allows modification of the value.
Accesses the bit at position {{|pos}}.
the value of the bit
an object of type {{|reference}} that allows modification of the value.
 


===Parameters===
===Parameters===
{{param list begin}}
{{begin}}
{{param list item | pos | position of the bit to return}}
{{|pos|position of the bit to return}}
{{param list end}}
{{end}}


===Return value===
===Return value===
1) the value of the requested bit
1the
 
of the requested bit


2) an object of type [[cpp/utility/bitset/reference|reference]] with the value of the bit.
.


===Example===
===Example===
{{example cpp
{{example
| code=
|code=
#include <iostream>
#include <iostream>
#include <bitset>


int main()  
int main()
{
{
     std::bitset<8> b1(42);
     std::bitset<8> b142
     for (int i = 0; i < b1.size(); ++i) {
     for (i = 0; i < b1.size(); ++i)
         std::cout << "b1[" << i << "]: " << b1[i] << '\n';
         std::cout << "b1[" << i << "]: " << b1[i] << '\n';
     }
    
     return 0;
     0;
}
}
| output=
|output=
b1[0]: 0
b1[0]: 0
b1[1]: 1
b1[1]: 1
Line 45: Line 56:
b1[6]: 0
b1[6]: 0
b1[7]: 0
b1[7]: 0
}}
}}




===See also===
===See also===


{{dcl list begin}}
{{|}}
{{dcl list template | cpp/utility/bitset/dcl list test}}
{{dcl list end}}

Latest revision as of 04:54, 28 March 2025

 
 
Utilities library
General utilities
Relational operators (deprecated in C++20)