Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an is_tuple_like trait for sequenceable type detection
- Loading branch information
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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 { }; | ||
}} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
set(tests | ||
is_callable | ||
is_tuple_like | ||
) | ||
|
||
foreach(test ${tests}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/util/tuple.hpp> | ||
#include <hpx/traits/is_tuple_like.hpp> | ||
#include <hpx/util/lightweight_test.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(); | ||
} |