Home | History | Annotate | Download | only in istream.iterator
      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 // <iterator>
     11 
     12 // Test fails due to use of is_trivially_* trait.
     13 // XFAIL: gcc-4.9
     14 
     15 // template <class T, class charT = char, class traits = char_traits<charT>,
     16 //           class Distance = ptrdiff_t>
     17 // class istream_iterator
     18 //     : public iterator<input_iterator_tag, T, Distance, const T*, const T&>
     19 // {
     20 // public:
     21 //     typedef charT char_type;
     22 //     typedef traits traits_type;
     23 //     typedef basic_istream<charT,traits> istream_type;
     24 //     ...
     25 //
     26 // Before C++17, we have:
     27 //   If T is a literal type, then the default constructor shall be a constexpr constructor.
     28 //   If T is a literal type, then this constructor shall be a trivial copy constructor.
     29 //   If T is a literal type, then this destructor shall be a trivial destructor.
     30 // C++17 says:
     31 //   If is_trivially_default_constructible_v<T> is true, then
     32 //       this constructor (the default ctor) is a constexpr constructor.
     33 //   If is_trivially_copy_constructible_v<T> is true, then
     34 //       this constructor (the copy ctor) is a trivial copy constructor.
     35 //   If is_trivially_destructible_v<T> is true, then this
     36 //       destructor is a trivial destructor.
     37 //  Testing the C++17 ctors for this are in the ctor tests.
     38 
     39 #include <iterator>
     40 #include <type_traits>
     41 #include <string>
     42 
     43 int main()
     44 {
     45     typedef std::istream_iterator<double> I1; // double is trivially destructible
     46     static_assert((std::is_convertible<I1,
     47         std::iterator<std::input_iterator_tag, double, std::ptrdiff_t,
     48         const double*, const double&> >::value), "");
     49     static_assert((std::is_same<I1::char_type, char>::value), "");
     50     static_assert((std::is_same<I1::traits_type, std::char_traits<char> >::value), "");
     51     static_assert((std::is_same<I1::istream_type, std::istream>::value), "");
     52     static_assert( std::is_trivially_copy_constructible<I1>::value, "");
     53     static_assert( std::is_trivially_destructible<I1>::value, "");
     54 
     55     typedef std::istream_iterator<unsigned, wchar_t> I2; // unsigned is trivially destructible
     56     static_assert((std::is_convertible<I2,
     57         std::iterator<std::input_iterator_tag, unsigned, std::ptrdiff_t,
     58         const unsigned*, const unsigned&> >::value), "");
     59     static_assert((std::is_same<I2::char_type, wchar_t>::value), "");
     60     static_assert((std::is_same<I2::traits_type, std::char_traits<wchar_t> >::value), "");
     61     static_assert((std::is_same<I2::istream_type, std::wistream>::value), "");
     62     static_assert( std::is_trivially_copy_constructible<I2>::value, "");
     63     static_assert( std::is_trivially_destructible<I2>::value, "");
     64 
     65     typedef std::istream_iterator<std::string> I3; // string is NOT trivially destructible
     66     static_assert(!std::is_trivially_copy_constructible<I3>::value, "");
     67     static_assert(!std::is_trivially_destructible<I3>::value, "");
     68 }
     69