C ++ 11等效于boost :: date_time :: not_a_date_time是什么? [英] What is the C++11 equivalent to boost::date_time::not_a_date_time?

查看:157
本文介绍了C ++ 11等效于boost :: date_time :: not_a_date_time是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改一个旧项目,同时我在更新一些内容以将其升级到C ++ 11。

I'm modifying an old project, and at the same time I'm updating several things to bring it up to C++11.

想要用std :: chrono中的新功能替换boost :: date_time的各种用法。但是我不知道boost :: date_time :: not_a_date_time的C ++ 11等价物是什么。

I'd like to replace various uses of boost::date_time with the new functionality in std::chrono. But I cannot figure out what is the C++11 equivalent of boost::date_time::not_a_date_time.

在C ++ 11中没有等价物来指示

Isn't there an equivalent in C++11 to indicate that a time_point variable hasn't yet been assigned, or doesn't contain a valid timestamp?

推荐答案

boost :: date_time 在内部使用整数时间表示,并在 boost / date_time / int_adapter.hpp

boost::date_time uses integer time representations internally, and defines the special values inside boost/date_time/int_adapter.hpp:

static const int_adapter  pos_infinity()
{
  return (::std::numeric_limits<int_type>::max)();
}
static const int_adapter  neg_infinity()
{
  return (::std::numeric_limits<int_type>::min)();
}
static const int_adapter  not_a_number()
{
  return (::std::numeric_limits<int_type>::max)()-1;
}
static  int_adapter max BOOST_PREVENT_MACRO_SUBSTITUTION ()
{
  return (::std::numeric_limits<int_type>::max)()-2;
}
static  int_adapter min BOOST_PREVENT_MACRO_SUBSTITUTION ()
{
  return (::std::numeric_limits<int_type>::min)()+1;
}

本质上,它保留某些整数值具有特殊含义。

Essentially, it reserves certain integer values to have special meanings.

但是,正如其他人指出的那样, std :: chrono 不提供这些特殊值(只有 min max 个函数);和 std :: numeric_limits 也不是专门的(请参见为什么std :: numeric_limits< seconds> :: max()返回0?)。

However, as others have pointed out, std::chrono does not offer these special values (there are only min and max functions); and std::numeric_limits is also not specialized (see Why does std::numeric_limits<seconds>::max() return 0?).

Ben Voigt的答案提供了一种可能的解决方法,但请注意,由于 std :: chrono 类不会指定此类语义,将NaN时间戳或持续时间交给您自己未编写的任何函数,很可能会触发未定义的行为。

Ben Voigt's answer presents a possible workaround, but be aware that since the std::chrono classes do not specify such semantics, handing a NaN timestamp or duration to any function you did not write yourself is likely going to trigger undefined behaviour.

这篇关于C ++ 11等效于boost :: date_time :: not_a_date_time是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆