Introduction
The c++ (cpp) weekday_indexed example is extracted from the most popular open source projects, you can refer to the following example for usage.
Programming language: C++ (Cpp)
Class/type: weekday_indexed
Example#1File:
ctor.pass.cppProject:
lichray/libcxx
int main()
{
using weekday = std::chrono::weekday;
using weekday_indexed = std::chrono::weekday_indexed;
ASSERT_NOEXCEPT(weekday_indexed{});
ASSERT_NOEXCEPT(weekday_indexed(weekday{1}, 1));
constexpr weekday_indexed wdi0{};
static_assert( wdi0.weekday() == weekday{}, "");
static_assert( wdi0.index() == 0, "");
static_assert(!wdi0.ok(), "");
constexpr weekday_indexed wdi1{std::chrono::Sunday, 2};
static_assert( wdi1.weekday() == std::chrono::Sunday, "");
static_assert( wdi1.index() == 2, "");
static_assert( wdi1.ok(), "");
for (unsigned i = 1; i <= 5; ++i)
{
weekday_indexed wdi(std::chrono::Tuesday, i);
assert( wdi.weekday() == std::chrono::Tuesday);
assert( wdi.index() == i);
assert( wdi.ok());
}
for (unsigned i = 6; i <= 20; ++i)
{
weekday_indexed wdi(std::chrono::Tuesday, i);
assert(!wdi.ok());
}
}
Example#2File:
weekday_indexed.pass.cppProject:
mitsutaka-takeda/date
int
main()
{
using namespace date;
constexpr weekday_indexed wdi = sun[1];
static_assert(wdi.weekday() == sun, "");
static_assert(wdi.index() == 1, "");
static_assert(wdi.ok(), "");
static_assert(wdi == weekday_indexed{sun, 1}, "");
static_assert(wdi != weekday_indexed{sun, 2}, "");
static_assert(wdi != weekday_indexed{mon, 1}, "");
std::ostringstream os;
os << wdi;
assert(os.str() == "Sun[1]");
}