literal for one day

Hi,

I have:

1
2
time_point<system_clock> tp;
tp += days{ 1 } + 23h + 55min; 	// days{1} + hours{23} + minutes{55}; 



I tried to use the literal for one day instead of days{1}, that is 1d, but the new line does not compile:

 
tp += 1d;



what is going on?


Regards,
Juan
using namespace std::literals::chrono_literals;

This operator is declared in the namespace std::literals::chrono_literals, where both literals and chrono_literals are inline namespaces. Access to this operator can be gained with:
using namespace std::literals,
using namespace std::chrono_literals, or
using namespace std::literals::chrono_literals.

In addition, within the namespace std::chrono, the directive using namespace literals::chrono_literals; is provided by the standard library, so that if a programmer uses using namespace std::chrono; to gain access to the classes in the chrono library, the corresponding literal operators become visible as well.

https://en.cppreference.com/w/cpp/chrono/operator%22%22d
One thing is the literal d, which is a cast from ull to std::chrono::day
as in:

1
2
3
4
5
inline namespace chrono_literals 
{
constexpr day operator""d(unsigned long long _Day) noexcept {
            return day{static_cast<unsigned int>(_Day)}; }
}


and yet another is days which is a duration...

so how can one add a day's duration to a time_point using a literal (since d is not a duration)

1
2
time_point<system_clock> tp;
tp += 1XXXX ;                


what is XXXX?
A std literal for days does not exists. See this:

https://en.cppreference.com/w/cpp/chrono/duration

You may use hours instead.
A std literal for days does not exists.

The day literal has existed since C++20, along with a year literal. Look at the link JLBorges gave.

A month literal doesn't exist, despite the fact that C++20 added a whole lot of extended functionality to the chrono library.

https://en.cppreference.com/w/cpp/header/chrono
@George P

day (of month) exists but days (duration) does not exist as literal.
Topic archived. No new replies allowed.