24 #ifndef PSS_ASTROTYPES_UNITS_BOOSTDURATIONCAST_H
25 #define PSS_ASTROTYPES_UNITS_BOOSTDURATIONCAST_H
31 namespace astrotypes {
41 template<
class BoostUnit>
49 template<
typename BoostType,
typename ChronoType>
57 template<
typename BoostType,
typename ChronoType>
76 template<
typename BoostType,
typename ChronoType>
90 template<
typename BoostQuantity,
typename ChronoNumericalRep,
typename PeriodType>
92 typename std::enable_if<boost::units::is_quantity<BoostQuantity>::value
93 && boost::units::is_unit_of_dimension<typename BoostQuantity::unit_type, boost::units::time_dimension>::value
97 duration_cast(
const std::chrono::duration<ChronoNumericalRep, PeriodType>& duration)
99 typedef std::chrono::duration<
typename BoostQuantity::value_type
101 return BoostQuantity().from_value(std::chrono::duration_cast<chrono_duration>(duration).count());
106 template<
typename BoostQuantity,
typename ChronoNumericalRep,
typename PeriodType>
108 typename std::enable_if<boost::units::is_quantity<BoostQuantity>::value
109 && boost::units::is_unit_of_dimension<typename BoostQuantity::unit_type, boost::units::time_dimension>::value
110 && is_equivalent<BoostQuantity, std::chrono::duration<ChronoNumericalRep, PeriodType>>::value
113 duration_cast(std::chrono::duration<ChronoNumericalRep, PeriodType>& duration)
115 return reinterpret_cast<BoostQuantity&
>(duration);
119 template<
typename BoostQuantity,
typename ChronoNumericalRep,
typename PeriodType>
121 typename std::enable_if<boost::units::is_quantity<BoostQuantity>::value
122 && boost::units::is_unit_of_dimension<typename BoostQuantity::unit_type, boost::units::time_dimension>::value
123 && is_equivalent<BoostQuantity, std::chrono::duration<ChronoNumericalRep, PeriodType>>::value
124 ,
const BoostQuantity&
126 duration_cast(
const std::chrono::duration<ChronoNumericalRep, PeriodType>& duration)
128 return reinterpret_cast<const BoostQuantity&
>(duration);
132 template<
typename ChronoDuration,
typename BoostNumericalRep,
typename BoostUnit>
134 typename std::enable_if<!boost::units::is_quantity<ChronoDuration>::value
135 && boost::units::is_unit_of_dimension<BoostUnit, boost::units::time_dimension>::value
136 && !is_equivalent<boost::units::quantity<BoostUnit, BoostNumericalRep>, ChronoDuration>::value
139 duration_cast(
const boost::units::quantity<BoostUnit, BoostNumericalRep>& duration)
141 typedef std::chrono::duration<BoostNumericalRep
146 template<
typename ChronoDuration,
typename BoostNumericalRep,
typename BoostUnit>
148 typename std::enable_if<!boost::units::is_quantity<ChronoDuration>::value
149 && boost::units::is_unit_of_dimension<BoostUnit, boost::units::time_dimension>::value
150 && is_equivalent<boost::units::quantity<BoostUnit, BoostNumericalRep>, ChronoDuration>::value
153 duration_cast(boost::units::quantity<BoostUnit, BoostNumericalRep>& duration)
155 return reinterpret_cast<ChronoDuration&
>(duration);
158 template<
typename ChronoDuration,
typename BoostNumericalRep,
typename BoostUnit>
160 typename std::enable_if<boost::units::is_unit_of_dimension<BoostUnit, boost::units::time_dimension>::value
161 && is_equivalent<boost::units::quantity<BoostUnit, BoostNumericalRep>, ChronoDuration>::value
162 ,
const ChronoDuration&
164 duration_cast(
const boost::units::quantity<BoostUnit, BoostNumericalRep>& duration)
166 return reinterpret_cast<const ChronoDuration&
>(duration);
169 template<
typename BoostDuration,
typename BoostNumericalRep,
typename BoostUnit>
171 typename std::enable_if<boost::units::is_quantity<BoostDuration>::value
172 && !is_equivalent<boost::units::quantity<BoostUnit, BoostNumericalRep>, BoostDuration>::value
175 duration_cast(boost::units::quantity<BoostUnit, BoostNumericalRep>
const& duration)
177 return static_cast<BoostDuration
>(duration);
185 #endif // PSS_ASTROTYPES_UNITS_BOOSTDURATIONCAST_H
constexpr std::enable_if< boost::units::is_quantity< BoostDuration >::value &&!is_equivalent< boost::units::quantity< BoostUnit, BoostNumericalRep >, BoostDuration >::value, BoostDuration >::type duration_cast(boost::units::quantity< BoostUnit, BoostNumericalRep > const &duration)
conversion helper from boost time units to the std::chrono::duration::period equivalent ...
determine is the NumericalRep of the chrono::duration and the boost::quatity are equivalent ...
determine is the units of the chrono::duration and the boost::quatity are equivalent ...
determine is the boost::quanity and the std::chrono:;duration are equivalent reperesentations i...
constexpr std::enable_if< boost::units::is_quantity< BoostQuantity >::value &&boost::units::is_unit_of_dimension< typename BoostQuantity::unit_type, boost::units::time_dimension >::value &&!is_equivalent< BoostQuantity, std::chrono::duration< ChronoNumericalRep, PeriodType > >::value, BoostQuantity >::type duration_cast(const std::chrono::duration< ChronoNumericalRep, PeriodType > &duration)
Mimic the std::duration_cast to convert to/from boost::units::quantity