std::bitset::test
De cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody> bool test( size_t pos ) const; |
||
Retorna o valor do bit no
pos posição.Original:
Returns the value of the bit at the position
pos.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Ao contrário
operator[](), realiza uma verificação de limites e joga std::out_of_range se pos não corresponde a uma posição válida no bitset.Original:
Unlike
operator[](), performs a bounds check and throws std::out_of_range if pos does not correspond to a valid position in the bitset.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Parâmetros
| pos | - | posição do bit para retornar
Original: position of the bit to return The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Valor de retorno
true se o bit solicitado está definido, caso contrário false.Original:
true if the requested bit is set, false otherwise.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Exceções
std::out_of_range se
pos não corresponde a uma posição válida no bitset.Original:
std::out_of_range if
pos does not correspond to a valid position within the bitset.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Exemplo
#include <iostream>
#include <bitset>
int main()
{
std::bitset<10> b1("1111010000");
size_t idx = 0;
while (idx < b1.size() && !b1.test(idx)) {
++idx;
}
if (idx < b1.size()) {
std::cout << "first set bit at index " << idx << '\n';
} else {
std::cout << "no set bits\n";
}
return 0;
}
Saída:
first set bit at index 4
Veja também
acessa pouco específico Original: accesses specific bit The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (função pública membro) | |