
The following code: template<typename int_t> inline typename boost::enable_if_c<boost::is_integral<int_t>::value, std::complex<int_t> >::value operator >> (std::complex<int_t> const&x, int bits) { return std::complex<int_t> (real (x) >> bits, imag (x) >> bits); } // template<typename int_t> // inline std::complex<int_t> // operator >> (std::complex<int_t> const&x, int bits) { // return std::complex<int_t> (real (x) >> bits, imag (x) >> bits); // } int main() { std::cout << (x >> 1) << '\n'; } gives: error: no match for 'operator>>' in 'x >> 1' (gcc-4.1.2) Uncomment the commented out version (without enable_if) and it compiles. What's wrong here?

on Fri Aug 31 2007, Neal Becker <ndbecker2-AT-gmail.com> wrote:
template<typename int_t> inline typename boost::enable_if_c<boost::is_integral<int_t>::value, std::complex<int_t> >::value operator >> (std::complex<int_t> const&x, int bits) { return std::complex<int_t> (real (x) >> bits, imag (x) >> bits); }
// template<typename int_t> // inline std::complex<int_t> // operator >> (std::complex<int_t> const&x, int bits) { // return std::complex<int_t> (real (x) >> bits, imag (x) >> bits); // }
int main() { std::cout << (x >> 1) << '\n'; }
gives: error: no match for 'operator>>' in 'x >> 1' (gcc-4.1.2)
Uncomment the commented out version (without enable_if) and it compiles. What's wrong here?
You need to replace ::value with ::type in the enable_if_c invocation. Though I don't know why you'd use enable_if_c when enable_if is so much nicer here. inline typename boost::enable_if<boost::is_integral<int_t>, std::complex<int_t> >::type BTW, the standard doesn't support instantiationi of std::complex on anything other than a floating point type. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com The Astoria Seminar ==> http://www.astoriaseminar.com

Neal Becker wrote:
The following code:
template<typename int_t> inline typename boost::enable_if_c<boost::is_integral<int_t>::value, std::complex<int_t> >::value operator >> (std::complex<int_t> const&x, int bits) { return std::complex<int_t> (real (x) >> bits, imag (x) >> bits); }
// template<typename int_t> // inline std::complex<int_t> // operator >> (std::complex<int_t> const&x, int bits) { // return std::complex<int_t> (real (x) >> bits, imag (x) >> bits); // }
int main() { std::cout << (x >> 1) << '\n'; }
gives: error: no match for 'operator>>' in 'x >> 1' (gcc-4.1.2)
Uncomment the commented out version (without enable_if) and it compiles. What's wrong here?
I figured it out, this works: template<typename int_t> inline typename boost::enable_if<boost::is_integral<int_t>, std::complex<int_t> >::type operator >> (std::complex<int_t> const&x, int bits) { return std::complex<int_t> (real (x) >> bits, imag (x) >> bits); }
participants (2)
-
David Abrahams
-
Neal Becker