Here is a sketch of what C++0x std::complex might look like. Minus, of course,
constexpr. Also included in the patch is a testfile that does the usual
init_list tests on std::complex overloads.

It fails to compile, with ambiguous overloads. As so:

%$bld/H-x86-gcc.20090927/bin/g++ -std=gnu++0x -g -O2
testsuite/26_numerics/complex/complex_init.cc 
testsuite/26_numerics/complex/complex_init.cc: In function ‘void
check_copy_list_initialization() [with _Tp = float]’:
testsuite/26_numerics/complex/complex_init.cc:33:41:   instantiated from here
testsuite/26_numerics/complex/complex_init.cc:18:42: error: call of overloaded
‘complex(<brace-enclosed initializer list>)’ is ambiguous
/mnt/disk/dolores/mnt/share/bld/H-x86-gcc.20090927/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0/complex:1458:3:
note: candidates are: std::complex<float>::complex(const std::complex<long
double>&)
/mnt/disk/dolores/mnt/share/bld/H-x86-gcc.20090927/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0/complex:1454:3:
note:                 std::complex<float>::complex(const std::complex<double>&)
/mnt/disk/dolores/mnt/share/bld/H-x86-gcc.20090927/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0/complex:1020:5:
note:                 std::complex<float>::complex(const std::complex<float>&)
testsuite/26_numerics/complex/complex_init.cc: In function ‘void
check_copy_list_initialization() [with _Tp = double]’:
testsuite/26_numerics/complex/complex_init.cc:34:42:   instantiated from here
testsuite/26_numerics/complex/complex_init.cc:18:42: error: call of overloaded
‘complex(<brace-enclosed initializer list>)’ is ambiguous
/mnt/disk/dolores/mnt/share/bld/H-x86-gcc.20090927/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0/complex:1462:3:
note: candidates are: std::complex<double>::complex(const std::complex<long
double>&)
/mnt/disk/dolores/mnt/share/bld/H-x86-gcc.20090927/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0/complex:1176:7:
note:                 std::complex<double>::complex(const std::complex<float>&)
/mnt/disk/dolores/mnt/share/bld/H-x86-gcc.20090927/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0/complex:1164:5:
note:                 std::complex<double>::complex(const
std::complex<double>&)
testsuite/26_numerics/complex/complex_init.cc: In function ‘void
check_copy_list_initialization() [with _Tp = long double]’:
testsuite/26_numerics/complex/complex_init.cc:35:47:   instantiated from here
testsuite/26_numerics/complex/complex_init.cc:18:42: error: call of overloaded
‘complex(<brace-enclosed initializer list>)’ is ambiguous
/mnt/disk/dolores/mnt/share/bld/H-x86-gcc.20090927/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0/complex:1324:7:
note: candidates are: std::complex<long double>::complex(const
std::complex<double>&)
/mnt/disk/dolores/mnt/share/bld/H-x86-gcc.20090927/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0/complex:1321:7:
note:                 std::complex<long double>::complex(const
std::complex<float>&)
/mnt/disk/dolores/mnt/share/bld/H-x86-gcc.20090927/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.5.0/../../../../include/c++/4.5.0/complex:1309:5:
note:                 std::complex<long double>::complex(const
std::complex<long double>&)


It's hard to tell w/o the constexpr overloads in. Thoughts?

-benjamin


-- 
           Summary: C++0x std::complex vs. initialization lists
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bkoz at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41510

Reply via email to