|
BDE 4.14.0 Production release
|
Provide an ordered set of (unique) bdlt::DayOfWeek::Enum values.
bdlt::DayOfWeek::Enum valuesThis component implements an efficient value-semantic, ordered set class, bdlt::DayOfWeekSet, for elements of the bdlt::DayOfWeek::Enum enumeration. As there are only seven possible element values, asymptotic performance characterization is not appropriate; all operations implicitly run in constant time and provide the no-throw guarantee.
In addition to the standard value-semantic operators =, ==, !=, and <<, the following canonical set of binary and unary (free) operators are defined on bdlt::DayOfWeekSet objects:
The corresponding assignment (member) operators |= , &=, ^=, and -= (but not ~=) are also provided.
This section illustrates intended use of this component.
A bdlt::DayOfWeekSet is useful for recording recurring appointments, or special days (e.g., weekend days), in a calendar. The following snippets of code illustrate how to create and use a bdlt::DayOfWeek set.
First, we create a couple of commonly useful sets. First we define the bdlt::DayOfWeekSet weekendDays:
Then, we notice that this set is initially empty.
Next, we add the days that characterize weekends:
Then, we observe that weekendDays now contains precisely the days we expect it to contain:
Next, we create the complementary bdlt::DayOfWeekSet weekDays directly from weekendDays via a combination of unary negation and copy construction:
Then, to create a set containing all of the days in the week, we do so via unary negation of the default constructed value:
Next, we observe that neither weekDays nor weekendDays represent the same value as ALL_DAYS, but their union does:
Then, we observe that similarly, neither weekDays nor weekendDays represents the same value as NO_DAYS, but their intersection does:
Next, we create the corresponding set eDays consisting of the only days of the week that have an E in them: TUESDAY and WEDNESDAY:
Then, we create a set consisting of days that have an n in them: MONDAY, WEDNESDAY, and SUNDAY. We create the corresponding set nDays starting with the value of eDays by first removing TUESDAY, and then adding SUNDAY and MONDAY:
Next, we observe that all eDays are weekDays, but that's not true of nDays:
Now, we observe that iteration order is defined by increasing enumerated bdlt::DayOfWeek::Day value [ SUN .. SAT ]. The following use of the forward (bi-directional) iterator:
produces:
on standard output.
Finally, we observe that, similarly, the following use of the reverse iterator:
produces: