std::chrono::weekday::ok
Von cppreference.com
| constexpr bool ok() const noexcept; |
(seit C++20) | |
Prüft, ob der in *this gespeicherte Wochentagswert im gültigen Bereich liegt, d.h. [0, 6].
[edit] Rückgabewert
true, wenn der in *this gespeicherte Wochentagswert im Bereich [0, 6] liegt. Andernfalls false.
[edit] Beispiel
Führen Sie diesen Code aus
#include <chrono> #include <iomanip> #include <iostream> #include <locale> #include <string> struct weekday_ok : std::numpunct<char> { std::string do_truename() const override { return " (is valid weekday)"; } std::string do_falsename() const override { return " (is not valid weekday)"; } }; int main() { std::cout.imbue(std::locale(std::cout.getloc(), new weekday_ok)); std::cout << std::boolalpha; for (const unsigned u : {0 /* Sun */, 1 /* Mon */, 6, 7 /* Sun */, 8, 9}) { const std::chrono::weekday wd{u}; std::cout << "u: " << u << "; wd: " << wd.c_encoding() << wd.ok() << '\n'; } }
Ausgabe
u: 0; wd: 0 (is valid weekday) u: 1; wd: 1 (is valid weekday) u: 6; wd: 6 (is valid weekday) u: 7; wd: 0 (is valid weekday) u: 8; wd: 8 (is not valid weekday) u: 9; wd: 9 (is not valid weekday)
[edit] Siehe auch
| ruft den gespeicherten Wochentagswert ab ruft den ISO 8601 Wochentagswert ab (public member function) |