Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support of std::array to hpx::util::tuple_size and tuple_element #2685

Merged
merged 1 commit into from
Jun 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions hpx/util/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <type_traits>
#include <utility>

#if defined(HPX_HAVE_CXX11_STD_ARRAY)
#include <array>
#endif

#if defined(HPX_MSVC_WARNING_PRAGMA)
#pragma warning(push)
#pragma warning(disable: 4520) // multiple default constructors specified
Expand Down Expand Up @@ -532,6 +536,13 @@ namespace hpx { namespace util
: boost::integral_constant<std::size_t, Size>
{};

#if defined(HPX_HAVE_CXX11_STD_ARRAY)
template <typename Type, std::size_t Size>
struct tuple_size<std::array<Type, Size> >
: boost::integral_constant<std::size_t, Size>
{};
#endif

// template <size_t I, class Tuple>
// class tuple_element
template <std::size_t I, typename T>
Expand Down Expand Up @@ -625,6 +636,26 @@ namespace hpx { namespace util
}
};

#if defined(HPX_HAVE_CXX11_STD_ARRAY)
template <std::size_t I, typename Type, std::size_t Size>
struct tuple_element<I, std::array<Type, Size> >
{
typedef Type type;

static HPX_CONSTEXPR HPX_HOST_DEVICE HPX_FORCEINLINE type&
get(std::array<Type, Size>& tuple) noexcept
{
return tuple[I];
}

static HPX_CONSTEXPR HPX_HOST_DEVICE HPX_FORCEINLINE type const&
get(std::array<Type, Size> const& tuple) noexcept
{
return tuple[I];
}
};
#endif

// 20.4.2.6, element access

// template <size_t I, class... Types>
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/util/tuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

// tuple_test_bench.cpp --------------------------------

#include <hpx/config.hpp>
#include <hpx/hpx_init.hpp>
#include <hpx/util/tuple.hpp>
#include <hpx/util/lightweight_test.hpp>
Expand All @@ -18,6 +19,10 @@
#include <type_traits>
#include <utility>

#if defined(HPX_HAVE_CXX11_STD_ARRAY)
#include <array>
#endif

// ----------------------------------------------------------------------------
// helpers
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -189,6 +194,11 @@ void element_access_test()
HPX_TEST((std::is_const<hpx::util::tuple_element<1, const hpx::util::tuple<int,
float> >::type>::value));

#if defined(HPX_HAVE_CXX11_STD_ARRAY)
HPX_TEST((std::is_same<hpx::util::tuple_element<1,
std::array<float, 4>>::type, float>::value));
#endif

dummy(i); dummy(i2); dummy(j); dummy(e); // avoid warns for unused variables
}

Expand Down Expand Up @@ -377,6 +387,12 @@ void tuple_length_test()
HPX_TEST(hpx::util::tuple_size<t1>::value == 3);
HPX_TEST(hpx::util::tuple_size<t2>::value == 0);

#if defined(HPX_HAVE_CXX11_STD_ARRAY)
{
using t3 = std::array<int, 4>;
HPX_TEST(hpx::util::tuple_size<t3>::value == 4);
}
#endif
}

// ----------------------------------------------------------------------------
Expand Down