Home | History | Annotate | Download | only in complex.ops
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <complex>
     11 
     12 // template<class T, class charT, class traits>
     13 //   basic_istream<charT, traits>&
     14 //   operator>>(basic_istream<charT, traits>& is, complex<T>& x);
     15 
     16 #include <complex>
     17 #include <sstream>
     18 #include <cassert>
     19 
     20 int main()
     21 {
     22     {
     23         std::istringstream is("5");
     24         std::complex<double> c;
     25         is >> c;
     26         assert(c == std::complex<double>(5, 0));
     27         assert(is.eof());
     28     }
     29     {
     30         std::istringstream is(" 5 ");
     31         std::complex<double> c;
     32         is >> c;
     33         assert(c == std::complex<double>(5, 0));
     34         assert(is.good());
     35     }
     36     {
     37         std::istringstream is(" 5, ");
     38         std::complex<double> c;
     39         is >> c;
     40         assert(c == std::complex<double>(5, 0));
     41         assert(is.good());
     42     }
     43     {
     44         std::istringstream is(" , 5, ");
     45         std::complex<double> c;
     46         is >> c;
     47         assert(c == std::complex<double>(0, 0));
     48         assert(is.fail());
     49     }
     50     {
     51         std::istringstream is("5.5 ");
     52         std::complex<double> c;
     53         is >> c;
     54         assert(c == std::complex<double>(5.5, 0));
     55         assert(is.good());
     56     }
     57     {
     58         std::istringstream is(" ( 5.5 ) ");
     59         std::complex<double> c;
     60         is >> c;
     61         assert(c == std::complex<double>(5.5, 0));
     62         assert(is.good());
     63     }
     64     {
     65         std::istringstream is("  5.5)");
     66         std::complex<double> c;
     67         is >> c;
     68         assert(c == std::complex<double>(5.5, 0));
     69         assert(is.good());
     70     }
     71     {
     72         std::istringstream is("(5.5 ");
     73         std::complex<double> c;
     74         is >> c;
     75         assert(c == std::complex<double>(0, 0));
     76         assert(is.fail());
     77     }
     78     {
     79         std::istringstream is("(5.5,");
     80         std::complex<double> c;
     81         is >> c;
     82         assert(c == std::complex<double>(0, 0));
     83         assert(is.fail());
     84     }
     85     {
     86         std::istringstream is("( -5.5 , -6.5 )");
     87         std::complex<double> c;
     88         is >> c;
     89         assert(c == std::complex<double>(-5.5, -6.5));
     90         assert(!is.eof());
     91     }
     92     {
     93         std::istringstream is("(-5.5,-6.5)");
     94         std::complex<double> c;
     95         is >> c;
     96         assert(c == std::complex<double>(-5.5, -6.5));
     97         assert(!is.eof());
     98     }
     99 }
    100