私は次のことができるようにしたいと思います:
std::cerr << std::chrono::system_clock::now() << std::endl;
そして、以下を取得します。
Wed May 1 11:11:12 2013
だから私は次のように書いた:
template<typename Clock, typename Duration>
std::ostream &operator<<(std::ostream &stream,
const std::chrono::time_point<Clock, Duration> &time_point) {
const time_t time = Clock::to_time_t(time_point);
#if __GNUC__ > 4 || \
((__GNUC__ == 4) && __GNUC_MINOR__ > 8 && __GNUC_REVISION__ > 1)
// Maybe the put_time will be implemented later?
struct tm tm;
localtime_r(&time, &tm);
return stream << std::put_time(tm, "%c");
#else
char buffer[26];
ctime_r(&time, buffer);
buffer[24] = '\0'; // Removes the newline that is added
return stream << buffer;
#endif
}
これは機能しますが、これを別の名前空間から呼び出すと問題が発生し続けます。これはグローバル名前空間にあるべきであるというのは正しいですか?