|
16 | 16 | #include <boost/mpl/divides.hpp>
|
17 | 17 | #include <boost/preprocessor/seq/enum.hpp>
|
18 | 18 | #include <boost/type_traits/is_same.hpp>
|
| 19 | +#include <boost/utility/enable_if.hpp> |
19 | 20 |
|
20 | 21 | #include <boost/units/heterogeneous_system.hpp>
|
21 | 22 | #include <boost/units/homogeneous_system.hpp>
|
@@ -326,15 +327,30 @@ struct conversion_impl<0>
|
326 | 327 | };
|
327 | 328 | };
|
328 | 329 |
|
| 330 | +template<typename Unit1, typename Unit2> |
| 331 | +class has_conversion_factor |
| 332 | +{ |
| 333 | + typedef char yes[1]; |
| 334 | + typedef char no[2]; |
| 335 | + |
| 336 | + template<typename T, typename U> static yes& test(char(*)[sizeof(conversion_factor(T(), U()))]); |
| 337 | + |
| 338 | + template<typename, typename> static no& test(...); |
| 339 | + |
| 340 | + public: |
| 341 | + enum { value = (sizeof(test<Unit1, Unit2>(0)) == sizeof(yes)) }; |
| 342 | +}; |
| 343 | + |
329 | 344 | } // namespace detail
|
330 | 345 |
|
331 | 346 | /// forward to conversion_factor (intentionally allowing ADL)
|
332 | 347 | /// INTERNAL ONLY
|
333 | 348 | template<class Unit1, class T1, class Unit2, class T2>
|
334 |
| -struct conversion_helper<quantity<Unit1, T1>, quantity<Unit2, T2> > |
| 349 | +struct conversion_helper<quantity<Unit1, T1>, quantity<Unit2, T2>, typename boost::enable_if_c<detail::has_conversion_factor<Unit1, Unit2>::value>::type> |
335 | 350 | {
|
336 | 351 | /// INTERNAL ONLY
|
337 | 352 | typedef quantity<Unit2, T2> destination_type;
|
| 353 | + |
338 | 354 | static BOOST_CONSTEXPR destination_type convert(const quantity<Unit1, T1>& source)
|
339 | 355 | {
|
340 | 356 | return(destination_type::from_value(static_cast<T2>(source.value() * conversion_factor(Unit1(), Unit2()))));
|
|
0 commit comments