[PATCH] D41748: [libcxx] [test] Fix Xxx_scan tests using nonstandard things and MSVC++ warnings
Marshall Clow via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 5 15:52:31 PST 2018
mclow.lists added a comment.
> The use of iota targeting vector<unsigned char> with an int parameter triggers warnings on MSVC++ assigning an into a unsigned char&
I hate your compiler.
Other than that (and the bit about identity), this looks fine to me.
================
Comment at: test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp:31
-template <class T = void>
-struct identity : std::unary_function<T, T>
-{
- constexpr const T& operator()(const T& x) const { return x;}
-};
-
-template <>
-struct identity<void>
-{
- template <class T>
- constexpr auto operator()(T&& x) const
- _NOEXCEPT_(noexcept(_VSTD::forward<T>(x)))
- -> decltype (_VSTD::forward<T>(x))
- { return _VSTD::forward<T>(x); }
-};
+const auto identity = [](auto&& x) { return std::forward<decltype(x)>(x); };
----------------
CaseyCarter wrote:
> Pre-existing: the identity transformation is an extremely poor choice for these `transform_foo` tests since failure to apply the transformation exactly once to each element does not affect the result of the algorithm.
I think I'd rather have this. It's constexpr and noexcept, unlike the lambda.
struct identity {
template <typename T>
constexpr auto operator()(T&& x) const
noexcept(noexcept(std::forward<T>(x)))
-> decltype (std::forward<T>(x))
{ return std::forward<T>(x); }
};
================
Comment at: test/std/numerics/numeric.ops/transform.exclusive.scan/transform_exclusive_scan_init_bop_uop.pass.cpp:31
-template <class T = void>
-struct identity : std::unary_function<T, T>
-{
- constexpr const T& operator()(const T& x) const { return x;}
-};
-
-template <>
-struct identity<void>
-{
- template <class T>
- constexpr auto operator()(T&& x) const
- _NOEXCEPT_(noexcept(_VSTD::forward<T>(x)))
- -> decltype (_VSTD::forward<T>(x))
- { return _VSTD::forward<T>(x); }
-};
+const auto identity = [](auto&& x) { return std::forward<decltype(x)>(x); };
----------------
mclow.lists wrote:
> CaseyCarter wrote:
> > Pre-existing: the identity transformation is an extremely poor choice for these `transform_foo` tests since failure to apply the transformation exactly once to each element does not affect the result of the algorithm.
> I think I'd rather have this. It's constexpr and noexcept, unlike the lambda.
>
> struct identity {
> template <typename T>
> constexpr auto operator()(T&& x) const
> noexcept(noexcept(std::forward<T>(x)))
> -> decltype (std::forward<T>(x))
> { return std::forward<T>(x); }
> };
>
I agree about the choice of `identity` as a transform.
https://reviews.llvm.org/D41748
More information about the cfe-commits
mailing list