[Boost-bugs] [ boost-Bugs-1315712 ] Adding boost::is_complex to type_traits.hpp

Bugs item #1315712, was opened at 2005-10-07 10:03 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=107586&aid=1315712&group_id=7586 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: type_traits Group: None Status: Open Resolution: None Priority: 5 Submitted By: Edward Grace (ejgrace) Assigned to: John Maddock (johnmaddock) Summary: Adding boost::is_complex to type_traits.hpp Initial Comment: Following a discussion on boost-users I am adding this to the bug system so it doesn't get lost. Can someone add a boost::is_complex<T> trait so that checks for complex numbers can be made. This is a common requirement in templated scientific code as complex numbers sometimes need to be treated differently. Attached is my implementation, please feel free to incorperate it. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=107586&aid=1315712&group_id=7586 ------------------------------------------------------- This SF.Net email is sponsored by: Power Architecture Resource Center: Free content, downloads, discussions, and more. http://solutions.newsforge.com/ibmarch.tmpl _______________________________________________ Boost-bugs mailing list Boost-bugs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/boost-bugs

SourceForge.net wrote:
Bugs item #1315712, was opened at 2005-10-07 10:03 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=107586&aid=1315712&group_id=7586
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: type_traits Group: None Status: Open Resolution: None Priority: 5 Submitted By: Edward Grace (ejgrace) Assigned to: John Maddock (johnmaddock) Summary: Adding boost::is_complex to type_traits.hpp
Initial Comment: Following a discussion on boost-users I am adding this to the bug system so it doesn't get lost.
Can someone add a boost::is_complex<T> trait so that checks for complex numbers can be made. This is a common requirement in templated scientific code as complex numbers sometimes need to be treated differently.
Attached is my implementation, please feel free to incorperate it.
Uh, where is it? There are a number of useful things to go with complex. Here is another. It is common to need the scalar type that corresponds to a numeric type, whether that type is complex or scalar. For example, the type returned by abs. Implementation is pretty trivial: #include <complex> template<typename T> struct Scalar { typedef T type; }; template<typename T> struct Scalar<std::complex<T> > { typedef T type; };

Uh, where is it?
It was posted to the boost-users list. Implementation is utterly trivial anyway.
There are a number of useful things to go with complex. Here is another.
It is common to need the scalar type that corresponds to a numeric type, whether that type is complex or scalar. For example, the type returned by abs. Implementation is pretty trivial:
Interesting, and good point. OK, is there any objection to is_complex being added, what about Neal's trait (and what to call it if it is added, "scalar" maybe?). John.

John Maddock wrote:
Uh, where is it?
It was posted to the boost-users list. Implementation is utterly trivial anyway.
There are a number of useful things to go with complex. Here is another.
It is common to need the scalar type that corresponds to a numeric type, whether that type is complex or scalar. For example, the type returned by abs. Implementation is pretty trivial:
Interesting, and good point.
OK, is there any objection to is_complex being added, what about Neal's trait (and what to call it if it is added, "scalar" maybe?).
I propose a collection of complex utilities. This would include: 1) is_complex 2) scalar 3) A collection of iterator adapters: 3.1) Transform complex sequence to scalar (yield alternating real/imag parts) 3.2) Inverse of 3.1 3.3) Pick off real part of complex 3.4) Pick off imag part of complex 3.5) zip 2 scalar sequences into complex sequence I have code based on boost iterator adapter for all the above.

I propose a collection of complex utilities. This would include:
1) is_complex 2) scalar 3) A collection of iterator adapters: 3.1) Transform complex sequence to scalar (yield alternating real/imag parts) 3.2) Inverse of 3.1 3.3) Pick off real part of complex 3.4) Pick off imag part of complex 3.5) zip 2 scalar sequences into complex sequence
I have code based on boost iterator adapter for all the above.
All sound useful, but we're not really talking type traits anymore :-) Sounds like a new submission to the Math lib maybe? John.

Oh, 1 more: There are many cases you want to define a function F that applies both to scalar, and when applied to complex the result F(x) = complex (F(real(x)), F(imag(x))). ComplexFunc is handy for this: template<typename UnaryFunction, typename in_t> inline std::complex<typename boost::result_of<UnaryFunction(typename in_t::value_type)>::type> ComplexFunc (UnaryFunction f, in_t x) { typedef std::complex<typename boost::result_of<UnaryFunction(typename in_t::value_type)>::type> ret_t; return ret_t (f (real (x)), f (imag (x))); }
participants (3)
-
John Maddock
-
Neal Becker
-
SourceForge.net