diff options
Diffstat (limited to 'test/std/algorithms')
13 files changed, 141 insertions, 56 deletions
diff --git a/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp b/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp index a9ccaf4cd959..b7322542931d 100644 --- a/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp +++ b/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp @@ -15,32 +15,49 @@ // void // generate_n(Iter first, Size n, Generator gen); +#ifdef _MSC_VER +#pragma warning(disable: 4244) // conversion from 'const double' to 'int', possible loss of data +#endif + #include <algorithm> #include <cassert> +#include "test_macros.h" #include "test_iterators.h" #include "user_defined_integral.hpp" -typedef UserDefinedIntegral<unsigned> UDI; - struct gen_test { int operator()() const {return 2;} }; -template <class Iter> +template <class Iter, class Size> void -test() +test2() { const unsigned n = 4; int ia[n] = {0}; - assert(std::generate_n(Iter(ia), UDI(n), gen_test()) == Iter(ia+n)); + assert(std::generate_n(Iter(ia), Size(n), gen_test()) == Iter(ia+n)); assert(ia[0] == 2); assert(ia[1] == 2); assert(ia[2] == 2); assert(ia[3] == 2); } +template <class Iter> +void +test() +{ + test2<Iter, int>(); + test2<Iter, unsigned int>(); + test2<Iter, long>(); + test2<Iter, unsigned long>(); + test2<Iter, UserDefinedIntegral<unsigned> >(); + test2<Iter, float>(); + test2<Iter, double>(); // this is PR#35498 + test2<Iter, long double>(); +} + int main() { test<forward_iterator<int*> >(); diff --git a/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp b/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp index ec0526c2dc5c..b837a0e514cf 100644 --- a/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp +++ b/test/std/algorithms/alg.nonmodifying/alg.count/count_if.pass.cpp @@ -21,10 +21,10 @@ #include "test_iterators.h" struct eq { - eq (int val) : v(val) {} - bool operator () (int v2) const { return v == v2; } - int v; - }; + eq (int val) : v(val) {} + bool operator () (int v2) const { return v == v2; } + int v; + }; int main() diff --git a/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp b/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp index 761d71bbf287..fa1faf17e0f4 100644 --- a/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp +++ b/test/std/algorithms/alg.nonmodifying/alg.find/find_if.pass.cpp @@ -21,10 +21,10 @@ #include "test_iterators.h" struct eq { - eq (int val) : v(val) {} - bool operator () (int v2) const { return v == v2; } - int v; - }; + eq (int val) : v(val) {} + bool operator () (int v2) const { return v == v2; } + int v; + }; int main() { diff --git a/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp b/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp index 2e52e260336d..1f3c34b2144f 100644 --- a/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp +++ b/test/std/algorithms/alg.nonmodifying/alg.find/find_if_not.pass.cpp @@ -21,10 +21,10 @@ #include "test_iterators.h" struct ne { - ne (int val) : v(val) {} - bool operator () (int v2) const { return v != v2; } - int v; - }; + ne (int val) : v(val) {} + bool operator () (int v2) const { return v != v2; } + int v; + }; int main() diff --git a/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp b/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp index f7f8ee092796..4874bcad833e 100644 --- a/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp +++ b/test/std/algorithms/alg.nonmodifying/alg.search/search_n.pass.cpp @@ -66,7 +66,7 @@ test() assert(std::search_n(Iter(ic), Iter(ic+sc), 4, 0) == Iter(ic+sc)); // Check that we properly convert the size argument to an integral. - std::search_n(Iter(ic), Iter(ic+sc), UserDefinedIntegral<unsigned>(0), 0); + (void)std::search_n(Iter(ic), Iter(ic+sc), UserDefinedIntegral<unsigned>(0), 0); } int main() diff --git a/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp b/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp index 8bc6f4d26bdb..ff459b348932 100644 --- a/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp +++ b/test/std/algorithms/alg.nonmodifying/alg.search/search_n_pred.pass.cpp @@ -142,7 +142,7 @@ test() count_equal::count = 0; // Check that we properly convert the size argument to an integral. - std::search_n(Iter(ic), Iter(ic+sc), UserDefinedIntegral<unsigned>(4), 0, count_equal()); + TEST_IGNORE_NODISCARD std::search_n(Iter(ic), Iter(ic+sc), UserDefinedIntegral<unsigned>(4), 0, count_equal()); count_equal::count = 0; } diff --git a/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp b/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp index eb37ccac5779..d4bc3fd70a81 100644 --- a/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp +++ b/test/std/algorithms/alg.nonmodifying/mismatch/mismatch.pass.cpp @@ -26,7 +26,7 @@ int main() int ia[] = {0, 1, 2, 2, 0, 1, 2, 3}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); int ib[] = {0, 1, 2, 3, 0, 1, 2, 3}; - const unsigned sb = sizeof(ib)/sizeof(ib[0]); ((void)sb); // unused in c++11 + const unsigned sb = sizeof(ib)/sizeof(ib[0]); ((void)sb); // unused in C++11 typedef input_iterator<const int*> II; typedef random_access_iterator<const int*> RAI; diff --git a/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp b/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp index d78809b48524..2a363826261e 100644 --- a/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp +++ b/test/std/algorithms/alg.nonmodifying/mismatch/mismatch_pred.pass.cpp @@ -32,7 +32,7 @@ int main() int ia[] = {0, 1, 2, 2, 0, 1, 2, 3}; const unsigned sa = sizeof(ia)/sizeof(ia[0]); int ib[] = {0, 1, 2, 3, 0, 1, 2, 3}; - const unsigned sb = sizeof(ib)/sizeof(ib[0]); ((void)sb); // unused in c++11 + const unsigned sb = sizeof(ib)/sizeof(ib[0]); ((void)sb); // unused in C++11 typedef input_iterator<const int*> II; typedef random_access_iterator<const int*> RAI; diff --git a/test/std/algorithms/alg.sorting/alg.clamp/clamp.pass.cpp b/test/std/algorithms/alg.sorting/alg.clamp/clamp.pass.cpp index 1e18720bfbb3..7d734144ddce 100644 --- a/test/std/algorithms/alg.sorting/alg.clamp/clamp.pass.cpp +++ b/test/std/algorithms/alg.sorting/alg.clamp/clamp.pass.cpp @@ -18,13 +18,13 @@ #include <cassert> struct Tag { - Tag() : val(0), tag("Default") {} - Tag(int a, const char *b) : val(a), tag(b) {} - ~Tag() {} + Tag() : val(0), tag("Default") {} + Tag(int a, const char *b) : val(a), tag(b) {} + ~Tag() {} - int val; - const char *tag; - }; + int val; + const char *tag; + }; bool eq(const Tag& rhs, const Tag& lhs) { return rhs.val == lhs.val && rhs.tag == lhs.tag; } // bool operator==(const Tag& rhs, const Tag& lhs) { return rhs.val == lhs.val; } diff --git a/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp b/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp index 683b07d32089..3743fa535239 100644 --- a/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp +++ b/test/std/algorithms/alg.sorting/alg.merge/inplace_merge.pass.cpp @@ -23,24 +23,24 @@ #if TEST_STD_VER >= 11 struct S { - S() : i_(0) {} - S(int i) : i_(i) {} + S() : i_(0) {} + S(int i) : i_(i) {} - S(const S& rhs) : i_(rhs.i_) {} - S( S&& rhs) : i_(rhs.i_) { rhs.i_ = -1; } + S(const S& rhs) : i_(rhs.i_) {} + S( S&& rhs) : i_(rhs.i_) { rhs.i_ = -1; } - S& operator =(const S& rhs) { i_ = rhs.i_; return *this; } - S& operator =( S&& rhs) { i_ = rhs.i_; rhs.i_ = -2; assert(this != &rhs); return *this; } - S& operator =(int i) { i_ = i; return *this; } + S& operator =(const S& rhs) { i_ = rhs.i_; return *this; } + S& operator =( S&& rhs) { i_ = rhs.i_; rhs.i_ = -2; assert(this != &rhs); return *this; } + S& operator =(int i) { i_ = i; return *this; } - bool operator <(const S& rhs) const { return i_ < rhs.i_; } - bool operator ==(const S& rhs) const { return i_ == rhs.i_; } - bool operator ==(int i) const { return i_ == i; } + bool operator <(const S& rhs) const { return i_ < rhs.i_; } + bool operator ==(const S& rhs) const { return i_ == rhs.i_; } + bool operator ==(int i) const { return i_ == i; } - void set(int i) { i_ = i; } + void set(int i) { i_ = i; } - int i_; - }; + int i_; + }; #endif std::mt19937 randomness; diff --git a/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp b/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp index 3d8902ec2271..992862a4ecf4 100644 --- a/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp +++ b/test/std/algorithms/alg.sorting/alg.merge/inplace_merge_comp.pass.cpp @@ -33,25 +33,25 @@ struct indirect_less }; struct S { - S() : i_(0) {} - S(int i) : i_(i) {} + S() : i_(0) {} + S(int i) : i_(i) {} - S(const S& rhs) : i_(rhs.i_) {} - S( S&& rhs) : i_(rhs.i_) { rhs.i_ = -1; } + S(const S& rhs) : i_(rhs.i_) {} + S( S&& rhs) : i_(rhs.i_) { rhs.i_ = -1; } - S& operator =(const S& rhs) { i_ = rhs.i_; return *this; } - S& operator =( S&& rhs) { i_ = rhs.i_; rhs.i_ = -2; assert(this != &rhs); return *this; } - S& operator =(int i) { i_ = i; return *this; } + S& operator =(const S& rhs) { i_ = rhs.i_; return *this; } + S& operator =( S&& rhs) { i_ = rhs.i_; rhs.i_ = -2; assert(this != &rhs); return *this; } + S& operator =(int i) { i_ = i; return *this; } - bool operator <(const S& rhs) const { return i_ < rhs.i_; } - bool operator >(const S& rhs) const { return i_ > rhs.i_; } - bool operator ==(const S& rhs) const { return i_ == rhs.i_; } - bool operator ==(int i) const { return i_ == i; } + bool operator <(const S& rhs) const { return i_ < rhs.i_; } + bool operator >(const S& rhs) const { return i_ > rhs.i_; } + bool operator ==(const S& rhs) const { return i_ == rhs.i_; } + bool operator ==(int i) const { return i_ == i; } - void set(int i) { i_ = i; } + void set(int i) { i_ = i; } - int i_; - }; + int i_; + }; #endif // TEST_STD_VER >= 11 @@ -116,6 +116,26 @@ test() test<Iter>(1000); } +struct less_by_first { + template <typename Pair> + bool operator()(const Pair& lhs, const Pair& rhs) { + return std::less<typename Pair::first_type>()(lhs.first, rhs.first); + } +}; + +void test_PR31166 () +{ + typedef std::pair<int, int> P; + typedef std::vector<P> V; + P vec[5] = {P(1, 0), P(2, 0), P(2, 1), P(2, 2), P(2, 3)}; + for ( int i = 0; i < 5; ++i ) { + V res(vec, vec + 5); + std::inplace_merge(res.begin(), res.begin() + i, res.end(), less_by_first()); + assert(res.size() == 5); + assert(std::equal(res.begin(), res.end(), vec)); + } +} + int main() { test<bidirectional_iterator<int*> >(); @@ -146,4 +166,6 @@ int main() delete [] ia; } #endif // TEST_STD_VER >= 11 + + test_PR31166(); } diff --git a/test/std/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp b/test/std/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp index 402d57dae69e..da76d2a36c18 100644 --- a/test/std/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp +++ b/test/std/algorithms/alg.sorting/alg.min.max/min_element_comp.pass.cpp @@ -87,8 +87,8 @@ struct less { constexpr bool operator ()( const int &x, const int &y) const { re void constexpr_test() { #if TEST_STD_VER >= 14 - constexpr auto p = std::min_element(il, il+8, less()); - static_assert(*p == 1, ""); + constexpr auto p = std::min_element(il, il+8, less()); + static_assert(*p == 1, ""); #endif } diff --git a/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_move.pass.cpp b/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_move.pass.cpp new file mode 100644 index 000000000000..078060176b73 --- /dev/null +++ b/test/std/algorithms/alg.sorting/alg.set.operations/set.union/set_union_move.pass.cpp @@ -0,0 +1,46 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// <algorithm> + +// template<InputIterator InIter1, InputIterator InIter2, typename OutIter, +// CopyConstructible Compare> +// requires OutputIterator<OutIter, InIter1::reference> +// && OutputIterator<OutIter, InIter2::reference> +// && Predicate<Compare, InIter1::value_type, InIter2::value_type> +// && Predicate<Compare, InIter2::value_type, InIter1::value_type> +// OutIter +// set_union(InIter1 first1, InIter1 last1, InIter2 first2, InIter2 last2, +// OutIter result, Compare comp); + +// UNSUPPORTED: c++98, c++03 + +#include <algorithm> +#include <cassert> +#include <iterator> +#include <vector> + +#include "MoveOnly.h" + + +int main() +{ + std::vector<MoveOnly> lhs, rhs; + lhs.push_back(MoveOnly(2)); + rhs.push_back(MoveOnly(2)); + + std::vector<MoveOnly> res; + std::set_union(std::make_move_iterator(lhs.begin()), + std::make_move_iterator(lhs.end()), + std::make_move_iterator(rhs.begin()), + std::make_move_iterator(rhs.end()), std::back_inserter(res)); + + assert(res.size() == 1); + assert(res[0].get() == 2); +} |