2014-09-17 9 views
2

나는 오래된 프로젝트를 수정하고 있으며, 동시에 C++ 11로 가져 오기 위해 몇 가지를 업데이트하고있다.boost :: date_time :: not_a_date_time에 해당하는 C++ 11은 무엇입니까?

나는 boost :: date_time의 다양한 용도를 std :: chrono의 새로운 기능으로 대체하고 싶습니다. 하지만 boost :: date_time :: not_a_date_time의 C++ 11 코드는 무엇인지 알 수 없습니다.

C++ 11에는 time_point 변수가 아직 지정되지 않았거나 유효한 시간 소인이 포함되어 있지 않음을 나타내는 해당 값이 없습니까?

+0

약간 혼란 스럽네요. "잘못된"std :: chrono :: time_point'를 어떻게 만듭니 까? [생성자] (http://en.cppreference.com/w/cpp/chrono/time_point/time_point)는 "유효한"시간 지점 만 만들 수 있습니다. – dyp

+0

@dyp 그게 내가 가지고있는 문제 야. 나는 std :: chrono로 어떻게하는지 알 수 없다. Boost :: date_time - 내가 대체하기를 원하는 라이브러리 - 생성자는 boost :: date_time :: not_a_date_time 중 하나 인 "특수 값"을 열거 할 수 있습니다. http://www.boost.org/doc/libs/1_56_0/doc/html/date_time/doxy.html#header.boost.date_time.special_defs_hpp –

+1

아, 문제를 이해하기 시작했습니다. 'std :: chrono'는'boost :: date_time'이 아닌'boost :: chrono'와 관련이 있습니다. – dyp

답변

1

은 그룹의 일부로서 존재한다는 사실을 감안할 때

bool is_infinity() const 
bool is_neg_infinity() const 
bool is_pos_infinity() const 
bool is_not_a_date_time() const 

는이 내부 표현에 대한 부동 소수점 형식을 사용하고 값을 설정하여 수행 꽤 분명하다 NaN (not-a-number).

std::chrono에서 표현 유형은 산술 유형이어야합니다. 따라서 부동 소수점 유형이 적합하며 동일한 트릭을 사용할 수 있습니다.

std::duration을 감안할 때, 당신은 다음

을 (부동 소수점 트랩을 트리거하지 않도록 당신이 조용한 NaN의 값이 아닌 신호 NaN이를 사용한다, 당연히)

std::isnan(dur.count()) 

사용하여 테스트 할 수

+0

나는이 대답을 이해할 수 없다. not_a_date_time의 열거 형이 부동 소수점 유형이고 그 것이 사실이라고 가정 할 때 명확한 점은 무엇입니까 (http://www.boost.org/doc/libs/1_56_0/doc/html/date_time/doxy.html#header.boost .date_time.special_defs_hpp) 어떻게하면 std :: chrono에서 같은 기능을 얻을 수 있습니까? –

+0

@ Stéphane : 'boost :: date_time'의 특수 값은 IEEE 부동 소수점 유형의 특수 값과 정확히 일치합니다. 'std :: chrono'의 모든 타입은 산술 타입과 유닛에 ('std :: chrono :: duration'을 통해) 매개 변수화됩니다. 그 산술 타입은'float' 또는'double' 일 수 있습니다. –

+0

또한 'chrono :: duration'의 'rep'는 산술 유형을 에뮬레이트하는 클래스 유형이 될 수 있습니다. 따라서 NaN에 대해 값 (예 :'LLONG_MIN') 중 하나를 예약 한 정수 기반의 'Number'클래스를 생성하고 그에 따라 산술을 구현할 수 있습니다. –

1

boost::date_timeboost/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; 
} 

본질적으로 특별한 의미를 갖기 위해 특정 정수 값을 예약합니다.

그러나 다른 사람들이 지적한대로 std::chrono에는 이러한 특수 값 (단지 min and max functions)이 없습니다. std::numeric_limits도 특수하지 않습니다 (Why does std::numeric_limits<seconds>::max() return 0? 참조).

Ben Voigt's answer은 가능한 해결 방법을 제시하지만 클래스는 이러한 의미를 지정하지 않으므로 직접 작성하지 않은 함수에 NaN 타임 스탬프 또는 기간을 건네면 정의되지 않은 동작이 트리거 될 수 있습니다.