From 72cd08f061d41c9df956242405d17666411e2672 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Tue, 9 Dec 2025 22:22:38 -0500 Subject: [PATCH] update to clang-format-21 --- .github/workflows/lint_and_format_check.yml | 6 +- benchmarks/competitors/servo-url/servo_url.h | 8 +- benchmarks/model_bench.cpp | 22 +- .../performancecounters/linux-perf-events.h | 4 +- benchmarks/wpt_bench.cpp | 24 +- fuzz/can_parse.cc | 2 +- fuzz/idna.cc | 2 +- fuzz/parse.cc | 6 +- fuzz/url_search_params.cc | 2 +- include/ada/common_defs.h | 6 +- include/ada/expected.h | 939 +++++++++--------- include/ada/url-inl.h | 10 +- include/ada/url.h | 32 +- include/ada/url_aggregator-inl.h | 8 +- include/ada/url_aggregator.h | 30 +- include/ada/url_components.h | 8 +- include/ada/url_search_params-inl.h | 18 +- include/ada/url_search_params.h | 20 +- singleheader/demo.cpp | 2 +- tests/wasm/wasm.cpp | 2 +- tests/wpt_url_tests.cpp | 38 +- tools/cli/line_iterator.h | 2 +- tools/run-clangcldocker.sh | 10 +- 23 files changed, 595 insertions(+), 606 deletions(-) diff --git a/.github/workflows/lint_and_format_check.yml b/.github/workflows/lint_and_format_check.yml index 8986adf9c..74a9aa361 100644 --- a/.github/workflows/lint_and_format_check.yml +++ b/.github/workflows/lint_and_format_check.yml @@ -29,7 +29,7 @@ jobs: - name: Run clang-format uses: jidicula/clang-format-action@6cd220de46c89139a0365edae93eee8eb30ca8fe # v4.16.0 with: - clang-format-version: '17' + clang-format-version: '21' fallback-style: 'Google' - uses: chartboost/ruff-action@e18ae971ccee1b2d7bbef113930f00c670b78da4 # v1.0.0 @@ -39,7 +39,7 @@ jobs: - name: Run clang-tidy run: > - cmake -B build -DADA_TESTING=ON -DCMAKE_CXX_CLANG_TIDY=clang-tidy-17 && + cmake -B build -DADA_TESTING=ON -DCMAKE_CXX_CLANG_TIDY=clang-tidy-21 && cmake --build build -j=4 env: - CXX: clang++-17 + CXX: clang++-21 diff --git a/benchmarks/competitors/servo-url/servo_url.h b/benchmarks/competitors/servo-url/servo_url.h index 406d5fc2f..95244fe3e 100644 --- a/benchmarks/competitors/servo-url/servo_url.h +++ b/benchmarks/competitors/servo-url/servo_url.h @@ -16,13 +16,13 @@ struct Url; extern "C" { -Url *parse_url(const char *raw_input, size_t raw_input_length); +Url* parse_url(const char* raw_input, size_t raw_input_length); -void free_url(Url *raw); +void free_url(Url* raw); -const char *parse_url_to_href(const char *raw_input, size_t raw_input_length); +const char* parse_url_to_href(const char* raw_input, size_t raw_input_length); -void free_string(const char *); +void free_string(const char*); } // extern "C" } // namespace servo_url diff --git a/benchmarks/model_bench.cpp b/benchmarks/model_bench.cpp index e9d1501d9..18c4bd565 100644 --- a/benchmarks/model_bench.cpp +++ b/benchmarks/model_bench.cpp @@ -9,7 +9,7 @@ #include "performancecounters/event_counter.h" event_collector collector; -bool file_exists(const char *filename) { +bool file_exists(const char* filename) { namespace fs = std::filesystem; std::filesystem::path f{filename}; if (std::filesystem::exists(filename)) { @@ -33,7 +33,7 @@ std::string read_file(std::string filename) { return out; } -std::vector split_string(const std::string &str) { +std::vector split_string(const std::string& str) { auto result = std::vector{}; std::stringstream ss{str}; for (std::string line; std::getline(ss, line, '\n');) { @@ -65,7 +65,7 @@ struct stat_numbers { bool has_search = false; }; -size_t count_ascii_bytes(const std::string &s) { +size_t count_ascii_bytes(const std::string& s) { size_t counter = 0; for (uint8_t c : s) { if (c < 128) { @@ -77,7 +77,7 @@ size_t count_ascii_bytes(const std::string &s) { template std::vector collect_values( - const std::vector &url_examples, size_t trials) { + const std::vector& url_examples, size_t trials) { std::vector numbers(url_examples.size()); for (size_t i = 0; i < url_examples.size(); i++) { numbers[i].url_string = url_examples[i]; @@ -96,7 +96,7 @@ std::vector collect_values( } volatile size_t href_size = 0; for (size_t i = 0; i < trials; i++) { - for (stat_numbers &n : numbers) { + for (stat_numbers& n : numbers) { std::atomic_thread_fence(std::memory_order_acquire); collector.start(); ada::result url = ada::parse(n.url_string); @@ -112,12 +112,12 @@ std::vector collect_values( } #ifdef ADA_URL_FILE -const char *default_file = ADA_URL_FILE; +const char* default_file = ADA_URL_FILE; #else -const char *default_file = nullptr; +const char* default_file = nullptr; #endif -std::vector init_data(const char *input = default_file) { +std::vector init_data(const char* input = default_file) { std::vector input_urls; if (input == nullptr) { return input_urls; @@ -133,7 +133,7 @@ std::vector init_data(const char *input = default_file) { return input_urls; } -void print(const stat_numbers &n) { +void print(const stat_numbers& n) { std::cout << std::setw(15) << n.url_string.size() << ","; std::cout << std::setw(15) << n.counters.best.cycles() << "," << std::setw(15) << size_t(n.counters.cycles()) << ","; @@ -238,13 +238,13 @@ void print(const std::vector numbers) { std::cout << std::endl; - for (const stat_numbers &n : numbers) { + for (const stat_numbers& n : numbers) { print(n); std::cout << std::endl; } } -int main(int argc, char **argv) { +int main(int argc, char** argv) { std::vector input_urls; if (argc == 1) { input_urls = init_data(); diff --git a/benchmarks/performancecounters/linux-perf-events.h b/benchmarks/performancecounters/linux-perf-events.h index 7ed0f8d24..8189fbac8 100644 --- a/benchmarks/performancecounters/linux-perf-events.h +++ b/benchmarks/performancecounters/linux-perf-events.h @@ -76,7 +76,7 @@ class LinuxEvents { } } - inline void end(std::vector &results) { + inline void end(std::vector& results) { if (fd != -1) { if (ioctl(fd, PERF_EVENT_IOC_DISABLE, PERF_IOC_FLAG_GROUP) == -1) { report_error("ioctl(PERF_EVENT_IOC_DISABLE)"); @@ -100,6 +100,6 @@ class LinuxEvents { bool is_working() { return working; } private: - void report_error(const std::string &) { working = false; } + void report_error(const std::string&) { working = false; } }; #endif \ No newline at end of file diff --git a/benchmarks/wpt_bench.cpp b/benchmarks/wpt_bench.cpp index 814e17db3..428626d93 100644 --- a/benchmarks/wpt_bench.cpp +++ b/benchmarks/wpt_bench.cpp @@ -11,7 +11,7 @@ enum { ALL_URLS = -1, }; -size_t init_data(const char *source, int which_url) { +size_t init_data(const char* source, int which_url) { ondemand::parser parser; std::vector> answer; @@ -66,15 +66,15 @@ size_t init_data(const char *source, int which_url) { } template -static void BasicBench_AdaURL(benchmark::State &state) { +static void BasicBench_AdaURL(benchmark::State& state) { // volatile to prevent optimizations. volatile size_t href_size = 0; for (auto _ : state) { - for (const std::pair &url_strings : + for (const std::pair& url_strings : url_examples) { ada::result base; - result *base_ptr = nullptr; + result* base_ptr = nullptr; if (!url_strings.second.empty()) { base = ada::parse(url_strings.second); if (base) { @@ -94,10 +94,10 @@ static void BasicBench_AdaURL(benchmark::State &state) { for (size_t i = 0; i < N; i++) { std::atomic_thread_fence(std::memory_order_acquire); collector.start(); - for (const std::pair &url_strings : + for (const std::pair& url_strings : url_examples) { ada::result base; - result *base_ptr = nullptr; + result* base_ptr = nullptr; if (!url_strings.second.empty()) { base = ada::parse(url_strings.second); if (base) { @@ -153,13 +153,13 @@ BENCHMARK(BasicBench_AdaURL_url_aggregator); #include -static void BasicBench_whatwg(benchmark::State &state) { +static void BasicBench_whatwg(benchmark::State& state) { volatile size_t success{}; for (auto _ : state) { - for (const std::pair &url_strings : + for (const std::pair& url_strings : url_examples) { upa::url base; - upa::url *base_ptr = nullptr; + upa::url* base_ptr = nullptr; if (!url_strings.second.empty()) { if (upa::success(base.parse(url_strings.second, nullptr))) { base_ptr = &base; @@ -176,10 +176,10 @@ static void BasicBench_whatwg(benchmark::State &state) { for (size_t i = 0; i < N; i++) { std::atomic_thread_fence(std::memory_order_acquire); collector.start(); - for (const std::pair &url_strings : + for (const std::pair& url_strings : url_examples) { upa::url base; - upa::url *base_ptr = nullptr; + upa::url* base_ptr = nullptr; if (!url_strings.second.empty()) { if (upa::success(base.parse(url_strings.second, nullptr))) { base_ptr = &base; @@ -227,7 +227,7 @@ static void BasicBench_whatwg(benchmark::State &state) { BENCHMARK(BasicBench_whatwg); #endif // ADA_url_whatwg_ENABLED -int main(int argc, char **argv) { +int main(int argc, char** argv) { int which_url = ALL_URLS; if (argc > 3 && std::string_view(argv[2]) == "--select") { which_url = std::atoi(argv[3]); diff --git a/fuzz/can_parse.cc b/fuzz/can_parse.cc index c7fe87b22..cff5deeee 100644 --- a/fuzz/can_parse.cc +++ b/fuzz/can_parse.cc @@ -6,7 +6,7 @@ #include "ada.cpp" #include "ada.h" -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { FuzzedDataProvider fdp(data, size); std::string source = fdp.ConsumeRandomLengthString(256); std::string base_source = fdp.ConsumeRandomLengthString(256); diff --git a/fuzz/idna.cc b/fuzz/idna.cc index fb8b7af2a..6a45aa0c8 100644 --- a/fuzz/idna.cc +++ b/fuzz/idna.cc @@ -6,7 +6,7 @@ #include "ada.cpp" #include "ada.h" -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { FuzzedDataProvider fdp(data, size); std::string source = fdp.ConsumeRandomLengthString(256); diff --git a/fuzz/parse.cc b/fuzz/parse.cc index ed8581c34..4bd08fc30 100644 --- a/fuzz/parse.cc +++ b/fuzz/parse.cc @@ -7,8 +7,8 @@ #include "ada.cpp" #include "ada.h" -bool is_valid_utf8_string(const char *buf, size_t len) { - const uint8_t *data = reinterpret_cast(buf); +bool is_valid_utf8_string(const char* buf, size_t len) { + const uint8_t* data = reinterpret_cast(buf); uint64_t pos = 0; uint32_t code_point = 0; while (pos < len) { @@ -91,7 +91,7 @@ bool is_valid_utf8_string(const char *buf, size_t len) { return true; } -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { FuzzedDataProvider fdp(data, size); std::string source = fdp.ConsumeRandomLengthString(256); diff --git a/fuzz/url_search_params.cc b/fuzz/url_search_params.cc index accba848a..3c94e3172 100644 --- a/fuzz/url_search_params.cc +++ b/fuzz/url_search_params.cc @@ -6,7 +6,7 @@ #include "ada.cpp" #include "ada.h" -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { FuzzedDataProvider fdp(data, size); std::string source = fdp.ConsumeRandomLengthString(256); std::string base_source = fdp.ConsumeRandomLengthString(256); diff --git a/include/ada/common_defs.h b/include/ada/common_defs.h index ac6e660eb..8dfbbbe3f 100644 --- a/include/ada/common_defs.h +++ b/include/ada/common_defs.h @@ -40,10 +40,10 @@ #endif // Align to N-byte boundary -#define ADA_ROUNDUP_N(a, n) (((a) + ((n)-1)) & ~((n)-1)) -#define ADA_ROUNDDOWN_N(a, n) ((a) & ~((n)-1)) +#define ADA_ROUNDUP_N(a, n) (((a) + ((n) - 1)) & ~((n) - 1)) +#define ADA_ROUNDDOWN_N(a, n) ((a) & ~((n) - 1)) -#define ADA_ISALIGNED_N(ptr, n) (((uintptr_t)(ptr) & ((n)-1)) == 0) +#define ADA_ISALIGNED_N(ptr, n) (((uintptr_t)(ptr) & ((n) - 1)) == 0) #if defined(ADA_REGULAR_VISUAL_STUDIO) diff --git a/include/ada/expected.h b/include/ada/expected.h index 5233a042a..c3567ccbc 100644 --- a/include/ada/expected.h +++ b/include/ada/expected.h @@ -151,25 +151,25 @@ class unexpected { static_assert(!std::is_same::value, "E must not be void"); unexpected() = delete; - constexpr explicit unexpected(const E &e) : m_val(e) {} + constexpr explicit unexpected(const E& e) : m_val(e) {} - constexpr explicit unexpected(E &&e) : m_val(std::move(e)) {} + constexpr explicit unexpected(E&& e) : m_val(std::move(e)) {} template ::value>::type * = nullptr> - constexpr explicit unexpected(Args &&...args) + E, Args&&...>::value>::type* = nullptr> + constexpr explicit unexpected(Args&&... args) : m_val(std::forward(args)...) {} template < class U, class... Args, typename std::enable_if &, Args &&...>::value>::type * = nullptr> - constexpr explicit unexpected(std::initializer_list l, Args &&...args) + E, std::initializer_list&, Args&&...>::value>::type* = nullptr> + constexpr explicit unexpected(std::initializer_list l, Args&&... args) : m_val(l, std::forward(args)...) {} - constexpr const E &value() const & { return m_val; } - TL_EXPECTED_11_CONSTEXPR E &value() & { return m_val; } - TL_EXPECTED_11_CONSTEXPR E &&value() && { return std::move(m_val); } - constexpr const E &&value() const && { return std::move(m_val); } + constexpr const E& value() const& { return m_val; } + TL_EXPECTED_11_CONSTEXPR E& value() & { return m_val; } + TL_EXPECTED_11_CONSTEXPR E&& value() && { return std::move(m_val); } + constexpr const E&& value() const&& { return std::move(m_val); } private: E m_val; @@ -181,32 +181,32 @@ unexpected(E) -> unexpected; #endif template -constexpr bool operator==(const unexpected &lhs, const unexpected &rhs) { +constexpr bool operator==(const unexpected& lhs, const unexpected& rhs) { return lhs.value() == rhs.value(); } template -constexpr bool operator!=(const unexpected &lhs, const unexpected &rhs) { +constexpr bool operator!=(const unexpected& lhs, const unexpected& rhs) { return lhs.value() != rhs.value(); } template -constexpr bool operator<(const unexpected &lhs, const unexpected &rhs) { +constexpr bool operator<(const unexpected& lhs, const unexpected& rhs) { return lhs.value() < rhs.value(); } template -constexpr bool operator<=(const unexpected &lhs, const unexpected &rhs) { +constexpr bool operator<=(const unexpected& lhs, const unexpected& rhs) { return lhs.value() <= rhs.value(); } template -constexpr bool operator>(const unexpected &lhs, const unexpected &rhs) { +constexpr bool operator>(const unexpected& lhs, const unexpected& rhs) { return lhs.value() > rhs.value(); } template -constexpr bool operator>=(const unexpected &lhs, const unexpected &rhs) { +constexpr bool operator>=(const unexpected& lhs, const unexpected& rhs) { return lhs.value() >= rhs.value(); } template -unexpected::type> make_unexpected(E &&e) { +unexpected::type> make_unexpected(E&& e) { return unexpected::type>(std::forward(e)); } @@ -217,7 +217,7 @@ static constexpr unexpect_t unexpect{}; namespace detail { template -[[noreturn]] TL_EXPECTED_11_CONSTEXPR void throw_exception(E &&e) { +[[noreturn]] TL_EXPECTED_11_CONSTEXPR void throw_exception(E&& e) { #ifdef TL_EXPECTED_EXCEPTIONS_ENABLED throw std::forward(e); #else @@ -276,16 +276,16 @@ template struct is_pointer_to_non_const_member_func : std::true_type {}; template -struct is_pointer_to_non_const_member_func +struct is_pointer_to_non_const_member_func : std::true_type {}; template -struct is_pointer_to_non_const_member_func +struct is_pointer_to_non_const_member_func : std::true_type {}; template struct is_const_or_const_ref : std::false_type {}; template -struct is_const_or_const_ref : std::true_type {}; +struct is_const_or_const_ref : std::true_type {}; template struct is_const_or_const_ref : std::true_type {}; #endif @@ -299,7 +299,7 @@ template < is_const_or_const_ref::value)>, #endif typename = enable_if_t>::value>, int = 0> -constexpr auto invoke(Fn &&f, Args &&...args) noexcept( +constexpr auto invoke(Fn&& f, Args&&... args) noexcept( noexcept(std::mem_fn(f)(std::forward(args)...))) -> decltype(std::mem_fn(f)(std::forward(args)...)) { return std::mem_fn(f)(std::forward(args)...); @@ -307,7 +307,7 @@ constexpr auto invoke(Fn &&f, Args &&...args) noexcept( template >::value>> -constexpr auto invoke(Fn &&f, Args &&...args) noexcept( +constexpr auto invoke(Fn&& f, Args&&... args) noexcept( noexcept(std::forward(f)(std::forward(args)...))) -> decltype(std::forward(f)(std::forward(args)...)) { return std::forward(f)(std::forward(args)...); @@ -347,7 +347,7 @@ namespace swap_adl_tests { struct tag {}; template -tag swap(T &, T &); +tag swap(T&, T&); template tag swap(T (&a)[N], T (&b)[N]); @@ -356,14 +356,14 @@ tag swap(T (&a)[N], T (&b)[N]); template std::false_type can_swap(...) noexcept(false); template (), std::declval()))> -std::true_type can_swap(int) noexcept(noexcept(swap(std::declval(), - std::declval()))); + class = decltype(swap(std::declval(), std::declval()))> +std::true_type can_swap(int) noexcept(noexcept(swap(std::declval(), + std::declval()))); template std::false_type uses_std(...); template -std::is_same(), std::declval())), tag> +std::is_same(), std::declval())), tag> uses_std(int); template @@ -420,7 +420,7 @@ using is_expected = is_expected_impl>; template using expected_enable_forward_value = detail::enable_if_t< - std::is_constructible::value && + std::is_constructible::value && !std::is_same, in_place_t>::value && !std::is_same, detail::decay_t>::value && !std::is_same, detail::decay_t>::value>; @@ -429,14 +429,14 @@ template using expected_enable_from_other = detail::enable_if_t< std::is_constructible::value && std::is_constructible::value && - !std::is_constructible &>::value && - !std::is_constructible &&>::value && - !std::is_constructible &>::value && - !std::is_constructible &&>::value && - !std::is_convertible &, T>::value && - !std::is_convertible &&, T>::value && - !std::is_convertible &, T>::value && - !std::is_convertible &&, T>::value>; + !std::is_constructible&>::value && + !std::is_constructible&&>::value && + !std::is_constructible&>::value && + !std::is_constructible&&>::value && + !std::is_convertible&, T>::value && + !std::is_convertible&&, T>::value && + !std::is_convertible&, T>::value && + !std::is_convertible&&, T>::value>; template using is_void_or = conditional_t::value, std::true_type, U>; @@ -474,29 +474,29 @@ struct expected_storage_base { constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {} template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr expected_storage_base(in_place_t, Args &&...args) + constexpr expected_storage_base(in_place_t, Args&&... args) : m_val(std::forward(args)...), m_has_val(true) {} template &, Args &&...>::value> * = nullptr> + T, std::initializer_list&, Args&&...>::value>* = nullptr> constexpr expected_storage_base(in_place_t, std::initializer_list il, - Args &&...args) + Args&&... args) : m_val(il, std::forward(args)...), m_has_val(true) {} template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr explicit expected_storage_base(unexpect_t, Args &&...args) + constexpr explicit expected_storage_base(unexpect_t, Args&&... args) : m_unexpect(std::forward(args)...), m_has_val(false) {} template &, Args &&...>::value> * = nullptr> + E, std::initializer_list&, Args&&...>::value>* = nullptr> constexpr explicit expected_storage_base(unexpect_t, std::initializer_list il, - Args &&...args) + Args&&... args) : m_unexpect(il, std::forward(args)...), m_has_val(false) {} ~expected_storage_base() { @@ -522,29 +522,29 @@ struct expected_storage_base { constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {} template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr expected_storage_base(in_place_t, Args &&...args) + constexpr expected_storage_base(in_place_t, Args&&... args) : m_val(std::forward(args)...), m_has_val(true) {} template &, Args &&...>::value> * = nullptr> + T, std::initializer_list&, Args&&...>::value>* = nullptr> constexpr expected_storage_base(in_place_t, std::initializer_list il, - Args &&...args) + Args&&... args) : m_val(il, std::forward(args)...), m_has_val(true) {} template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr explicit expected_storage_base(unexpect_t, Args &&...args) + constexpr explicit expected_storage_base(unexpect_t, Args&&... args) : m_unexpect(std::forward(args)...), m_has_val(false) {} template &, Args &&...>::value> * = nullptr> + E, std::initializer_list&, Args&&...>::value>* = nullptr> constexpr explicit expected_storage_base(unexpect_t, std::initializer_list il, - Args &&...args) + Args&&... args) : m_unexpect(il, std::forward(args)...), m_has_val(false) {} ~expected_storage_base() = default; @@ -564,29 +564,29 @@ struct expected_storage_base { : m_no_init(), m_has_val(false) {} template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr expected_storage_base(in_place_t, Args &&...args) + constexpr expected_storage_base(in_place_t, Args&&... args) : m_val(std::forward(args)...), m_has_val(true) {} template &, Args &&...>::value> * = nullptr> + T, std::initializer_list&, Args&&...>::value>* = nullptr> constexpr expected_storage_base(in_place_t, std::initializer_list il, - Args &&...args) + Args&&... args) : m_val(il, std::forward(args)...), m_has_val(true) {} template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr explicit expected_storage_base(unexpect_t, Args &&...args) + constexpr explicit expected_storage_base(unexpect_t, Args&&... args) : m_unexpect(std::forward(args)...), m_has_val(false) {} template &, Args &&...>::value> * = nullptr> + E, std::initializer_list&, Args&&...>::value>* = nullptr> constexpr explicit expected_storage_base(unexpect_t, std::initializer_list il, - Args &&...args) + Args&&... args) : m_unexpect(il, std::forward(args)...), m_has_val(false) {} ~expected_storage_base() { @@ -610,29 +610,29 @@ struct expected_storage_base { constexpr expected_storage_base(no_init_t) : m_no_init(), m_has_val(false) {} template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr expected_storage_base(in_place_t, Args &&...args) + constexpr expected_storage_base(in_place_t, Args&&... args) : m_val(std::forward(args)...), m_has_val(true) {} template &, Args &&...>::value> * = nullptr> + T, std::initializer_list&, Args&&...>::value>* = nullptr> constexpr expected_storage_base(in_place_t, std::initializer_list il, - Args &&...args) + Args&&... args) : m_val(il, std::forward(args)...), m_has_val(true) {} template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr explicit expected_storage_base(unexpect_t, Args &&...args) + constexpr explicit expected_storage_base(unexpect_t, Args&&... args) : m_unexpect(std::forward(args)...), m_has_val(false) {} template &, Args &&...>::value> * = nullptr> + E, std::initializer_list&, Args&&...>::value>* = nullptr> constexpr explicit expected_storage_base(unexpect_t, std::initializer_list il, - Args &&...args) + Args&&... args) : m_unexpect(il, std::forward(args)...), m_has_val(false) {} ~expected_storage_base() { @@ -663,17 +663,17 @@ struct expected_storage_base { constexpr expected_storage_base(in_place_t) : m_has_val(true) {} template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr explicit expected_storage_base(unexpect_t, Args &&...args) + constexpr explicit expected_storage_base(unexpect_t, Args&&... args) : m_unexpect(std::forward(args)...), m_has_val(false) {} template &, Args &&...>::value> * = nullptr> + E, std::initializer_list&, Args&&...>::value>* = nullptr> constexpr explicit expected_storage_base(unexpect_t, std::initializer_list il, - Args &&...args) + Args&&... args) : m_unexpect(il, std::forward(args)...), m_has_val(false) {} ~expected_storage_base() = default; @@ -694,17 +694,17 @@ struct expected_storage_base { constexpr expected_storage_base(in_place_t) : m_dummy(), m_has_val(true) {} template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr explicit expected_storage_base(unexpect_t, Args &&...args) + constexpr explicit expected_storage_base(unexpect_t, Args&&... args) : m_unexpect(std::forward(args)...), m_has_val(false) {} template &, Args &&...>::value> * = nullptr> + E, std::initializer_list&, Args&&...>::value>* = nullptr> constexpr explicit expected_storage_base(unexpect_t, std::initializer_list il, - Args &&...args) + Args&&... args) : m_unexpect(il, std::forward(args)...), m_has_val(false) {} ~expected_storage_base() { @@ -727,19 +727,19 @@ struct expected_operations_base : expected_storage_base { using expected_storage_base::expected_storage_base; template - void construct(Args &&...args) noexcept { + void construct(Args&&... args) noexcept { new (std::addressof(this->m_val)) T(std::forward(args)...); this->m_has_val = true; } template - void construct_with(Rhs &&rhs) noexcept { + void construct_with(Rhs&& rhs) noexcept { new (std::addressof(this->m_val)) T(std::forward(rhs).get()); this->m_has_val = true; } template - void construct_error(Args &&...args) noexcept { + void construct_error(Args&&... args) noexcept { new (std::addressof(this->m_unexpect)) unexpected(std::forward(args)...); this->m_has_val = false; @@ -754,9 +754,9 @@ struct expected_operations_base : expected_storage_base { // This overload handles the case where we can just copy-construct `T` // directly into place without throwing. template ::value> - * = nullptr> - void assign(const expected_operations_base &rhs) noexcept { + detail::enable_if_t::value>* = + nullptr> + void assign(const expected_operations_base& rhs) noexcept { if (!this->m_has_val && rhs.m_has_val) { geterr().~unexpected(); construct(rhs.get()); @@ -769,9 +769,9 @@ struct expected_operations_base : expected_storage_base { // `T`, then no-throw move it into place if the copy was successful. template ::value && - std::is_nothrow_move_constructible::value> - * = nullptr> - void assign(const expected_operations_base &rhs) noexcept { + std::is_nothrow_move_constructible::value>* = + nullptr> + void assign(const expected_operations_base& rhs) noexcept { if (!this->m_has_val && rhs.m_has_val) { T tmp = rhs.get(); geterr().~unexpected(); @@ -787,10 +787,10 @@ struct expected_operations_base : expected_storage_base { // then we move the old unexpected value back into place before rethrowing the // exception. template ::value && - !std::is_nothrow_move_constructible::value> - * = nullptr> - void assign(const expected_operations_base &rhs) { + detail::enable_if_t< + !std::is_nothrow_copy_constructible::value && + !std::is_nothrow_move_constructible::value>* = nullptr> + void assign(const expected_operations_base& rhs) { if (!this->m_has_val && rhs.m_has_val) { auto tmp = std::move(geterr()); geterr().~unexpected(); @@ -812,9 +812,9 @@ struct expected_operations_base : expected_storage_base { // These overloads do the same as above, but for rvalues template ::value> - * = nullptr> - void assign(expected_operations_base &&rhs) noexcept { + detail::enable_if_t::value>* = + nullptr> + void assign(expected_operations_base&& rhs) noexcept { if (!this->m_has_val && rhs.m_has_val) { geterr().~unexpected(); construct(std::move(rhs).get()); @@ -824,9 +824,9 @@ struct expected_operations_base : expected_storage_base { } template ::value> - * = nullptr> - void assign(expected_operations_base &&rhs) { + detail::enable_if_t< + !std::is_nothrow_move_constructible::value>* = nullptr> + void assign(expected_operations_base&& rhs) { if (!this->m_has_val && rhs.m_has_val) { auto tmp = std::move(geterr()); geterr().~unexpected(); @@ -848,7 +848,7 @@ struct expected_operations_base : expected_storage_base { #else // If exceptions are disabled then we can just copy-construct - void assign(const expected_operations_base &rhs) noexcept { + void assign(const expected_operations_base& rhs) noexcept { if (!this->m_has_val && rhs.m_has_val) { geterr().~unexpected(); construct(rhs.get()); @@ -857,7 +857,7 @@ struct expected_operations_base : expected_storage_base { } } - void assign(expected_operations_base &&rhs) noexcept { + void assign(expected_operations_base&& rhs) noexcept { if (!this->m_has_val && rhs.m_has_val) { geterr().~unexpected(); construct(std::move(rhs).get()); @@ -870,7 +870,7 @@ struct expected_operations_base : expected_storage_base { // The common part of move/copy assigning template - void assign_common(Rhs &&rhs) { + void assign_common(Rhs&& rhs) { if (this->m_has_val) { if (rhs.m_has_val) { get() = std::forward(rhs).get(); @@ -887,22 +887,22 @@ struct expected_operations_base : expected_storage_base { bool has_value() const { return this->m_has_val; } - TL_EXPECTED_11_CONSTEXPR T &get() & { return this->m_val; } - constexpr const T &get() const & { return this->m_val; } - TL_EXPECTED_11_CONSTEXPR T &&get() && { return std::move(this->m_val); } + TL_EXPECTED_11_CONSTEXPR T& get() & { return this->m_val; } + constexpr const T& get() const& { return this->m_val; } + TL_EXPECTED_11_CONSTEXPR T&& get() && { return std::move(this->m_val); } #ifndef TL_EXPECTED_NO_CONSTRR - constexpr const T &&get() const && { return std::move(this->m_val); } + constexpr const T&& get() const&& { return std::move(this->m_val); } #endif - TL_EXPECTED_11_CONSTEXPR unexpected &geterr() & { + TL_EXPECTED_11_CONSTEXPR unexpected& geterr() & { return this->m_unexpect; } - constexpr const unexpected &geterr() const & { return this->m_unexpect; } - TL_EXPECTED_11_CONSTEXPR unexpected &&geterr() && { + constexpr const unexpected& geterr() const& { return this->m_unexpect; } + TL_EXPECTED_11_CONSTEXPR unexpected&& geterr() && { return std::move(this->m_unexpect); } #ifndef TL_EXPECTED_NO_CONSTRR - constexpr const unexpected &&geterr() const && { + constexpr const unexpected&& geterr() const&& { return std::move(this->m_unexpect); } #endif @@ -924,19 +924,19 @@ struct expected_operations_base : expected_storage_base { // This function doesn't use its argument, but needs it so that code in // levels above this can work independently of whether T is void template - void construct_with(Rhs &&) noexcept { + void construct_with(Rhs&&) noexcept { this->m_has_val = true; } template - void construct_error(Args &&...args) noexcept { + void construct_error(Args&&... args) noexcept { new (std::addressof(this->m_unexpect)) unexpected(std::forward(args)...); this->m_has_val = false; } template - void assign(Rhs &&rhs) noexcept { + void assign(Rhs&& rhs) noexcept { if (!this->m_has_val) { if (rhs.m_has_val) { geterr().~unexpected(); @@ -953,15 +953,15 @@ struct expected_operations_base : expected_storage_base { bool has_value() const { return this->m_has_val; } - TL_EXPECTED_11_CONSTEXPR unexpected &geterr() & { + TL_EXPECTED_11_CONSTEXPR unexpected& geterr() & { return this->m_unexpect; } - constexpr const unexpected &geterr() const & { return this->m_unexpect; } - TL_EXPECTED_11_CONSTEXPR unexpected &&geterr() && { + constexpr const unexpected& geterr() const& { return this->m_unexpect; } + TL_EXPECTED_11_CONSTEXPR unexpected&& geterr() && { return std::move(this->m_unexpect); } #ifndef TL_EXPECTED_NO_CONSTRR - constexpr const unexpected &&geterr() const && { + constexpr const unexpected&& geterr() const&& { return std::move(this->m_unexpect); } #endif @@ -987,7 +987,7 @@ struct expected_copy_base : expected_operations_base { using expected_operations_base::expected_operations_base; expected_copy_base() = default; - expected_copy_base(const expected_copy_base &rhs) + expected_copy_base(const expected_copy_base& rhs) : expected_operations_base(no_init) { if (rhs.has_value()) { this->construct_with(rhs); @@ -996,9 +996,9 @@ struct expected_copy_base : expected_operations_base { } } - expected_copy_base(expected_copy_base &&rhs) = default; - expected_copy_base &operator=(const expected_copy_base &rhs) = default; - expected_copy_base &operator=(expected_copy_base &&rhs) = default; + expected_copy_base(expected_copy_base&& rhs) = default; + expected_copy_base& operator=(const expected_copy_base& rhs) = default; + expected_copy_base& operator=(expected_copy_base&& rhs) = default; }; // This class manages conditionally having a trivial move constructor @@ -1023,9 +1023,9 @@ struct expected_move_base : expected_copy_base { using expected_copy_base::expected_copy_base; expected_move_base() = default; - expected_move_base(const expected_move_base &rhs) = default; + expected_move_base(const expected_move_base& rhs) = default; - expected_move_base(expected_move_base &&rhs) noexcept( + expected_move_base(expected_move_base&& rhs) noexcept( std::is_nothrow_move_constructible::value) : expected_copy_base(no_init) { if (rhs.has_value()) { @@ -1034,8 +1034,8 @@ struct expected_move_base : expected_copy_base { this->construct_error(std::move(rhs.geterr())); } } - expected_move_base &operator=(const expected_move_base &rhs) = default; - expected_move_base &operator=(expected_move_base &&rhs) = default; + expected_move_base& operator=(const expected_move_base& rhs) = default; + expected_move_base& operator=(expected_move_base&& rhs) = default; }; // This class manages conditionally having a trivial copy assignment operator @@ -1058,14 +1058,14 @@ struct expected_copy_assign_base : expected_move_base { using expected_move_base::expected_move_base; expected_copy_assign_base() = default; - expected_copy_assign_base(const expected_copy_assign_base &rhs) = default; + expected_copy_assign_base(const expected_copy_assign_base& rhs) = default; - expected_copy_assign_base(expected_copy_assign_base &&rhs) = default; - expected_copy_assign_base &operator=(const expected_copy_assign_base &rhs) { + expected_copy_assign_base(expected_copy_assign_base&& rhs) = default; + expected_copy_assign_base& operator=(const expected_copy_assign_base& rhs) { this->assign(rhs); return *this; } - expected_copy_assign_base &operator=(expected_copy_assign_base &&rhs) = + expected_copy_assign_base& operator=(expected_copy_assign_base&& rhs) = default; }; @@ -1098,17 +1098,17 @@ struct expected_move_assign_base using expected_copy_assign_base::expected_copy_assign_base; expected_move_assign_base() = default; - expected_move_assign_base(const expected_move_assign_base &rhs) = default; + expected_move_assign_base(const expected_move_assign_base& rhs) = default; - expected_move_assign_base(expected_move_assign_base &&rhs) = default; + expected_move_assign_base(expected_move_assign_base&& rhs) = default; - expected_move_assign_base &operator=(const expected_move_assign_base &rhs) = + expected_move_assign_base& operator=(const expected_move_assign_base& rhs) = default; - expected_move_assign_base &operator=( - expected_move_assign_base - &&rhs) noexcept(std::is_nothrow_move_constructible::value && - std::is_nothrow_move_assignable::value) { + expected_move_assign_base& + operator=(expected_move_assign_base&& rhs) noexcept( + std::is_nothrow_move_constructible::value && + std::is_nothrow_move_assignable::value) { this->assign(std::move(rhs)); return *this; } @@ -1123,44 +1123,44 @@ template ::value)> struct expected_delete_ctor_base { expected_delete_ctor_base() = default; - expected_delete_ctor_base(const expected_delete_ctor_base &) = default; - expected_delete_ctor_base(expected_delete_ctor_base &&) noexcept = default; - expected_delete_ctor_base &operator=(const expected_delete_ctor_base &) = + expected_delete_ctor_base(const expected_delete_ctor_base&) = default; + expected_delete_ctor_base(expected_delete_ctor_base&&) noexcept = default; + expected_delete_ctor_base& operator=(const expected_delete_ctor_base&) = default; - expected_delete_ctor_base &operator=(expected_delete_ctor_base &&) noexcept = + expected_delete_ctor_base& operator=(expected_delete_ctor_base&&) noexcept = default; }; template struct expected_delete_ctor_base { expected_delete_ctor_base() = default; - expected_delete_ctor_base(const expected_delete_ctor_base &) = default; - expected_delete_ctor_base(expected_delete_ctor_base &&) noexcept = delete; - expected_delete_ctor_base &operator=(const expected_delete_ctor_base &) = + expected_delete_ctor_base(const expected_delete_ctor_base&) = default; + expected_delete_ctor_base(expected_delete_ctor_base&&) noexcept = delete; + expected_delete_ctor_base& operator=(const expected_delete_ctor_base&) = default; - expected_delete_ctor_base &operator=(expected_delete_ctor_base &&) noexcept = + expected_delete_ctor_base& operator=(expected_delete_ctor_base&&) noexcept = default; }; template struct expected_delete_ctor_base { expected_delete_ctor_base() = default; - expected_delete_ctor_base(const expected_delete_ctor_base &) = delete; - expected_delete_ctor_base(expected_delete_ctor_base &&) noexcept = default; - expected_delete_ctor_base &operator=(const expected_delete_ctor_base &) = + expected_delete_ctor_base(const expected_delete_ctor_base&) = delete; + expected_delete_ctor_base(expected_delete_ctor_base&&) noexcept = default; + expected_delete_ctor_base& operator=(const expected_delete_ctor_base&) = default; - expected_delete_ctor_base &operator=(expected_delete_ctor_base &&) noexcept = + expected_delete_ctor_base& operator=(expected_delete_ctor_base&&) noexcept = default; }; template struct expected_delete_ctor_base { expected_delete_ctor_base() = default; - expected_delete_ctor_base(const expected_delete_ctor_base &) = delete; - expected_delete_ctor_base(expected_delete_ctor_base &&) noexcept = delete; - expected_delete_ctor_base &operator=(const expected_delete_ctor_base &) = + expected_delete_ctor_base(const expected_delete_ctor_base&) = delete; + expected_delete_ctor_base(expected_delete_ctor_base&&) noexcept = delete; + expected_delete_ctor_base& operator=(const expected_delete_ctor_base&) = default; - expected_delete_ctor_base &operator=(expected_delete_ctor_base &&) noexcept = + expected_delete_ctor_base& operator=(expected_delete_ctor_base&&) noexcept = default; }; @@ -1178,49 +1178,45 @@ template ::value)> struct expected_delete_assign_base { expected_delete_assign_base() = default; - expected_delete_assign_base(const expected_delete_assign_base &) = default; - expected_delete_assign_base(expected_delete_assign_base &&) noexcept = - default; - expected_delete_assign_base &operator=(const expected_delete_assign_base &) = + expected_delete_assign_base(const expected_delete_assign_base&) = default; + expected_delete_assign_base(expected_delete_assign_base&&) noexcept = default; + expected_delete_assign_base& operator=(const expected_delete_assign_base&) = default; - expected_delete_assign_base &operator=( - expected_delete_assign_base &&) noexcept = default; + expected_delete_assign_base& operator=( + expected_delete_assign_base&&) noexcept = default; }; template struct expected_delete_assign_base { expected_delete_assign_base() = default; - expected_delete_assign_base(const expected_delete_assign_base &) = default; - expected_delete_assign_base(expected_delete_assign_base &&) noexcept = - default; - expected_delete_assign_base &operator=(const expected_delete_assign_base &) = + expected_delete_assign_base(const expected_delete_assign_base&) = default; + expected_delete_assign_base(expected_delete_assign_base&&) noexcept = default; + expected_delete_assign_base& operator=(const expected_delete_assign_base&) = default; - expected_delete_assign_base &operator=( - expected_delete_assign_base &&) noexcept = delete; + expected_delete_assign_base& operator=( + expected_delete_assign_base&&) noexcept = delete; }; template struct expected_delete_assign_base { expected_delete_assign_base() = default; - expected_delete_assign_base(const expected_delete_assign_base &) = default; - expected_delete_assign_base(expected_delete_assign_base &&) noexcept = - default; - expected_delete_assign_base &operator=(const expected_delete_assign_base &) = + expected_delete_assign_base(const expected_delete_assign_base&) = default; + expected_delete_assign_base(expected_delete_assign_base&&) noexcept = default; + expected_delete_assign_base& operator=(const expected_delete_assign_base&) = delete; - expected_delete_assign_base &operator=( - expected_delete_assign_base &&) noexcept = default; + expected_delete_assign_base& operator=( + expected_delete_assign_base&&) noexcept = default; }; template struct expected_delete_assign_base { expected_delete_assign_base() = default; - expected_delete_assign_base(const expected_delete_assign_base &) = default; - expected_delete_assign_base(expected_delete_assign_base &&) noexcept = - default; - expected_delete_assign_base &operator=(const expected_delete_assign_base &) = + expected_delete_assign_base(const expected_delete_assign_base&) = default; + expected_delete_assign_base(expected_delete_assign_base&&) noexcept = default; + expected_delete_assign_base& operator=(const expected_delete_assign_base&) = delete; - expected_delete_assign_base &operator=( - expected_delete_assign_base &&) noexcept = delete; + expected_delete_assign_base& operator=( + expected_delete_assign_base&&) noexcept = delete; }; // This is needed to be able to construct the expected_default_ctor_base which @@ -1238,13 +1234,13 @@ template struct expected_default_ctor_base { constexpr expected_default_ctor_base() noexcept = delete; constexpr expected_default_ctor_base( - expected_default_ctor_base const &) noexcept = default; - constexpr expected_default_ctor_base(expected_default_ctor_base &&) noexcept = + expected_default_ctor_base const&) noexcept = default; + constexpr expected_default_ctor_base(expected_default_ctor_base&&) noexcept = + default; + expected_default_ctor_base& operator=( + expected_default_ctor_base const&) noexcept = default; + expected_default_ctor_base& operator=(expected_default_ctor_base&&) noexcept = default; - expected_default_ctor_base &operator=( - expected_default_ctor_base const &) noexcept = default; - expected_default_ctor_base &operator=( - expected_default_ctor_base &&) noexcept = default; constexpr explicit expected_default_ctor_base(default_constructor_tag) {} }; @@ -1271,14 +1267,14 @@ class bad_expected_access : public std::exception { public: explicit bad_expected_access(E e) : m_val(std::move(e)) {} - virtual const char *what() const noexcept override { + virtual const char* what() const noexcept override { return "Bad expected access"; } - const E &error() const & { return m_val; } - E &error() & { return m_val; } - const E &&error() const && { return std::move(m_val); } - E &&error() && { return std::move(m_val); } + const E& error() const& { return m_val; } + E& error() & { return m_val; } + const E&& error() const&& { return std::move(m_val); } + E&& error() && { return std::move(m_val); } private: E m_val; @@ -1306,26 +1302,26 @@ class expected : private detail::expected_move_assign_base, "T must not be unexpected"); static_assert(!std::is_reference::value, "E must not be a reference"); - T *valptr() { return std::addressof(this->m_val); } - const T *valptr() const { return std::addressof(this->m_val); } - unexpected *errptr() { return std::addressof(this->m_unexpect); } - const unexpected *errptr() const { + T* valptr() { return std::addressof(this->m_val); } + const T* valptr() const { return std::addressof(this->m_val); } + unexpected* errptr() { return std::addressof(this->m_unexpect); } + const unexpected* errptr() const { return std::addressof(this->m_unexpect); } template ::value> * = nullptr> - TL_EXPECTED_11_CONSTEXPR U &val() { + detail::enable_if_t::value>* = nullptr> + TL_EXPECTED_11_CONSTEXPR U& val() { return this->m_val; } - TL_EXPECTED_11_CONSTEXPR unexpected &err() { return this->m_unexpect; } + TL_EXPECTED_11_CONSTEXPR unexpected& err() { return this->m_unexpect; } template ::value> * = nullptr> - constexpr const U &val() const { + detail::enable_if_t::value>* = nullptr> + constexpr const U& val() const { return this->m_val; } - constexpr const unexpected &err() const { return this->m_unexpect; } + constexpr const unexpected& err() const { return this->m_unexpect; } using impl_base = detail::expected_move_assign_base; using ctor_base = detail::expected_default_ctor_base; @@ -1338,46 +1334,46 @@ class expected : private detail::expected_move_assign_base, #if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \ !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55) template - TL_EXPECTED_11_CONSTEXPR auto and_then(F &&f) & { + TL_EXPECTED_11_CONSTEXPR auto and_then(F&& f) & { return and_then_impl(*this, std::forward(f)); } template - TL_EXPECTED_11_CONSTEXPR auto and_then(F &&f) && { + TL_EXPECTED_11_CONSTEXPR auto and_then(F&& f) && { return and_then_impl(std::move(*this), std::forward(f)); } template - constexpr auto and_then(F &&f) const & { + constexpr auto and_then(F&& f) const& { return and_then_impl(*this, std::forward(f)); } #ifndef TL_EXPECTED_NO_CONSTRR template - constexpr auto and_then(F &&f) const && { + constexpr auto and_then(F&& f) const&& { return and_then_impl(std::move(*this), std::forward(f)); } #endif #else template - TL_EXPECTED_11_CONSTEXPR auto and_then(F &&f) & -> decltype(and_then_impl( - std::declval(), std::forward(f))) { + TL_EXPECTED_11_CONSTEXPR auto and_then(F&& f) & -> decltype(and_then_impl( + std::declval(), std::forward(f))) { return and_then_impl(*this, std::forward(f)); } template - TL_EXPECTED_11_CONSTEXPR auto and_then(F &&f) && -> decltype(and_then_impl( - std::declval(), std::forward(f))) { + TL_EXPECTED_11_CONSTEXPR auto and_then(F&& f) && -> decltype(and_then_impl( + std::declval(), std::forward(f))) { return and_then_impl(std::move(*this), std::forward(f)); } template - constexpr auto and_then(F &&f) const & -> decltype(and_then_impl( - std::declval(), std::forward(f))) { + constexpr auto and_then(F&& f) const& -> decltype(and_then_impl( + std::declval(), std::forward(f))) { return and_then_impl(*this, std::forward(f)); } #ifndef TL_EXPECTED_NO_CONSTRR template - constexpr auto and_then(F &&f) const && -> decltype(and_then_impl( - std::declval(), std::forward(f))) { + constexpr auto and_then(F&& f) const&& -> decltype(and_then_impl( + std::declval(), std::forward(f))) { return and_then_impl(std::move(*this), std::forward(f)); } #endif @@ -1386,46 +1382,45 @@ class expected : private detail::expected_move_assign_base, #if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \ !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55) template - TL_EXPECTED_11_CONSTEXPR auto map(F &&f) & { + TL_EXPECTED_11_CONSTEXPR auto map(F&& f) & { return expected_map_impl(*this, std::forward(f)); } template - TL_EXPECTED_11_CONSTEXPR auto map(F &&f) && { + TL_EXPECTED_11_CONSTEXPR auto map(F&& f) && { return expected_map_impl(std::move(*this), std::forward(f)); } template - constexpr auto map(F &&f) const & { + constexpr auto map(F&& f) const& { return expected_map_impl(*this, std::forward(f)); } template - constexpr auto map(F &&f) const && { + constexpr auto map(F&& f) const&& { return expected_map_impl(std::move(*this), std::forward(f)); } #else template TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl( - std::declval(), std::declval())) - map(F &&f) & { + std::declval(), std::declval())) map(F&& f) & { return expected_map_impl(*this, std::forward(f)); } template TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(std::declval(), - std::declval())) - map(F &&f) && { + std::declval())) + map(F&& f) && { return expected_map_impl(std::move(*this), std::forward(f)); } template - constexpr decltype(expected_map_impl(std::declval(), - std::declval())) - map(F &&f) const & { + constexpr decltype(expected_map_impl(std::declval(), + std::declval())) + map(F&& f) const& { return expected_map_impl(*this, std::forward(f)); } #ifndef TL_EXPECTED_NO_CONSTRR template - constexpr decltype(expected_map_impl(std::declval(), - std::declval())) - map(F &&f) const && { + constexpr decltype(expected_map_impl(std::declval(), + std::declval())) map(F&& f) + const&& { return expected_map_impl(std::move(*this), std::forward(f)); } #endif @@ -1434,46 +1429,45 @@ class expected : private detail::expected_move_assign_base, #if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \ !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55) template - TL_EXPECTED_11_CONSTEXPR auto transform(F &&f) & { + TL_EXPECTED_11_CONSTEXPR auto transform(F&& f) & { return expected_map_impl(*this, std::forward(f)); } template - TL_EXPECTED_11_CONSTEXPR auto transform(F &&f) && { + TL_EXPECTED_11_CONSTEXPR auto transform(F&& f) && { return expected_map_impl(std::move(*this), std::forward(f)); } template - constexpr auto transform(F &&f) const & { + constexpr auto transform(F&& f) const& { return expected_map_impl(*this, std::forward(f)); } template - constexpr auto transform(F &&f) const && { + constexpr auto transform(F&& f) const&& { return expected_map_impl(std::move(*this), std::forward(f)); } #else template TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl( - std::declval(), std::declval())) - transform(F &&f) & { + std::declval(), std::declval())) transform(F&& f) & { return expected_map_impl(*this, std::forward(f)); } template TL_EXPECTED_11_CONSTEXPR decltype(expected_map_impl(std::declval(), - std::declval())) - transform(F &&f) && { + std::declval())) + transform(F&& f) && { return expected_map_impl(std::move(*this), std::forward(f)); } template - constexpr decltype(expected_map_impl(std::declval(), - std::declval())) - transform(F &&f) const & { + constexpr decltype(expected_map_impl(std::declval(), + std::declval())) + transform(F&& f) const& { return expected_map_impl(*this, std::forward(f)); } #ifndef TL_EXPECTED_NO_CONSTRR template - constexpr decltype(expected_map_impl(std::declval(), - std::declval())) - transform(F &&f) const && { + constexpr decltype(expected_map_impl(std::declval(), + std::declval())) transform(F&& f) + const&& { return expected_map_impl(std::move(*this), std::forward(f)); } #endif @@ -1482,46 +1476,45 @@ class expected : private detail::expected_move_assign_base, #if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \ !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55) template - TL_EXPECTED_11_CONSTEXPR auto map_error(F &&f) & { + TL_EXPECTED_11_CONSTEXPR auto map_error(F&& f) & { return map_error_impl(*this, std::forward(f)); } template - TL_EXPECTED_11_CONSTEXPR auto map_error(F &&f) && { + TL_EXPECTED_11_CONSTEXPR auto map_error(F&& f) && { return map_error_impl(std::move(*this), std::forward(f)); } template - constexpr auto map_error(F &&f) const & { + constexpr auto map_error(F&& f) const& { return map_error_impl(*this, std::forward(f)); } template - constexpr auto map_error(F &&f) const && { + constexpr auto map_error(F&& f) const&& { return map_error_impl(std::move(*this), std::forward(f)); } #else template - TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval(), - std::declval())) - map_error(F &&f) & { + TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl( + std::declval(), std::declval())) map_error(F&& f) & { return map_error_impl(*this, std::forward(f)); } template - TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval(), - std::declval())) - map_error(F &&f) && { + TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval(), + std::declval())) + map_error(F&& f) && { return map_error_impl(std::move(*this), std::forward(f)); } template - constexpr decltype(map_error_impl(std::declval(), - std::declval())) - map_error(F &&f) const & { + constexpr decltype(map_error_impl(std::declval(), + std::declval())) + map_error(F&& f) const& { return map_error_impl(*this, std::forward(f)); } #ifndef TL_EXPECTED_NO_CONSTRR template - constexpr decltype(map_error_impl(std::declval(), - std::declval())) - map_error(F &&f) const && { + constexpr decltype(map_error_impl(std::declval(), + std::declval())) map_error(F&& f) + const&& { return map_error_impl(std::move(*this), std::forward(f)); } #endif @@ -1529,149 +1522,147 @@ class expected : private detail::expected_move_assign_base, #if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \ !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55) template - TL_EXPECTED_11_CONSTEXPR auto transform_error(F &&f) & { + TL_EXPECTED_11_CONSTEXPR auto transform_error(F&& f) & { return map_error_impl(*this, std::forward(f)); } template - TL_EXPECTED_11_CONSTEXPR auto transform_error(F &&f) && { + TL_EXPECTED_11_CONSTEXPR auto transform_error(F&& f) && { return map_error_impl(std::move(*this), std::forward(f)); } template - constexpr auto transform_error(F &&f) const & { + constexpr auto transform_error(F&& f) const& { return map_error_impl(*this, std::forward(f)); } template - constexpr auto transform_error(F &&f) const && { + constexpr auto transform_error(F&& f) const&& { return map_error_impl(std::move(*this), std::forward(f)); } #else template - TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval(), - std::declval())) - transform_error(F &&f) & { + TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl( + std::declval(), + std::declval())) transform_error(F&& f) & { return map_error_impl(*this, std::forward(f)); } template - TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval(), - std::declval())) - transform_error(F &&f) && { + TL_EXPECTED_11_CONSTEXPR decltype(map_error_impl(std::declval(), + std::declval())) + transform_error(F&& f) && { return map_error_impl(std::move(*this), std::forward(f)); } template - constexpr decltype(map_error_impl(std::declval(), - std::declval())) - transform_error(F &&f) const & { + constexpr decltype(map_error_impl(std::declval(), + std::declval())) + transform_error(F&& f) const& { return map_error_impl(*this, std::forward(f)); } #ifndef TL_EXPECTED_NO_CONSTRR template - constexpr decltype(map_error_impl(std::declval(), - std::declval())) - transform_error(F &&f) const && { + constexpr decltype(map_error_impl(std::declval(), + std::declval())) transform_error(F&& f) + const&& { return map_error_impl(std::move(*this), std::forward(f)); } #endif #endif template - expected TL_EXPECTED_11_CONSTEXPR or_else(F &&f) & { + expected TL_EXPECTED_11_CONSTEXPR or_else(F&& f) & { return or_else_impl(*this, std::forward(f)); } template - expected TL_EXPECTED_11_CONSTEXPR or_else(F &&f) && { + expected TL_EXPECTED_11_CONSTEXPR or_else(F&& f) && { return or_else_impl(std::move(*this), std::forward(f)); } template - expected constexpr or_else(F &&f) const & { + expected constexpr or_else(F&& f) const& { return or_else_impl(*this, std::forward(f)); } #ifndef TL_EXPECTED_NO_CONSTRR template - expected constexpr or_else(F &&f) const && { + expected constexpr or_else(F&& f) const&& { return or_else_impl(std::move(*this), std::forward(f)); } #endif constexpr expected() = default; - constexpr expected(const expected &rhs) = default; - constexpr expected(expected &&rhs) = default; - expected &operator=(const expected &rhs) = default; - expected &operator=(expected &&rhs) = default; + constexpr expected(const expected& rhs) = default; + constexpr expected(expected&& rhs) = default; + expected& operator=(const expected& rhs) = default; + expected& operator=(expected&& rhs) = default; template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr expected(in_place_t, Args &&...args) + constexpr expected(in_place_t, Args&&... args) : impl_base(in_place, std::forward(args)...), ctor_base(detail::default_constructor_tag{}) {} template &, Args &&...>::value> * = nullptr> - constexpr expected(in_place_t, std::initializer_list il, Args &&...args) + T, std::initializer_list&, Args&&...>::value>* = nullptr> + constexpr expected(in_place_t, std::initializer_list il, Args&&... args) : impl_base(in_place, il, std::forward(args)...), ctor_base(detail::default_constructor_tag{}) {} - template ::value> * = - nullptr, - detail::enable_if_t::value> * = - nullptr> - explicit constexpr expected(const unexpected &e) + template < + class G = E, + detail::enable_if_t::value>* = nullptr, + detail::enable_if_t::value>* = nullptr> + explicit constexpr expected(const unexpected& e) : impl_base(unexpect, e.value()), ctor_base(detail::default_constructor_tag{}) {} template < class G = E, - detail::enable_if_t::value> * = - nullptr, - detail::enable_if_t::value> * = nullptr> - constexpr expected(unexpected const &e) + detail::enable_if_t::value>* = nullptr, + detail::enable_if_t::value>* = nullptr> + constexpr expected(unexpected const& e) : impl_base(unexpect, e.value()), ctor_base(detail::default_constructor_tag{}) {} template < class G = E, - detail::enable_if_t::value> * = nullptr, - detail::enable_if_t::value> * = nullptr> - explicit constexpr expected(unexpected &&e) noexcept( - std::is_nothrow_constructible::value) + detail::enable_if_t::value>* = nullptr, + detail::enable_if_t::value>* = nullptr> + explicit constexpr expected(unexpected&& e) noexcept( + std::is_nothrow_constructible::value) : impl_base(unexpect, std::move(e.value())), ctor_base(detail::default_constructor_tag{}) {} template < class G = E, - detail::enable_if_t::value> * = nullptr, - detail::enable_if_t::value> * = nullptr> - constexpr expected(unexpected &&e) noexcept( - std::is_nothrow_constructible::value) + detail::enable_if_t::value>* = nullptr, + detail::enable_if_t::value>* = nullptr> + constexpr expected(unexpected&& e) noexcept( + std::is_nothrow_constructible::value) : impl_base(unexpect, std::move(e.value())), ctor_base(detail::default_constructor_tag{}) {} template ::value> * = + detail::enable_if_t::value>* = nullptr> - constexpr explicit expected(unexpect_t, Args &&...args) + constexpr explicit expected(unexpect_t, Args&&... args) : impl_base(unexpect, std::forward(args)...), ctor_base(detail::default_constructor_tag{}) {} template &, Args &&...>::value> * = nullptr> + E, std::initializer_list&, Args&&...>::value>* = nullptr> constexpr explicit expected(unexpect_t, std::initializer_list il, - Args &&...args) + Args&&... args) : impl_base(unexpect, il, std::forward(args)...), ctor_base(detail::default_constructor_tag{}) {} template ::value && - std::is_convertible::value)> * = + detail::enable_if_t::value && + std::is_convertible::value)>* = nullptr, - detail::expected_enable_from_other - * = nullptr> - explicit TL_EXPECTED_11_CONSTEXPR expected(const expected &rhs) + detail::expected_enable_from_other* = nullptr> + explicit TL_EXPECTED_11_CONSTEXPR expected(const expected& rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { this->construct(*rhs); @@ -1680,13 +1671,13 @@ class expected : private detail::expected_move_assign_base, } } - template ::value && - std::is_convertible::value)> * = - nullptr, - detail::expected_enable_from_other - * = nullptr> - TL_EXPECTED_11_CONSTEXPR expected(const expected &rhs) + template < + class U, class G, + detail::enable_if_t<(std::is_convertible::value && + std::is_convertible::value)>* = nullptr, + detail::expected_enable_from_other* = + nullptr> + TL_EXPECTED_11_CONSTEXPR expected(const expected& rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { this->construct(*rhs); @@ -1697,10 +1688,10 @@ class expected : private detail::expected_move_assign_base, template < class U, class G, - detail::enable_if_t::value && - std::is_convertible::value)> * = nullptr, - detail::expected_enable_from_other * = nullptr> - explicit TL_EXPECTED_11_CONSTEXPR expected(expected &&rhs) + detail::enable_if_t::value && + std::is_convertible::value)>* = nullptr, + detail::expected_enable_from_other* = nullptr> + explicit TL_EXPECTED_11_CONSTEXPR expected(expected&& rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { this->construct(std::move(*rhs)); @@ -1711,10 +1702,10 @@ class expected : private detail::expected_move_assign_base, template < class U, class G, - detail::enable_if_t<(std::is_convertible::value && - std::is_convertible::value)> * = nullptr, - detail::expected_enable_from_other * = nullptr> - TL_EXPECTED_11_CONSTEXPR expected(expected &&rhs) + detail::enable_if_t<(std::is_convertible::value && + std::is_convertible::value)>* = nullptr, + detail::expected_enable_from_other* = nullptr> + TL_EXPECTED_11_CONSTEXPR expected(expected&& rhs) : ctor_base(detail::default_constructor_tag{}) { if (rhs.has_value()) { this->construct(std::move(*rhs)); @@ -1723,33 +1714,31 @@ class expected : private detail::expected_move_assign_base, } } - template < - class U = T, - detail::enable_if_t::value> * = nullptr, - detail::expected_enable_forward_value * = nullptr> - explicit TL_EXPECTED_MSVC2015_CONSTEXPR expected(U &&v) + template ::value>* = nullptr, + detail::expected_enable_forward_value* = nullptr> + explicit TL_EXPECTED_MSVC2015_CONSTEXPR expected(U&& v) : expected(in_place, std::forward(v)) {} - template < - class U = T, - detail::enable_if_t::value> * = nullptr, - detail::expected_enable_forward_value * = nullptr> - TL_EXPECTED_MSVC2015_CONSTEXPR expected(U &&v) + template ::value>* = nullptr, + detail::expected_enable_forward_value* = nullptr> + TL_EXPECTED_MSVC2015_CONSTEXPR expected(U&& v) : expected(in_place, std::forward(v)) {} template < class U = T, class G = T, - detail::enable_if_t::value> * = + detail::enable_if_t::value>* = nullptr, - detail::enable_if_t::value> * = nullptr, + detail::enable_if_t::value>* = nullptr, detail::enable_if_t< (!std::is_same, detail::decay_t>::value && !detail::conjunction, std::is_same>>::value && std::is_constructible::value && - std::is_assignable::value && - std::is_nothrow_move_constructible::value)> * = nullptr> - expected &operator=(U &&v) { + std::is_assignable::value && + std::is_nothrow_move_constructible::value)>* = nullptr> + expected& operator=(U&& v) { if (has_value()) { val() = std::forward(v); } else { @@ -1763,17 +1752,17 @@ class expected : private detail::expected_move_assign_base, template < class U = T, class G = T, - detail::enable_if_t::value> * = + detail::enable_if_t::value>* = nullptr, - detail::enable_if_t::value> * = nullptr, + detail::enable_if_t::value>* = nullptr, detail::enable_if_t< (!std::is_same, detail::decay_t>::value && !detail::conjunction, std::is_same>>::value && std::is_constructible::value && - std::is_assignable::value && - std::is_nothrow_move_constructible::value)> * = nullptr> - expected &operator=(U &&v) { + std::is_assignable::value && + std::is_nothrow_move_constructible::value)>* = nullptr> + expected& operator=(U&& v) { if (has_value()) { val() = std::forward(v); } else { @@ -1799,8 +1788,8 @@ class expected : private detail::expected_move_assign_base, template ::value && - std::is_assignable::value> * = nullptr> - expected &operator=(const unexpected &rhs) { + std::is_assignable::value>* = nullptr> + expected& operator=(const unexpected& rhs) { if (!has_value()) { err() = rhs; } else { @@ -1814,8 +1803,8 @@ class expected : private detail::expected_move_assign_base, template ::value && - std::is_move_assignable::value> * = nullptr> - expected &operator=(unexpected &&rhs) noexcept { + std::is_move_assignable::value>* = nullptr> + expected& operator=(unexpected&& rhs) noexcept { if (!has_value()) { err() = std::move(rhs); } else { @@ -1828,8 +1817,8 @@ class expected : private detail::expected_move_assign_base, } template ::value> * = nullptr> - void emplace(Args &&...args) { + T, Args&&...>::value>* = nullptr> + void emplace(Args&&... args) { if (has_value()) { val().~T(); } else { @@ -1840,8 +1829,8 @@ class expected : private detail::expected_move_assign_base, } template ::value> * = nullptr> - void emplace(Args &&...args) { + T, Args&&...>::value>* = nullptr> + void emplace(Args&&... args) { if (has_value()) { val().~T(); ::new (valptr()) T(std::forward(args)...); @@ -1866,8 +1855,8 @@ class expected : private detail::expected_move_assign_base, template &, Args &&...>::value> * = nullptr> - void emplace(std::initializer_list il, Args &&...args) { + T, std::initializer_list&, Args&&...>::value>* = nullptr> + void emplace(std::initializer_list il, Args&&... args) { if (has_value()) { T t(il, std::forward(args)...); val() = std::move(t); @@ -1880,8 +1869,8 @@ class expected : private detail::expected_move_assign_base, template &, Args &&...>::value> * = nullptr> - void emplace(std::initializer_list il, Args &&...args) { + T, std::initializer_list&, Args&&...>::value>* = nullptr> + void emplace(std::initializer_list il, Args&&... args) { if (has_value()) { T t(il, std::forward(args)...); val() = std::move(t); @@ -1912,30 +1901,30 @@ class expected : private detail::expected_move_assign_base, using e_is_nothrow_move_constructible = std::true_type; using move_constructing_e_can_throw = std::false_type; - void swap_where_both_have_value(expected & /*rhs*/, t_is_void) noexcept { + void swap_where_both_have_value(expected& /*rhs*/, t_is_void) noexcept { // swapping void is a no-op } - void swap_where_both_have_value(expected &rhs, t_is_not_void) { + void swap_where_both_have_value(expected& rhs, t_is_not_void) { using std::swap; swap(val(), rhs.val()); } - void swap_where_only_one_has_value(expected &rhs, t_is_void) noexcept( + void swap_where_only_one_has_value(expected& rhs, t_is_void) noexcept( std::is_nothrow_move_constructible::value) { ::new (errptr()) unexpected_type(std::move(rhs.err())); rhs.err().~unexpected_type(); std::swap(this->m_has_val, rhs.m_has_val); } - void swap_where_only_one_has_value(expected &rhs, t_is_not_void) { + void swap_where_only_one_has_value(expected& rhs, t_is_not_void) { swap_where_only_one_has_value_and_t_is_not_void( rhs, typename std::is_nothrow_move_constructible::type{}, typename std::is_nothrow_move_constructible::type{}); } void swap_where_only_one_has_value_and_t_is_not_void( - expected &rhs, t_is_nothrow_move_constructible, + expected& rhs, t_is_nothrow_move_constructible, e_is_nothrow_move_constructible) noexcept { auto temp = std::move(val()); val().~T(); @@ -1946,7 +1935,7 @@ class expected : private detail::expected_move_assign_base, } void swap_where_only_one_has_value_and_t_is_not_void( - expected &rhs, t_is_nothrow_move_constructible, + expected& rhs, t_is_nothrow_move_constructible, move_constructing_e_can_throw) { auto temp = std::move(val()); val().~T(); @@ -1969,7 +1958,7 @@ class expected : private detail::expected_move_assign_base, } void swap_where_only_one_has_value_and_t_is_not_void( - expected &rhs, move_constructing_t_can_throw, + expected& rhs, move_constructing_t_can_throw, e_is_nothrow_move_constructible) { auto temp = std::move(rhs.err()); rhs.err().~unexpected_type(); @@ -1997,7 +1986,7 @@ class expected : private detail::expected_move_assign_base, detail::is_swappable::value && (std::is_nothrow_move_constructible::value || std::is_nothrow_move_constructible::value)> - swap(expected &rhs) noexcept(std::is_nothrow_move_constructible::value && + swap(expected& rhs) noexcept(std::is_nothrow_move_constructible::value && detail::is_nothrow_swappable::value && std::is_nothrow_move_constructible::value && detail::is_nothrow_swappable::value) { @@ -2013,36 +2002,36 @@ class expected : private detail::expected_move_assign_base, } } - constexpr const T *operator->() const { + constexpr const T* operator->() const { TL_ASSERT(has_value()); return valptr(); } - TL_EXPECTED_11_CONSTEXPR T *operator->() { + TL_EXPECTED_11_CONSTEXPR T* operator->() { TL_ASSERT(has_value()); return valptr(); } template ::value> * = nullptr> - constexpr const U &operator*() const & { + detail::enable_if_t::value>* = nullptr> + constexpr const U& operator*() const& { TL_ASSERT(has_value()); return val(); } template ::value> * = nullptr> - TL_EXPECTED_11_CONSTEXPR U &operator*() & { + detail::enable_if_t::value>* = nullptr> + TL_EXPECTED_11_CONSTEXPR U& operator*() & { TL_ASSERT(has_value()); return val(); } template ::value> * = nullptr> - constexpr const U &&operator*() const && { + detail::enable_if_t::value>* = nullptr> + constexpr const U&& operator*() const&& { TL_ASSERT(has_value()); return std::move(val()); } template ::value> * = nullptr> - TL_EXPECTED_11_CONSTEXPR U &&operator*() && { + detail::enable_if_t::value>* = nullptr> + TL_EXPECTED_11_CONSTEXPR U&& operator*() && { TL_ASSERT(has_value()); return std::move(val()); } @@ -2051,62 +2040,62 @@ class expected : private detail::expected_move_assign_base, constexpr explicit operator bool() const noexcept { return this->m_has_val; } template ::value> * = nullptr> - TL_EXPECTED_11_CONSTEXPR const U &value() const & { + detail::enable_if_t::value>* = nullptr> + TL_EXPECTED_11_CONSTEXPR const U& value() const& { if (!has_value()) detail::throw_exception(bad_expected_access(err().value())); return val(); } template ::value> * = nullptr> - TL_EXPECTED_11_CONSTEXPR U &value() & { + detail::enable_if_t::value>* = nullptr> + TL_EXPECTED_11_CONSTEXPR U& value() & { if (!has_value()) detail::throw_exception(bad_expected_access(err().value())); return val(); } template ::value> * = nullptr> - TL_EXPECTED_11_CONSTEXPR const U &&value() const && { + detail::enable_if_t::value>* = nullptr> + TL_EXPECTED_11_CONSTEXPR const U&& value() const&& { if (!has_value()) detail::throw_exception(bad_expected_access(std::move(err()).value())); return std::move(val()); } template ::value> * = nullptr> - TL_EXPECTED_11_CONSTEXPR U &&value() && { + detail::enable_if_t::value>* = nullptr> + TL_EXPECTED_11_CONSTEXPR U&& value() && { if (!has_value()) detail::throw_exception(bad_expected_access(std::move(err()).value())); return std::move(val()); } - constexpr const E &error() const & { + constexpr const E& error() const& { TL_ASSERT(!has_value()); return err().value(); } - TL_EXPECTED_11_CONSTEXPR E &error() & { + TL_EXPECTED_11_CONSTEXPR E& error() & { TL_ASSERT(!has_value()); return err().value(); } - constexpr const E &&error() const && { + constexpr const E&& error() const&& { TL_ASSERT(!has_value()); return std::move(err().value()); } - TL_EXPECTED_11_CONSTEXPR E &&error() && { + TL_EXPECTED_11_CONSTEXPR E&& error() && { TL_ASSERT(!has_value()); return std::move(err().value()); } template - constexpr T value_or(U &&v) const & { + constexpr T value_or(U&& v) const& { static_assert(std::is_copy_constructible::value && - std::is_convertible::value, + std::is_convertible::value, "T must be copy-constructible and convertible to from U&&"); return bool(*this) ? **this : static_cast(std::forward(v)); } template - TL_EXPECTED_11_CONSTEXPR T value_or(U &&v) && { + TL_EXPECTED_11_CONSTEXPR T value_or(U&& v) && { static_assert(std::is_move_constructible::value && - std::is_convertible::value, + std::is_convertible::value, "T must be move-constructible and convertible to from U&&"); return bool(*this) ? std::move(**this) : static_cast(std::forward(v)); } @@ -2122,10 +2111,10 @@ using ret_t = expected>; #ifdef TL_EXPECTED_CXX14 template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), *std::declval()))> -constexpr auto and_then_impl(Exp &&exp, F &&f) { +constexpr auto and_then_impl(Exp&& exp, F&& f) { static_assert(detail::is_expected::value, "F must return an expected"); return exp.has_value() @@ -2134,9 +2123,9 @@ constexpr auto and_then_impl(Exp &&exp, F &&f) { } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval()))> -constexpr auto and_then_impl(Exp &&exp, F &&f) { +constexpr auto and_then_impl(Exp&& exp, F&& f) { static_assert(detail::is_expected::value, "F must return an expected"); return exp.has_value() ? detail::invoke(std::forward(f)) @@ -2148,8 +2137,8 @@ struct TC; template (), *std::declval())), - detail::enable_if_t>::value> * = nullptr> -auto and_then_impl(Exp &&exp, F &&f) -> Ret { + detail::enable_if_t>::value>* = nullptr> +auto and_then_impl(Exp&& exp, F&& f) -> Ret { static_assert(detail::is_expected::value, "F must return an expected"); return exp.has_value() @@ -2159,8 +2148,8 @@ auto and_then_impl(Exp &&exp, F &&f) -> Ret { template ())), - detail::enable_if_t>::value> * = nullptr> -constexpr auto and_then_impl(Exp &&exp, F &&f) -> Ret { + detail::enable_if_t>::value>* = nullptr> +constexpr auto and_then_impl(Exp&& exp, F&& f) -> Ret { static_assert(detail::is_expected::value, "F must return an expected"); return exp.has_value() ? detail::invoke(std::forward(f)) @@ -2170,11 +2159,11 @@ constexpr auto and_then_impl(Exp &&exp, F &&f) -> Ret { #ifdef TL_EXPECTED_CXX14 template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), *std::declval())), - detail::enable_if_t::value> * = nullptr> -constexpr auto expected_map_impl(Exp &&exp, F &&f) { + detail::enable_if_t::value>* = nullptr> +constexpr auto expected_map_impl(Exp&& exp, F&& f) { using result = ret_t>; return exp.has_value() ? result(detail::invoke(std::forward(f), *std::forward(exp))) @@ -2182,11 +2171,11 @@ constexpr auto expected_map_impl(Exp &&exp, F &&f) { } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), *std::declval())), - detail::enable_if_t::value> * = nullptr> -auto expected_map_impl(Exp &&exp, F &&f) { + detail::enable_if_t::value>* = nullptr> +auto expected_map_impl(Exp&& exp, F&& f) { using result = expected>; if (exp.has_value()) { detail::invoke(std::forward(f), *std::forward(exp)); @@ -2197,20 +2186,20 @@ auto expected_map_impl(Exp &&exp, F &&f) { } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval())), - detail::enable_if_t::value> * = nullptr> -constexpr auto expected_map_impl(Exp &&exp, F &&f) { + detail::enable_if_t::value>* = nullptr> +constexpr auto expected_map_impl(Exp&& exp, F&& f) { using result = ret_t>; return exp.has_value() ? result(detail::invoke(std::forward(f))) : result(unexpect, std::forward(exp).error()); } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval())), - detail::enable_if_t::value> * = nullptr> -auto expected_map_impl(Exp &&exp, F &&f) { + detail::enable_if_t::value>* = nullptr> +auto expected_map_impl(Exp&& exp, F&& f) { using result = expected>; if (exp.has_value()) { detail::invoke(std::forward(f)); @@ -2221,12 +2210,12 @@ auto expected_map_impl(Exp &&exp, F &&f) { } #else template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), *std::declval())), - detail::enable_if_t::value> * = nullptr> + detail::enable_if_t::value>* = nullptr> -constexpr auto expected_map_impl(Exp &&exp, F &&f) +constexpr auto expected_map_impl(Exp&& exp, F&& f) -> ret_t> { using result = ret_t>; @@ -2236,12 +2225,12 @@ constexpr auto expected_map_impl(Exp &&exp, F &&f) } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), *std::declval())), - detail::enable_if_t::value> * = nullptr> + detail::enable_if_t::value>* = nullptr> -auto expected_map_impl(Exp &&exp, F &&f) -> expected> { +auto expected_map_impl(Exp&& exp, F&& f) -> expected> { if (exp.has_value()) { detail::invoke(std::forward(f), *std::forward(exp)); return {}; @@ -2251,11 +2240,11 @@ auto expected_map_impl(Exp &&exp, F &&f) -> expected> { } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval())), - detail::enable_if_t::value> * = nullptr> + detail::enable_if_t::value>* = nullptr> -constexpr auto expected_map_impl(Exp &&exp, F &&f) +constexpr auto expected_map_impl(Exp&& exp, F&& f) -> ret_t> { using result = ret_t>; @@ -2264,11 +2253,11 @@ constexpr auto expected_map_impl(Exp &&exp, F &&f) } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval())), - detail::enable_if_t::value> * = nullptr> + detail::enable_if_t::value>* = nullptr> -auto expected_map_impl(Exp &&exp, F &&f) -> expected> { +auto expected_map_impl(Exp&& exp, F&& f) -> expected> { if (exp.has_value()) { detail::invoke(std::forward(f)); return {}; @@ -2281,11 +2270,11 @@ auto expected_map_impl(Exp &&exp, F &&f) -> expected> { #if defined(TL_EXPECTED_CXX14) && !defined(TL_EXPECTED_GCC49) && \ !defined(TL_EXPECTED_GCC54) && !defined(TL_EXPECTED_GCC55) template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -constexpr auto map_error_impl(Exp &&exp, F &&f) { + detail::enable_if_t::value>* = nullptr> +constexpr auto map_error_impl(Exp&& exp, F&& f) { using result = expected, detail::decay_t>; return exp.has_value() ? result(*std::forward(exp)) @@ -2293,11 +2282,11 @@ constexpr auto map_error_impl(Exp &&exp, F &&f) { std::forward(exp).error())); } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -auto map_error_impl(Exp &&exp, F &&f) { + detail::enable_if_t::value>* = nullptr> +auto map_error_impl(Exp&& exp, F&& f) { using result = expected, monostate>; if (exp.has_value()) { return result(*std::forward(exp)); @@ -2307,11 +2296,11 @@ auto map_error_impl(Exp &&exp, F &&f) { return result(unexpect, monostate{}); } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -constexpr auto map_error_impl(Exp &&exp, F &&f) { + detail::enable_if_t::value>* = nullptr> +constexpr auto map_error_impl(Exp&& exp, F&& f) { using result = expected, detail::decay_t>; return exp.has_value() ? result() @@ -2319,11 +2308,11 @@ constexpr auto map_error_impl(Exp &&exp, F &&f) { std::forward(exp).error())); } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -auto map_error_impl(Exp &&exp, F &&f) { + detail::enable_if_t::value>* = nullptr> +auto map_error_impl(Exp&& exp, F&& f) { using result = expected, monostate>; if (exp.has_value()) { return result(); @@ -2334,11 +2323,11 @@ auto map_error_impl(Exp &&exp, F &&f) { } #else template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -constexpr auto map_error_impl(Exp &&exp, F &&f) + detail::enable_if_t::value>* = nullptr> +constexpr auto map_error_impl(Exp&& exp, F&& f) -> expected, detail::decay_t> { using result = expected, detail::decay_t>; @@ -2349,11 +2338,11 @@ constexpr auto map_error_impl(Exp &&exp, F &&f) } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -auto map_error_impl(Exp &&exp, F &&f) -> expected, monostate> { + detail::enable_if_t::value>* = nullptr> +auto map_error_impl(Exp&& exp, F&& f) -> expected, monostate> { using result = expected, monostate>; if (exp.has_value()) { return result(*std::forward(exp)); @@ -2364,11 +2353,11 @@ auto map_error_impl(Exp &&exp, F &&f) -> expected, monostate> { } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -constexpr auto map_error_impl(Exp &&exp, F &&f) + detail::enable_if_t::value>* = nullptr> +constexpr auto map_error_impl(Exp&& exp, F&& f) -> expected, detail::decay_t> { using result = expected, detail::decay_t>; @@ -2379,11 +2368,11 @@ constexpr auto map_error_impl(Exp &&exp, F &&f) } template >::value> * = nullptr, + detail::enable_if_t>::value>* = nullptr, class Ret = decltype(detail::invoke(std::declval(), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -auto map_error_impl(Exp &&exp, F &&f) -> expected, monostate> { + detail::enable_if_t::value>* = nullptr> +auto map_error_impl(Exp&& exp, F&& f) -> expected, monostate> { using result = expected, monostate>; if (exp.has_value()) { return result(); @@ -2398,8 +2387,8 @@ auto map_error_impl(Exp &&exp, F &&f) -> expected, monostate> { template (), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -constexpr auto or_else_impl(Exp &&exp, F &&f) { + detail::enable_if_t::value>* = nullptr> +constexpr auto or_else_impl(Exp&& exp, F&& f) { static_assert(detail::is_expected::value, "F must return an expected"); return exp.has_value() ? std::forward(exp) : detail::invoke(std::forward(f), @@ -2409,8 +2398,8 @@ constexpr auto or_else_impl(Exp &&exp, F &&f) { template (), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -detail::decay_t or_else_impl(Exp &&exp, F &&f) { + detail::enable_if_t::value>* = nullptr> +detail::decay_t or_else_impl(Exp&& exp, F&& f) { return exp.has_value() ? std::forward(exp) : (detail::invoke(std::forward(f), std::forward(exp).error()), @@ -2420,8 +2409,8 @@ detail::decay_t or_else_impl(Exp &&exp, F &&f) { template (), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -auto or_else_impl(Exp &&exp, F &&f) -> Ret { + detail::enable_if_t::value>* = nullptr> +auto or_else_impl(Exp&& exp, F&& f) -> Ret { static_assert(detail::is_expected::value, "F must return an expected"); return exp.has_value() ? std::forward(exp) : detail::invoke(std::forward(f), @@ -2431,8 +2420,8 @@ auto or_else_impl(Exp &&exp, F &&f) -> Ret { template (), std::declval().error())), - detail::enable_if_t::value> * = nullptr> -detail::decay_t or_else_impl(Exp &&exp, F &&f) { + detail::enable_if_t::value>* = nullptr> +detail::decay_t or_else_impl(Exp&& exp, F&& f) { return exp.has_value() ? std::forward(exp) : (detail::invoke(std::forward(f), std::forward(exp).error()), @@ -2442,65 +2431,65 @@ detail::decay_t or_else_impl(Exp &&exp, F &&f) { } // namespace detail template -constexpr bool operator==(const expected &lhs, - const expected &rhs) { +constexpr bool operator==(const expected& lhs, + const expected& rhs) { return (lhs.has_value() != rhs.has_value()) ? false : (!lhs.has_value() ? lhs.error() == rhs.error() : *lhs == *rhs); } template -constexpr bool operator!=(const expected &lhs, - const expected &rhs) { +constexpr bool operator!=(const expected& lhs, + const expected& rhs) { return (lhs.has_value() != rhs.has_value()) ? true : (!lhs.has_value() ? lhs.error() != rhs.error() : *lhs != *rhs); } template -constexpr bool operator==(const expected &lhs, - const expected &rhs) { +constexpr bool operator==(const expected& lhs, + const expected& rhs) { return (lhs.has_value() != rhs.has_value()) ? false : (!lhs.has_value() ? lhs.error() == rhs.error() : true); } template -constexpr bool operator!=(const expected &lhs, - const expected &rhs) { +constexpr bool operator!=(const expected& lhs, + const expected& rhs) { return (lhs.has_value() != rhs.has_value()) ? true : (!lhs.has_value() ? lhs.error() == rhs.error() : false); } template -constexpr bool operator==(const expected &x, const U &v) { +constexpr bool operator==(const expected& x, const U& v) { return x.has_value() ? *x == v : false; } template -constexpr bool operator==(const U &v, const expected &x) { +constexpr bool operator==(const U& v, const expected& x) { return x.has_value() ? *x == v : false; } template -constexpr bool operator!=(const expected &x, const U &v) { +constexpr bool operator!=(const expected& x, const U& v) { return x.has_value() ? *x != v : true; } template -constexpr bool operator!=(const U &v, const expected &x) { +constexpr bool operator!=(const U& v, const expected& x) { return x.has_value() ? *x != v : true; } template -constexpr bool operator==(const expected &x, const unexpected &e) { +constexpr bool operator==(const expected& x, const unexpected& e) { return x.has_value() ? false : x.error() == e.value(); } template -constexpr bool operator==(const unexpected &e, const expected &x) { +constexpr bool operator==(const unexpected& e, const expected& x) { return x.has_value() ? false : x.error() == e.value(); } template -constexpr bool operator!=(const expected &x, const unexpected &e) { +constexpr bool operator!=(const expected& x, const unexpected& e) { return x.has_value() ? true : x.error() != e.value(); } template -constexpr bool operator!=(const unexpected &e, const expected &x) { +constexpr bool operator!=(const unexpected& e, const expected& x) { return x.has_value() ? true : x.error() != e.value(); } @@ -2509,9 +2498,9 @@ template ::value) && detail::is_swappable::value && std::is_move_constructible::value && - detail::is_swappable::value> * = nullptr> -void swap(expected &lhs, - expected &rhs) noexcept(noexcept(lhs.swap(rhs))) { + detail::is_swappable::value>* = nullptr> +void swap(expected& lhs, + expected& rhs) noexcept(noexcept(lhs.swap(rhs))) { lhs.swap(rhs); } } // namespace tl diff --git a/include/ada/url-inl.h b/include/ada/url-inl.h index 3061cd098..1e8288ad8 100644 --- a/include/ada/url-inl.h +++ b/include/ada/url-inl.h @@ -35,7 +35,7 @@ namespace ada { [[nodiscard]] inline bool url::has_hostname() const noexcept { return host.has_value(); } -inline std::ostream &operator<<(std::ostream &out, const ada::url &u) { +inline std::ostream& operator<<(std::ostream& out, const ada::url& u) { return out << u.to_string(); } @@ -133,7 +133,7 @@ inline void url::update_base_search(std::string_view input, query = ada::unicode::percent_encode(input, query_percent_encode_set); } -inline void url::update_base_search(std::optional &&input) { +inline void url::update_base_search(std::optional&& input) { query = std::move(input); } @@ -167,7 +167,7 @@ constexpr void url::clear_search() { query = std::nullopt; } constexpr void url::set_protocol_as_file() { type = ada::scheme::type::FILE; } -inline void url::set_scheme(std::string &&new_scheme) noexcept { +inline void url::set_scheme(std::string&& new_scheme) noexcept { type = ada::scheme::get_scheme_type(new_scheme); // We only move the 'scheme' if it is non-special. if (!is_special()) { @@ -175,12 +175,12 @@ inline void url::set_scheme(std::string &&new_scheme) noexcept { } } -constexpr void url::copy_scheme(ada::url &&u) noexcept { +constexpr void url::copy_scheme(ada::url&& u) noexcept { non_special_scheme = u.non_special_scheme; type = u.type; } -constexpr void url::copy_scheme(const ada::url &u) { +constexpr void url::copy_scheme(const ada::url& u) { non_special_scheme = u.non_special_scheme; type = u.type; } diff --git a/include/ada/url.h b/include/ada/url.h index 70b62605b..eacedbb69 100644 --- a/include/ada/url.h +++ b/include/ada/url.h @@ -44,10 +44,10 @@ struct url_aggregator; */ struct url : url_base { url() = default; - url(const url &u) = default; - url(url &&u) noexcept = default; - url &operator=(url &&u) noexcept = default; - url &operator=(const url &u) = default; + url(const url& u) = default; + url(url&& u) noexcept = default; + url& operator=(url&& u) noexcept = default; + url& operator=(const url& u) = default; ~url() override = default; /** @@ -178,7 +178,7 @@ struct url : url_base { * @return a constant reference to the underlying string. * @see https://url.spec.whatwg.org/#dom-url-username */ - [[nodiscard]] const std::string &get_username() const noexcept; + [[nodiscard]] const std::string& get_username() const noexcept; /** * @return Returns true on successful operation. @@ -244,7 +244,7 @@ struct url : url_base { * @return a constant reference to the underlying string. * @see https://url.spec.whatwg.org/#dom-url-password */ - [[nodiscard]] const std::string &get_password() const noexcept; + [[nodiscard]] const std::string& get_password() const noexcept; /** * Return this's URL's port, serialized. @@ -296,22 +296,22 @@ struct url : url_base { private: friend ada::url ada::parser::parse_url(std::string_view, - const ada::url *); + const ada::url*); friend ada::url_aggregator ada::parser::parse_url( - std::string_view, const ada::url_aggregator *); + std::string_view, const ada::url_aggregator*); friend void ada::helpers::strip_trailing_spaces_from_opaque_path( - ada::url &url) noexcept; + ada::url& url) noexcept; friend ada::url ada::parser::parse_url_impl(std::string_view, - const ada::url *); + const ada::url*); friend ada::url_aggregator ada::parser::parse_url_impl< - ada::url_aggregator, true>(std::string_view, const ada::url_aggregator *); + ada::url_aggregator, true>(std::string_view, const ada::url_aggregator*); inline void update_unencoded_base_hash(std::string_view input); inline void update_base_hostname(std::string_view input); inline void update_base_search(std::string_view input, const uint8_t query_percent_encode_set[]); - inline void update_base_search(std::optional &&input); + inline void update_base_search(std::optional&& input); inline void update_base_pathname(std::string_view input); inline void update_base_username(std::string_view input); inline void update_base_password(std::string_view input); @@ -401,23 +401,23 @@ struct url : url_base { * scheme string, be lower-cased, not contain spaces or tabs. It should * have no spurious trailing or leading content. */ - inline void set_scheme(std::string &&new_scheme) noexcept; + inline void set_scheme(std::string&& new_scheme) noexcept; /** * Take the scheme from another URL. The scheme string is moved from the * provided url. */ - constexpr void copy_scheme(ada::url &&u) noexcept; + constexpr void copy_scheme(ada::url&& u) noexcept; /** * Take the scheme from another URL. The scheme string is copied from the * provided url. */ - constexpr void copy_scheme(const ada::url &u); + constexpr void copy_scheme(const ada::url& u); }; // struct url -inline std::ostream &operator<<(std::ostream &out, const ada::url &u); +inline std::ostream& operator<<(std::ostream& out, const ada::url& u); } // namespace ada #endif // ADA_URL_H diff --git a/include/ada/url_aggregator-inl.h b/include/ada/url_aggregator-inl.h index c220de2b9..cf678acb7 100644 --- a/include/ada/url_aggregator-inl.h +++ b/include/ada/url_aggregator-inl.h @@ -20,7 +20,7 @@ namespace ada { inline void url_aggregator::update_base_authority( - std::string_view base_buffer, const ada::url_components &base) { + std::string_view base_buffer, const ada::url_components& base) { std::string_view input = base_buffer.substr( base.protocol_end, base.host_start - base.protocol_end); ada_log("url_aggregator::update_base_authority ", input); @@ -722,7 +722,7 @@ constexpr bool url_aggregator::cannot_have_credentials_or_port() const { components.host_start == components.host_end; } -[[nodiscard]] ada_really_inline const ada::url_components & +[[nodiscard]] ada_really_inline const ada::url_components& url_aggregator::get_components() const noexcept { return components; } @@ -1100,8 +1100,8 @@ constexpr void url_aggregator::set_protocol_as_file() { return helpers::substring(buffer, components.pathname_start, ending_index); } -inline std::ostream &operator<<(std::ostream &out, - const ada::url_aggregator &u) { +inline std::ostream& operator<<(std::ostream& out, + const ada::url_aggregator& u) { return out << u.to_string(); } diff --git a/include/ada/url_aggregator.h b/include/ada/url_aggregator.h index ab43e8cdc..255a632c6 100644 --- a/include/ada/url_aggregator.h +++ b/include/ada/url_aggregator.h @@ -28,10 +28,10 @@ namespace parser {} */ struct url_aggregator : url_base { url_aggregator() = default; - url_aggregator(const url_aggregator &u) = default; - url_aggregator(url_aggregator &&u) noexcept = default; - url_aggregator &operator=(url_aggregator &&u) noexcept = default; - url_aggregator &operator=(const url_aggregator &u) = default; + url_aggregator(const url_aggregator& u) = default; + url_aggregator(url_aggregator&& u) noexcept = default; + url_aggregator& operator=(url_aggregator&& u) noexcept = default; + url_aggregator& operator=(const url_aggregator& u) = default; ~url_aggregator() override = default; bool set_href(std::string_view input); @@ -172,7 +172,7 @@ struct url_aggregator : url_base { * @see * https://github.com/servo/rust-url/blob/b65a45515c10713f6d212e6726719a020203cc98/url/src/quirks.rs#L31 */ - [[nodiscard]] ada_really_inline const url_components &get_components() + [[nodiscard]] ada_really_inline const url_components& get_components() const noexcept; /** * Returns a string representation of this URL. @@ -214,23 +214,23 @@ struct url_aggregator : url_base { private: // helper methods friend void helpers::strip_trailing_spaces_from_opaque_path( - url_aggregator &url) noexcept; + url_aggregator& url) noexcept; // parse_url methods friend url_aggregator parser::parse_url( - std::string_view, const url_aggregator *); + std::string_view, const url_aggregator*); friend url_aggregator parser::parse_url_impl( - std::string_view, const url_aggregator *); + std::string_view, const url_aggregator*); friend url_aggregator parser::parse_url_impl( - std::string_view, const url_aggregator *); + std::string_view, const url_aggregator*); #if ADA_INCLUDE_URL_PATTERN // url_pattern methods template friend tl::expected, errors> parse_url_pattern_impl( - std::variant &&input, - const std::string_view *base_url, const url_pattern_options *options); + std::variant&& input, + const std::string_view* base_url, const url_pattern_options* options); #endif // ADA_INCLUDE_URL_PATTERN std::string buffer{}; @@ -292,12 +292,12 @@ struct url_aggregator : url_base { ada_really_inline bool parse_host(std::string_view input); inline void update_base_authority(std::string_view base_buffer, - const url_components &base); + const url_components& base); inline void update_unencoded_base_hash(std::string_view input); inline void update_base_hostname(std::string_view input); inline void update_base_search(std::string_view input); inline void update_base_search(std::string_view input, - const uint8_t *query_percent_encode_set); + const uint8_t* query_percent_encode_set); inline void update_base_pathname(std::string_view input); inline void update_base_username(std::string_view input); inline void append_base_username(std::string_view input); @@ -326,13 +326,13 @@ struct url_aggregator : url_base { */ inline void set_scheme_from_view_with_colon( std::string_view new_scheme_with_colon) noexcept; - inline void copy_scheme(const url_aggregator &u) noexcept; + inline void copy_scheme(const url_aggregator& u) noexcept; inline void update_host_to_base_host(const std::string_view input) noexcept; }; // url_aggregator -inline std::ostream &operator<<(std::ostream &out, const url &u); +inline std::ostream& operator<<(std::ostream& out, const url& u); } // namespace ada #endif diff --git a/include/ada/url_components.h b/include/ada/url_components.h index 3c7594540..ed6c11bf1 100644 --- a/include/ada/url_components.h +++ b/include/ada/url_components.h @@ -19,10 +19,10 @@ struct url_components { constexpr static uint32_t omitted = uint32_t(-1); url_components() = default; - url_components(const url_components &u) = default; - url_components(url_components &&u) noexcept = default; - url_components &operator=(url_components &&u) noexcept = default; - url_components &operator=(const url_components &u) = default; + url_components(const url_components& u) = default; + url_components(url_components&& u) noexcept = default; + url_components& operator=(url_components&& u) noexcept = default; + url_components& operator=(const url_components& u) = default; ~url_components() = default; /* diff --git a/include/ada/url_search_params-inl.h b/include/ada/url_search_params-inl.h index 5787a0598..5820215bb 100644 --- a/include/ada/url_search_params-inl.h +++ b/include/ada/url_search_params-inl.h @@ -77,7 +77,7 @@ inline size_t url_search_params::size() const noexcept { return params.size(); } inline std::optional url_search_params::get( const std::string_view key) { auto entry = std::ranges::find_if( - params, [&key](const auto ¶m) { return param.first == key; }); + params, [&key](const auto& param) { return param.first == key; }); if (entry == params.end()) { return std::nullopt; @@ -90,7 +90,7 @@ inline std::vector url_search_params::get_all( const std::string_view key) { std::vector out{}; - for (auto ¶m : params) { + for (auto& param : params) { if (param.first == key) { out.emplace_back(param.second); } @@ -101,13 +101,13 @@ inline std::vector url_search_params::get_all( inline bool url_search_params::has(const std::string_view key) noexcept { auto entry = std::ranges::find_if( - params, [&key](const auto ¶m) { return param.first == key; }); + params, [&key](const auto& param) { return param.first == key; }); return entry != params.end(); } inline bool url_search_params::has(std::string_view key, std::string_view value) noexcept { - auto entry = std::ranges::find_if(params, [&key, &value](const auto ¶m) { + auto entry = std::ranges::find_if(params, [&key, &value](const auto& param) { return param.first == key && param.second == value; }); return entry != params.end(); @@ -136,7 +136,7 @@ inline std::string url_search_params::to_string() const { inline void url_search_params::set(const std::string_view key, const std::string_view value) { - const auto find = [&key](const auto ¶m) { return param.first == key; }; + const auto find = [&key](const auto& param) { return param.first == key; }; auto it = std::ranges::find_if(params, find); @@ -151,20 +151,20 @@ inline void url_search_params::set(const std::string_view key, inline void url_search_params::remove(const std::string_view key) { std::erase_if(params, - [&key](const auto ¶m) { return param.first == key; }); + [&key](const auto& param) { return param.first == key; }); } inline void url_search_params::remove(const std::string_view key, const std::string_view value) { - std::erase_if(params, [&key, &value](const auto ¶m) { + std::erase_if(params, [&key, &value](const auto& param) { return param.first == key && param.second == value; }); } inline void url_search_params::sort() { // We rely on the fact that the content is valid UTF-8. - std::ranges::stable_sort(params, [](const key_value_pair &lhs, - const key_value_pair &rhs) { + std::ranges::stable_sort(params, [](const key_value_pair& lhs, + const key_value_pair& rhs) { size_t i = 0, j = 0; uint32_t low_surrogate1 = 0, low_surrogate2 = 0; while ((i < lhs.first.size() || low_surrogate1 != 0) && diff --git a/include/ada/url_search_params.h b/include/ada/url_search_params.h index fb8ead258..886741c47 100644 --- a/include/ada/url_search_params.h +++ b/include/ada/url_search_params.h @@ -48,10 +48,10 @@ struct url_search_params { initialize(input); } - url_search_params(const url_search_params &u) = default; - url_search_params(url_search_params &&u) noexcept = default; - url_search_params &operator=(url_search_params &&u) noexcept = default; - url_search_params &operator=(const url_search_params &u) = default; + url_search_params(const url_search_params& u) = default; + url_search_params(url_search_params&& u) noexcept = default; + url_search_params& operator=(url_search_params&& u) noexcept = default; + url_search_params& operator=(const url_search_params& u) = default; ~url_search_params() = default; [[nodiscard]] inline size_t size() const noexcept; @@ -167,11 +167,11 @@ struct url_search_params { template struct url_search_params_iter { inline url_search_params_iter() : params(EMPTY) {} - url_search_params_iter(const url_search_params_iter &u) = default; - url_search_params_iter(url_search_params_iter &&u) noexcept = default; - url_search_params_iter &operator=(url_search_params_iter &&u) noexcept = + url_search_params_iter(const url_search_params_iter& u) = default; + url_search_params_iter(url_search_params_iter&& u) noexcept = default; + url_search_params_iter& operator=(url_search_params_iter&& u) noexcept = default; - url_search_params_iter &operator=(const url_search_params_iter &u) = default; + url_search_params_iter& operator=(const url_search_params_iter& u) = default; ~url_search_params_iter() = default; /** @@ -183,9 +183,9 @@ struct url_search_params_iter { private: static url_search_params EMPTY; - inline url_search_params_iter(url_search_params ¶ms_) : params(params_) {} + inline url_search_params_iter(url_search_params& params_) : params(params_) {} - url_search_params ¶ms; + url_search_params& params; size_t pos = 0; friend struct url_search_params; diff --git a/singleheader/demo.cpp b/singleheader/demo.cpp index c70fa75e8..62eb74dbe 100644 --- a/singleheader/demo.cpp +++ b/singleheader/demo.cpp @@ -2,7 +2,7 @@ #include "ada.h" #include -int main(int, char *[]) { +int main(int, char*[]) { auto url = ada::parse("https://www.google.com"); if (!url) { std::cout << "failure" << std::endl; diff --git a/tests/wasm/wasm.cpp b/tests/wasm/wasm.cpp index 3df8e5ab1..75d081dd2 100644 --- a/tests/wasm/wasm.cpp +++ b/tests/wasm/wasm.cpp @@ -11,7 +11,7 @@ struct parse_result { ada::url_components components; }; -parse_result parse(const std::string &input) { +parse_result parse(const std::string& input) { auto out = ada::parse(input); parse_result result; if (!out.has_value()) { diff --git a/tests/wpt_url_tests.cpp b/tests/wpt_url_tests.cpp index 3550613df..1d1fcc797 100644 --- a/tests/wpt_url_tests.cpp +++ b/tests/wpt_url_tests.cpp @@ -18,7 +18,7 @@ // an out-of-bound access. template ada::result ada_parse(std::string_view view, - const result_type *base = nullptr) { + const result_type* base = nullptr) { std::cout << "about to parse '" << view << "' [" << view.size() << " bytes]" << std::endl; std::unique_ptr buffer(new char[view.size()]); @@ -28,9 +28,9 @@ ada::result ada_parse(std::string_view view, } template ada::result ada_parse(std::string_view view, - const ada::url *base); + const ada::url* base); template ada::result ada_parse( - std::string_view view, const ada::url_aggregator *base); + std::string_view view, const ada::url_aggregator* base); #include "simdjson.h" @@ -39,15 +39,15 @@ using namespace simdjson; #ifndef WPT_DATA_DIR #define WPT_DATA_DIR "wpt/" #endif -const char *PERCENT_ENCODING_JSON = WPT_DATA_DIR "percent-encoding.json"; -const char *SETTERS_TESTS_JSON = WPT_DATA_DIR "setters_tests.json"; -const char *ADA_SETTERS_TESTS_JSON = +const char* PERCENT_ENCODING_JSON = WPT_DATA_DIR "percent-encoding.json"; +const char* SETTERS_TESTS_JSON = WPT_DATA_DIR "setters_tests.json"; +const char* ADA_SETTERS_TESTS_JSON = WPT_DATA_DIR "ada_extra_setters_tests.json"; -const char *TOASCII_JSON = WPT_DATA_DIR "toascii.json"; -const char *IDNA_TEST_V2 = WPT_DATA_DIR "IdnaTestV2.json"; -const char *URLTESTDATA_JSON = WPT_DATA_DIR "urltestdata.json"; -const char *ADA_URLTESTDATA_JSON = WPT_DATA_DIR "ada_extra_urltestdata.json"; -const char *VERIFYDNSLENGTH_TESTS_JSON = +const char* TOASCII_JSON = WPT_DATA_DIR "toascii.json"; +const char* IDNA_TEST_V2 = WPT_DATA_DIR "IdnaTestV2.json"; +const char* URLTESTDATA_JSON = WPT_DATA_DIR "urltestdata.json"; +const char* ADA_URLTESTDATA_JSON = WPT_DATA_DIR "ada_extra_urltestdata.json"; +const char* VERIFYDNSLENGTH_TESTS_JSON = WPT_DATA_DIR "verifydnslength_tests.json"; using Types = testing::Types; @@ -57,7 +57,7 @@ TYPED_TEST_SUITE(wpt_url_tests_typed, Types); std::stringstream error_buffer; -bool file_exists(const char *filename) { +bool file_exists(const char* filename) { namespace fs = std::filesystem; std::filesystem::path f{filename}; if (std::filesystem::exists(filename)) { @@ -98,7 +98,7 @@ TEST(wpt_url_tests, idna_test_v2_to_ascii) { ASSERT_EQ(str_expected_output, given_output); } } - } catch (simdjson::simdjson_error &error) { + } catch (simdjson::simdjson_error& error) { // Some tests include invalid unicode characters. Let's omit the errors. // FAIL() << "JSON error: " << error.what() << " near " // << doc.current_location() << " in " << IDNA_TEST_V2 << std::endl; @@ -140,7 +140,7 @@ TEST(wpt_url_tests, percent_encoding) { counter++; } } - } catch (simdjson::simdjson_error &error) { + } catch (simdjson::simdjson_error& error) { std::cerr << "JSON error: " << error.what() << " near " << doc.current_location() << " in " << TOASCII_JSON << std::endl; FAIL(); @@ -246,7 +246,7 @@ TYPED_TEST(wpt_url_tests_typed, setters_tests_encoding) { } } } - } catch (simdjson::simdjson_error &error) { + } catch (simdjson::simdjson_error& error) { std::cerr << "JSON error: " << error.what() << " near " << doc.current_location() << " in " << source << std::endl; FAIL(); @@ -327,7 +327,7 @@ TYPED_TEST(wpt_url_tests_typed, toascii_encoding) { } } } - } catch (simdjson::simdjson_error &error) { + } catch (simdjson::simdjson_error& error) { std::cerr << "JSON error: " << error.what() << " near " << doc.current_location() << " in " << TOASCII_JSON << std::endl; FAIL(); @@ -450,7 +450,7 @@ TYPED_TEST(wpt_url_tests_typed, urltestdata_encoding) { } } } - } catch (simdjson::simdjson_error &error) { + } catch (simdjson::simdjson_error& error) { std::cerr << "JSON error: " << error.what() << " near " << doc.current_location() << " in " << source << std::endl; FAIL(); @@ -461,7 +461,7 @@ TYPED_TEST(wpt_url_tests_typed, urltestdata_encoding) { } TEST(wpt_url_tests, verify_dns_length) { - const char *source = VERIFYDNSLENGTH_TESTS_JSON; + const char* source = VERIFYDNSLENGTH_TESTS_JSON; size_t counter{}; ondemand::parser parser; ASSERT_TRUE(file_exists(source)); @@ -486,7 +486,7 @@ TEST(wpt_url_tests, verify_dns_length) { counter++; } } - } catch (simdjson::simdjson_error &error) { + } catch (simdjson::simdjson_error& error) { std::cerr << "JSON error: " << error.what() << " near " << doc.current_location() << " in " << source << std::endl; FAIL(); diff --git a/tools/cli/line_iterator.h b/tools/cli/line_iterator.h index a60439064..aa2afa132 100644 --- a/tools/cli/line_iterator.h +++ b/tools/cli/line_iterator.h @@ -6,7 +6,7 @@ struct line_iterator { std::string_view all_text{}; size_t next_end_of_line{0}; - line_iterator(const char *_buffer, size_t _len) : all_text(_buffer, _len) {} + line_iterator(const char* _buffer, size_t _len) : all_text(_buffer, _len) {} inline bool find_another_complete_line() noexcept { next_end_of_line = all_text.find('\n'); diff --git a/tools/run-clangcldocker.sh b/tools/run-clangcldocker.sh index 5f6c0713d..3c432d897 100755 --- a/tools/run-clangcldocker.sh +++ b/tools/run-clangcldocker.sh @@ -5,10 +5,10 @@ SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" MAINSOURCE=$SCRIPTPATH/.. ALL_ADA_FILES=$(cd $MAINSOURCE && git ls-tree --full-tree --name-only -r HEAD | grep -e ".*\.\(c\|h\|cc\|cpp\|hh\)\$") -if clang-format-17 --version 2>/dev/null | grep -qF 'version 17.'; then - cd $MAINSOURCE; clang-format-17 --style=file --verbose -i "$@" $ALL_ADA_FILES +if clang-format-21 --version 2>/dev/null | grep -qF 'version 21.'; then + cd $MAINSOURCE; clang-format-21 --style=file --verbose -i "$@" $ALL_ADA_FILES exit 0 -elif clang-format --version 2>/dev/null | grep -qF 'version 17.'; then +elif clang-format --version 2>/dev/null | grep -qF 'version 21.'; then cd $MAINSOURCE; clang-format --style=file --verbose -i "$@" $ALL_ADA_FILES exit 0 fi @@ -17,6 +17,6 @@ command -v docker >/dev/null 2>&1 || { echo >&2 "Please install docker. E.g., go docker info >/dev/null 2>&1 || { echo >&2 "Docker server is not running? type 'docker info'."; exit 1; } if [ -t 0 ]; then DOCKER_ARGS=-it; fi -docker pull kszonek/clang-format-17 +docker pull xianpengshen/clang-tools:21 -docker run --rm $DOCKER_ARGS -v "$MAINSOURCE":"$MAINSOURCE":Z -w "$MAINSOURCE" -u "$(id -u $USER):$(id -g $USER)" kszonek/clang-format-17 --style=file --verbose -i "$@" $ALL_ADA_FILES +docker run --rm $DOCKER_ARGS -v "$MAINSOURCE":"$MAINSOURCE":Z -w "$MAINSOURCE" -u "$(id -u $USER):$(id -g $USER)" xianpengshen/clang-tools:21 clang-format-21 --style=file --verbose -i "$@" $ALL_ADA_FILES