Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
ArithmeticConversionTraits.h
1
16
17#pragma once
18
28
29#if defined(ArithmeticConversionTraits_RECURSES)
30#error Recursive header files inclusion detected in ArithmeticConversionTraits.h
31#else // defined(ArithmeticConversionTraits_RECURSES)
33#define ArithmeticConversionTraits_RECURSES
34
35#if !defined ArithmeticConversionTraits_h
37#define ArithmeticConversionTraits_h
38
40// Inclusions
41#include <type_traits>
42#include "DGtal/base/Common.h"
44
45namespace DGtal
46{
47
49 // template class ArithmeticConversionTraits
91 template <typename T, typename U, typename Enable = void>
93 {
94 };
95
100 template <typename T, typename U>
102 typename std::enable_if<
103 ! std::is_same< T, typename std::remove_cv< typename std::remove_reference<T>::type >::type >::value
104 || ! std::is_same< U, typename std::remove_cv< typename std::remove_reference<U>::type >::type >::value >::type >
106 typename std::remove_cv< typename std::remove_reference<T>::type >::type,
107 typename std::remove_cv< typename std::remove_reference<U>::type >::type >
108 {
109 };
110
111
119 template <typename T, typename U>
120 struct ArithmeticConversionTraits< T, U, typename std::enable_if< std::is_arithmetic<T>::value
121 && std::is_arithmetic<U>::value >::type >
122 {
123 using type = typename std::common_type<T, U>::type;
124 };
125
133 template <typename T, typename U>
135
143 template <typename T, typename U, typename Enable = void>
145 : std::false_type
146 {
147 };
148
157 template <typename T, typename U>
159 typename std::conditional<false, ArithmeticConversionType<T, U>, void>::type >
160 : std::true_type
161 {
162 };
163
164
175 template <typename LHS,typename RHS,typename... Args >
176 inline
178 constructFromArithmeticConversion( LHS const& lhs, RHS const& rhs, Args &&... args )
179 {
180 boost::ignore_unused_variable_warning(lhs);
181 boost::ignore_unused_variable_warning(rhs);
182
183 return ArithmeticConversionType<LHS, RHS>( std::forward<Args>(args)... );
184 }
185
190 template <typename T>
191 struct ArithmeticConversionTraits<T, BigInteger,typename std::enable_if< std::is_integral<T>::value >::type >
192 {
194 };
195
200 template <typename U>
201 struct ArithmeticConversionTraits<BigInteger, U,typename std::enable_if< std::is_integral<U>::value >::type >
202 {
204 };
205
211 template <>
216} // namespace DGtal
217
218
219#endif // !defined ArithmeticConversionTraits_h
220
221#undef ArithmeticConversionTraits_RECURSES
222#endif // else defined(ArithmeticConversionTraits_RECURSES)
DGtal is the top-level namespace which contains all DGtal functions and types.
ArithmeticConversionType< LHS, RHS > constructFromArithmeticConversion(LHS const &lhs, RHS const &rhs, Args &&... args)
Call constructor for the result type of an arithmetic operation.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>, boost::multiprecision::et_off > BigInteger
Definition BasicTypes.h:75
typename ArithmeticConversionTraits< T, U >::type ArithmeticConversionType
Result type of arithmetic binary operators between two given types.
STL namespace.
Aim: Trait class to get result type of arithmetic binary operators between two given types.
Helper to determine if an arithmetic operation between two given types has a valid result type (ie is...