PR modula2/115112 Incorrect line debugging information occurs during INC builtin
[gcc.git] / libstdc++-v3 / testsuite / 25_algorithms / pstl / alg_merge / merge.cc
blobeab12608515a2ccbddfb2f48610b8860c9d764a3
1 // -*- C++ -*-
2 // { dg-options "-ltbb" }
3 // { dg-do run { target c++17 } }
4 // { dg-timeout-factor 3 }
5 // { dg-require-effective-target tbb_backend }
7 //===-- merge.pass.cpp ----------------------------------------------------===//
8 //
9 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
10 // See https://llvm.org/LICENSE.txt for license information.
11 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13 //===----------------------------------------------------------------------===//
15 #include "pstl/pstl_test_config.h"
17 #ifdef PSTL_STANDALONE_TESTS
18 #include <algorithm>
19 #include <functional>
20 #include "pstl/execution"
21 #include "pstl/algorithm"
23 #else
24 #include <execution>
25 #include <algorithm>
26 #include <functional>
27 #endif // PSTL_STANDALONE_TESTS
29 #include "pstl/test_utils.h"
31 using namespace TestUtils;
33 struct test_merge
35 template <typename Policy, typename InputIterator1, typename InputIterator2, typename OutputIterator,
36 typename Compare>
37 void
38 operator()(Policy&& exec, InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
39 OutputIterator out_first, OutputIterator out_last, Compare comp)
41 using namespace std;
43 const auto res = merge(exec, first1, last1, first2, last2, out_first, comp);
44 EXPECT_TRUE(res == out_last, "wrong return result from merge with predicate");
45 EXPECT_TRUE(is_sorted(out_first, res, comp), "wrong result from merge with predicate");
46 EXPECT_TRUE(includes(out_first, res, first1, last1, comp), "first sequence is not a part of result");
47 EXPECT_TRUE(includes(out_first, res, first2, last2, comp), "second sequence is not a part of result");
50 const auto res = merge(exec, first1, last1, first2, last2, out_first);
51 EXPECT_TRUE(res == out_last, "wrong return result from merge");
52 EXPECT_TRUE(is_sorted(out_first, res), "wrong result from merge");
56 // for reverse iterators
57 template <typename Policy, typename InputIterator1, typename InputIterator2, typename OutputIterator,
58 typename Compare>
59 void
60 operator()(Policy&& exec, std::reverse_iterator<InputIterator1> first1, std::reverse_iterator<InputIterator1> last1,
61 std::reverse_iterator<InputIterator2> first2, std::reverse_iterator<InputIterator2> last2,
62 std::reverse_iterator<OutputIterator> out_first, std::reverse_iterator<OutputIterator> out_last, Compare)
64 using namespace std;
65 typedef typename std::iterator_traits<std::reverse_iterator<InputIterator1>>::value_type T;
66 const auto res = merge(exec, first1, last1, first2, last2, out_first, std::greater<T>());
68 EXPECT_TRUE(res == out_last, "wrong return result from merge with predicate");
69 EXPECT_TRUE(is_sorted(out_first, res, std::greater<T>()), "wrong result from merge with predicate");
70 EXPECT_TRUE(includes(out_first, res, first1, last1, std::greater<T>()),
71 "first sequence is not a part of result");
72 EXPECT_TRUE(includes(out_first, res, first2, last2, std::greater<T>()),
73 "second sequence is not a part of result");
77 template <typename T, typename Generator1, typename Generator2>
78 void
79 test_merge_by_type(Generator1 generator1, Generator2 generator2)
81 using namespace std;
82 size_t max_size = 100000;
83 Sequence<T> in1(max_size, generator1);
84 Sequence<T> in2(max_size / 2, generator2);
85 Sequence<T> out(in1.size() + in2.size());
86 std::sort(in1.begin(), in1.end());
87 std::sort(in2.begin(), in2.end());
89 for (size_t size = 0; size <= max_size; size = size <= 16 ? size + 1 : size_t(3.1415 * size))
91 invoke_on_all_policies(test_merge(), in1.cbegin(), in1.cbegin() + size, in2.data(), in2.data() + size / 2,
92 out.begin(), out.begin() + 1.5 * size, std::less<T>());
93 invoke_on_all_policies(test_merge(), in1.data(), in1.data() + size, in2.cbegin(), in2.cbegin() + size / 2,
94 out.begin(), out.begin() + 3 * size / 2, std::less<T>());
98 template <typename T>
99 struct test_non_const
101 template <typename Policy, typename InputIterator, typename OutputIterator>
102 void
103 operator()(Policy&& exec, InputIterator input_iter, OutputIterator out_iter)
105 merge(exec, input_iter, input_iter, input_iter, input_iter, out_iter, non_const(std::less<T>()));
110 main()
112 test_merge_by_type<int32_t>([](size_t v) { return (v % 2 == 0 ? v : -v) * 3; }, [](size_t v) { return v * 2; });
113 test_merge_by_type<float64_t>([](size_t v) { return float64_t(v); }, [](size_t v) { return float64_t(v - 100); });
115 #if !defined(_PSTL_ICC_16_17_TEST_64_TIMEOUT)
116 test_merge_by_type<Wrapper<int16_t>>([](size_t v) { return Wrapper<int16_t>(v % 100); },
117 [](size_t v) { return Wrapper<int16_t>(v % 10); });
118 #endif
120 test_algo_basic_double<int32_t>(run_for_rnd_fw<test_non_const<int32_t>>());
122 std::cout << done() << std::endl;
123 return 0;