mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-04 13:14:26 +02:00
Updated FAQ (markdown)
10
FAQ.md
10
FAQ.md
@@ -27,29 +27,29 @@ The programmer would probably use it like this:
|
|||||||
year_month_day
|
year_month_day
|
||||||
get_meeting_date(year y, month m)
|
get_meeting_date(year y, month m)
|
||||||
{
|
{
|
||||||
return year_month_day{tue[3]/m/y + days{1}};
|
return year_month_day{Tuesday[3]/m/y + days{1}};
|
||||||
}
|
}
|
||||||
|
|
||||||
That is super-compact syntax! Here is what it costs:
|
That is super-compact syntax! Here is what it costs:
|
||||||
|
|
||||||
1. Convert `tue[3]/m/y` (`year_month_weekday`) to `sys_days` in order to add `days`.
|
1. Convert `Tuesday[3]/m/y` (`year_month_weekday`) to `sys_days` in order to add `days`.
|
||||||
2. Convert the `sys_days` computed back to `year_month_weekday`.
|
2. Convert the `sys_days` computed back to `year_month_weekday`.
|
||||||
3. Convert the temporary `year_month_weekday` computed in 2 back to `sys_days`.
|
3. Convert the temporary `year_month_weekday` computed in 2 back to `sys_days`.
|
||||||
4. Convert the `sys_days` to a `year_month_day`.
|
4. Convert the `sys_days` to a `year_month_day`.
|
||||||
|
|
||||||
4 conversions.
|
4 conversions.
|
||||||
|
|
||||||
Here is the way you have to write this function today (because `tue[3]/m/y + days{1}` is a compile-time error):
|
Here is the way you have to write this function today (because `Tuesday[3]/m/y + days{1}` is a compile-time error):
|
||||||
|
|
||||||
year_month_day
|
year_month_day
|
||||||
get_meeting_date(year y, month m)
|
get_meeting_date(year y, month m)
|
||||||
{
|
{
|
||||||
return year_month_day{sys_days{tue[3]/m/y} + days{1}};
|
return year_month_day{sys_days{Tuesday[3]/m/y} + days{1}};
|
||||||
}
|
}
|
||||||
|
|
||||||
The syntax is slightly more verbose in that you have to explicitly convert the `year_month_weekday` into a `sys_days` in order to perform the day-oriented arithmetic. Here is what it costs:
|
The syntax is slightly more verbose in that you have to explicitly convert the `year_month_weekday` into a `sys_days` in order to perform the day-oriented arithmetic. Here is what it costs:
|
||||||
|
|
||||||
1. Convert `tue[3]/m/y` (`year_month_weekday`) to `sys_days` in order to add `days`.
|
1. Convert `Tuesday[3]/m/y` (`year_month_weekday`) to `sys_days` in order to add `days`.
|
||||||
2. Convert the `sys_days` to a `year_month_day`.
|
2. Convert the `sys_days` to a `year_month_day`.
|
||||||
|
|
||||||
2 conversions. Roughly twice as fast!
|
2 conversions. Roughly twice as fast!
|
||||||
|
Reference in New Issue
Block a user