DGtal 1.3.0
Loading...
Searching...
No Matches
ArithmeticConversionTraits.h
1
17#pragma once
18
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>
121 typename std::enable_if< std::is_arithmetic<T>::value
122 && std::is_arithmetic<U>::value >::type >
123 {
124 using type = typename std::common_type<T, U>::type;
125 };
126
134 template <typename T, typename U>
136
144 template <typename T, typename U, typename Enable = void>
146 : std::false_type
147 {
148 };
149
158 template <typename T, typename U>
160 typename std::conditional<false, ArithmeticConversionType<T, U>, void>::type >
161 : std::true_type
162 {
163 };
164
165
176 template <
177 typename LHS,
178 typename RHS,
179 typename... Args >
180 inline
182 constructFromArithmeticConversion( LHS const& lhs, RHS const& rhs, Args &&... args )
183 {
184 boost::ignore_unused_variable_warning(lhs);
185 boost::ignore_unused_variable_warning(rhs);
186
187 return ArithmeticConversionType<LHS, RHS>( std::forward<Args>(args)... );
188 }
189
190#ifdef WITH_GMP
198 template <typename T, typename GMP1, typename GMP2>
199 struct ArithmeticConversionTraits<T, __gmp_expr<GMP1, GMP2>,
200 typename std::enable_if< std::is_integral<T>::value >::type >
201 {
203 };
204
212 template <typename GMP1, typename GMP2, typename U>
213 struct ArithmeticConversionTraits<__gmp_expr<GMP1, GMP2>, U,
214 typename std::enable_if< std::is_integral<U>::value >::type >
215 {
217 };
218
226 template <typename GMPL1, typename GMPL2, typename GMPR1, typename GMPR2>
227 struct ArithmeticConversionTraits<__gmp_expr<GMPL1, GMPL2>, __gmp_expr<GMPR1, GMPR2>>
228 {
230 };
231#endif
232
233} // namespace DGtal
234
235#endif // !defined ArithmeticConversionTraits_h
236
237#undef ArithmeticConversionTraits_RECURSES
238#endif // else defined(ArithmeticConversionTraits_RECURSES)
DGtal is the top-level namespace which contains all DGtal functions and types.
typename ArithmeticConversionTraits< T, U >::type ArithmeticConversionType
Result type of arithmetic binary operators between two given types.
ArithmeticConversionType< LHS, RHS > constructFromArithmeticConversion(LHS const &lhs, RHS const &rhs, Args &&... args)
Call constructor for the result type of an arithmetic operation.
mpz_class BigInteger
Multi-precision integer with GMP implementation.
Definition: BasicTypes.h:79
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...