-
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move is_contiguous_iterator to type_support
- Loading branch information
1 parent
8531572
commit 07deffe
Showing
7 changed files
with
133 additions
and
49 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
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
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
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
81 changes: 81 additions & 0 deletions
81
libs/core/type_support/include/hpx/type_support/is_contiguous_iterator.hpp
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,81 @@ | ||
// Copyright (c) 2007-2022 Hartmut Kaiser | ||
// | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// 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) | ||
|
||
#pragma once | ||
|
||
#include <array> | ||
#include <type_traits> | ||
#include <utility> | ||
#include <vector> | ||
|
||
namespace hpx::traits { | ||
/////////////////////////////////////////////////////////////////////////// | ||
// Iterators are contiguous if they are pointers (without concepts we have | ||
// no generic way of determining whether an iterator is contiguous) | ||
|
||
namespace detail { | ||
|
||
// Iterators returned from std::vector are contiguous (by definition) | ||
template <typename Iter> | ||
using iter_value_type_t = | ||
typename std::iterator_traits<Iter>::value_type; | ||
|
||
template <typename Iter> | ||
struct is_known_iterator | ||
: std::bool_constant< | ||
std::is_same_v< // for std::vector | ||
typename std::vector<iter_value_type_t<Iter>>::iterator, | ||
Iter> || | ||
std::is_same_v<typename std::vector< | ||
iter_value_type_t<Iter>>::const_iterator, | ||
Iter> || // for std::array | ||
std::is_same_v< | ||
typename std::array<iter_value_type_t<Iter>, 0>::iterator, | ||
Iter> || | ||
std::is_same_v<typename std::array<iter_value_type_t<Iter>, | ||
0>::const_iterator, | ||
Iter>> | ||
{ | ||
}; | ||
|
||
template <typename T> | ||
struct is_known_iterator<T[]> : std::false_type | ||
{ | ||
}; | ||
|
||
template <typename T, int N> | ||
struct is_known_iterator<T[N]> : std::false_type | ||
{ | ||
}; | ||
} // namespace detail | ||
|
||
template <typename Iter, | ||
bool not_known_vector = | ||
// When _GLIBCXX_DEBUG is defined vectors are contiguous, but the iterators | ||
// are not plain pointers. | ||
#if defined(_GLIBCXX_DEBUG) | ||
false | ||
#else | ||
detail::is_known_iterator<Iter>::value | ||
#endif | ||
> | ||
struct is_contiguous_iterator : std::is_pointer<Iter>::type | ||
{ | ||
}; | ||
|
||
template <typename Iter> | ||
struct is_contiguous_iterator<Iter, true> : std::true_type | ||
{ | ||
}; | ||
|
||
template <typename Iter> | ||
using is_contiguous_iterator_t = | ||
typename is_contiguous_iterator<Iter>::type; | ||
|
||
template <typename Iter> | ||
inline constexpr bool is_contiguous_iterator_v = | ||
is_contiguous_iterator<Iter>::value; | ||
} // namespace hpx::traits |
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
46 changes: 46 additions & 0 deletions
46
libs/core/type_support/tests/unit/is_contiguous_iterator.cpp
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,46 @@ | ||
// Copyright (c) 2023 Isidoros Tsaousis-Seiras | ||
// | ||
// SPDX-License-Identifier: BSL-1.0 | ||
// 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 <cassert> | ||
#include <vector> | ||
#include <array> | ||
|
||
#include <hpx/type_support/is_contiguous_iterator.hpp> | ||
|
||
using hpx::traits::is_contiguous_iterator_v; | ||
|
||
// std::vector<int>::iterator is a contiguous iterator | ||
static_assert(is_contiguous_iterator_v<std::vector<int>::iterator>); | ||
static_assert(is_contiguous_iterator_v<std::vector<int>::const_iterator>); | ||
// reverse_iterator is not a contiguous iterator | ||
static_assert(!is_contiguous_iterator_v<std::vector<int>::reverse_iterator>); | ||
static_assert( | ||
!is_contiguous_iterator_v<std::vector<int>::const_reverse_iterator>); | ||
|
||
// std::array<int, 4>::iterator is a contiguous iterator | ||
static_assert(is_contiguous_iterator_v<std::array<int, 4>::iterator>); | ||
static_assert(is_contiguous_iterator_v<std::array<int, 4>::const_iterator>); | ||
// reverse_iterator is not a contiguous iterator | ||
static_assert(!is_contiguous_iterator_v<std::array<int, 4>::reverse_iterator>); | ||
static_assert( | ||
!is_contiguous_iterator_v<std::array<int, 4>::const_reverse_iterator>); | ||
|
||
// pointers are contiguous iterators | ||
static_assert(is_contiguous_iterator_v<int*>); | ||
static_assert(is_contiguous_iterator_v<int const*>); | ||
static_assert(is_contiguous_iterator_v<int (*)[]>); | ||
static_assert(is_contiguous_iterator_v<int const (*)[]>); | ||
static_assert(is_contiguous_iterator_v<int (*)[4]>); | ||
static_assert(is_contiguous_iterator_v<int const (*)[4]>); | ||
|
||
// arrays are not contiguous iterators | ||
static_assert(!is_contiguous_iterator_v<int[]>); | ||
static_assert(!is_contiguous_iterator_v<int[4]>); | ||
static_assert(!is_contiguous_iterator_v<int const[]>); | ||
static_assert(!is_contiguous_iterator_v<int const[4]>); | ||
|
||
|
||
int main(int, char*[]) {} |