Commit 01543cc4 authored by Paul's avatar Paul
Browse files

Fix dangling reference

parent 0666f839
......@@ -69,7 +69,7 @@ auto operator<<(std::ostream& os, const T& x) -> decltype(os << x.name())
{
os << x.name();
char delim = '[';
reflect_each(x, [&](auto& y, auto name) {
reflect_each(x, [&](auto&& y, auto name) {
os << delim;
os << name << "=";
stream_write_value(os, y);
......
......@@ -39,6 +39,41 @@ auto reflectable_impl(rank<1>, T&& x)
template <class T>
auto reflectable_impl(rank<0>, T &&) -> decltype(std::false_type{});
template<class T>
struct remove_rvalue_reference
{
using type = T;
};
template<class T>
struct remove_rvalue_reference<T&&>
{
using type = T;
};
template<class T>
struct wrapper
{
using type = typename remove_rvalue_reference<T>::type;
type data;
type get() const
{
return data;
}
};
template<class T>
wrapper<T> wrap(std::remove_reference_t<T>& x)
{
return wrapper<T>{std::forward<T>(x)};
}
template< class... Ts >
std::tuple<typename remove_rvalue_reference<Ts>::type...> auto_tuple(Ts&&... xs)
{
return {std::forward<Ts>(xs)...};
}
} // namespace detail
template <class T>
......@@ -53,14 +88,14 @@ auto reflect(T& x, Selector f)
template <class T>
auto reflect_tie(T& x)
{
return reflect(x, [](auto&& y, auto&&...) { return std::ref(y); })(
[](auto&&... xs) { return std::tie(xs.get()...); });
return reflect(x, [](auto&& y, auto&&...) { return detail::wrap<decltype(y)>(y); })(
[](auto&&... xs) { return detail::auto_tuple(xs.get()...); });
}
template <class T, class F>
void reflect_each(T& x, F f)
{
return reflect(x, [](auto&& y, auto... ys) { return pack(std::ref(y), ys...); })(
return reflect(x, [](auto&& y, auto... ys) { return pack(detail::wrap<decltype(y)>(y), ys...); })(
[&](auto&&... xs) {
each_args([&](auto p) { p([&](auto&& y, auto... ys) { f(y.get(), ys...); }); }, xs...);
});
......
......@@ -165,24 +165,26 @@ inline fused_operator_args make_fused_args()
template <class F>
auto reflect(miopenActivationDescriptor_t ad, F f)
{
assert(ad != nullptr);
miopenActivationMode_t mode = miopenActivationPASTHRU;
double alpha = 0.0;
double beta = 0.0;
double gamma = 0.0;
miopenGetActivationDescriptor(ad, &mode, &alpha, &beta, &gamma);
return pack(f(mode, "mode"), f(alpha, "alpha"), f(beta, "beta"), f(gamma, "gamma"));
return pack(f(std::move(mode), "mode"), f(std::move(alpha), "alpha"), f(std::move(beta), "beta"), f(std::move(gamma), "gamma"));
}
template <class F>
auto reflect(miopenLRNDescriptor_t lrnd, F f)
{
assert(lrnd != nullptr);
miopenLRNMode_t mode = miopenLRNWithinChannel;
unsigned int n = 0;
double alpha = 0.0;
double beta = 0.0;
double k = 0.0;
miopenGetLRNDescriptor(lrnd, &mode, &n, &alpha, &beta, &k);
return pack(f(mode, "mode"), f(n, "n"), f(alpha, "alpha"), f(beta, "beta"), f(k, "k"));
return pack(f(std::move(mode), "mode"), f(std::move(n), "n"), f(std::move(alpha), "alpha"), f(std::move(beta), "beta"), f(std::move(k), "k"));
}
} // namespace gpu
......
......@@ -69,7 +69,7 @@ auto operator<<(std::ostream& os, const T& x) -> decltype(os << x.name())
{
os << x.name();
char delim = '[';
reflect_each(x, [&](auto& y, auto name) {
reflect_each(x, [&](auto&& y, auto name) {
os << delim;
os << name << "=";
stream_write_value(os, y);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment