Permalink
Browse files

Add an is_tuple_like trait for sequenceable type detection

  • Loading branch information...
Naios committed Jun 7, 2017
1 parent df67d48 commit aed3ff37d65c49eb4db8b244563b1ff406ea1847
Showing with 80 additions and 0 deletions.
  1. +1 −0 hpx/include/traits.hpp
  2. +31 −0 hpx/traits/is_tuple_like.hpp
  3. +1 −0 tests/unit/traits/CMakeLists.txt
  4. +47 −0 tests/unit/traits/is_tuple_like.cpp
View
@@ -53,6 +53,7 @@
#include <hpx/traits/is_placeholder.hpp>
#include <hpx/traits/is_range.hpp>
#include <hpx/traits/is_timed_executor.hpp>
#include <hpx/traits/is_tuple_like.hpp>
#include <hpx/traits/is_valid_action.hpp>
#include <hpx/traits/managed_component_policies.hpp>
#include <hpx/traits/needs_automatic_registration.hpp>
@@ -0,0 +1,31 @@
// Copyright (c) 2017 Denis Blank
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#if !defined(HPX_TRAITS_IS_TUPLE_LIKE_HPP)
#define HPX_TRAITS_IS_TUPLE_LIKE_HPP
#include <type_traits>
#include <hpx/util/always_void.hpp>
#include <hpx/util/tuple.hpp>
namespace hpx {
namespace traits {
/// Deduces to a true type if the given parameter T
/// has a specific tuple like size.
template <typename T, typename = void>
struct is_tuple_like : std::false_type
{
};
template <typename T>
struct is_tuple_like<T,
typename util::always_void<decltype(util::tuple_size<T>::value)>::type>
: std::true_type
{
};
} // namespace traits
} // namespace hpx
#endif
@@ -5,6 +5,7 @@
set(tests
is_callable
is_tuple_like
)
foreach(test ${tests})
@@ -0,0 +1,47 @@
// Copyright (c) 2017 Denis Blank
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#include <utility>
#include <vector>
#if defined(HPX_HAVE_CXX11_STD_ARRAY)
#include <array>
#endif
#include <hpx/config.hpp>
#include <hpx/traits/is_tuple_like.hpp>
#include <hpx/util/lightweight_test.hpp>
#include <hpx/util/tuple.hpp>
void tuple_like_true()
{
using hpx::traits::is_tuple_like;
HPX_TEST_EQ((is_tuple_like<hpx::util::tuple<int, int, int>>::value), true);
HPX_TEST_EQ((is_tuple_like<std::pair<int, int>>::value), true);
#if defined(HPX_HAVE_CXX11_STD_ARRAY)
HPX_TEST_EQ((is_tuple_like<std::array<int, 4>>::value), true);
#endif
}
void tuple_like_false()
{
using hpx::traits::is_tuple_like;
HPX_TEST_EQ((is_tuple_like<int>::value), false);
HPX_TEST_EQ((is_tuple_like<std::vector<int>>::value), false);
}
///////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
{
tuple_like_true();
tuple_like_false();
}
return hpx::util::report_errors();
}

0 comments on commit aed3ff3

Please sign in to comment.