// 26.3.7 values:
-// real
+template <class _Tp, bool = is_integral<_Tp>::value,
+ bool = is_floating_point<_Tp>::value
+ >
+struct __libcpp_complex_overload_traits {};
-template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-_Tp
-real(const complex<_Tp>& __c)
+// Integral Types
+template <class _Tp>
+struct __libcpp_complex_overload_traits<_Tp, true, false>
{
- return __c.real();
-}
+ typedef double _ValueType;
+ typedef complex<double> _ComplexType;
+};
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-long double
-real(long double __re)
+// Floating point types
+template <class _Tp>
+struct __libcpp_complex_overload_traits<_Tp, false, true>
{
- return __re;
-}
+ typedef _Tp _ValueType;
+ typedef complex<_Tp> _ComplexType;
+};
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-double
-real(double __re)
-{
- return __re;
-}
+// real
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-typename enable_if
-<
- is_integral<_Tp>::value,
- double
->::type
-real(_Tp __re)
+_Tp
+real(const complex<_Tp>& __c)
{
- return __re;
+ return __c.real();
}
+template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-float
-real(float __re)
+typename __libcpp_complex_overload_traits<_Tp>::_ValueType
+real(_Tp __re)
{
return __re;
}
return __c.imag();
}
+template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-long double
-imag(long double __re)
-{
- return 0;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-double
-imag(double __re)
-{
- return 0;
-}
-
-template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-typename enable_if
-<
- is_integral<_Tp>::value,
- double
->::type
-imag(_Tp __re)
-{
- return 0;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
-float
-imag(float __re)
+typename __libcpp_complex_overload_traits<_Tp>::_ValueType
+imag(_Tp __re)
{
return 0;
}
return atan2(__c.imag(), __c.real());
}
+template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
-long double
-arg(long double __re)
+typename enable_if<
+ is_same<_Tp, long double>::value,
+ long double
+>::type
+arg(_Tp __re)
{
return atan2l(0.L, __re);
}
-inline _LIBCPP_INLINE_VISIBILITY
-double
-arg(double __re)
-{
- return atan2(0., __re);
-}
-
template<class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
- is_integral<_Tp>::value,
+ is_integral<_Tp>::value || is_same<_Tp, double>::value,
double
>::type
arg(_Tp __re)
return atan2(0., __re);
}
+template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
-float
-arg(float __re)
+typename enable_if<
+ is_same<_Tp, float>::value,
+ float
+>::type
+arg(_Tp __re)
{
return atan2f(0.F, __re);
}
return __c.real() * __c.real() + __c.imag() * __c.imag();
}
+template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
-long double
-norm(long double __re)
-{
- return __re * __re;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-double
-norm(double __re)
-{
- return __re * __re;
-}
-
-template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
-typename enable_if
-<
- is_integral<_Tp>::value,
- double
->::type
+typename __libcpp_complex_overload_traits<_Tp>::_ValueType
norm(_Tp __re)
{
- return (double)__re * __re;
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-float
-norm(float __re)
-{
- return __re * __re;
+ typedef typename __libcpp_complex_overload_traits<_Tp>::_ValueType _ValueType;
+ return static_cast<_ValueType>(__re) * __re;
}
// conj
return complex<_Tp>(__c.real(), -__c.imag());
}
+template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
-complex<long double>
-conj(long double __re)
-{
- return complex<long double>(__re);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-complex<double>
-conj(double __re)
-{
- return complex<double>(__re);
-}
-
-template<class _Tp>
-inline _LIBCPP_INLINE_VISIBILITY
-typename enable_if
-<
- is_integral<_Tp>::value,
- complex<double>
->::type
+typename __libcpp_complex_overload_traits<_Tp>::_ComplexType
conj(_Tp __re)
{
- return complex<double>(__re);
+ typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType;
+ return _ComplexType(__re);
}
-inline _LIBCPP_INLINE_VISIBILITY
-complex<float>
-conj(float __re)
-{
- return complex<float>(__re);
-}
+
// proj
return __r;
}
+template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
-complex<long double>
-proj(long double __re)
-{
- if (isinf(__re))
- __re = abs(__re);
- return complex<long double>(__re);
-}
-
-inline _LIBCPP_INLINE_VISIBILITY
-complex<double>
-proj(double __re)
+typename enable_if
+<
+ is_floating_point<_Tp>::value,
+ typename __libcpp_complex_overload_traits<_Tp>::_ComplexType
+>::type
+proj(_Tp __re)
{
if (isinf(__re))
__re = abs(__re);
- return complex<double>(__re);
+ return complex<_Tp>(__re);
}
-template<class _Tp>
+template <class _Tp>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
is_integral<_Tp>::value,
- complex<double>
+ typename __libcpp_complex_overload_traits<_Tp>::_ComplexType
>::type
proj(_Tp __re)
{
- return complex<double>(__re);
+ typedef typename __libcpp_complex_overload_traits<_Tp>::_ComplexType _ComplexType;
+ return _ComplexType(__re);
}
-inline _LIBCPP_INLINE_VISIBILITY
-complex<float>
-proj(float __re)
-{
- if (isinf(__re))
- __re = abs(__re);
- return complex<float>(__re);
-}
// polar
--- /dev/null
+//===----------------------------------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+// <complex>
+
+// Test that UDT's convertible to an integral or floating point type do not
+// participate in overload resolution.
+
+#include <complex>
+#include <type_traits>
+#include <cassert>
+
+template <class IntT>
+struct UDT {
+ operator IntT() const { return 1; }
+};
+
+UDT<float> ft;
+UDT<double> dt;
+UDT<long double> ldt;
+UDT<int> it;
+UDT<unsigned long> uit;
+
+int main()
+{
+ {
+ std::real(ft); // expected-error {{no matching function}}
+ std::real(dt); // expected-error {{no matching function}}
+ std::real(ldt); // expected-error {{no matching function}}
+ std::real(it); // expected-error {{no matching function}}
+ std::real(uit); // expected-error {{no matching function}}
+ }
+ {
+ std::imag(ft); // expected-error {{no matching function}}
+ std::imag(dt); // expected-error {{no matching function}}
+ std::imag(ldt); // expected-error {{no matching function}}
+ std::imag(it); // expected-error {{no matching function}}
+ std::imag(uit); // expected-error {{no matching function}}
+ }
+ {
+ std::arg(ft); // expected-error {{no matching function}}
+ std::arg(dt); // expected-error {{no matching function}}
+ std::arg(ldt); // expected-error {{no matching function}}
+ std::arg(it); // expected-error {{no matching function}}
+ std::arg(uit); // expected-error {{no matching function}}
+ }
+ {
+ std::norm(ft); // expected-error {{no matching function}}
+ std::norm(dt); // expected-error {{no matching function}}
+ std::norm(ldt); // expected-error {{no matching function}}
+ std::norm(it); // expected-error {{no matching function}}
+ std::norm(uit); // expected-error {{no matching function}}
+ }
+ {
+ std::conj(ft); // expected-error {{no matching function}}
+ std::conj(dt); // expected-error {{no matching function}}
+ std::conj(ldt); // expected-error {{no matching function}}
+ std::conj(it); // expected-error {{no matching function}}
+ std::conj(uit); // expected-error {{no matching function}}
+ }
+ {
+ std::proj(ft); // expected-error {{no matching function}}
+ std::proj(dt); // expected-error {{no matching function}}
+ std::proj(ldt); // expected-error {{no matching function}}
+ std::proj(it); // expected-error {{no matching function}}
+ std::proj(uit); // expected-error {{no matching function}}
+ }
+}