Skip to content

Commit

Permalink
🛠️ Remove tag_invoke entirely
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Aug 6, 2024
1 parent fc30abb commit 51fa73e
Show file tree
Hide file tree
Showing 22 changed files with 194 additions and 66 deletions.
24 changes: 18 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
#
# ============================================================================>

cmake_minimum_required(VERSION 3.21.0)
cmake_policy(VERSION 3.21)
cmake_minimum_required(VERSION 3.28.0)

# # Project kickstart
# Includes a bunch of basic flags and utilities shared across projects
Expand Down Expand Up @@ -223,9 +222,9 @@ if (ZTD_TEXT_EXAMPLES OR ZTD_TEXT_BENCHMARKS)
simdutf
GIT_REPOSITORY https://github.com/simdutf/simdutf
GIT_SHALLOW ON
GIT_TAG master)
GIT_TAG master
EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(simdutf)
set_property(DIRECTORY "${simdutf_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL YES)
endfunction()
simdutf_dependency_jail()

Expand All @@ -240,13 +239,26 @@ if (ZTD_TEXT_EXAMPLES OR ZTD_TEXT_BENCHMARKS)
boost.text
GIT_REPOSITORY https://github.com/ThePhD/text
GIT_SHALLOW ON
GIT_TAG master)
GIT_TAG master
EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(boost.text)
set_property(DIRECTORY "${boost.text_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL YES)
endfunction()
if (ZTD_TEXT_BOOST.TEXT)
boost_text_dependency_jail()
endif()
if (ZTD_TEXT_BENCHMARKS)
function(unicode_lipsum_dependency_jail)
# unicode_lipsum check
FetchContent_Declare(
unicode_lipsum
GIT_REPOSITORY https://github.com/lemire/unicode_lipsum
GIT_SHALLOW ON
GIT_TAG main
EXCLUDE_FROM_ALL)
FetchContent_MakeAvailable(unicode_lipsum)
endfunction()
unicode_lipsum_dependency_jail()
endif()
endif()

if(ZTD_TEXT_TESTS)
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function (google_benchmark_dependency_jail)
google_benchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG main
EXCLUDE_FROM_ALL
)
# Benchmark variables, internal setup
set(BENCHMARK_ENABLE_EXCEPTIONS ON)
Expand All @@ -55,7 +56,6 @@ function (google_benchmark_dependency_jail)
set(HAVE_STD_REGEX ON)
endif()
FetchContent_MakeAvailable(google_benchmark)
set_property(DIRECTORY "${google_benchmark_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL YES)
endfunction()
google_benchmark_dependency_jail()

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/barrier/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#
# =========================================================================== #

# # Benchmarks
# # Benchmarks data, compiled behind a shared data barrier
file(GLOB_RECURSE ztd.text.benchmarks.barrier.sources
LIST_DIRECTORIES FALSE
CONFIGURE_DEPENDS
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/conversion_speed/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ function (generate_converion_speed_benchmark_targets name data_name title)
ZTD_TEXT_BENCHMARKS_CONVERSION_SPEED_CUNEICODE_SINGLE_FROM_BULK_BENCHMARKS=$<IF:$<BOOL:${ZTD_TEXT_BENCHMARKS_INTERNALS}>,1,0>
ZTD_TEXT_BENCHMARKS_CONVERSION_SPEED_CUNEICODE_BASIC_UNCHECKED_BENCHMARKS=$<IF:$<BOOL:${ZTD_TEXT_BENCHMARKS_INTERNALS}>,1,0>
ZTD_TEXT_BENCHMARKS_CONVERSION_SPEED_CUNEICODE_SINGLE_FROM_BULK_UNCHECKED_BENCHMARKS=$<IF:$<BOOL:${ZTD_TEXT_BENCHMARKS_INTERNALS}>,1,0>
ZTD_TEXT_BENCHMARKS_CONVERSION_SPEED_ICU_BENCHMARKS=1
ZTD_TEXT_BENCHMARKS_CONVERSION_SPEED_ICONV_BENCHMARKS=1
ZTD_TEXT_BENCHMARKS_CONVERSION_SPEED_ICU_BENCHMARKS=$<IF:$<BOOL:${ZTD_TEXT_ICU}>,1,0>
ZTD_TEXT_BENCHMARKS_CONVERSION_SPEED_ICONV_BENCHMARKS=$<IF:$<BOOL:${ZTD_TEXT_LIBICONV}>,1,0>
ZTD_TEXT_BENCHMARKS_CONVERSION_SPEED_ENCODING_C_BENCHMARKS=1
ZTD_TEXT_BENCHMARKS_CONVERSION_SPEED_CTRE_BENCHMARKS=1
ZTD_TEXT_BENCHMARKS_CONVERSION_SPEED_SIMDUTF_BENCHMARKS=1
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/conversion_speed/source/cuneicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
const ztd_char##FROM_N##_t* input = input_data.data(); \
size_t output_size = output_data.size(); \
ztd_char##TO_N##_t* output = output_data.data(); \
cnc_mcerr err = cnc_c##FROM_N##sntoc##TO_N##sn(&output_size, &output, &input_size, &input, &cstate); \
cnc_mcerr err = cnc_c##FROM_N##snrtoc##TO_N##sn(&output_size, &output, &input_size, &input, &cstate); \
if (err != cnc_mcerr_ok) { \
result = false; \
} \
Expand Down
13 changes: 7 additions & 6 deletions benchmarks/conversion_speed/source/standard_c++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <ztd/idk/charN_t.hpp>
#include <ztd/idk/detail/unicode.hpp>
#include <ztd/idk/endian.hpp>
#include <ztd/idk/mbstate_t.hpp>

#include <barrier/barrier.h>

Expand All @@ -66,7 +67,7 @@ static void utf16_to_utf32_well_formed_standard_cpp(benchmark::State& state) {
to_char_t* output = output_data.data();
to_char_t* const output_last = output_data.data() + output_data.size();
for (auto _ : state) {
std::mbstate_t state {};
ztd_mbstate_t state {};
const char* char_input = reinterpret_cast<const char*>(input);
const char* char_input_last = reinterpret_cast<const char*>(input_last);
const char* char_input_next;
Expand Down Expand Up @@ -110,7 +111,7 @@ static void utf32_to_utf16_well_formed_standard_cpp(benchmark::State& state) {
to_char_t* output = output_data.data();
to_char_t* const output_last = output_data.data() + output_data.size();
for (auto _ : state) {
std::mbstate_t state {};
ztd_mbstate_t state {};
char* char_output = reinterpret_cast<char*>(output);
char* char_output_last = reinterpret_cast<char*>(output_last);
const from_char_t* input_next;
Expand Down Expand Up @@ -155,7 +156,7 @@ static void utf32_to_utf8_well_formed_standard_cpp(benchmark::State& state) {
to_char_t* output = output_data.data();
to_char_t* const output_last = output_data.data() + output_data.size();
for (auto _ : state) {
std::mbstate_t state {};
ztd_mbstate_t state {};
char* char_output = reinterpret_cast<char*>(output);
char* char_output_last = reinterpret_cast<char*>(output_last);
const from_char_t* input_next;
Expand Down Expand Up @@ -201,7 +202,7 @@ static void utf8_to_utf32_well_formed_standard_cpp(benchmark::State& state) {
to_char_t* output = output_data.data();
to_char_t* const output_last = output_data.data() + output_data.size();
for (auto _ : state) {
std::mbstate_t state {};
ztd_mbstate_t state {};
const char* char_input = reinterpret_cast<const char*>(input);
const char* char_input_last = reinterpret_cast<const char*>(input_last);
const char* char_input_next;
Expand Down Expand Up @@ -246,7 +247,7 @@ static void utf16_to_utf8_well_formed_standard_cpp(benchmark::State& state) {
to_char_t* output = output_data.data();
to_char_t* const output_last = output_data.data() + output_data.size();
for (auto _ : state) {
std::mbstate_t state {};
ztd_mbstate_t state {};
char* char_output = reinterpret_cast<char*>(output);
char* char_output_last = reinterpret_cast<char*>(output_last);
const from_char_t* input_next;
Expand Down Expand Up @@ -292,7 +293,7 @@ static void utf8_to_utf16_well_formed_standard_cpp(benchmark::State& state) {
to_char_t* output = output_data.data();
to_char_t* const output_last = output_data.data() + output_data.size();
for (auto _ : state) {
std::mbstate_t state {};
ztd_mbstate_t state {};
const char* char_input = reinterpret_cast<const char*>(input);
const char* char_input_last = reinterpret_cast<const char*>(input_last);
const char* char_input_next;
Expand Down
13 changes: 7 additions & 6 deletions benchmarks/conversion_speed/source/standard_c++.init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <ztd/idk/charN_t.hpp>
#include <ztd/idk/detail/unicode.hpp>
#include <ztd/idk/endian.hpp>
#include <ztd/idk/mbstate_t.hpp>

#include <barrier/barrier.h>

Expand All @@ -65,7 +66,7 @@ static void utf16_to_utf32_init_well_formed_standard_cpp(benchmark::State& state
std::locale current_loc = {};
auto codecvt_ptr = new std::codecvt_utf16<char32_t, codecvt_max_code_utfs, codecvt_target_mode>();
current_loc = std::locale(current_loc, codecvt_ptr);
std::mbstate_t state {};
std::ztd_mbstate_t state {};
const char* char_input = reinterpret_cast<const char*>(input);
const char* char_input_last = reinterpret_cast<const char*>(input_last);
const char* char_input_next;
Expand Down Expand Up @@ -108,7 +109,7 @@ static void utf32_to_utf16_init_well_formed_standard_cpp(benchmark::State& state
std::locale current_loc = {};
auto codecvt_ptr = new std::codecvt_utf16<char32_t, codecvt_max_code_utfs, codecvt_target_mode>();
current_loc = std::locale(current_loc, codecvt_ptr);
std::mbstate_t state {};
ztd_mbstate_t state {};
char* char_output = reinterpret_cast<char*>(output);
char* char_output_last = reinterpret_cast<char*>(output_last);
const from_char_t* input_next;
Expand Down Expand Up @@ -153,7 +154,7 @@ static void utf32_to_utf8_init_well_formed_standard_cpp(benchmark::State& state)
std::locale current_loc = {};
auto codecvt_ptr = new std::codecvt_utf8<char32_t, codecvt_max_code_utfs, codecvt_target_mode>();
current_loc = std::locale(current_loc, codecvt_ptr);
std::mbstate_t state {};
ztd_mbstate_t state {};
char* char_output = reinterpret_cast<char*>(output);
char* char_output_last = reinterpret_cast<char*>(output_last);
const from_char_t* input_next;
Expand Down Expand Up @@ -199,7 +200,7 @@ static void utf8_to_utf32_init_well_formed_standard_cpp(benchmark::State& state)
std::locale current_loc = {};
auto codecvt_ptr = new std::codecvt_utf8<char32_t, codecvt_max_code_utfs, codecvt_target_mode>();
current_loc = std::locale(current_loc, codecvt_ptr);
std::mbstate_t state {};
ztd_mbstate_t state {};
const char* char_input = reinterpret_cast<const char*>(input);
const char* char_input_last = reinterpret_cast<const char*>(input_last);
const char* char_input_next;
Expand Down Expand Up @@ -244,7 +245,7 @@ static void utf16_to_utf8_init_well_formed_standard_cpp(benchmark::State& state)
std::locale current_loc = {};
auto codecvt_ptr = new std::codecvt_utf8_utf16<char16_t, codecvt_max_code_utfs, codecvt_target_mode>();
current_loc = std::locale(current_loc, codecvt_ptr);
std::mbstate_t state {};
ztd_mbstate_t state {};
char* char_output = reinterpret_cast<char*>(output);
char* char_output_last = reinterpret_cast<char*>(output_last);
const from_char_t* input_next;
Expand Down Expand Up @@ -290,7 +291,7 @@ static void utf8_to_utf16_init_well_formed_standard_cpp(benchmark::State& state)
std::locale current_loc = {};
auto codecvt_ptr = new std::codecvt_utf8_utf16<char16_t, codecvt_max_code_utfs, codecvt_target_mode>();
current_loc = std::locale(current_loc, codecvt_ptr);
std::mbstate_t state {};
ztd_mbstate_t state {};
const char* char_input = reinterpret_cast<const char*>(input);
const char* char_input_last = reinterpret_cast<const char*>(input_last);
const char* char_input_next;
Expand Down
17 changes: 9 additions & 8 deletions benchmarks/conversion_speed/source/standard_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include <ztd/idk/c_span.h>
#include <ztd/idk/charN_t.hpp>
#include <ztd/idk/mbstate_t.hpp>
#include <barrier/barrier.h>

#if ZTD_IS_ON(ZTD_CUCHAR)
Expand All @@ -55,8 +56,8 @@ static void utf16_to_utf32_well_formed_standard_c(benchmark::State& state) {
std::vector<to_char_t> output_data(c_span_char32_t_size(u32_data));
bool result = true;
for (auto _ : state) {
mbstate_t from_state {};
mbstate_t to_state {};
ztd_mbstate_t from_state {};
ztd_mbstate_t to_state {};
char intermediate_data[MB_LEN_MAX * 2];
to_char_t* output = output_data.data();
to_char_t* output_last = output_data.data() + output_data.size();
Expand Down Expand Up @@ -149,8 +150,8 @@ static void utf32_to_utf16_well_formed_standard_c(benchmark::State& state) {
std::vector<to_char_t> output_data(c_span_char16_t_size(u16_data));
bool result = true;
for (auto _ : state) {
mbstate_t from_state {};
mbstate_t to_state {};
ztd_mbstate_t from_state {};
ztd_mbstate_t to_state {};
char intermediate_data[MB_LEN_MAX * 2];
to_char_t* output = output_data.data();
to_char_t* output_last = output_data.data() + output_data.size();
Expand Down Expand Up @@ -244,7 +245,7 @@ static void utf32_to_utf8_well_formed_standard_c(benchmark::State& state) {
std::vector<to_char_t> output_data(c_span_char8_t_size(u8_data));
bool result = true;
for (auto _ : state) {
mbstate_t from_state {};
ztd_mbstate_t from_state {};
to_char_t* output = output_data.data();
to_char_t* output_last = output_data.data() + output_data.size();
const from_char_t* input = input_data.data();
Expand Down Expand Up @@ -286,7 +287,7 @@ static void utf8_to_utf32_well_formed_standard_c(benchmark::State& state) {
std::vector<to_char_t> output_data(c_span_char32_t_size(u32_data));
bool result = true;
for (auto _ : state) {
mbstate_t to_state {};
ztd_mbstate_t to_state {};
const from_char_t* input = input_data.data();
const from_char_t* const input_last = input_data.data() + input_data.size();
to_char_t* output = output_data.data();
Expand Down Expand Up @@ -362,7 +363,7 @@ static void utf16_to_utf8_well_formed_standard_c(benchmark::State& state) {
std::vector<to_char_t> output_data(c_span_char8_t_size(u8_data));
bool result = true;
for (auto _ : state) {
mbstate_t from_state {};
ztd_mbstate_t from_state {};
to_char_t* output = output_data.data();
to_char_t* output_last = output_data.data() + output_data.size();
const from_char_t* input = input_data.data();
Expand Down Expand Up @@ -404,7 +405,7 @@ static void utf8_to_utf16_well_formed_standard_c(benchmark::State& state) {
std::vector<to_char_t> output_data(c_span_char16_t_size(u16_data));
bool result = true;
for (auto _ : state) {
mbstate_t to_state {};
ztd_mbstate_t to_state {};
const from_char_t* input = input_data.data();
const from_char_t* const input_last = input_data.data() + input_data.size();
to_char_t* output = output_data.data();
Expand Down
4 changes: 4 additions & 0 deletions documentation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@

# Dependencies
find_package(Doxygen REQUIRED)
if (NOT ZTD_TEXT_DOCUMENTATION_NO_SPHINX)
find_package(Sphinx REQUIRED)
else()
find_package(Sphinx QUIET)
endif()

# For the install target and related directories
include(GNUInstallDirs)
Expand Down
2 changes: 1 addition & 1 deletion documentation/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
rst_prolog = """
.. |ub| replace:: ☢️☢️Undefined Behavior☢️☢️
.. |specializations_okay_different_types| replace:: User Specializations: ✔️ Okay! You can add other types to this classification by specializing the class template. Your specialization must have a type definition named ``type`` (as in, ``using type = ...;`` or `typedef ... type;``) inside of the class specialization that is ``public:``\ ly accessible. Note that specializing any type not explicitly marked with this notice is |ub|.
.. |specializations_okay_different_types| replace:: User Specializations: ✔️ Okay! You can add other types to this classification by specializing the class template. Your specialization must have a type definition named ``type`` (as in, ``using type = ...;`` or `typedef ... type;``) inside of the class specialization that is ``public:``-ly accessible. Note that specializing any type not explicitly marked with this notice is |ub|.
.. |specializations_okay_true_false_type| replace:: User Specializations: ✔️ Okay! You can add other types to this classification by specializing the class template to a definition that derives from ``std::true_type``, or turn it off explicitly by having a definition that derives from ``std::false_type``. Note that specializing any type not explicitly marked with this notice is |ub|.
Expand Down
15 changes: 12 additions & 3 deletions examples/documentation/snippets/source/runtime_locale_encoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
// This example doesn't work on Apple/libc++ because they don't have
// standard C or C++ headers.

#include <ztd/idk/mbstate_t.hpp>

#include <cstddef>
#if defined(__has_include) && __has_include(<cuchar>)
#include <cuchar>
Expand All @@ -50,7 +52,6 @@ extern "C" {
#define WIN32_LEAN_AND_MEAN 1
#include <windows.h>
#else

#endif

class runtime_locale {
Expand All @@ -63,23 +64,31 @@ class runtime_locale {
inline static constexpr std::size_t max_code_units = MB_LEN_MAX;

struct decode_state {
std::mbstate_t c_stdlib_state;
ztd_mbstate_t c_stdlib_state;

decode_state() noexcept : c_stdlib_state() {
// properly set for mbrtoc32 state
code_point ghost_ouput[2] {};
UCHAR_ACCESS mbrtoc32(ghost_ouput, "\0", 1, &c_stdlib_state);
}

bool is_complete() const noexcept {
return UCHAR_ACCESS mbsinit(&c_stdlib_state) != 0;
}
};

struct encode_state {
std::mbstate_t c_stdlib_state;
ztd_mbstate_t c_stdlib_state;

encode_state() noexcept : c_stdlib_state() {
// properly set for c32rtomb state
code_unit ghost_ouput[MB_LEN_MAX] {};
UCHAR_ACCESS c32rtomb(ghost_ouput, U'\0', &c_stdlib_state);
}

bool is_complete() const noexcept {
return UCHAR_ACCESS mbsinit(&c_stdlib_state) != 0;
}
};

bool contains_unicode_encoding() const noexcept {
Expand Down
15 changes: 13 additions & 2 deletions include/ztd/text/code_point.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,26 @@
#include <ztd/prologue.hpp>

//////
/// @file code point abstractions
/// @file code_point.hpp
///
/// @brief code point abstractions

//////
/// @namespace ztd
///
/// @brief The core library namespace.

//////
/// @namespace ztd::text
///
/// @brief The text library namespace.

namespace ztd { namespace text {
ZTD_TEXT_INLINE_ABI_NAMESPACE_OPEN_I_

//////
/// @addtogroup ztd_text_properties Property and Trait Helpers
/// @{
/////

//////
/// @brief Retrieves the code point type for the given type.
Expand Down
2 changes: 1 addition & 1 deletion include/ztd/text/decode_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ namespace ztd { namespace text {
/// @brief The reconstruct extension point for rebuilding an encoding view from its iterator and sentinel
/// type.
template <typename _Encoding, typename _Range, typename _ErrorHandler, typename _State>
constexpr decode_view<_Encoding, _Range, _ErrorHandler, _State> tag_invoke(ztd::tag_t<ranges::reconstruct>,
constexpr decode_view<_Encoding, _Range, _ErrorHandler, _State> reconstruct(
::std::in_place_type_t<decode_view<_Encoding, _Range, _ErrorHandler, _State>>,
typename decode_view<_Encoding, _Range, _ErrorHandler, _State>::iterator __it,
typename decode_view<_Encoding, _Range, _ErrorHandler, _State>::sentinel) noexcept(::std::
Expand Down
Loading

0 comments on commit 51fa73e

Please sign in to comment.