Permalink
Browse files

Fix tuple_cat when using r-value references (and move only types)

* Add a unit tests for this.
  • Loading branch information...
Naios committed Jul 22, 2017
1 parent dcfb503 commit db4f99e61bfdc335ae7ab3a86f3e7b0c71f79d31
Showing with 47 additions and 0 deletions.
  1. +30 −0 hpx/util/tuple.hpp
  2. +17 −0 tests/unit/util/tuple.cpp
View
@@ -580,6 +580,12 @@ namespace hpx { namespace util
{
return tuple._impl.template get<I>();
}
static HPX_CONSTEXPR HPX_HOST_DEVICE HPX_FORCEINLINE type&&
get(tuple<Ts...>&& tuple) noexcept
{
return std::move(tuple._impl.template get<I>());
}
};
template <typename T0, typename T1>
@@ -598,6 +604,12 @@ namespace hpx { namespace util
{
return tuple.first;
}
static HPX_CONSTEXPR HPX_HOST_DEVICE HPX_FORCEINLINE type&&
get(std::pair<T0, T1>&& tuple) noexcept
{
return std::move(tuple.first);
}
};
template <typename T0, typename T1>
@@ -616,6 +628,12 @@ namespace hpx { namespace util
{
return tuple.second;
}
static HPX_CONSTEXPR HPX_HOST_DEVICE HPX_FORCEINLINE type&&
get(std::pair<T0, T1>&& tuple) noexcept
{
return std::move(tuple.second);
}
};
template <std::size_t I, typename Type, std::size_t Size>
@@ -634,6 +652,12 @@ namespace hpx { namespace util
{
return tuple[I];
}
static HPX_CONSTEXPR HPX_HOST_DEVICE HPX_FORCEINLINE type&&
get(boost::array<Type, Size>&& tuple) noexcept
{
return std::move(tuple[I]);
}
};
#if defined(HPX_HAVE_CXX11_STD_ARRAY)
@@ -653,6 +677,12 @@ namespace hpx { namespace util
{
return tuple[I];
}
static HPX_CONSTEXPR HPX_HOST_DEVICE HPX_FORCEINLINE type&&
get(std::array<Type, Size>&& tuple) noexcept
{
return std::move(tuple[I]);
}
};
#endif
View
@@ -15,6 +15,7 @@
#include <hpx/util/lightweight_test.hpp>
#include <functional>
#include <memory>
#include <string>
#include <type_traits>
#include <utility>
@@ -354,6 +355,22 @@ void tuple_cat_test()
HPX_TEST((res == expected));
}
// Cat move only types
{
auto t0 = hpx::util::make_tuple(std::unique_ptr<int>(new int(0)));
auto t1 = hpx::util::make_tuple(std::unique_ptr<int>(new int(1)));
auto t2 = hpx::util::make_tuple(std::unique_ptr<int>(new int(2)));
hpx::util::tuple<std::unique_ptr<int>, std::unique_ptr<int>,
std::unique_ptr<int>>
result = hpx::util::tuple_cat(
std::move(t0), std::move(t1), std::move(t2));
HPX_TEST_EQ((*hpx::util::get<0>(result)), 0);
HPX_TEST_EQ((*hpx::util::get<1>(result)), 1);
HPX_TEST_EQ((*hpx::util::get<2>(result)), 2);
}
}
// ----------------------------------------------------------------------------

0 comments on commit db4f99e

Please sign in to comment.