I recently read that the literal suffices like s
, h
, ms
etc in C++14 have been put in the namespace std::literals
. So if I'm to use them then I should either include the namespace or use std::literals::
to denote those suffixes. However when I tried the following program (cpp.sh/9ytu) without using any of the above I got the required output :-
#include <iostream>
#include <thread>
using namespace std;
int main()
{
auto str = "He is there"s;
auto timegap = 1s;
cout << "The string is :-" << endl;
this_thread::sleep_for(timegap);
cout << str;
return 0;
}
/*Output:-
The string is :-
He is there
*/
As you can see I haven't included any namespace
or std::literals::
still my program runs correctly. I tried this in Orwell DevC++, C++ Shell, Coliru & got the same output everywhere. What's the issue ?
literals
and chrono_literals
are inline namespaces - see [time.syn] in this particular case:
inline namespace literals {
inline namespace chrono_literals {
// 20.12.5.8, suffixes for duration literals
constexpr chrono::hours h(unsigned long long);
[…]
Therefore, due to using namespace std;
, all UDLs are found.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With