[libcxx] r319675 - Fix PR#35948: generate_n does not accept floating point Size arguments.
Marshall Clow via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 4 10:59:14 PST 2017
Author: marshall
Date: Mon Dec 4 10:59:14 2017
New Revision: 319675
URL: http://llvm.org/viewvc/llvm-project?rev=319675&view=rev
Log:
Fix PR#35948: generate_n does not accept floating point Size arguments.
Modified:
libcxx/trunk/include/type_traits
libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
Modified: libcxx/trunk/include/type_traits
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=319675&r1=319674&r2=319675&view=diff
==============================================================================
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Mon Dec 4 10:59:14 2017
@@ -4652,6 +4652,11 @@ long long __convert_to_integral(long lon
inline _LIBCPP_INLINE_VISIBILITY
unsigned long long __convert_to_integral(unsigned long long __val) {return __val; }
+template<typename _Fp>
+inline _LIBCPP_INLINE_VISIBILITY
+typename enable_if<is_floating_point<_Fp>::value, long long>::type
+ __convert_to_integral(_Fp __val) { return __val; }
+
#ifndef _LIBCPP_HAS_NO_INT128
inline _LIBCPP_INLINE_VISIBILITY
__int128_t __convert_to_integral(__int128_t __val) { return __val; }
Modified: libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp?rev=319675&r1=319674&r2=319675&view=diff
==============================================================================
--- libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp (original)
+++ libcxx/trunk/test/std/algorithms/alg.modifying.operations/alg.generate/generate_n.pass.cpp Mon Dec 4 10:59:14 2017
@@ -18,29 +18,42 @@
#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*> >();
More information about the cfe-commits
mailing list