Boost logo

Boost Users :

From: Edward Grace (ej.grace_at_[hidden])
Date: 2005-09-28 02:46:42


Dear all,

Can someone add an is_complex<T>::value trait to type_traits.hpp

::boost::is_complex<T>::value

trait to type_traits.hpp

I have found myself having to do this frequently. It strikes me that for
templated scientific codes it is a common requirement.

Below is my implementation, please feel free to add it. I should probably
inform the maintainer as well, John Maddock but there is no obvious way of
contacting him via the boost site.

 namespace boost {
    /**
     * @brief Default trait for determining if a type is complex at
     * compile-time.
     *
     * If the supplied template parameter type is not a std::complex<>
     * then this struct is instantiated and the ::value enum will be 0
     * at compile time.
     *
     * See also boost::is_float and associated in
     * boost/type_traits.hpp
     */
    template <typename T>
    struct is_complex : ::boost::mpl::false_{};

    /**
     * @brief Overloaded trait for std::complex<> to determine if a
     * type is complex at compile-time.
     *
     * If the supplied type is std::complex<double> or similar this
     * overloaded struct is instantiated and the ::value enum will be
     * 1 at compile-time.
     *
     * See also boost::is_float and associated in
     * boost/type_traits.hpp
     */
    template <typename T>
    struct is_complex<std::complex<T> > : ::boost::mpl::true_{};
  }

-ed

-- 
Dr. Edward Grace
Photonics Group, Physics Department
Blackett Laboratory
Imperial College
SW7 2BW
t: 020 759 47719
e: ej.grace_at_[hidden]
w: http://ptweb.op.ph.ic.ac.uk/~graceej

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net