GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
std::bitset::reference(3) C++ Standard Libary std::bitset::reference(3)

std::bitset::reference - std::bitset::reference


class reference;


The std::bitset class includes std::bitset::reference as a publicly-accessible
nested class. This class is used as a proxy object to allow users to interact with
individual bits of a bitset, since standard C++ types (like references and pointers)
are not built with enough precision to specify individual bits.


The primary use of std::bitset::reference is to provide an l-value that can be
returned from operator[].


Any reads or writes to a bitset that happen via a std::bitset::reference potentially
read or write to the entire underlying bitset.


constructor constructs the reference. Accessible only to std::bitset itself
(private member function)
destructor destroys the reference
(public member function)
operator= assigns a bool to the referenced bit
(public member function)
operator bool returns the referenced bit
(public member function)
operator~ returns inverted referenced bit
(public member function)
flip flips the referenced bit
(public member function)

std::bitset<N>::reference::~reference


~reference(); (until C++23)
constexpr ~reference(); (since C++23)


Destroys the reference.

std::bitset<N>::reference::operator=


reference& operator=( bool x ); (until C++11)
reference& operator=( bool x ) noexcept; (since C++11)
(until C++23)
constexpr reference& operator=( bool x ) (since C++23)
noexcept; (1)
reference& operator=( const reference& x ); (until C++11)
reference& operator=( const reference& x ) (since C++11)
noexcept; (2) (until C++23)
constexpr reference& operator=( const reference& (since C++23)
x ) noexcept;


Assigns a value to the referenced bit.


x - value to assign

Return value


*this

std::bitset<N>::reference::operator bool


operator bool() const; (until C++11)
operator bool() const noexcept; (since C++11)
(until C++23)
constexpr operator bool() const noexcept; (since C++23)


Returns the value of the referenced bit.


(none)

Return value


The referenced bit.

std::bitset<N>::reference::operator~


bool operator~() const; (until C++11)
bool operator~() const noexcept; (since C++11)
(until C++23)
constexpr bool operator~() const noexcept; (since C++23)


Returns the inverse of the referenced bit.


(none)

Return value


The inverse of the referenced bit.

std::bitset<N>::reference::flip


reference& flip(); (until C++11)
reference& flip() noexcept; (since C++11)
(until C++23)
constexpr reference& flip() noexcept; (since C++23)


Inverts the referenced bit.


(none)

Return value


*this

// Run this code


#include <bitset>
#include <iostream>


int main()
{
std::bitset<4> bs( 0b1110 );


std::bitset<4>::reference ref = bs[2]; // auto ref = bs[2];


auto info = [&](int n) {
std::cout << n << ") bs: " << bs << "; ref bit: " << ref << '\n';
};


info(1);
ref = false;
info(2);
ref = true;
info(3);
ref.flip();
info(4);
ref = bs[1]; // operator=( const reference& x )
info(5);


std::cout << "6) ~ref bit: " << ~ref << '\n';
}


1) bs: 1110; ref bit: 1
2) bs: 1010; ref bit: 0
3) bs: 1110; ref bit: 1
4) bs: 1010; ref bit: 0
5) bs: 1110; ref bit: 1
6) ~ref bit: 0


operator[] accesses specific bit
(public member function)

2022.07.31 http://cppreference.com

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.