quantity.hpp 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. // Boost.Units - A C++ library for zero-overhead dimensional analysis and
  2. // unit/quantity manipulation and conversion
  3. //
  4. // Copyright (C) 2003-2008 Matthias Christian Schabel
  5. // Copyright (C) 2007-2008 Steven Watanabe
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See
  8. // accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_UNITS_QUANTITY_HPP
  11. #define BOOST_UNITS_QUANTITY_HPP
  12. #include <algorithm>
  13. #include <boost/config.hpp>
  14. #include <boost/static_assert.hpp>
  15. #include <boost/mpl/bool.hpp>
  16. #include <boost/mpl/and.hpp>
  17. #include <boost/mpl/not.hpp>
  18. #include <boost/mpl/or.hpp>
  19. #include <boost/mpl/assert.hpp>
  20. #include <boost/utility/enable_if.hpp>
  21. #include <boost/type_traits/is_arithmetic.hpp>
  22. #include <boost/type_traits/is_convertible.hpp>
  23. #include <boost/type_traits/is_integral.hpp>
  24. #include <boost/type_traits/is_same.hpp>
  25. #include <boost/units/conversion.hpp>
  26. #include <boost/units/dimensionless_type.hpp>
  27. #include <boost/units/homogeneous_system.hpp>
  28. #include <boost/units/operators.hpp>
  29. #include <boost/units/static_rational.hpp>
  30. #include <boost/units/units_fwd.hpp>
  31. #include <boost/units/detail/dimensionless_unit.hpp>
  32. namespace boost {
  33. namespace units {
  34. namespace detail {
  35. template<class T, class Enable = void>
  36. struct is_base_unit : mpl::false_ {};
  37. template<class T>
  38. struct is_base_unit<T, typename T::boost_units_is_base_unit_type> : mpl::true_ {};
  39. template<class Source, class Destination>
  40. struct is_narrowing_conversion_impl : mpl::bool_<(sizeof(Source) > sizeof(Destination))> {};
  41. template<class Source, class Destination>
  42. struct is_non_narrowing_conversion :
  43. mpl::and_<
  44. boost::is_convertible<Source, Destination>,
  45. mpl::not_<
  46. mpl::and_<
  47. boost::is_arithmetic<Source>,
  48. boost::is_arithmetic<Destination>,
  49. mpl::or_<
  50. mpl::and_<
  51. is_integral<Destination>,
  52. mpl::not_<is_integral<Source> >
  53. >,
  54. is_narrowing_conversion_impl<Source, Destination>
  55. >
  56. >
  57. >
  58. >
  59. {};
  60. template<>
  61. struct is_non_narrowing_conversion<long double, double> : mpl::false_ {};
  62. // msvc 7.1 needs extra disambiguation
  63. template<class T, class U>
  64. struct disable_if_is_same
  65. {
  66. typedef void type;
  67. };
  68. template<class T>
  69. struct disable_if_is_same<T, T> {};
  70. }
  71. /// class declaration
  72. template<class Unit,class Y>
  73. class quantity
  74. {
  75. // base units are not the same as units.
  76. BOOST_MPL_ASSERT_NOT((detail::is_base_unit<Unit>));
  77. enum { force_instantiation_of_unit = sizeof(Unit) };
  78. typedef void (quantity::*unspecified_null_pointer_constant_type)(int*******);
  79. public:
  80. typedef quantity<Unit,Y> this_type;
  81. typedef Y value_type;
  82. typedef Unit unit_type;
  83. BOOST_CONSTEXPR quantity() : val_()
  84. {
  85. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  86. }
  87. BOOST_CONSTEXPR quantity(unspecified_null_pointer_constant_type) : val_()
  88. {
  89. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  90. }
  91. BOOST_CONSTEXPR quantity(const this_type& source) : val_(source.val_)
  92. {
  93. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  94. }
  95. // Need to make sure that the destructor of
  96. // Unit which contains the checking is instantiated,
  97. // on sun.
  98. #ifdef __SUNPRO_CC
  99. ~quantity() {
  100. unit_type force_unit_instantiation;
  101. }
  102. #endif
  103. //~quantity() { }
  104. BOOST_CXX14_CONSTEXPR this_type& operator=(const this_type& source)
  105. {
  106. val_ = source.val_;
  107. return *this;
  108. }
  109. #ifndef BOOST_NO_SFINAE
  110. /// implicit conversion between value types is allowed if allowed for value types themselves
  111. template<class YY>
  112. BOOST_CONSTEXPR quantity(const quantity<Unit,YY>& source,
  113. typename boost::enable_if<detail::is_non_narrowing_conversion<YY, Y> >::type* = 0) :
  114. val_(source.value())
  115. {
  116. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  117. }
  118. /// implicit conversion between value types is not allowed if not allowed for value types themselves
  119. template<class YY>
  120. explicit BOOST_CONSTEXPR quantity(const quantity<Unit,YY>& source,
  121. typename boost::disable_if<detail::is_non_narrowing_conversion<YY, Y> >::type* = 0) :
  122. val_(static_cast<Y>(source.value()))
  123. {
  124. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  125. }
  126. #else
  127. /// implicit conversion between value types is allowed if allowed for value types themselves
  128. template<class YY>
  129. BOOST_CONSTEXPR quantity(const quantity<Unit,YY>& source) :
  130. val_(source.value())
  131. {
  132. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  133. BOOST_STATIC_ASSERT((boost::is_convertible<YY, Y>::value == true));
  134. }
  135. #endif
  136. /// implicit assignment between value types is allowed if allowed for value types themselves
  137. template<class YY>
  138. BOOST_CXX14_CONSTEXPR this_type& operator=(const quantity<Unit,YY>& source)
  139. {
  140. BOOST_STATIC_ASSERT((boost::is_convertible<YY, Y>::value == true));
  141. *this = this_type(source);
  142. return *this;
  143. }
  144. #ifndef BOOST_NO_SFINAE
  145. /// explicit conversion between different unit systems is allowed if implicit conversion is disallowed
  146. template<class Unit2,class YY>
  147. explicit
  148. BOOST_CONSTEXPR quantity(const quantity<Unit2,YY>& source,
  149. typename boost::disable_if<
  150. mpl::and_<
  151. //is_implicitly_convertible should be undefined when the
  152. //units are not convertible at all
  153. typename is_implicitly_convertible<Unit2,Unit>::type,
  154. detail::is_non_narrowing_conversion<YY, Y>
  155. >,
  156. typename detail::disable_if_is_same<Unit, Unit2>::type
  157. >::type* = 0)
  158. : val_(conversion_helper<quantity<Unit2,YY>,this_type>::convert(source).value())
  159. {
  160. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  161. BOOST_STATIC_ASSERT((boost::is_convertible<YY,Y>::value == true));
  162. }
  163. /// implicit conversion between different unit systems is allowed if each fundamental dimension is implicitly convertible
  164. template<class Unit2,class YY>
  165. BOOST_CONSTEXPR quantity(const quantity<Unit2,YY>& source,
  166. typename boost::enable_if<
  167. mpl::and_<
  168. typename is_implicitly_convertible<Unit2,Unit>::type,
  169. detail::is_non_narrowing_conversion<YY, Y>
  170. >,
  171. typename detail::disable_if_is_same<Unit, Unit2>::type
  172. >::type* = 0)
  173. : val_(conversion_helper<quantity<Unit2,YY>,this_type>::convert(source).value())
  174. {
  175. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  176. BOOST_STATIC_ASSERT((boost::is_convertible<YY,Y>::value == true));
  177. }
  178. #else
  179. /// without SFINAE we can't distinguish between explicit and implicit conversions so
  180. /// the conversion is always explicit
  181. template<class Unit2,class YY>
  182. explicit BOOST_CONSTEXPR quantity(const quantity<Unit2,YY>& source)
  183. : val_(conversion_helper<quantity<Unit2,YY>,this_type>::convert(source).value())
  184. {
  185. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  186. BOOST_STATIC_ASSERT((boost::is_convertible<YY,Y>::value == true));
  187. }
  188. #endif
  189. /// implicit assignment between different unit systems is allowed if each fundamental dimension is implicitly convertible
  190. template<class Unit2,class YY>
  191. BOOST_CXX14_CONSTEXPR this_type& operator=(const quantity<Unit2,YY>& source)
  192. {
  193. BOOST_STATIC_ASSERT((is_implicitly_convertible<Unit2,unit_type>::value == true));
  194. BOOST_STATIC_ASSERT((boost::is_convertible<YY,Y>::value == true));
  195. *this = this_type(source);
  196. return *this;
  197. }
  198. BOOST_CONSTEXPR const value_type& value() const { return val_; } ///< constant accessor to value
  199. ///< can add a quantity of the same type if add_typeof_helper<value_type,value_type>::type is convertible to value_type
  200. template<class Unit2, class YY>
  201. BOOST_CXX14_CONSTEXPR this_type& operator+=(const quantity<Unit2, YY>& source)
  202. {
  203. BOOST_STATIC_ASSERT((boost::is_same<typename add_typeof_helper<Unit, Unit2>::type, Unit>::value));
  204. val_ += source.value();
  205. return *this;
  206. }
  207. ///< can subtract a quantity of the same type if subtract_typeof_helper<value_type,value_type>::type is convertible to value_type
  208. template<class Unit2, class YY>
  209. BOOST_CXX14_CONSTEXPR this_type& operator-=(const quantity<Unit2, YY>& source)
  210. {
  211. BOOST_STATIC_ASSERT((boost::is_same<typename subtract_typeof_helper<Unit, Unit2>::type, Unit>::value));
  212. val_ -= source.value();
  213. return *this;
  214. }
  215. template<class Unit2, class YY>
  216. BOOST_CXX14_CONSTEXPR this_type& operator*=(const quantity<Unit2, YY>& source)
  217. {
  218. BOOST_STATIC_ASSERT((boost::is_same<typename multiply_typeof_helper<Unit, Unit2>::type, Unit>::value));
  219. val_ *= source.value();
  220. return *this;
  221. }
  222. template<class Unit2, class YY>
  223. BOOST_CXX14_CONSTEXPR this_type& operator/=(const quantity<Unit2, YY>& source)
  224. {
  225. BOOST_STATIC_ASSERT((boost::is_same<typename divide_typeof_helper<Unit, Unit2>::type, Unit>::value));
  226. val_ /= source.value();
  227. return *this;
  228. }
  229. ///< can multiply a quantity by a scalar value_type if multiply_typeof_helper<value_type,value_type>::type is convertible to value_type
  230. BOOST_CXX14_CONSTEXPR this_type& operator*=(const value_type& source) { val_ *= source; return *this; }
  231. ///< can divide a quantity by a scalar value_type if divide_typeof_helper<value_type,value_type>::type is convertible to value_type
  232. BOOST_CXX14_CONSTEXPR this_type& operator/=(const value_type& source) { val_ /= source; return *this; }
  233. /// Construct quantity directly from @c value_type (potentially dangerous).
  234. static BOOST_CONSTEXPR this_type from_value(const value_type& val) { return this_type(val, 0); }
  235. protected:
  236. explicit BOOST_CONSTEXPR quantity(const value_type& val, int) : val_(val) { }
  237. private:
  238. value_type val_;
  239. };
  240. /// Specialization for dimensionless quantities. Implicit conversions between
  241. /// unit systems are allowed because all dimensionless quantities are equivalent.
  242. /// Implicit construction and assignment from and conversion to @c value_type is
  243. /// also allowed.
  244. template<class System,class Y>
  245. class quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System),Y>
  246. {
  247. public:
  248. typedef quantity<unit<dimensionless_type,System>,Y> this_type;
  249. typedef Y value_type;
  250. typedef System system_type;
  251. typedef dimensionless_type dimension_type;
  252. typedef unit<dimension_type,system_type> unit_type;
  253. BOOST_CONSTEXPR quantity() : val_()
  254. {
  255. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  256. }
  257. /// construction from raw @c value_type is allowed
  258. BOOST_CONSTEXPR quantity(value_type val) : val_(val)
  259. {
  260. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  261. }
  262. BOOST_CONSTEXPR quantity(const this_type& source) : val_(source.val_)
  263. {
  264. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  265. }
  266. //~quantity() { }
  267. BOOST_CXX14_CONSTEXPR this_type& operator=(const this_type& source)
  268. {
  269. val_ = source.val_;
  270. return *this;
  271. }
  272. #ifndef BOOST_NO_SFINAE
  273. /// implicit conversion between value types is allowed if allowed for value types themselves
  274. template<class YY>
  275. BOOST_CONSTEXPR quantity(const quantity<unit<dimension_type,system_type>,YY>& source,
  276. typename boost::enable_if<detail::is_non_narrowing_conversion<YY, Y> >::type* = 0) :
  277. val_(source.value())
  278. {
  279. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  280. }
  281. /// implicit conversion between value types is not allowed if not allowed for value types themselves
  282. template<class YY>
  283. explicit BOOST_CONSTEXPR quantity(const quantity<unit<dimension_type,system_type>,YY>& source,
  284. typename boost::disable_if<detail::is_non_narrowing_conversion<YY, Y> >::type* = 0) :
  285. val_(static_cast<Y>(source.value()))
  286. {
  287. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  288. }
  289. #else
  290. /// implicit conversion between value types is allowed if allowed for value types themselves
  291. template<class YY>
  292. BOOST_CONSTEXPR quantity(const quantity<unit<dimension_type,system_type>,YY>& source) :
  293. val_(source.value())
  294. {
  295. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  296. BOOST_STATIC_ASSERT((boost::is_convertible<YY, Y>::value == true));
  297. }
  298. #endif
  299. /// implicit assignment between value types is allowed if allowed for value types themselves
  300. template<class YY>
  301. BOOST_CXX14_CONSTEXPR this_type& operator=(const quantity<unit<dimension_type,system_type>,YY>& source)
  302. {
  303. BOOST_STATIC_ASSERT((boost::is_convertible<YY,Y>::value == true));
  304. *this = this_type(source);
  305. return *this;
  306. }
  307. #if 1
  308. /// implicit conversion between different unit systems is allowed
  309. template<class System2, class Y2>
  310. BOOST_CONSTEXPR quantity(const quantity<unit<dimensionless_type, System2>,Y2>& source,
  311. #ifdef __SUNPRO_CC
  312. typename boost::enable_if<
  313. boost::mpl::and_<
  314. detail::is_non_narrowing_conversion<Y2, Y>,
  315. detail::is_dimensionless_system<System2>
  316. >
  317. >::type* = 0
  318. #else
  319. typename boost::enable_if<detail::is_non_narrowing_conversion<Y2, Y> >::type* = 0,
  320. typename detail::disable_if_is_same<System, System2>::type* = 0,
  321. typename boost::enable_if<detail::is_dimensionless_system<System2> >::type* = 0
  322. #endif
  323. ) :
  324. val_(source.value())
  325. {
  326. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  327. }
  328. /// implicit conversion between different unit systems is allowed
  329. template<class System2, class Y2>
  330. explicit BOOST_CONSTEXPR quantity(const quantity<unit<dimensionless_type, System2>,Y2>& source,
  331. #ifdef __SUNPRO_CC
  332. typename boost::enable_if<
  333. boost::mpl::and_<
  334. boost::mpl::not_<detail::is_non_narrowing_conversion<Y2, Y> >,
  335. detail::is_dimensionless_system<System2>
  336. >
  337. >::type* = 0
  338. #else
  339. typename boost::disable_if<detail::is_non_narrowing_conversion<Y2, Y> >::type* = 0,
  340. typename detail::disable_if_is_same<System, System2>::type* = 0,
  341. typename boost::enable_if<detail::is_dimensionless_system<System2> >::type* = 0
  342. #endif
  343. ) :
  344. val_(static_cast<Y>(source.value()))
  345. {
  346. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  347. }
  348. #else
  349. /// implicit conversion between different unit systems is allowed
  350. template<class System2, class Y2>
  351. BOOST_CONSTEXPR quantity(const quantity<unit<dimensionless_type,homogeneous_system<System2> >,Y2>& source) :
  352. val_(source.value())
  353. {
  354. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  355. BOOST_STATIC_ASSERT((boost::is_convertible<Y2, Y>::value == true));
  356. }
  357. #endif
  358. /// conversion between different unit systems is explicit when
  359. /// the units are not equivalent.
  360. template<class System2, class Y2>
  361. explicit BOOST_CONSTEXPR quantity(const quantity<unit<dimensionless_type, System2>,Y2>& source,
  362. typename boost::disable_if<detail::is_dimensionless_system<System2> >::type* = 0) :
  363. val_(conversion_helper<quantity<unit<dimensionless_type, System2>,Y2>, this_type>::convert(source).value())
  364. {
  365. BOOST_UNITS_CHECK_LAYOUT_COMPATIBILITY(this_type, Y);
  366. }
  367. #ifndef __SUNPRO_CC
  368. /// implicit assignment between different unit systems is allowed
  369. template<class System2>
  370. BOOST_CXX14_CONSTEXPR this_type& operator=(const quantity<BOOST_UNITS_DIMENSIONLESS_UNIT(System2),Y>& source)
  371. {
  372. *this = this_type(source);
  373. return *this;
  374. }
  375. #endif
  376. /// implicit conversion to @c value_type is allowed
  377. BOOST_CONSTEXPR operator value_type() const { return val_; }
  378. BOOST_CONSTEXPR const value_type& value() const { return val_; } ///< constant accessor to value
  379. ///< can add a quantity of the same type if add_typeof_helper<value_type,value_type>::type is convertible to value_type
  380. BOOST_CXX14_CONSTEXPR this_type& operator+=(const this_type& source) { val_ += source.val_; return *this; }
  381. ///< can subtract a quantity of the same type if subtract_typeof_helper<value_type,value_type>::type is convertible to value_type
  382. BOOST_CXX14_CONSTEXPR this_type& operator-=(const this_type& source) { val_ -= source.val_; return *this; }
  383. ///< can multiply a quantity by a scalar value_type if multiply_typeof_helper<value_type,value_type>::type is convertible to value_type
  384. BOOST_CXX14_CONSTEXPR this_type& operator*=(const value_type& val) { val_ *= val; return *this; }
  385. ///< can divide a quantity by a scalar value_type if divide_typeof_helper<value_type,value_type>::type is convertible to value_type
  386. BOOST_CXX14_CONSTEXPR this_type& operator/=(const value_type& val) { val_ /= val; return *this; }
  387. /// Construct quantity directly from @c value_type.
  388. static BOOST_CONSTEXPR this_type from_value(const value_type& val) { return this_type(val); }
  389. private:
  390. value_type val_;
  391. };
  392. #ifdef BOOST_MSVC
  393. // HACK: For some obscure reason msvc 8.0 needs these specializations
  394. template<class System, class T>
  395. class quantity<unit<int, System>, T> {};
  396. template<class T>
  397. class quantity<int, T> {};
  398. #endif
  399. } // namespace units
  400. } // namespace boost
  401. #if BOOST_UNITS_HAS_BOOST_TYPEOF
  402. #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP()
  403. BOOST_TYPEOF_REGISTER_TEMPLATE(boost::units::quantity, 2)
  404. #endif
  405. namespace boost {
  406. namespace units {
  407. namespace detail {
  408. /// helper class for quantity_cast
  409. template<class X,class Y> struct quantity_cast_helper;
  410. /// specialization for casting to the value type
  411. template<class Y,class X,class Unit>
  412. struct quantity_cast_helper<Y,quantity<Unit,X> >
  413. {
  414. typedef Y type;
  415. BOOST_CONSTEXPR type operator()(quantity<Unit,X>& source) const { return const_cast<X&>(source.value()); }
  416. };
  417. /// specialization for casting to the value type
  418. template<class Y,class X,class Unit>
  419. struct quantity_cast_helper<Y,const quantity<Unit,X> >
  420. {
  421. typedef Y type;
  422. BOOST_CONSTEXPR type operator()(const quantity<Unit,X>& source) const { return source.value(); }
  423. };
  424. } // namespace detail
  425. /// quantity_cast provides mutating access to underlying quantity value_type
  426. template<class X,class Y>
  427. inline
  428. BOOST_CONSTEXPR
  429. X
  430. quantity_cast(Y& source)
  431. {
  432. return detail::quantity_cast_helper<X,Y>()(source);
  433. }
  434. template<class X,class Y>
  435. inline
  436. BOOST_CONSTEXPR
  437. X
  438. quantity_cast(const Y& source)
  439. {
  440. return detail::quantity_cast_helper<X,const Y>()(source);
  441. }
  442. /// swap quantities
  443. template<class Unit,class Y>
  444. inline void swap(quantity<Unit,Y>& lhs, quantity<Unit,Y>& rhs)
  445. {
  446. using std::swap;
  447. swap(quantity_cast<Y&>(lhs),quantity_cast<Y&>(rhs));
  448. }
  449. /// specialize unary plus typeof helper
  450. /// INTERNAL ONLY
  451. template<class Unit,class Y>
  452. struct unary_plus_typeof_helper< quantity<Unit,Y> >
  453. {
  454. typedef typename unary_plus_typeof_helper<Y>::type value_type;
  455. typedef typename unary_plus_typeof_helper<Unit>::type unit_type;
  456. typedef quantity<unit_type,value_type> type;
  457. };
  458. /// specialize unary minus typeof helper
  459. /// INTERNAL ONLY
  460. template<class Unit,class Y>
  461. struct unary_minus_typeof_helper< quantity<Unit,Y> >
  462. {
  463. typedef typename unary_minus_typeof_helper<Y>::type value_type;
  464. typedef typename unary_minus_typeof_helper<Unit>::type unit_type;
  465. typedef quantity<unit_type,value_type> type;
  466. };
  467. /// specialize add typeof helper
  468. /// INTERNAL ONLY
  469. template<class Unit1,
  470. class Unit2,
  471. class X,
  472. class Y>
  473. struct add_typeof_helper< quantity<Unit1,X>,quantity<Unit2,Y> >
  474. {
  475. typedef typename add_typeof_helper<X,Y>::type value_type;
  476. typedef typename add_typeof_helper<Unit1,Unit2>::type unit_type;
  477. typedef quantity<unit_type,value_type> type;
  478. };
  479. /// for sun CC we need to invoke SFINAE at
  480. /// the top level, otherwise it will silently
  481. /// return int.
  482. template<class Dim1, class System1,
  483. class Dim2, class System2,
  484. class X,
  485. class Y>
  486. struct add_typeof_helper< quantity<unit<Dim1, System1>,X>,quantity<unit<Dim2, System2>,Y> >
  487. {
  488. };
  489. template<class Dim,
  490. class System,
  491. class X,
  492. class Y>
  493. struct add_typeof_helper< quantity<unit<Dim, System>,X>,quantity<unit<Dim, System>,Y> >
  494. {
  495. typedef typename add_typeof_helper<X,Y>::type value_type;
  496. typedef unit<Dim, System> unit_type;
  497. typedef quantity<unit_type,value_type> type;
  498. };
  499. /// specialize subtract typeof helper
  500. /// INTERNAL ONLY
  501. template<class Unit1,
  502. class Unit2,
  503. class X,
  504. class Y>
  505. struct subtract_typeof_helper< quantity<Unit1,X>,quantity<Unit2,Y> >
  506. {
  507. typedef typename subtract_typeof_helper<X,Y>::type value_type;
  508. typedef typename subtract_typeof_helper<Unit1,Unit2>::type unit_type;
  509. typedef quantity<unit_type,value_type> type;
  510. };
  511. // Force adding different units to fail on sun.
  512. template<class Dim1, class System1,
  513. class Dim2, class System2,
  514. class X,
  515. class Y>
  516. struct subtract_typeof_helper< quantity<unit<Dim1, System1>,X>,quantity<unit<Dim2, System2>,Y> >
  517. {
  518. };
  519. template<class Dim,
  520. class System,
  521. class X,
  522. class Y>
  523. struct subtract_typeof_helper< quantity<unit<Dim, System>,X>,quantity<unit<Dim, System>,Y> >
  524. {
  525. typedef typename subtract_typeof_helper<X,Y>::type value_type;
  526. typedef unit<Dim, System> unit_type;
  527. typedef quantity<unit_type,value_type> type;
  528. };
  529. /// scalar times unit typeof helper
  530. /// INTERNAL ONLY
  531. template<class System,
  532. class Dim,
  533. class X>
  534. struct multiply_typeof_helper< X,unit<Dim,System> >
  535. {
  536. typedef X value_type;
  537. typedef unit<Dim,System> unit_type;
  538. typedef quantity<unit_type,value_type> type;
  539. };
  540. /// unit times scalar typeof helper
  541. /// INTERNAL ONLY
  542. template<class System,
  543. class Dim,
  544. class X>
  545. struct multiply_typeof_helper< unit<Dim,System>,X >
  546. {
  547. typedef X value_type;
  548. typedef unit<Dim,System> unit_type;
  549. typedef quantity<unit_type,value_type> type;
  550. };
  551. /// scalar times quantity typeof helper
  552. /// INTERNAL ONLY
  553. template<class Unit,
  554. class X,
  555. class Y>
  556. struct multiply_typeof_helper< X,quantity<Unit,Y> >
  557. {
  558. typedef typename multiply_typeof_helper<X,Y>::type value_type;
  559. typedef Unit unit_type;
  560. typedef quantity<unit_type,value_type> type;
  561. };
  562. /// disambiguate
  563. /// INTERNAL ONLY
  564. template<class Unit,
  565. class Y>
  566. struct multiply_typeof_helper< one,quantity<Unit,Y> >
  567. {
  568. typedef quantity<Unit,Y> type;
  569. };
  570. /// quantity times scalar typeof helper
  571. /// INTERNAL ONLY
  572. template<class Unit,
  573. class X,
  574. class Y>
  575. struct multiply_typeof_helper< quantity<Unit,X>,Y >
  576. {
  577. typedef typename multiply_typeof_helper<X,Y>::type value_type;
  578. typedef Unit unit_type;
  579. typedef quantity<unit_type,value_type> type;
  580. };
  581. /// disambiguate
  582. /// INTERNAL ONLY
  583. template<class Unit,
  584. class X>
  585. struct multiply_typeof_helper< quantity<Unit,X>,one >
  586. {
  587. typedef quantity<Unit,X> type;
  588. };
  589. /// unit times quantity typeof helper
  590. /// INTERNAL ONLY
  591. template<class Unit,
  592. class System,
  593. class Dim,
  594. class X>
  595. struct multiply_typeof_helper< unit<Dim,System>,quantity<Unit,X> >
  596. {
  597. typedef X value_type;
  598. typedef typename multiply_typeof_helper< unit<Dim,System>,Unit >::type unit_type;
  599. typedef quantity<unit_type,value_type> type;
  600. };
  601. /// quantity times unit typeof helper
  602. /// INTERNAL ONLY
  603. template<class Unit,
  604. class System,
  605. class Dim,
  606. class X>
  607. struct multiply_typeof_helper< quantity<Unit,X>,unit<Dim,System> >
  608. {
  609. typedef X value_type;
  610. typedef typename multiply_typeof_helper< Unit,unit<Dim,System> >::type unit_type;
  611. typedef quantity<unit_type,value_type> type;
  612. };
  613. /// quantity times quantity typeof helper
  614. /// INTERNAL ONLY
  615. template<class Unit1,
  616. class Unit2,
  617. class X,
  618. class Y>
  619. struct multiply_typeof_helper< quantity<Unit1,X>,quantity<Unit2,Y> >
  620. {
  621. typedef typename multiply_typeof_helper<X,Y>::type value_type;
  622. typedef typename multiply_typeof_helper<Unit1,Unit2>::type unit_type;
  623. typedef quantity<unit_type,value_type> type;
  624. };
  625. /// scalar divided by unit typeof helper
  626. /// INTERNAL ONLY
  627. template<class System,
  628. class Dim,
  629. class X>
  630. struct divide_typeof_helper< X,unit<Dim,System> >
  631. {
  632. typedef X value_type;
  633. typedef typename power_typeof_helper< unit<Dim,System>,static_rational<-1> >::type unit_type;
  634. typedef quantity<unit_type,value_type> type;
  635. };
  636. /// unit divided by scalar typeof helper
  637. /// INTERNAL ONLY
  638. template<class System,
  639. class Dim,
  640. class X>
  641. struct divide_typeof_helper< unit<Dim,System>,X >
  642. {
  643. typedef typename divide_typeof_helper<X,X>::type value_type;
  644. typedef unit<Dim,System> unit_type;
  645. typedef quantity<unit_type,value_type> type;
  646. };
  647. /// scalar divided by quantity typeof helper
  648. /// INTERNAL ONLY
  649. template<class Unit,
  650. class X,
  651. class Y>
  652. struct divide_typeof_helper< X,quantity<Unit,Y> >
  653. {
  654. typedef typename divide_typeof_helper<X,Y>::type value_type;
  655. typedef typename power_typeof_helper< Unit,static_rational<-1> >::type unit_type;
  656. typedef quantity<unit_type,value_type> type;
  657. };
  658. /// disambiguate
  659. /// INTERNAL ONLY
  660. template<class Unit,
  661. class Y>
  662. struct divide_typeof_helper< one,quantity<Unit,Y> >
  663. {
  664. typedef quantity<Unit,Y> type;
  665. };
  666. /// quantity divided by scalar typeof helper
  667. /// INTERNAL ONLY
  668. template<class Unit,
  669. class X,
  670. class Y>
  671. struct divide_typeof_helper< quantity<Unit,X>,Y >
  672. {
  673. typedef typename divide_typeof_helper<X,Y>::type value_type;
  674. typedef Unit unit_type;
  675. typedef quantity<unit_type,value_type> type;
  676. };
  677. /// disambiguate
  678. /// INTERNAL ONLY
  679. template<class Unit,
  680. class X>
  681. struct divide_typeof_helper< quantity<Unit,X>,one >
  682. {
  683. typedef quantity<Unit,X> type;
  684. };
  685. /// unit divided by quantity typeof helper
  686. /// INTERNAL ONLY
  687. template<class Unit,
  688. class System,
  689. class Dim,
  690. class X>
  691. struct divide_typeof_helper< unit<Dim,System>,quantity<Unit,X> >
  692. {
  693. typedef typename divide_typeof_helper<X,X>::type value_type;
  694. typedef typename divide_typeof_helper< unit<Dim,System>,Unit >::type unit_type;
  695. typedef quantity<unit_type,value_type> type;
  696. };
  697. /// quantity divided by unit typeof helper
  698. /// INTERNAL ONLY
  699. template<class Unit,
  700. class System,
  701. class Dim,
  702. class X>
  703. struct divide_typeof_helper< quantity<Unit,X>,unit<Dim,System> >
  704. {
  705. typedef X value_type;
  706. typedef typename divide_typeof_helper< Unit,unit<Dim,System> >::type unit_type;
  707. typedef quantity<unit_type,value_type> type;
  708. };
  709. /// quantity divided by quantity typeof helper
  710. /// INTERNAL ONLY
  711. template<class Unit1,
  712. class Unit2,
  713. class X,
  714. class Y>
  715. struct divide_typeof_helper< quantity<Unit1,X>,quantity<Unit2,Y> >
  716. {
  717. typedef typename divide_typeof_helper<X,Y>::type value_type;
  718. typedef typename divide_typeof_helper<Unit1,Unit2>::type unit_type;
  719. typedef quantity<unit_type,value_type> type;
  720. };
  721. /// specialize power typeof helper
  722. /// INTERNAL ONLY
  723. template<class Unit,long N,long D,class Y>
  724. struct power_typeof_helper< quantity<Unit,Y>,static_rational<N,D> >
  725. {
  726. typedef typename power_typeof_helper<Y,static_rational<N,D> >::type value_type;
  727. typedef typename power_typeof_helper<Unit,static_rational<N,D> >::type unit_type;
  728. typedef quantity<unit_type,value_type> type;
  729. static BOOST_CONSTEXPR type value(const quantity<Unit,Y>& x)
  730. {
  731. return type::from_value(power_typeof_helper<Y,static_rational<N,D> >::value(x.value()));
  732. }
  733. };
  734. /// specialize root typeof helper
  735. /// INTERNAL ONLY
  736. template<class Unit,long N,long D,class Y>
  737. struct root_typeof_helper< quantity<Unit,Y>,static_rational<N,D> >
  738. {
  739. typedef typename root_typeof_helper<Y,static_rational<N,D> >::type value_type;
  740. typedef typename root_typeof_helper<Unit,static_rational<N,D> >::type unit_type;
  741. typedef quantity<unit_type,value_type> type;
  742. static BOOST_CONSTEXPR type value(const quantity<Unit,Y>& x)
  743. {
  744. return type::from_value(root_typeof_helper<Y,static_rational<N,D> >::value(x.value()));
  745. }
  746. };
  747. /// runtime unit times scalar
  748. /// INTERNAL ONLY
  749. template<class System,
  750. class Dim,
  751. class Y>
  752. inline
  753. BOOST_CONSTEXPR
  754. typename multiply_typeof_helper< unit<Dim,System>,Y >::type
  755. operator*(const unit<Dim,System>&,const Y& rhs)
  756. {
  757. typedef typename multiply_typeof_helper< unit<Dim,System>,Y >::type type;
  758. return type::from_value(rhs);
  759. }
  760. /// runtime unit divided by scalar
  761. template<class System,
  762. class Dim,
  763. class Y>
  764. inline
  765. BOOST_CONSTEXPR
  766. typename divide_typeof_helper< unit<Dim,System>,Y >::type
  767. operator/(const unit<Dim,System>&,const Y& rhs)
  768. {
  769. typedef typename divide_typeof_helper<unit<Dim,System>,Y>::type type;
  770. return type::from_value(Y(1)/rhs);
  771. }
  772. /// runtime scalar times unit
  773. template<class System,
  774. class Dim,
  775. class Y>
  776. inline
  777. BOOST_CONSTEXPR
  778. typename multiply_typeof_helper< Y,unit<Dim,System> >::type
  779. operator*(const Y& lhs,const unit<Dim,System>&)
  780. {
  781. typedef typename multiply_typeof_helper< Y,unit<Dim,System> >::type type;
  782. return type::from_value(lhs);
  783. }
  784. /// runtime scalar divided by unit
  785. template<class System,
  786. class Dim,
  787. class Y>
  788. inline
  789. BOOST_CONSTEXPR
  790. typename divide_typeof_helper< Y,unit<Dim,System> >::type
  791. operator/(const Y& lhs,const unit<Dim,System>&)
  792. {
  793. typedef typename divide_typeof_helper< Y,unit<Dim,System> >::type type;
  794. return type::from_value(lhs);
  795. }
  796. ///// runtime quantity times scalar
  797. //template<class Unit,
  798. // class X,
  799. // class Y>
  800. //inline
  801. //BOOST_CONSTEXPR
  802. //typename multiply_typeof_helper< quantity<Unit,X>,Y >::type
  803. //operator*(const quantity<Unit,X>& lhs,const Y& rhs)
  804. //{
  805. // typedef typename multiply_typeof_helper< quantity<Unit,X>,Y >::type type;
  806. //
  807. // return type::from_value(lhs.value()*rhs);
  808. //}
  809. //
  810. ///// runtime scalar times quantity
  811. //template<class Unit,
  812. // class X,
  813. // class Y>
  814. //inline
  815. //BOOST_CONSTEXPR
  816. //typename multiply_typeof_helper< X,quantity<Unit,Y> >::type
  817. //operator*(const X& lhs,const quantity<Unit,Y>& rhs)
  818. //{
  819. // typedef typename multiply_typeof_helper< X,quantity<Unit,Y> >::type type;
  820. //
  821. // return type::from_value(lhs*rhs.value());
  822. //}
  823. /// runtime quantity times scalar
  824. template<class Unit,
  825. class X>
  826. inline
  827. BOOST_CONSTEXPR
  828. typename multiply_typeof_helper< quantity<Unit,X>,X >::type
  829. operator*(const quantity<Unit,X>& lhs,const X& rhs)
  830. {
  831. typedef typename multiply_typeof_helper< quantity<Unit,X>,X >::type type;
  832. return type::from_value(lhs.value()*rhs);
  833. }
  834. /// runtime scalar times quantity
  835. template<class Unit,
  836. class X>
  837. inline
  838. BOOST_CONSTEXPR
  839. typename multiply_typeof_helper< X,quantity<Unit,X> >::type
  840. operator*(const X& lhs,const quantity<Unit,X>& rhs)
  841. {
  842. typedef typename multiply_typeof_helper< X,quantity<Unit,X> >::type type;
  843. return type::from_value(lhs*rhs.value());
  844. }
  845. ///// runtime quantity divided by scalar
  846. //template<class Unit,
  847. // class X,
  848. // class Y>
  849. //inline
  850. //BOOST_CONSTEXPR
  851. //typename divide_typeof_helper< quantity<Unit,X>,Y >::type
  852. //operator/(const quantity<Unit,X>& lhs,const Y& rhs)
  853. //{
  854. // typedef typename divide_typeof_helper< quantity<Unit,X>,Y >::type type;
  855. //
  856. // return type::from_value(lhs.value()/rhs);
  857. //}
  858. //
  859. ///// runtime scalar divided by quantity
  860. //template<class Unit,
  861. // class X,
  862. // class Y>
  863. //inline
  864. //BOOST_CONSTEXPR
  865. //typename divide_typeof_helper< X,quantity<Unit,Y> >::type
  866. //operator/(const X& lhs,const quantity<Unit,Y>& rhs)
  867. //{
  868. // typedef typename divide_typeof_helper< X,quantity<Unit,Y> >::type type;
  869. //
  870. // return type::from_value(lhs/rhs.value());
  871. //}
  872. /// runtime quantity divided by scalar
  873. template<class Unit,
  874. class X>
  875. inline
  876. BOOST_CONSTEXPR
  877. typename divide_typeof_helper< quantity<Unit,X>,X >::type
  878. operator/(const quantity<Unit,X>& lhs,const X& rhs)
  879. {
  880. typedef typename divide_typeof_helper< quantity<Unit,X>,X >::type type;
  881. return type::from_value(lhs.value()/rhs);
  882. }
  883. /// runtime scalar divided by quantity
  884. template<class Unit,
  885. class X>
  886. inline
  887. BOOST_CONSTEXPR
  888. typename divide_typeof_helper< X,quantity<Unit,X> >::type
  889. operator/(const X& lhs,const quantity<Unit,X>& rhs)
  890. {
  891. typedef typename divide_typeof_helper< X,quantity<Unit,X> >::type type;
  892. return type::from_value(lhs/rhs.value());
  893. }
  894. /// runtime unit times quantity
  895. template<class System1,
  896. class Dim1,
  897. class Unit2,
  898. class Y>
  899. inline
  900. BOOST_CONSTEXPR
  901. typename multiply_typeof_helper< unit<Dim1,System1>,quantity<Unit2,Y> >::type
  902. operator*(const unit<Dim1,System1>&,const quantity<Unit2,Y>& rhs)
  903. {
  904. typedef typename multiply_typeof_helper< unit<Dim1,System1>,quantity<Unit2,Y> >::type type;
  905. return type::from_value(rhs.value());
  906. }
  907. /// runtime unit divided by quantity
  908. template<class System1,
  909. class Dim1,
  910. class Unit2,
  911. class Y>
  912. inline
  913. BOOST_CONSTEXPR
  914. typename divide_typeof_helper< unit<Dim1,System1>,quantity<Unit2,Y> >::type
  915. operator/(const unit<Dim1,System1>&,const quantity<Unit2,Y>& rhs)
  916. {
  917. typedef typename divide_typeof_helper< unit<Dim1,System1>,quantity<Unit2,Y> >::type type;
  918. return type::from_value(Y(1)/rhs.value());
  919. }
  920. /// runtime quantity times unit
  921. template<class Unit1,
  922. class System2,
  923. class Dim2,
  924. class Y>
  925. inline
  926. BOOST_CONSTEXPR
  927. typename multiply_typeof_helper< quantity<Unit1,Y>,unit<Dim2,System2> >::type
  928. operator*(const quantity<Unit1,Y>& lhs,const unit<Dim2,System2>&)
  929. {
  930. typedef typename multiply_typeof_helper< quantity<Unit1,Y>,unit<Dim2,System2> >::type type;
  931. return type::from_value(lhs.value());
  932. }
  933. /// runtime quantity divided by unit
  934. template<class Unit1,
  935. class System2,
  936. class Dim2,
  937. class Y>
  938. inline
  939. BOOST_CONSTEXPR
  940. typename divide_typeof_helper< quantity<Unit1,Y>,unit<Dim2,System2> >::type
  941. operator/(const quantity<Unit1,Y>& lhs,const unit<Dim2,System2>&)
  942. {
  943. typedef typename divide_typeof_helper< quantity<Unit1,Y>,unit<Dim2,System2> >::type type;
  944. return type::from_value(lhs.value());
  945. }
  946. /// runtime unary plus quantity
  947. template<class Unit,class Y>
  948. BOOST_CONSTEXPR
  949. typename unary_plus_typeof_helper< quantity<Unit,Y> >::type
  950. operator+(const quantity<Unit,Y>& val)
  951. {
  952. typedef typename unary_plus_typeof_helper< quantity<Unit,Y> >::type type;
  953. return type::from_value(+val.value());
  954. }
  955. /// runtime unary minus quantity
  956. template<class Unit,class Y>
  957. BOOST_CONSTEXPR
  958. typename unary_minus_typeof_helper< quantity<Unit,Y> >::type
  959. operator-(const quantity<Unit,Y>& val)
  960. {
  961. typedef typename unary_minus_typeof_helper< quantity<Unit,Y> >::type type;
  962. return type::from_value(-val.value());
  963. }
  964. /// runtime quantity plus quantity
  965. template<class Unit1,
  966. class Unit2,
  967. class X,
  968. class Y>
  969. inline
  970. BOOST_CONSTEXPR
  971. typename add_typeof_helper< quantity<Unit1,X>,quantity<Unit2,Y> >::type
  972. operator+(const quantity<Unit1,X>& lhs,
  973. const quantity<Unit2,Y>& rhs)
  974. {
  975. typedef typename add_typeof_helper< quantity<Unit1,X>,quantity<Unit2,Y> >::type type;
  976. return type::from_value(lhs.value()+rhs.value());
  977. }
  978. /// runtime quantity minus quantity
  979. template<class Unit1,
  980. class Unit2,
  981. class X,
  982. class Y>
  983. inline
  984. BOOST_CONSTEXPR
  985. typename subtract_typeof_helper< quantity<Unit1,X>,quantity<Unit2,Y> >::type
  986. operator-(const quantity<Unit1,X>& lhs,
  987. const quantity<Unit2,Y>& rhs)
  988. {
  989. typedef typename subtract_typeof_helper< quantity<Unit1,X>,quantity<Unit2,Y> >::type type;
  990. return type::from_value(lhs.value()-rhs.value());
  991. }
  992. /// runtime quantity times quantity
  993. template<class Unit1,
  994. class Unit2,
  995. class X,
  996. class Y>
  997. inline
  998. BOOST_CONSTEXPR
  999. typename multiply_typeof_helper< quantity<Unit1,X>,quantity<Unit2,Y> >::type
  1000. operator*(const quantity<Unit1,X>& lhs,
  1001. const quantity<Unit2,Y>& rhs)
  1002. {
  1003. typedef typename multiply_typeof_helper< quantity<Unit1,X>,
  1004. quantity<Unit2,Y> >::type type;
  1005. return type::from_value(lhs.value()*rhs.value());
  1006. }
  1007. /// runtime quantity divided by quantity
  1008. template<class Unit1,
  1009. class Unit2,
  1010. class X,
  1011. class Y>
  1012. inline
  1013. BOOST_CONSTEXPR
  1014. typename divide_typeof_helper< quantity<Unit1,X>,quantity<Unit2,Y> >::type
  1015. operator/(const quantity<Unit1,X>& lhs,
  1016. const quantity<Unit2,Y>& rhs)
  1017. {
  1018. typedef typename divide_typeof_helper< quantity<Unit1,X>,
  1019. quantity<Unit2,Y> >::type type;
  1020. return type::from_value(lhs.value()/rhs.value());
  1021. }
  1022. /// runtime operator==
  1023. template<class Unit,
  1024. class X,
  1025. class Y>
  1026. inline
  1027. BOOST_CONSTEXPR
  1028. bool
  1029. operator==(const quantity<Unit,X>& val1,
  1030. const quantity<Unit,Y>& val2)
  1031. {
  1032. return val1.value() == val2.value();
  1033. }
  1034. /// runtime operator!=
  1035. template<class Unit,
  1036. class X,
  1037. class Y>
  1038. inline
  1039. BOOST_CONSTEXPR
  1040. bool
  1041. operator!=(const quantity<Unit,X>& val1,
  1042. const quantity<Unit,Y>& val2)
  1043. {
  1044. return val1.value() != val2.value();
  1045. }
  1046. /// runtime operator<
  1047. template<class Unit,
  1048. class X,
  1049. class Y>
  1050. inline
  1051. BOOST_CONSTEXPR
  1052. bool
  1053. operator<(const quantity<Unit,X>& val1,
  1054. const quantity<Unit,Y>& val2)
  1055. {
  1056. return val1.value() < val2.value();
  1057. }
  1058. /// runtime operator<=
  1059. template<class Unit,
  1060. class X,
  1061. class Y>
  1062. inline
  1063. BOOST_CONSTEXPR
  1064. bool
  1065. operator<=(const quantity<Unit,X>& val1,
  1066. const quantity<Unit,Y>& val2)
  1067. {
  1068. return val1.value() <= val2.value();
  1069. }
  1070. /// runtime operator>
  1071. template<class Unit,
  1072. class X,
  1073. class Y>
  1074. inline
  1075. BOOST_CONSTEXPR
  1076. bool
  1077. operator>(const quantity<Unit,X>& val1,
  1078. const quantity<Unit,Y>& val2)
  1079. {
  1080. return val1.value() > val2.value();
  1081. }
  1082. /// runtime operator>=
  1083. template<class Unit,
  1084. class X,
  1085. class Y>
  1086. inline
  1087. BOOST_CONSTEXPR
  1088. bool
  1089. operator>=(const quantity<Unit,X>& val1,
  1090. const quantity<Unit,Y>& val2)
  1091. {
  1092. return val1.value() >= val2.value();
  1093. }
  1094. } // namespace units
  1095. } // namespace boost
  1096. #endif // BOOST_UNITS_QUANTITY_HPP