diff --git a/CMakeLists.txt b/CMakeLists.txt index db992c2..7b6a02b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,6 @@ target_sources( include/stdx/intrusive_list.hpp include/stdx/iterator.hpp include/stdx/latched.hpp - include/stdx/memory.hpp include/stdx/numeric.hpp include/stdx/optional.hpp include/stdx/panic.hpp diff --git a/docs/header_graph.mmd b/docs/header_graph.mmd index b771ba7..5a4fcbe 100644 --- a/docs/header_graph.mmd +++ b/docs/header_graph.mmd @@ -19,8 +19,6 @@ flowchart BT type_traits --> ct_conversions %% level 3 - memory(memory.hpp) - memory --> type_traits iterator(iterator.hpp) iterator --> type_traits concepts(concepts.hpp) @@ -53,11 +51,9 @@ flowchart BT %% level 6 span(span.hpp) - span ----> memory span ----> iterator span --> bit byterator(byterator.hpp) - byterator ----> memory byterator --> bit cx_set(cx_set.hpp) cx_set ---> cx_map diff --git a/docs/index.adoc b/docs/index.adoc index efd3605..d781b1a 100644 --- a/docs/index.adoc +++ b/docs/index.adoc @@ -33,7 +33,6 @@ include::intrusive_forward_list.adoc[] include::intrusive_list.adoc[] include::iterator.adoc[] include::latched.adoc[] -include::memory.adoc[] include::numeric.adoc[] include::optional.adoc[] include::panic.adoc[] diff --git a/docs/intro.adoc b/docs/intro.adoc index 1a3764e..b11a48d 100644 --- a/docs/intro.adoc +++ b/docs/intro.adoc @@ -88,7 +88,6 @@ The following headers are available: * https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/intrusive_list.hpp[`intrusive_list.hpp`] * https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/iterator.hpp[`iterator.hpp`] * https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/latched.hpp[`latched.hpp`] -* https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/memory.hpp[`memory.hpp`] * https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/numeric.hpp[`numeric.hpp`] * https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/optional.hpp[`optional.hpp`] * https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/panic.hpp[`panic.hpp`] diff --git a/docs/memory.adoc b/docs/memory.adoc deleted file mode 100644 index 8afee50..0000000 --- a/docs/memory.adoc +++ /dev/null @@ -1,7 +0,0 @@ - -== `memory.hpp` - -https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/memory.hpp[`memory.hpp`] -contains one thing: - -* https://en.cppreference.com/w/cpp/memory/to_address[`to_address`] (from C++20) diff --git a/include/stdx/byterator.hpp b/include/stdx/byterator.hpp index fc5b1a4..deea5d3 100644 --- a/include/stdx/byterator.hpp +++ b/include/stdx/byterator.hpp @@ -2,14 +2,13 @@ #include #include -#include #include #include #include #include -#include #include +#include #include namespace stdx { @@ -45,7 +44,7 @@ template class byterator { [[nodiscard]] friend constexpr auto operator==(byterator const &x, It y) -> bool { return static_cast(x.ptr) == - static_cast(stdx::to_address(y)); + static_cast(std::to_address(y)); } [[nodiscard]] friend constexpr auto operator<=>(byterator const &x, @@ -56,7 +55,7 @@ template class byterator { requires std::is_same_v, T> [[nodiscard]] friend constexpr auto operator<=>(byterator const &x, It y) { return static_cast(x.ptr) <=> - static_cast(stdx::to_address(y)); + static_cast(std::to_address(y)); } public: @@ -67,7 +66,7 @@ template class byterator { using iterator_category = std::random_access_iterator_tag; template - explicit byterator(It it) : ptr(bit_cast(stdx::to_address(it))) {} + explicit byterator(It it) : ptr(bit_cast(std::to_address(it))) {} [[nodiscard]] constexpr auto operator->() const -> byte_t * { return ptr; } [[nodiscard]] constexpr auto operator*() const -> byte_t & { return *ptr; } diff --git a/include/stdx/memory.hpp b/include/stdx/memory.hpp deleted file mode 100644 index c55d84d..0000000 --- a/include/stdx/memory.hpp +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include - -#include - -namespace stdx { -inline namespace v1 { -template constexpr auto to_address(T *p) noexcept -> T * { - static_assert(not stdx::is_function_v, - "to_address on a function pointer is ill-formed"); - return p; -} - -namespace detail::detect { -template -constexpr auto pointer_traits_to_address = false; - -template -constexpr auto pointer_traits_to_address< - T, std::void_t::to_address( - std::declval()))>> = true; -} // namespace detail::detect - -template constexpr auto to_address(T const &t) { - if constexpr (detail::detect::pointer_traits_to_address) { - return std::pointer_traits::to_address(t); - } else { - return stdx::to_address(t.operator->()); - } -} -} // namespace v1 -} // namespace stdx diff --git a/include/stdx/span.hpp b/include/stdx/span.hpp index b5c543d..316979f 100644 --- a/include/stdx/span.hpp +++ b/include/stdx/span.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -12,6 +11,7 @@ #include #include #include +#include #include namespace stdx { @@ -85,12 +85,12 @@ class span : public detail::span_base { template requires(dependent_extent != dynamic_extent) explicit constexpr span(It first, SizeOrEnd) - : ptr{stdx::to_address(first)} {} + : ptr{std::to_address(first)} {} template requires(dependent_extent == dynamic_extent) constexpr span(It first, SizeOrEnd sore) - : base_t{first, sore}, ptr{stdx::to_address(first)} {} + : base_t{first, sore}, ptr{std::to_address(first)} {} template constexpr explicit(false) span(std::array &arr LIFETIMEBOUND) noexcept @@ -120,13 +120,13 @@ class span : public detail::span_base { template requires(dependent_extent != dynamic_extent) explicit constexpr span(R &&r) - : ptr{stdx::to_address(std::begin(std::forward(r)))} {} + : ptr{std::to_address(std::begin(std::forward(r)))} {} template requires(dependent_extent == dynamic_extent) explicit constexpr span(R &&r) : base_t{std::begin(std::forward(r)), std::end(std::forward(r))}, - ptr{stdx::to_address(std::begin(std::forward(r)))} {} + ptr{std::to_address(std::begin(std::forward(r)))} {} template requires(dependent_extent != dynamic_extent and N == dynamic_extent) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5f36f3f..490128d 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -56,7 +56,6 @@ add_tests( is_constant_evaluated iterator latched - memory numeric optional overload diff --git a/test/byterator.cpp b/test/byterator.cpp index 2fef49b..f6c243a 100644 --- a/test/byterator.cpp +++ b/test/byterator.cpp @@ -4,12 +4,13 @@ #include #include +#include TEST_CASE("constructible from an iterator", "[byterator]") { auto const a = std::array{1, 2, 3, 4}; auto const b = stdx::byterator{std::begin(a)}; - CHECK(static_cast(stdx::to_address(std::begin(a))) == - static_cast(stdx::to_address(b))); + CHECK(static_cast(std::to_address(std::begin(a))) == + static_cast(std::to_address(b))); } TEST_CASE("equality comparable to iterator", "[byterator]") { diff --git a/test/fail/CMakeLists.txt b/test/fail/CMakeLists.txt index c39f7b5..86de53d 100644 --- a/test/fail/CMakeLists.txt +++ b/test/fail/CMakeLists.txt @@ -31,7 +31,6 @@ add_fail_tests( subspan_too_big subspan_wrapping template_for_each_not_list - to_address_undefined_on_function tuple_index_out_of_bounds tuple_equality_mismatch tuple_equality_with_element diff --git a/test/fail/to_address_undefined_on_function.cpp b/test/fail/to_address_undefined_on_function.cpp deleted file mode 100644 index 572a16f..0000000 --- a/test/fail/to_address_undefined_on_function.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include - -// EXPECT: to_address on a function pointer is ill-formed - -namespace { -auto f() -> void {} -} // namespace - -auto main() -> int { [[maybe_unused]] auto p = stdx::to_address(f); } diff --git a/test/memory.cpp b/test/memory.cpp deleted file mode 100644 index 0dae011..0000000 --- a/test/memory.cpp +++ /dev/null @@ -1,54 +0,0 @@ -#include - -#include - -#include -#include -#include - -TEST_CASE("to_address for pointer (constexpr)", "[memory]") { - constexpr static int a{}; - constexpr static auto p = &a; - STATIC_REQUIRE(stdx::to_address(p) == p); -} - -TEST_CASE("to_address for pointer (runtime)", "[memory]") { - int a; // deliberately uninitialized - auto p = &a; - CHECK(stdx::to_address(p) == p); -} - -TEST_CASE("to_address for iterator", "[memory]") { - std::vector v{1, 2, 3}; - auto p = std::begin(v); - CHECK(stdx::to_address(p) == std::data(v)); -} - -namespace { -struct fancy {}; -} // namespace - -template <> struct std::pointer_traits { - constexpr static auto to_address(fancy) { return 42; } -}; - -TEST_CASE("to_address for fancy pointer", "[memory]") { - fancy f{}; - CHECK(stdx::to_address(f) == 42); -} - -namespace { -struct fancier { - constexpr static int value = 17; - constexpr auto operator->() const { return &value; } -}; -} // namespace - -template <> struct std::pointer_traits { - constexpr static auto to_address(fancier) { return 42; } -}; - -TEST_CASE("to_address for fancy pointer (prefer pointer_traits)", "[memory]") { - fancier f{}; - CHECK(stdx::to_address(f) == 42); -} diff --git a/test/span.cpp b/test/span.cpp index c3e8a93..c13c287 100644 --- a/test/span.cpp +++ b/test/span.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include TEMPLATE_TEST_CASE("span exposes types", "[span]", std::uint8_t, @@ -418,7 +419,7 @@ TEST_CASE("subspan of span", "[span]") { constexpr auto s6 = s1.subspan<4, 0>(); STATIC_REQUIRE( std::is_same_v const>); - STATIC_REQUIRE(std::data(s6) == stdx::to_address(std::end(a))); + STATIC_REQUIRE(std::data(s6) == std::to_address(std::end(a))); } TEST_CASE("subspan of dynamic span", "[span]") { @@ -445,7 +446,7 @@ TEST_CASE("subspan of dynamic span", "[span]") { auto s6 = s1.subspan<4, 0>(); STATIC_REQUIRE(std::is_same_v>); - CHECK(std::data(s6) == stdx::to_address(std::end(a))); + CHECK(std::data(s6) == std::to_address(std::end(a))); } TEST_CASE("span is explicitly convertible from dynamic to fixed", "[span]") { diff --git a/usage_test/main.cpp b/usage_test/main.cpp index 06dcc39..22b8bf6 100644 --- a/usage_test/main.cpp +++ b/usage_test/main.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include #include #include