Skip to content

Commit

Permalink
✨ Contiguous markings
Browse files Browse the repository at this point in the history
- 💬 Specific to GCC but necessary on Clang! May need to add MSVC ones too.
  • Loading branch information
ThePhD committed Jul 2, 2021
1 parent 1da2d1d commit 87404d5
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 11 deletions.
12 changes: 7 additions & 5 deletions include/ztd/text/detail/iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include <ztd/text/detail/adl.hpp>
#include <ztd/text/detail/type_traits.hpp>
#include <ztd/text/detail/memory.hpp>
#include <ztd/text/detail/mark_contiguous.hpp>

#include <iterator>
#include <type_traits>
Expand All @@ -61,10 +62,11 @@ namespace ztd { namespace text {
//////
using contiguous_iterator_tag =
#if ZTD_TEXT_IS_ON(ZTD_TEXT_STD_LIBRARY_CONTIGUOUS_ITERATOR_TAG_I_)
::std::contiguous_iterator_tag;
::std::contiguous_iterator_tag
#else
__txt_detail::__contiguous_iterator_tag;
__txt_detail::__contiguous_iterator_tag
#endif
;

namespace __txt_detail {

Expand Down Expand Up @@ -215,10 +217,10 @@ namespace ztd { namespace text {
= ::std::is_base_of_v<_Tag, __iterator_concept_t<_It>>;

template <typename _It>
inline constexpr bool __is_iterator_contiguous_iterator_v
= (
inline constexpr bool __is_iterator_contiguous_iterator_v = __mark_contiguous<_It>::value
|| (
#if ZTD_TEXT_IS_ON(ZTD_TEXT_STD_LIBRARY_CONTIGUOUS_ITERATOR_TAG_I_)
__is_iterator_concept_or_better_v<contiguous_iterator_tag, _It>)
__is_iterator_concept_or_better_v<contiguous_iterator_tag, _It>)
|| (__is_iterator_concept_or_better_v<contiguous_iterator_tag, _It> &&
#else
::std::is_pointer_v<_It> &&
Expand Down
64 changes: 64 additions & 0 deletions include/ztd/text/detail/mark_contiguous.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// =============================================================================
//
// ztd.text
// Copyright © 2021 JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
// Contact: opensource@soasis.org
//
// Commercial License Usage
// Licensees holding valid commercial ztd.text licenses may use this file in
// accordance with the commercial license agreement provided with the
// Software or, alternatively, in accordance with the terms contained in
// a written agreement between you and Shepherd's Oasis, LLC.
// For licensing terms and conditions see your agreement. For
// further information contact opensource@soasis.org.
//
// Apache License Version 2 Usage
// Alternatively, this file may be used under the terms of Apache License
// Version 2.0 (the "License") for non-commercial use; you may not use this
// file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ============================================================================>

#pragma once

#ifndef ZTD_TEXT_DETAIL_MARK_CONTIGUOUS_HPP
#define ZTD_TEXT_DETAIL_MARK_CONTIGUOUS_HPP

#include <ztd/text/version.hpp>

#include <ztd/text/detail/span.hpp>

#include <type_traits>

#include <ztd/text/detail/prologue.hpp>

namespace ztd { namespace text {
ZTD_TEXT_INLINE_ABI_NAMESPACE_OPEN_I_

namespace __txt_detail {

template <typename _It>
struct __mark_contiguous : public ::std::integral_constant<bool, ::std::is_pointer_v<_It>> { };

#if ZTD_TEXT_IS_ON(ZTD_TEXT_LIBSTDCXX_I_)
template <typename _It, typename _Parent>
struct __mark_contiguous<::__gnu_cxx::__normal_iterator<_It, _Parent>> : public __mark_contiguous<_It> { };
#endif

} // namespace __txt_detail

ZTD_TEXT_INLINE_ABI_NAMESPACE_CLOSE_I_
}} // namespace ztd::text

#include <ztd/text/detail/epilogue.hpp>

#endif // ZTD_TEXT_DETAIL_MARK_CONTIGUOUS_HPP
17 changes: 11 additions & 6 deletions include/ztd/text/subrange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,16 @@ namespace ztd { namespace text {
/// @brief The iterator category. Same as the iterator category for @p _It.
///
//////
using iterator_category = __txt_detail::__iterator_category_t<iterator>;
using iterator_category
= ::std::conditional_t<__txt_detail::__is_iterator_contiguous_iterator_v<iterator>,
contiguous_iterator_tag, __txt_detail::__iterator_category_t<iterator>>;
//////
/// @brief The iterator concept. Same as the iterator concept for @p _It.
///
//////
using iterator_concept = __txt_detail::__iterator_concept_t<iterator>;
using iterator_concept
= ::std::conditional_t<__txt_detail::__is_iterator_contiguous_iterator_v<iterator>,
contiguous_iterator_tag, __txt_detail::__iterator_concept_t<iterator>>;
//////
/// @brief The @c pointer type. Same as the @c pointer type for @p _It.
///
Expand Down Expand Up @@ -344,9 +348,8 @@ namespace ztd { namespace text {
/// @remarks This function call only works if the @c iterator_concept is a @c contiguous_iterator_tag or
/// better.
//////
template <typename _Dummy = _It,
::std::enable_if_t<
__txt_detail::__is_iterator_concept_or_better_v<contiguous_iterator_tag, _Dummy>>* = nullptr>
template <typename _Dummy = _It,
::std::enable_if_t<__txt_detail::__is_iterator_contiguous_iterator_v<_Dummy>>* = nullptr>
constexpr pointer data() const noexcept {
return __txt_detail::__adl::__adl_to_address(this->_M_it);
}
Expand Down Expand Up @@ -532,7 +535,9 @@ namespace ztd { namespace text {
ZTD_TEXT_INLINE_ABI_NAMESPACE_CLOSE_I_
}} // namespace ztd::text

#if ZTD_TEXT_IS_ON(ZTD_TEXT_STD_LIBRARY_CONCEPTS_I_) && ZTD_TEXT_IS_ON(ZTD_TEXT_STD_LIBRARY_RANGES_I_)
#if (ZTD_TEXT_IS_ON(ZTD_TEXT_LIBSTDCXX_I_) && ZTD_TEXT_IS_ON(ZTD_TEXT_STD_LIBRARY_CONCEPTS_I_)) \
|| (ZTD_TEXT_IS_ON(ZTD_TEXT_LIBVCXX_I_) && ZTD_TEXT_IS_ON(ZTD_TEXT_STD_LIBRARY_CONCEPTS_I_)) \
|| (ZTD_TEXT_IS_ON(ZTD_TEXT_STD_LIBRARY_RANGES_I_))
namespace std { namespace ranges {

template <typename _It, typename _Sen, ::ztd::text::__txt_detail::__subrange_kind _Kind>
Expand Down
31 changes: 31 additions & 0 deletions tests/inclusion/source/ztd/text/detail/mark_contiguous.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// =============================================================================
//
// ztd.text
// Copyright © 2021 JeanHeyd "ThePhD" Meneide and Shepherd's Oasis, LLC
// Contact: opensource@soasis.org
//
// Commercial License Usage
// Licensees holding valid commercial ztd.text licenses may use this file in
// accordance with the commercial license agreement provided with the
// Software or, alternatively, in accordance with the terms contained in
// a written agreement between you and Shepherd's Oasis, LLC.
// For licensing terms and conditions see your agreement. For
// further information contact opensource@soasis.org.
//
// Apache License Version 2 Usage
// Alternatively, this file may be used under the terms of Apache License
// Version 2.0 (the "License") for non-commercial use; you may not use this
// file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// ============================================================================>

#include <ztd/text/detail/mark_contiguous.hpp>

0 comments on commit 87404d5

Please sign in to comment.