| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <iterator> |
| 10 | |
| 11 | // class istream_iterator |
| 12 | |
| 13 | // istream_iterator(); // constexpr since C++11 |
| 14 | // C++17 says: If is_trivially_default_constructible_v<T> is true, then this |
| 15 | // constructor is a constexpr constructor. |
| 16 | |
| 17 | #include <cassert> |
| 18 | #include <iterator> |
| 19 | #include <string> |
| 20 | #include <type_traits> |
| 21 | |
| 22 | #include "test_macros.h" |
| 23 | |
| 24 | struct S { S(); }; // not constexpr |
| 25 | |
| 26 | #if TEST_STD_VER > 14 |
| 27 | template <typename T, bool isTrivial = std::is_trivially_default_constructible_v<T>> |
| 28 | struct test_trivial { |
| 29 | void operator ()() const { |
| 30 | constexpr std::istream_iterator<T> it; |
| 31 | (void)it; |
| 32 | } |
| 33 | }; |
| 34 | |
| 35 | template <typename T> |
| 36 | struct test_trivial<T, false> { |
| 37 | void operator ()() const {} |
| 38 | }; |
| 39 | #endif |
| 40 | |
| 41 | |
| 42 | int main(int, char**) { |
| 43 | { |
| 44 | typedef std::istream_iterator<int> T; |
| 45 | T it; |
| 46 | assert(it == T()); |
| 47 | #if TEST_STD_VER >= 11 |
| 48 | constexpr T it2; |
| 49 | (void)it2; |
| 50 | #endif |
| 51 | } |
| 52 | |
| 53 | #if TEST_STD_VER > 14 |
| 54 | test_trivial<int>()(); |
| 55 | test_trivial<char>()(); |
| 56 | test_trivial<double>()(); |
| 57 | test_trivial<S>()(); |
| 58 | test_trivial<std::string>()(); |
| 59 | #endif |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |