Skip to content

Commit

Permalink
✅ Update the tests to avoid incorrent default for literals
Browse files Browse the repository at this point in the history
- ✨ Make sure the basic_ versions of all the converting functions exist
  • Loading branch information
ThePhD committed Feb 26, 2021
1 parent 01d33cd commit bcdeff5
Show file tree
Hide file tree
Showing 10 changed files with 355 additions and 175 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ string(CONCAT --warn-pedantic $<$<BOOL:${ZTD_TEXT_DIAGNOSTIC_PEDANTIC}>:-Wpedant
string(CONCAT --warn-default $<
$<AND:
$<BOOL:${ZTD_TEXT_DIAGNOSTIC_DEFAULTS}>,
$<NOT:$<BOOL:${MSVC}>>,
$<NOT:$<BOOL:MSVC>>,
>:-Wall
>)
string(CONCAT --deny-errors $<$<BOOL:${ZTD_TEXT_DIAGNOSTIC_ERRORS}>:-Werror>)
Expand Down
3 changes: 1 addition & 2 deletions include/ztd/text/count_code_points.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ namespace ztd { namespace text {
///
/// @remarks This method will first check if an ADL Extension Point @c text_count_code_points is callable with the
/// given arguments. If it is, then that method will be used to do the work after forwarding all four arguments to
/// that function call. Otherwise, a combination of implementation techniques will be used to count code units,
/// with a loop over the @c .encode call into an intermediate, unseen buffer being the most basic choice.
/// that function call. Otherwise, this defers to ztd::text::basic_count_code_points.
//////
template <typename _Input, typename _Encoding, typename _ErrorHandler, typename _State>
constexpr auto count_code_points(
Expand Down
4 changes: 1 addition & 3 deletions include/ztd/text/count_code_units.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ namespace ztd { namespace text {
///
/// @remarks This method will first check if an ADL Extension Point @c text_count_code_units is callable with the
/// given arguments. If it is, then that method will be used to do the work after forwarding all four arguments to
/// that function call. Otherwise, a combination of implementation techniques will be used to count code units,
/// with a loop over the @c .decode call into an intermediate, unseen buffer being the most basic guaranteed
/// implementation attempt.
/// that function call. Otherwise, it defers to ztd::text::basic_count_code_units.
//////
template <typename _Input, typename _Encoding, typename _ErrorHandler, typename _State>
constexpr auto count_code_units(
Expand Down
56 changes: 38 additions & 18 deletions include/ztd/text/decode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,14 +371,23 @@ namespace ztd { namespace text {
__output.reserve(__output_size_hint);
}
}
if constexpr (__detail::__is_detected_v<__detail::__detect_object_decode_one, _UEncoding, _IntermediateInput,
_Unbounded, _ErrorHandler, _State>) {
// We can use the unbounded stuff
_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);
return __detail::__replace_result_output(::std::move(__stateful_result), ::std::move(__output));
if constexpr (__detail::__is_decode_error_handler_callable_v<_Encoding, _IntermediateInput, _Unbounded,
_ErrorHandler, _State>) {
if constexpr (__detail::__is_decode_one_callable_v<_Encoding, _IntermediateInput, _Unbounded,
_ErrorHandler, _State>) {
// We can use the unbounded stuff
_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);
return __detail::__replace_result_output(::std::move(__stateful_result), ::std::move(__output));
}
else {
auto __stateful_result = __detail::__intermediate_decode_to_storage(::std::forward<_Input>(__input),
::std::forward<_Encoding>(__encoding), __output,
::std::forward<_ErrorHandler>(__error_handler), __state);
return __detail::__replace_result_output(::std::move(__stateful_result), ::std::move(__output));
}
}
else {
auto __stateful_result = __detail::__intermediate_decode_to_storage(::std::forward<_Input>(__input),
Expand Down Expand Up @@ -515,16 +524,27 @@ namespace ztd { namespace text {
__output.reserve(__output_size_hint);
}
}
if constexpr (__detail::__is_detected_v<__detail::__detect_object_decode_one, _UEncoding, _IntermediateInput,
_Unbounded, _ErrorHandler, _State>) {
// We can use the unbounded stuff
_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);
// We are explicitly discarding this information with this function call.
(void)__stateful_result;
return __output;
if constexpr (__detail::__is_decode_error_handler_callable_v<_Encoding, _IntermediateInput, _Unbounded,
_ErrorHandler, _State>) {
if constexpr (__detail::__is_decode_one_callable_v<_Encoding, _IntermediateInput, _Unbounded,
_ErrorHandler, _State>) {
// We can use the unbounded stuff
// We can use the unbounded stuff
_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);
// We are explicitly discarding this information with this function call.
(void)__stateful_result;
return __output;
}
else {
auto __stateful_result = __detail::__intermediate_decode_to_storage(::std::forward<_Input>(__input),
::std::forward<_Encoding>(__encoding), __output,
::std::forward<_ErrorHandler>(__error_handler), __state);
(void)__stateful_result;
return __output;
}
}
else {
auto __stateful_result = __detail::__intermediate_decode_to_storage(::std::forward<_Input>(__input),
Expand Down
19 changes: 13 additions & 6 deletions include/ztd/text/decode_result.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace ztd { namespace text {
///
/// @param[in] __input The input range to store.
/// @param[in] __output The output range to store.
/// @param[in] __error_code The error code for the encode operation, taken as the first of either the decode
/// @param[in] __error_code The error code for the decode operation, taken as the first of either the decode
/// operation that failed.
/// @param[in] __handled_error Whether or not an error was handled. Some error handlers are corrective (see
/// ztd::text::replacement_handler), and so the error code is not enough to determine if the handler was
Expand Down Expand Up @@ -162,7 +162,7 @@ namespace ztd { namespace text {
/// @param[in] __input The input range to store.
/// @param[in] __output The output range to store.
/// @param[in] __state The state related to the Encoding that performed the decode operation.
/// @param[in] __error_code The error code for the encode operation, taken as the first of either the decode
/// @param[in] __error_code The error code for the decode operation, taken as the first of either the decode
/// operation that failed.
/// @param[in] __handled_error Whether or not an error was handled. Some error handlers are corrective (see
/// ztd::text::replacement_handler), and so the error code is not enough to determine if the handler was
Expand Down Expand Up @@ -230,12 +230,19 @@ namespace ztd { namespace text {
::std::forward<_ArgState>(__state), __error_code, __error_code != encoding_error::ok);
}

template <typename _Encoding, typename _Input, typename _Output, typename _ErrorHandler, typename _State>
inline constexpr bool __is_decode_error_handler_callable_v = __is_detected_v<__detect_callable_handler,
_ErrorHandler, _Encoding, __reconstruct_decode_result_t<__remove_cvref_t<_Input>, _Output, _State>,
::ztd::text::span<code_unit_t<_Encoding>>>;

template <typename _Encoding, typename _Input, typename _Output, typename _ErrorHandler, typename _State>
inline constexpr bool __is_decode_one_callable_v
= __is_detected_v<__detect_object_decode_one, _Encoding, _Input, _Output, _ErrorHandler, _State>&&
__is_detected_v<__detect_callable_handler, _ErrorHandler, _Encoding,
__reconstruct_decode_result_t<__remove_cvref_t<_Input>, _Output, _State>,
::ztd::text::span<code_unit_t<_Encoding>>>;
= __is_detected_v<__detect_object_decode_one, _Encoding, _Input, _Output, _ErrorHandler, _State>;

template <typename _Encoding, typename _Input, typename _Output, typename _ErrorHandler, typename _State>
inline constexpr bool __is_decode_one_and_error_handler_callable_v
= __is_decode_one_callable_v<_Encoding, _Input, _Output, _ErrorHandler, _State>&&
__is_decode_error_handler_callable_v<_Encoding, _Input, _Output, _ErrorHandler, _State>;
} // namespace __detail

ZTD_TEXT_INLINE_ABI_NAMESPACE_CLOSE_I_
Expand Down
33 changes: 21 additions & 12 deletions include/ztd/text/encode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,23 @@ namespace ztd { namespace text {
__output.reserve(__output_size_hint);
}
}
if constexpr (__detail::__is_encode_one_callable_v<_UEncoding, _IntermediateInput, _Unbounded, _ErrorHandler,
_State>) {
// We can use the unbounded stuff
_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);
return __detail::__replace_result_output(::std::move(__stateful_result), ::std::move(__output));
if constexpr (__detail::__is_encode_error_handler_callable_v<_Encoding, _IntermediateInput, _Unbounded,
_ErrorHandler, _State>) {
if constexpr (__detail::__is_encode_one_callable_v<_Encoding, _IntermediateInput, _Unbounded,
_ErrorHandler, _State>) {
// We can use the unbounded stuff
_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);
return __detail::__replace_result_output(::std::move(__stateful_result), ::std::move(__output));
}
else {
auto __stateful_result = __detail::__intermediate_encode_to_storage(::std::forward<_Input>(__input),
::std::forward<_Encoding>(__encoding), __output,
::std::forward<_ErrorHandler>(__error_handler), __state);
return __detail::__replace_result_output(::std::move(__stateful_result), ::std::move(__output));
}
}
else {
auto __stateful_result = __detail::__intermediate_encode_to_storage(::std::forward<_Input>(__input),
Expand Down Expand Up @@ -517,10 +526,10 @@ namespace ztd { namespace text {
__output.reserve(__output_size_hint);
}
}
if constexpr (__detail::__is_encode_error_handler_callable_v<_Encoding, _Input, _Unbounded, _ErrorHandler,
_State>) {
if constexpr (__detail::__is_encode_one_callable_v<_Encoding, _Input, _Unbounded, _ErrorHandler,
_State>) {
if constexpr (__detail::__is_encode_error_handler_callable_v<_Encoding, _IntermediateInput, _Unbounded,
_ErrorHandler, _State>) {
if constexpr (__detail::__is_encode_one_callable_v<_Encoding, _IntermediateInput, _Unbounded,
_ErrorHandler, _State>) {
// We can use the unbounded stuff
_Unbounded __insert_view(::std::back_inserter(__output));
auto __stateful_result
Expand Down

0 comments on commit bcdeff5

Please sign in to comment.