2017-01-25 27 views

回答

7

您可以執行自己的類型特徵來檢查chrono::duration。事情是這樣的:

template<class T> 
struct is_duration : std::false_type {}; 

template<class Rep, class Period> 
struct is_duration<std::chrono::duration<Rep, Period>> : std::true_type {}; 

然後你可以:

static_assert(is_duration<T>::value, "must be duration");