Skip to content

Commit

Permalink
✨ R-values are now passable into lots of things!
Browse files Browse the repository at this point in the history
Closes #22
  • Loading branch information
ThePhD committed Aug 23, 2021
1 parent 74acc3b commit 940f282
Show file tree
Hide file tree
Showing 12 changed files with 283 additions and 25 deletions.
4 changes: 4 additions & 0 deletions documentation/source/api/encodings/utf16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ UTF-16

.. doxygentypedef:: ztd::text::utf16_t

.. doxygenvariable:: ztd::text::wide_utf16

.. doxygentypedef:: ztd::text::wide_utf16_t



Base Template
Expand Down
4 changes: 4 additions & 0 deletions documentation/source/api/encodings/utf32.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ UTF-32

.. doxygentypedef:: ztd::text::utf32_t

.. doxygenvariable:: ztd::text::wide_utf32

.. doxygentypedef:: ztd::text::wide_utf32_t



Base Template
Expand Down
13 changes: 13 additions & 0 deletions include/ztd/ranges/adl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,19 @@ namespace ztd { namespace ranges {
template <typename _Range>
using detect_adl_empty = decltype(ranges_adl::adl_empty(::std::declval<::std::add_lvalue_reference_t<_Range>>()));

template <typename _Range>
using detect_adl_begin = decltype(ranges_adl::adl_begin(::std::declval<_Range>()));

template <typename _Range>
using detect_adl_end = decltype(ranges_adl::adl_end(::std::declval<_Range>()));

template <typename _Ty>
struct is_range
: ::std::integral_constant<bool, is_detected_v<detect_adl_begin, _Ty> && is_detected_v<detect_adl_end, _Ty>> { };

template <typename _Ty>
inline constexpr bool is_range_v = is_range<_Ty>::value;

ZTD_RANGES_INLINE_ABI_NAMESPACE_CLOSE_I_
}} // namespace ztd::ranges

Expand Down
4 changes: 2 additions & 2 deletions include/ztd/ranges/reconstruct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ namespace ztd { namespace ranges {
else {
return (*this)(::std::forward<_InPlaceOrIt>(__inplace_or_iterator),
::std::forward<_RangeOrSen>(__range_or_sentinel),
ranges_adl::adl_begin(::std::forward<_RangeOrSen>(__range_or_sentinel)),
ranges_adl::adl_end(::std::forward<_RangeOrSen>(__range_or_sentinel)));
ranges_adl::adl_begin(__range_or_sentinel),
ranges_adl::adl_end(__range_or_sentinel));
}
}
else if constexpr (((::std::is_class_v<_InPlaceOrIt> || ::std::is_enum_v<_InPlaceOrIt>)
Expand Down
11 changes: 4 additions & 7 deletions include/ztd/ranges/subrange.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ namespace ztd { namespace ranges {
::std::enable_if_t<!::std::is_same_v<remove_cvref_t<_Range>, __subrange>>* = nullptr>
constexpr __subrange(_Range&& __range) noexcept(::std::is_nothrow_constructible_v<__subrange,
range_iterator_t<remove_cvref_t<_Range>>, range_sentinel_t<remove_cvref_t<_Range>>>)
: __subrange(ranges_adl::adl_begin(::std::forward<_Range>(__range)),
ranges_adl::adl_end(::std::forward<_Range>(__range))) {
: __subrange(ranges_adl::adl_begin(__range), ranges_adl::adl_end(__range)) {
}

//////
Expand All @@ -187,11 +186,9 @@ namespace ztd { namespace ranges {
//////
template <typename _Range, __subrange_kind _StrawmanKind = _Kind,
::std::enable_if_t<(_StrawmanKind == __subrange_kind::sized)>* = nullptr>
constexpr __subrange(_Range&& __range, size_type __size) noexcept(
noexcept(__subrange(ranges_adl::adl_begin(::std::forward<_Range>(__range)),
ranges_adl::adl_end(::std::forward<_Range>(__range)), ::std::move(__size))))
: __subrange(ranges_adl::adl_begin(::std::forward<_Range>(__range)),
ranges_adl::adl_end(::std::forward<_Range>(__range)), ::std::move(__size)) {
constexpr __subrange(_Range&& __range, size_type __size) noexcept(noexcept(
__subrange(ranges_adl::adl_begin(__range), ranges_adl::adl_end(__range), ::std::move(__size))))
: __subrange(ranges_adl::adl_begin(__range), ranges_adl::adl_end(__range), ::std::move(__size)) {
}

//////
Expand Down
77 changes: 77 additions & 0 deletions include/ztd/ranges/view.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// =============================================================================
//
// 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_RANGES_VIEW_HPP
#define ZTD_RANGES_VIEW_HPP

#include <ztd/ranges/version.hpp>

#include <ztd/ranges/range.hpp>

#if ZTD_IS_ON(ZTD_STD_LIBRARY_RANGES_I_)
#include <ranges>
#endif

#include <ztd/prologue.hpp>

namespace ztd { namespace ranges {
ZTD_RANGES_INLINE_ABI_NAMESPACE_OPEN_I_

namespace __rng_detail {
template <typename _Ty>
inline constexpr bool __enable_view
#if ZTD_IS_ON(ZTD_STD_LIBRARY_RANGES_I_)
::std::ranges::enable_view<_Ty>
#else
= false
#endif
;
} // namespace __rng_detail

template <typename _Ty>
struct is_view
: ::std::integral_constant<bool,
(__rng_detail::__enable_view<_Ty> && is_range_v<_Ty> // clang-format hack
&& ::std::is_move_constructible_v<_Ty> && ::std::is_move_assignable_v<_Ty>)
|| (is_range_v<_Ty> && !::std::is_const_v<_Ty> && ::std::is_lvalue_reference_v<_Ty>) // clang-format
// hack
> { };

template <typename _Ty>
inline constexpr bool is_view_v = is_view<_Ty>::value;

ZTD_RANGES_INLINE_ABI_NAMESPACE_CLOSE_I_
}} // namespace ztd::ranges

#include <ztd/epilogue.hpp>

#endif // ZTD_RANGES_VIEW_HPP
13 changes: 7 additions & 6 deletions include/ztd/text/decode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <ztd/text/detail/encoding_range.hpp>
#include <ztd/text/type_traits.hpp>
#include <ztd/text/detail/transcode_one.hpp>
#include <ztd/text/detail/forward_if_move_only.hpp>

#include <ztd/ranges/unbounded.hpp>
#include <ztd/idk/span.hpp>
Expand Down Expand Up @@ -395,9 +396,9 @@ namespace ztd { namespace text {
using _BackInserterIterator = decltype(::std::back_inserter(::std::declval<_OutputContainer&>()));
using _Unbounded = ranges::unbounded_view<_BackInserterIterator>;
_Unbounded __insert_view(::std::back_inserter(__output));
auto __stateful_result
= decode_into(::std::forward<_Input>(__input), ::std::forward<_Encoding>(__encoding),
::std::move(__insert_view), ::std::forward<_ErrorHandler>(__error_handler), __state);
auto __stateful_result = decode_into(__txt_detail::__forward_if_move_only<_Input>(__input),
::std::forward<_Encoding>(__encoding), ::std::move(__insert_view),
::std::forward<_ErrorHandler>(__error_handler), __state);
return __txt_detail::__replace_result_output(::std::move(__stateful_result), ::std::move(__output));
}
else {
Expand Down Expand Up @@ -513,9 +514,9 @@ namespace ztd { namespace text {
using _BackInserterIterator = decltype(::std::back_inserter(::std::declval<_OutputContainer&>()));
using _Unbounded = ranges::unbounded_view<_BackInserterIterator>;
_Unbounded __insert_view(::std::back_inserter(__output));
auto __stateful_result
= decode_into(::std::forward<_Input>(__input), ::std::forward<_Encoding>(__encoding),
::std::move(__insert_view), ::std::forward<_ErrorHandler>(__error_handler), __state);
auto __stateful_result = decode_into(__txt_detail::__forward_if_move_only<_Input>(__input),
::std::forward<_Encoding>(__encoding), ::std::move(__insert_view),
::std::forward<_ErrorHandler>(__error_handler), __state);
// We are explicitly discarding this information with this function call.
(void)__stateful_result;
return __output;
Expand Down
71 changes: 71 additions & 0 deletions include/ztd/text/detail/forward_if_move_only.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@




// =============================================================================
//
// 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 ZT_TEXT_DETAIL_FORWARD_IF_MOVE_ONLY_HPP
#define ZT_TEXT_DETAIL_FORWARD_IF_MOVE_ONLY_HPP

#include <ztd/text/version.hpp>

#include <type_traits>
#include <utility>

#include <ztd/prologue.hpp>

namespace ztd { namespace text {
ZTD_TEXT_INLINE_ABI_NAMESPACE_OPEN_I_
namespace __txt_detail {

template <typename _Val>
decltype(auto) __forward_if_move_only(_Val&& __val) noexcept {
constexpr bool _IsMoveOnly
= ::std::is_rvalue_reference_v<
_Val> && ::std::is_move_constructible_v<_Val> && ::std::is_move_assignable_v<_Val> && !::std::is_copy_constructible_v<_Val> && !::std::is_copy_assignable_v<_Val>;
if constexpr (_IsMoveOnly) {
return ::std::forward<_Val>(__val);
}
else {
return __val;
}
}

} // namespace __txt_detail

ZTD_TEXT_INLINE_ABI_NAMESPACE_CLOSE_I_
}} // namespace ztd::text

#include <ztd/epilogue.hpp>

#endif // ZT_TEXT_DETAIL_FORWARD_IF_MOVE_ONLY_HPP
13 changes: 7 additions & 6 deletions include/ztd/text/encode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
#include <ztd/text/detail/encoding_range.hpp>
#include <ztd/text/detail/transcode_one.hpp>
#include <ztd/text/detail/span_or_reconstruct.hpp>
#include <ztd/text/detail/forward_if_move_only.hpp>

#include <ztd/ranges/unbounded.hpp>
#include <ztd/idk/span.hpp>
Expand Down Expand Up @@ -285,9 +286,9 @@ namespace ztd { namespace text {
using _BackInserterIterator = decltype(::std::back_inserter(::std::declval<_OutputContainer&>()));
using _Unbounded = ranges::unbounded_view<_BackInserterIterator>;
_Unbounded __insert_view(::std::back_inserter(__output));
auto __stateful_result
= encode_into(::std::forward<_Input>(__input), ::std::forward<_Encoding>(__encoding),
::std::move(__insert_view), ::std::forward<_ErrorHandler>(__error_handler), __state);
auto __stateful_result = encode_into(__txt_detail::__forward_if_move_only<_Input>(__input),
::std::forward<_Encoding>(__encoding), ::std::move(__insert_view),
::std::forward<_ErrorHandler>(__error_handler), __state);
(void)__stateful_result;
return __output;
}
Expand Down Expand Up @@ -432,9 +433,9 @@ namespace ztd { namespace text {
using _BackInserterIterator = decltype(::std::back_inserter(::std::declval<_OutputContainer&>()));
using _Unbounded = ranges::unbounded_view<_BackInserterIterator>;
_Unbounded __insert_view(::std::back_inserter(__output));
auto __stateful_result
= encode_into(::std::forward<_Input>(__input), ::std::forward<_Encoding>(__encoding),
::std::move(__insert_view), ::std::forward<_ErrorHandler>(__error_handler), __state);
auto __stateful_result = encode_into(__txt_detail::__forward_if_move_only<_Input>(__input),
::std::forward<_Encoding>(__encoding), ::std::move(__insert_view),
::std::forward<_ErrorHandler>(__error_handler), __state);
return __txt_detail::__replace_result_output(::std::move(__stateful_result), ::std::move(__output));
}
else {
Expand Down
5 changes: 3 additions & 2 deletions include/ztd/text/transcode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <ztd/text/detail/encoding_range.hpp>
#include <ztd/text/detail/transcode_extension_points.hpp>
#include <ztd/text/detail/span_or_reconstruct.hpp>
#include <ztd/text/detail/forward_if_move_only.hpp>

#include <ztd/ranges/unbounded.hpp>
#include <ztd/idk/span.hpp>
Expand Down Expand Up @@ -460,7 +461,7 @@ namespace ztd { namespace text {
using _Unbounded = ranges::unbounded_view<_BackInserterIterator>;
// We can use the unbounded stuff
_Unbounded __insert_view(::std::back_inserter(__output));
auto __stateful_result = transcode_into(::std::forward<_Input>(__input),
auto __stateful_result = transcode_into(__txt_detail::__forward_if_move_only<_Input>(__input),
::std::forward<_FromEncoding>(__from_encoding), ::std::move(__insert_view),
::std::forward<_ToEncoding>(__to_encoding),
::std::forward<_FromErrorHandler>(__from_error_handler),
Expand Down Expand Up @@ -524,7 +525,7 @@ namespace ztd { namespace text {
using _BackInserterIterator = decltype(::std::back_inserter(::std::declval<_OutputContainer&>()));
using _Unbounded = ranges::unbounded_view<_BackInserterIterator>;
auto __insert_view = _Unbounded(::std::back_inserter(__output));
auto __stateful_result = transcode_into(::std::forward<_Input>(__input),
auto __stateful_result = transcode_into(__txt_detail::__forward_if_move_only<_Input>(__input),
::std::forward<_FromEncoding>(__from_encoding), ::std::move(__insert_view),
::std::forward<_ToEncoding>(__to_encoding), ::std::forward<_FromErrorHandler>(__from_error_handler),
::std::forward<_ToErrorHandler>(__to_error_handler), __from_state, __to_state);
Expand Down
4 changes: 2 additions & 2 deletions include/ztd/text/utf16.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ namespace ztd { namespace text {
using _Result = __txt_detail::__reconstruct_decode_result_t<_InputRange, _OutputRange, state>;
constexpr bool __call_error_handler = !is_ignorable_error_handler_v<_UErrorHandler>;

auto __init = ranges::ranges_adl::adl_begin(::std::forward<_InputRange>(__input));
auto __inlast = ranges::ranges_adl::adl_end(::std::forward<_InputRange>(__input));
auto __init = ranges::ranges_adl::adl_begin(__input);
auto __inlast = ranges::ranges_adl::adl_end(__input);
if constexpr (__call_error_handler) {
if (__init == __inlast) {
// an exhausted sequence is fine
Expand Down

0 comments on commit 940f282

Please sign in to comment.