1///////////////////////////////////////////////////////////////////////////////
2/// \file complex.hpp
3///
4// Copyright 2005 Eric Niebler. Distributed under the Boost
5// Software License, Version 1.0. (See accompanying file
6// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
8#ifndef BOOST_NUMERIC_FUNCTIONAL_COMPLEX_HPP_EAN_01_17_2006
9#define BOOST_NUMERIC_FUNCTIONAL_COMPLEX_HPP_EAN_01_17_2006
10
11#ifdef BOOST_NUMERIC_FUNCTIONAL_HPP_INCLUDED
12# error Include this file before boost/accumulators/numeric/functional.hpp
13#endif
14
15#include <complex>
16#include <boost/mpl/or.hpp>
17#include <boost/type_traits/is_same.hpp>
18#include <boost/utility/enable_if.hpp>
19#include <boost/typeof/std/complex.hpp>
20#include <boost/accumulators/numeric/functional_fwd.hpp>
21
22namespace boost { namespace numeric { namespace operators
23{
24 // So that the stats compile when Sample type is std::complex
25 template<typename T, typename U>
26 typename
27 disable_if<
28 mpl::or_<is_same<T, U>, is_same<std::complex<T>, U> >
29 , std::complex<T>
30 >::type
31 operator *(std::complex<T> ri, U const &u)
32 {
33 // BUGBUG promote result to typeof(T()*u) ?
34 return ri *= static_cast<T>(u);
35 }
36
37 template<typename T, typename U>
38 typename
39 disable_if<
40 mpl::or_<is_same<T, U>, is_same<std::complex<T>, U> >
41 , std::complex<T>
42 >::type
43 operator /(std::complex<T> ri, U const &u)
44 {
45 // BUGBUG promote result to typeof(T()*u) ?
46 return ri /= static_cast<T>(u);
47 }
48
49}}} // namespace boost::numeric::operators
50
51namespace boost { namespace numeric
52{
53 namespace detail
54 {
55 template<typename T>
56 struct one_complex
57 {
58 static std::complex<T> const value;
59 };
60
61 template<typename T>
62 std::complex<T> const one_complex<T>::value
63 = std::complex<T>(numeric::one<T>::value, numeric::one<T>::value);
64 }
65
66 /// INTERNAL ONLY
67 ///
68 template<typename T>
69 struct one<std::complex<T> >
70 : detail::one_complex<T>
71 {
72 typedef one type;
73 typedef std::complex<T> value_type;
74 operator value_type const & () const
75 {
76 return detail::one_complex<T>::value;
77 }
78 };
79
80}} // namespace boost::numeric
81
82#endif
83

source code of boost/boost/accumulators/numeric/functional/complex.hpp