]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/iterators/stream.iterators/istream.iterator/types.pass.cpp
Vendor import of libc++ trunk r302418:
[FreeBSD/FreeBSD.git] / test / std / iterators / stream.iterators / istream.iterator / types.pass.cpp
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 #include "test_macros.h"
44
45 int main()
46 {
47     typedef std::istream_iterator<double> I1; // double is trivially destructible
48 #if TEST_STD_VER <= 14
49     static_assert((std::is_convertible<I1,
50         std::iterator<std::input_iterator_tag, double, std::ptrdiff_t,
51         const double*, const double&> >::value), "");
52 #else
53     static_assert((std::is_same<I1::iterator_category, std::input_iterator_tag>::value), "");
54     static_assert((std::is_same<I1::value_type, double>::value), "");
55     static_assert((std::is_same<I1::difference_type, std::ptrdiff_t>::value), "");
56     static_assert((std::is_same<I1::pointer, const double*>::value), "");
57     static_assert((std::is_same<I1::reference, const double&>::value), "");
58 #endif
59     static_assert((std::is_same<I1::char_type, char>::value), "");
60     static_assert((std::is_same<I1::traits_type, std::char_traits<char> >::value), "");
61     static_assert((std::is_same<I1::istream_type, std::istream>::value), "");
62     static_assert( std::is_trivially_copy_constructible<I1>::value, "");
63     static_assert( std::is_trivially_destructible<I1>::value, "");
64
65     typedef std::istream_iterator<unsigned, wchar_t> I2; // unsigned is trivially destructible
66 #if TEST_STD_VER <= 14
67     static_assert((std::is_convertible<I2,
68         std::iterator<std::input_iterator_tag, unsigned, std::ptrdiff_t,
69         const unsigned*, const unsigned&> >::value), "");
70 #else
71     static_assert((std::is_same<I2::iterator_category, std::input_iterator_tag>::value), "");
72     static_assert((std::is_same<I2::value_type, unsigned>::value), "");
73     static_assert((std::is_same<I2::difference_type, std::ptrdiff_t>::value), "");
74     static_assert((std::is_same<I2::pointer, const unsigned*>::value), "");
75     static_assert((std::is_same<I2::reference, const unsigned&>::value), "");
76 #endif
77     static_assert((std::is_same<I2::char_type, wchar_t>::value), "");
78     static_assert((std::is_same<I2::traits_type, std::char_traits<wchar_t> >::value), "");
79     static_assert((std::is_same<I2::istream_type, std::wistream>::value), "");
80     static_assert( std::is_trivially_copy_constructible<I2>::value, "");
81     static_assert( std::is_trivially_destructible<I2>::value, "");
82
83     typedef std::istream_iterator<std::string> I3; // string is NOT trivially destructible
84     static_assert(!std::is_trivially_copy_constructible<I3>::value, "");
85     static_assert(!std::is_trivially_destructible<I3>::value, "");
86 }