diff --git a/CMakeLists.txt b/CMakeLists.txt index d276c35..c3ea45f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,55 +15,6 @@ option( ${PROJECT_IS_TOP_LEVEL} ) -# [CPP.NO_FLAG_FORKING] -set(BEMAN_ANY_VIEW_DESIGN - "ENUM" - CACHE STRING - "Enable alternative design for any_view_options. Default: ENUM. Values: { ENUM, TRAITS, NAMED }." -) - -set(BEMAN_ANY_VIEW_OPTION - "COPYABLE" - CACHE STRING - "Enable opt-in option for any_view. Default: COPYABLE. Values: { COPYABLE, MOVE_ONLY }." -) - -set(BEMAN_ANY_VIEW_USE_ENUM OFF) -set(BEMAN_ANY_VIEW_USE_TRAITS OFF) -set(BEMAN_ANY_VIEW_USE_NAMED OFF) -set(BEMAN_ANY_VIEW_USE_COPYABLE OFF) -set(BEMAN_ANY_VIEW_USE_MOVE_ONLY OFF) - -if(BEMAN_ANY_VIEW_DESIGN STREQUAL "ENUM") - set(BEMAN_ANY_VIEW_USE_ENUM ON) -elseif(BEMAN_ANY_VIEW_DESIGN STREQUAL "TRAITS") - set(BEMAN_ANY_VIEW_USE_TRAITS ON) -elseif(BEMAN_ANY_VIEW_DESIGN STREQUAL "NAMED") - set(BEMAN_ANY_VIEW_USE_NAMED ON) -else() - message( - FATAL_ERROR - "BEMAN_ANY_VIEW_DESIGN must be one of { ENUM, TRAITS, NAMED }; got ${BEMAN_ANY_VIEW_DESIGN}" - ) -endif() - -if(BEMAN_ANY_VIEW_OPTION STREQUAL "COPYABLE") - set(BEMAN_ANY_VIEW_USE_COPYABLE ON) -elseif(BEMAN_ANY_VIEW_OPTION STREQUAL "MOVE_ONLY") - set(BEMAN_ANY_VIEW_USE_MOVE_ONLY ON) -else() - message( - FATAL_ERROR - "BEMAN_ANY_VIEW_OPTION must be one of { COPYABLE, MOVE_ONLY }; got ${BEMAN_ANY_VIEW_OPTION}" - ) -endif() - -configure_file( - "${PROJECT_SOURCE_DIR}/include/beman/any_view/config.hpp.in" - "${PROJECT_BINARY_DIR}/include/beman/any_view/config.hpp" - @ONLY -) - include(FetchContent) include(GNUInstallDirs) @@ -75,7 +26,6 @@ target_include_directories( beman.any_view INTERFACE $ - $ $ ) diff --git a/README.md b/README.md index 77d5439..e8c4b98 100644 --- a/README.md +++ b/README.md @@ -82,18 +82,9 @@ target_link_libraries(yourlib PUBLIC beman::any_view) ## Reference -### Designs - -
-ENUM (default) - Synopsis: ```cpp -#define BEMAN_ANY_VIEW_USE_ENUM() 1 -#define BEMAN_ANY_VIEW_USE_TRAITS() 0 -#define BEMAN_ANY_VIEW_USE_NAMED() 0 - namespace beman::any_view { enum class any_view_options { @@ -104,11 +95,7 @@ enum class any_view_options { contiguous = 0b0001111, sized = 0b0010000, borrowed = 0b0100000, -#if BEMAN_ANY_VIEW_USE_COPYABLE() copyable = 0b1000000, -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - move_only = 0b1000000, -#endif }; constexpr auto operator|(any_view_options l, any_view_options r) noexcept -> any_view_options; @@ -133,11 +120,7 @@ class any_view : public std::ranges::view_interface; // exposition-only static constexpr bool copyable = // exposition-only -#if BEMAN_ANY_VIEW_USE_COPYABLE() (OptionsV & any_view_options::copyable) == any_view_options::copyable; -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - (OptionsV & any_view_options::move_only) != any_view_options::move_only; -#endif static constexpr bool sized = // exposition-only (OptionsV & any_view_options::sized) == any_view_options::sized; @@ -169,205 +152,8 @@ inline constexpr bool std::ranges::enable_borrowed_range< (OptionsV & beman::any_view::any_view_options::borrowed) == beman::any_view::any_view_options::borrowed; ``` -
- -
-TRAITS - -Synopsis: - -```cpp -#define BEMAN_ANY_VIEW_USE_ENUM() 0 -#define BEMAN_ANY_VIEW_USE_TRAITS() 1 -#define BEMAN_ANY_VIEW_USE_NAMED() 0 - -namespace beman::any_view { - -struct default_range_traits {}; - -template -struct range_traits { - using iterator_concept = /*range-concept-t*/; - using reference_type = std::ranges::range_reference_t; - using rvalue_reference_type = std::ranges::range_rvalue_reference_t; - using difference_type = std::ranges::range_difference_t; - - static constexpr bool sized = std::ranges::sized_range; - static constexpr bool borrowed = std::ranges::borrowed_range; -#if BEMAN_ANY_VIEW_USE_COPYABLE() - static constexpr bool copyable = std::copyable; -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - static constexpr bool move_only = not std::copyable; -#endif -}; - -template -class any_view : public std::ranges::view_interface> { - class iterator; // exposition-only - class sentinel; // exposition-only - - using difference_type = /*difference-type-or-t*/; // exposition-only - using size_type = /*make-unsigned-like-t*/; // exposition-only - - static constexpr bool copyable = // exposition-only -#if BEMAN_ANY_VIEW_USE_COPYABLE() - /*copyable-or-v*/; -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - not /*move-only-or-v*/; -#endif - - static constexpr bool sized = /*sized-or-v*/; // exposition-only - - public: - template RangeT> - constexpr any_view(RangeT&& range); - - constexpr any_view(const any_view&) requires copyable; - - constexpr any_view(any_view&&) noexcept; - - constexpr auto operator=(const any_view&) -> any_view& requires copyable; - - constexpr auto operator=(any_view&&) noexcept -> any_view&; - - constexpr auto begin() -> iterator; - - constexpr auto end() -> sentinel; - - constexpr auto size() const -> size_type requires sized; -}; - -} // namespace beman::any_view - -template -inline constexpr bool std::ranges::enable_borrowed_range> = - /*borrowed-or-v*/; -``` - -
- -
-NAMED - -Synopsis: - -```cpp -#define BEMAN_ANY_VIEW_USE_ENUM() 0 -#define BEMAN_ANY_VIEW_USE_TRAITS() 0 -#define BEMAN_ANY_VIEW_USE_NAMED() 1 - -namespace beman::any_view { - -template -struct type_t { - using type = T; -}; - -template -inline constexpr type_t type{}; - -template , - class DiffT = std::ptrdiff_t> -struct any_view_options { - type_t reference_type; - type_t iterator_concept = {}; - bool sized = false; -#if BEMAN_ANY_VIEW_USE_COPYABLE() - bool copyable = false; -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - bool move_only = false; -#endif - bool borrowed = false; - type_t rvalue_reference_type = {}; - type_t difference_type = {}; -}; - -template }> -class any_view : public std::ranges::view_interface> { - class iterator; // exposition-only - class sentinel; // exposition-only - - using difference_type = decltype(OptionsV.difference_type)::type; // exposition-only - using size_type = /*make-unsigned-like-t*/; // exposition-only - - static constexpr bool copyable = // exposition-only -#if BEMAN_ANY_VIEW_USE_COPYABLE() - OptionsV.copyable; -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - not OptionsV.move_only; -#endif - - static constexpr bool sized = OptionsV.sized; // exposition-only - - public: - template RangeT> - constexpr any_view(RangeT&& range); - - constexpr any_view(const any_view&) requires copyable; - - constexpr any_view(any_view&&) noexcept; - - constexpr auto operator=(const any_view&) -> any_view& requires copyable; - - constexpr auto operator=(any_view&&) noexcept -> any_view&; - - constexpr auto begin() -> iterator; - - constexpr auto end() -> sentinel; - - constexpr auto size() const -> size_type requires sized; -}; - -} // namespace beman::any_view - -template -inline constexpr bool std::ranges::enable_borrowed_range> = - OptionsV.borrowed; -``` - -
- -### Options - -
-COPYABLE (default) - -Synopsis: - -```cpp -#define BEMAN_ANY_VIEW_USE_COPYABLE() 1 -#define BEMAN_ANY_VIEW_USE_MOVE_ONLY() 0 -``` - -
- -
-MOVE_ONLY - -Synopsis: - -```cpp -#define BEMAN_ANY_VIEW_USE_COPYABLE() 0 -#define BEMAN_ANY_VIEW_USE_MOVE_ONLY() 1 -``` - -
- ## Building -### CMake configuration variables - -```text --DBEMAN_ANY_VIEW_DESIGN=ENUM --DBEMAN_ANY_VIEW_DESIGN=TRAITS --DBEMAN_ANY_VIEW_DESIGN=NAMED - --DBEMAN_ANY_VIEW_OPTION=COPYABLE --DBEMAN_ANY_VIEW_OPTION=MOVE_ONLY -``` - There are workflows available in CMake presets such as `gcc-debug`: ```bash diff --git a/include/beman/any_view/any_view.hpp b/include/beman/any_view/any_view.hpp index 18b871f..82d9ee8 100644 --- a/include/beman/any_view/any_view.hpp +++ b/include/beman/any_view/any_view.hpp @@ -3,60 +3,30 @@ #ifndef BEMAN_ANY_VIEW_ANY_VIEW_HPP #define BEMAN_ANY_VIEW_ANY_VIEW_HPP -#include -#include -#include -#include #include -#include - -#if BEMAN_ANY_VIEW_USE_ENUM() - -#include -#include - -#elif BEMAN_ANY_VIEW_USE_TRAITS() - -#include -#include - -#elif BEMAN_ANY_VIEW_USE_NAMED() - -#include - -#endif - -#include namespace beman::any_view { namespace detail { template -concept viewable_range_compatible_with = not std::same_as, AnyViewT> and - ext_viewable_range_compatible_with>; +concept viewable_range_compatible_with = + not std::same_as, AnyViewT> and ext_viewable_range_compatible_with; } // namespace detail -#if BEMAN_ANY_VIEW_USE_ENUM() - template , class DiffT = std::ptrdiff_t> class any_view : public std::ranges::view_interface> { - using iterator_concept = decltype(detail::get_iterator_concept()); + using iterator_concept = decltype(detail::get_iter_concept()); using iterator = detail::any_iterator; using sentinel = std::default_sentinel_t; using size_type = std::make_unsigned_t; - static constexpr bool sized = (OptionsV & any_view_options::sized) == any_view_options::sized; - static constexpr bool copyable = -#if BEMAN_ANY_VIEW_USE_COPYABLE() - (OptionsV & any_view_options::copyable) == any_view_options::copyable; -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - (OptionsV & any_view_options::move_only) != any_view_options::move_only; -#endif + static constexpr bool sized = (OptionsV & any_view_options::sized) == any_view_options::sized; + static constexpr bool copyable = (OptionsV & any_view_options::copyable) == any_view_options::copyable; using interface_type = detail::view_interface; // inplace storage sufficient for a vtable pointer and a std::vector @@ -96,158 +66,11 @@ class any_view : public std::ranges::view_interface -class any_view : public std::ranges::view_interface> { - using iterator_concept = detail::iterator_concept_or_t; - using reference_type = detail::reference_type_or_t; - using rvalue_reference_type = - detail::rvalue_reference_type_or_t, RangeTraitsT>; - using difference_type = detail::difference_type_or_t; - using iterator = - detail::any_iterator; - using sentinel = std::default_sentinel_t; - using size_type = std::make_unsigned_t; - - static constexpr bool sized = detail::sized_or_v; - static constexpr bool copyable = -#if BEMAN_ANY_VIEW_USE_COPYABLE() - detail::copyable_or_v; -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - not detail::move_only_or_v; -#endif - - using interface_type = - detail::view_interface; - // inplace storage sufficient for a vtable pointer and a std::vector - detail::intrusive_small_ptr view_ptr; - - template - static consteval auto get_in_place_adaptor_type() { - return std::in_place_type>>; - } - - public: - template RangeT> - constexpr any_view(RangeT&& range) - : view_ptr(get_in_place_adaptor_type(), std::views::all(std::forward(range))) {} - - constexpr any_view(const any_view&) - requires copyable - = default; - - constexpr any_view(any_view&&) noexcept = default; - - constexpr auto operator=(const any_view&) -> any_view& - requires copyable - = default; - - constexpr auto operator=(any_view&&) noexcept -> any_view& = default; - - [[nodiscard]] constexpr auto begin() -> iterator { return view_ptr->begin(); } - - [[nodiscard]] constexpr auto end() -> sentinel { return std::default_sentinel; } - - [[nodiscard]] constexpr auto size() const -> size_type - requires sized - { - return view_ptr->size(); - } -}; - -#elif BEMAN_ANY_VIEW_USE_NAMED() - -template }> -class any_view : public std::ranges::view_interface> { - using iterator_concept = decltype(OptionsV.iterator_concept)::type; - using reference_type = decltype(OptionsV.reference_type)::type; - using rvalue_reference_type = decltype(OptionsV.rvalue_reference_type)::type; - using difference_type = decltype(OptionsV.difference_type)::type; - using iterator = - detail::any_iterator; - using sentinel = std::default_sentinel_t; - using size_type = std::make_unsigned_t; - - static constexpr bool sized = OptionsV.sized; - static constexpr bool copyable = -#if BEMAN_ANY_VIEW_USE_COPYABLE() - OptionsV.copyable; -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - not OptionsV.move_only; -#endif - - using interface_type = - detail::view_interface; - // inplace storage sufficient for a vtable pointer and a std::vector - detail::intrusive_small_ptr view_ptr; - - template - static consteval auto get_in_place_adaptor_type() { - return std::in_place_type>>; - } - - public: - template RangeT> - constexpr any_view(RangeT&& range) - : view_ptr(get_in_place_adaptor_type(), std::views::all(std::forward(range))) {} - - constexpr any_view(const any_view&) - requires copyable - = default; - - constexpr any_view(any_view&&) noexcept = default; - - constexpr auto operator=(const any_view&) -> any_view& - requires copyable - = default; - - constexpr auto operator=(any_view&&) noexcept -> any_view& = default; - - [[nodiscard]] constexpr auto begin() -> iterator { return view_ptr->begin(); } - - [[nodiscard]] constexpr auto end() -> sentinel { return std::default_sentinel; } - - [[nodiscard]] constexpr auto size() const -> size_type - requires sized - { - return view_ptr->size(); - } -}; - -#endif - } // namespace beman::any_view -#if BEMAN_ANY_VIEW_USE_ENUM() - template inline constexpr bool std::ranges::enable_borrowed_range> = (OptionsV & beman::any_view::any_view_options::borrowed) == beman::any_view::any_view_options::borrowed; -#elif BEMAN_ANY_VIEW_USE_TRAITS() - -template -inline constexpr bool std::ranges::enable_borrowed_range> = - beman::any_view::detail::borrowed_or_v; - -#elif BEMAN_ANY_VIEW_USE_NAMED() - -template -inline constexpr bool std::ranges::enable_borrowed_range> = - OptionsV.borrowed; - -#endif - #endif // BEMAN_ANY_VIEW_ANY_VIEW_HPP diff --git a/include/beman/any_view/any_view_options.hpp b/include/beman/any_view/any_view_options.hpp index 1e356f9..19c234b 100644 --- a/include/beman/any_view/any_view_options.hpp +++ b/include/beman/any_view/any_view_options.hpp @@ -3,24 +3,8 @@ #ifndef BEMAN_ANY_VIEW_ANY_VIEW_OPTIONS_HPP #define BEMAN_ANY_VIEW_ANY_VIEW_OPTIONS_HPP -#include - -#if BEMAN_ANY_VIEW_USE_ENUM() - -#include - -#elif BEMAN_ANY_VIEW_USE_NAMED() - -#include - -#include - -#endif - namespace beman::any_view { -#if BEMAN_ANY_VIEW_USE_ENUM() - enum class any_view_options { input = 0b0000000, forward = 0b0000001, @@ -29,11 +13,7 @@ enum class any_view_options { contiguous = 0b0001111, sized = 0b0010000, borrowed = 0b0100000, -#if BEMAN_ANY_VIEW_USE_COPYABLE() - copyable = 0b1000000, -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - move_only = 0b1000000, -#endif + copyable = 0b1000000, }; [[nodiscard]] constexpr auto operator|(any_view_options l, any_view_options r) noexcept -> any_view_options { @@ -58,58 +38,6 @@ constexpr auto operator&=(any_view_options& l, any_view_options r) noexcept -> a constexpr auto operator^=(any_view_options& l, any_view_options r) noexcept -> any_view_options& { return l = l ^ r; } -namespace detail { - -template -[[nodiscard]] consteval auto get_iterator_concept() { - using enum any_view_options; - constexpr auto iterator_concept = OptionsV & contiguous; - - if constexpr (iterator_concept == contiguous) { - return std::contiguous_iterator_tag{}; - } else if constexpr (iterator_concept == random_access) { - return std::random_access_iterator_tag{}; - } else if constexpr (iterator_concept == bidirectional) { - return std::bidirectional_iterator_tag{}; - } else if constexpr (iterator_concept == forward) { - return std::forward_iterator_tag{}; - } else { - return std::input_iterator_tag{}; - } -} - -} // namespace detail - -#elif BEMAN_ANY_VIEW_USE_NAMED() - -template -struct type_t { - using type = T; -}; - -template -inline constexpr type_t type{}; - -template , - class DiffT = std::ptrdiff_t> -struct any_view_options { - type_t reference_type; - type_t iterator_concept = {}; - bool sized = false; -#if BEMAN_ANY_VIEW_USE_COPYABLE() - bool copyable = false; -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - bool move_only = false; -#endif - bool borrowed = false; - type_t rvalue_reference_type = {}; - type_t difference_type = {}; -}; - -#endif - } // namespace beman::any_view #endif // BEMAN_ANY_VIEW_ANY_VIEW_OPTIONS_HPP diff --git a/include/beman/any_view/concepts.hpp b/include/beman/any_view/concepts.hpp index 1f6ed67..87bac8c 100644 --- a/include/beman/any_view/concepts.hpp +++ b/include/beman/any_view/concepts.hpp @@ -4,46 +4,44 @@ #define BEMAN_ANY_VIEW_CONCEPTS_HPP #include -#include +#include + +#include namespace beman::any_view { namespace detail { -template +template concept iterator_compatible_with = - contiguous_iterator_compatible_with> and + contiguous_iterator_compatible_with> and contiguous_reference_convertible_to, - reference_type_t, - iterator_concept_t> and - std::convertible_to, rvalue_reference_type_t> and - std::convertible_to, difference_type_t>; - -template -concept sized_range_compatible_with = not RangeTraitsT::sized or std::ranges::sized_range; - -template -concept borrowed_range_compatible_with = not RangeTraitsT::borrowed or std::ranges::borrowed_range; - -template -concept copyable_view_compatible_with = -#if BEMAN_ANY_VIEW_USE_COPYABLE() - not RangeTraitsT::copyable -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - RangeTraitsT::move_only -#endif - or std::copyable; - -template + std::iter_reference_t, + iter_concept_t> and + std::convertible_to, std::iter_rvalue_reference_t> and + std::convertible_to, std::iter_difference_t>; + +template +concept sized_range_compatible_with = not std::ranges::sized_range or std::ranges::sized_range; + +template +concept borrowed_range_compatible_with = + not std::ranges::borrowed_range or std::ranges::borrowed_range; + +template +concept copyable_view_compatible_with = not std::copyable or std::copyable; + +template concept view_compatible_with = - std::ranges::view and iterator_compatible_with, RangeTraitsT> and - sized_range_compatible_with and borrowed_range_compatible_with and - copyable_view_compatible_with; + std::ranges::view and + iterator_compatible_with, std::ranges::iterator_t> and + sized_range_compatible_with and borrowed_range_compatible_with and + copyable_view_compatible_with; } // namespace detail -template +template concept ext_viewable_range_compatible_with = - std::ranges::viewable_range and detail::view_compatible_with, RangeTraitsT>; + std::ranges::viewable_range and detail::view_compatible_with, AnyViewT>; } // namespace beman::any_view diff --git a/include/beman/any_view/config.hpp.in b/include/beman/any_view/config.hpp.in deleted file mode 100644 index 5352bed..0000000 --- a/include/beman/any_view/config.hpp.in +++ /dev/null @@ -1,13 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#ifndef BEMAN_ANY_VIEW_CONFIG_HPP -#define BEMAN_ANY_VIEW_CONFIG_HPP - -#cmakedefine01 BEMAN_ANY_VIEW_USE_ENUM() -#cmakedefine01 BEMAN_ANY_VIEW_USE_TRAITS() -#cmakedefine01 BEMAN_ANY_VIEW_USE_NAMED() - -#cmakedefine01 BEMAN_ANY_VIEW_USE_COPYABLE() -#cmakedefine01 BEMAN_ANY_VIEW_USE_MOVE_ONLY() - -#endif // BEMAN_ANY_VIEW_CONFIG_HPP diff --git a/include/beman/any_view/detail/any_iterator.hpp b/include/beman/any_view/detail/any_iterator.hpp index 81b0041..8d4bf21 100644 --- a/include/beman/any_view/detail/any_iterator.hpp +++ b/include/beman/any_view/detail/any_iterator.hpp @@ -6,12 +6,6 @@ #include #include #include -#include -#include - -#include -#include -#include namespace beman::any_view::detail { @@ -21,13 +15,6 @@ class any_iterator { using rvalue_reference = RValueRefT; using pointer = std::add_pointer_t; - struct range_traits { - using iterator_concept = IterConceptT; - using reference_type = RefT; - using rvalue_reference_type = RValueRefT; - using difference_type = DiffT; - }; - static constexpr bool forward = std::derived_from; static constexpr bool bidirectional = std::derived_from; static constexpr bool random_access = std::derived_from; @@ -48,7 +35,7 @@ class any_iterator { using element_type = ElementT; using difference_type = DiffT; - template IteratorT, std::sentinel_for SentinelT> + template IteratorT, std::sentinel_for SentinelT> constexpr any_iterator(IteratorT iterator, SentinelT sentinel) : iterator_ptr(get_in_place_adaptor_type(), std::move(iterator), std::move(sentinel)) {} diff --git a/include/beman/any_view/detail/concepts.hpp b/include/beman/any_view/detail/concepts.hpp index f25cbe8..0435e97 100644 --- a/include/beman/any_view/detail/concepts.hpp +++ b/include/beman/any_view/detail/concepts.hpp @@ -3,8 +3,6 @@ #ifndef BEMAN_ANY_VIEW_DETAIL_CONCEPTS_HPP #define BEMAN_ANY_VIEW_DETAIL_CONCEPTS_HPP -#include - #include namespace beman::any_view::detail { diff --git a/include/beman/any_view/detail/type_traits.hpp b/include/beman/any_view/detail/type_traits.hpp index e307255..6fcd5c7 100644 --- a/include/beman/any_view/detail/type_traits.hpp +++ b/include/beman/any_view/detail/type_traits.hpp @@ -3,7 +3,9 @@ #ifndef BEMAN_ANY_VIEW_DETAIL_TYPE_TRAITS_HPP #define BEMAN_ANY_VIEW_DETAIL_TYPE_TRAITS_HPP -#include +#include + +#include namespace beman::any_view::detail { @@ -16,6 +18,42 @@ struct as_rvalue : std::type_identity {}; template using as_rvalue_t = as_rvalue::type; +template +[[nodiscard]] consteval auto get_iter_concept() { + using enum any_view_options; + constexpr auto iterator_concept = OptionsV & contiguous; + + if constexpr (iterator_concept == contiguous) { + return std::contiguous_iterator_tag{}; + } else if constexpr (iterator_concept == random_access) { + return std::random_access_iterator_tag{}; + } else if constexpr (iterator_concept == bidirectional) { + return std::bidirectional_iterator_tag{}; + } else if constexpr (iterator_concept == forward) { + return std::forward_iterator_tag{}; + } else { + return std::input_iterator_tag{}; + } +} + +template +[[nodiscard]] consteval auto get_iter_concept() { + if constexpr (std::contiguous_iterator) { + return std::contiguous_iterator_tag{}; + } else if constexpr (std::random_access_iterator) { + return std::random_access_iterator_tag{}; + } else if constexpr (std::bidirectional_iterator) { + return std::bidirectional_iterator_tag{}; + } else if constexpr (std::forward_iterator) { + return std::forward_iterator_tag{}; + } else { + return std::input_iterator_tag{}; + } +} + +template +using iter_concept_t = decltype(get_iter_concept()); + } // namespace beman::any_view::detail #endif // BEMAN_ANY_VIEW_DETAIL_TYPE_TRAITS_HPP diff --git a/include/beman/any_view/detail/view_adaptor.hpp b/include/beman/any_view/detail/view_adaptor.hpp index 21c65db..8315539 100644 --- a/include/beman/any_view/detail/view_adaptor.hpp +++ b/include/beman/any_view/detail/view_adaptor.hpp @@ -3,12 +3,8 @@ #ifndef BEMAN_ANY_VIEW_DETAIL_VIEW_ADAPTOR_HPP #define BEMAN_ANY_VIEW_DETAIL_VIEW_ADAPTOR_HPP -#include -#include #include -#include - namespace beman::any_view::detail { template diff --git a/include/beman/any_view/range_traits.hpp b/include/beman/any_view/range_traits.hpp deleted file mode 100644 index 7b86544..0000000 --- a/include/beman/any_view/range_traits.hpp +++ /dev/null @@ -1,95 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#ifndef BEMAN_ANY_VIEW_RANGE_TRAITS_HPP -#define BEMAN_ANY_VIEW_RANGE_TRAITS_HPP - -#include -#include - -#include - -namespace beman::any_view { -namespace detail { - -template -[[nodiscard]] consteval auto get_range_concept() { - if constexpr (std::ranges::contiguous_range) { - return std::contiguous_iterator_tag{}; - } else if constexpr (std::ranges::random_access_range) { - return std::random_access_iterator_tag{}; - } else if constexpr (std::ranges::bidirectional_range) { - return std::bidirectional_iterator_tag{}; - } else if constexpr (std::ranges::forward_range) { - return std::forward_iterator_tag{}; - } else { - return std::input_iterator_tag{}; - } -} - -template -using range_concept_t = decltype(detail::get_range_concept()); - -template class OpT, class... ArgsT> -struct detected_or : std::type_identity {}; - -template class OpT, class... ArgsT> - requires requires { typename OpT; } -struct detected_or : std::type_identity> {}; - -template class OpT, class... ArgsT> -using detected_or_t = detected_or::type; - -#define BEMAN_ANY_VIEW_TYPE_TRAIT(name) \ - template \ - using name##_t = RangeTraitsT::name; \ - \ - template \ - using name##_or_t = detected_or_t - -BEMAN_ANY_VIEW_TYPE_TRAIT(iterator_concept); -BEMAN_ANY_VIEW_TYPE_TRAIT(reference_type); -BEMAN_ANY_VIEW_TYPE_TRAIT(rvalue_reference_type); -BEMAN_ANY_VIEW_TYPE_TRAIT(difference_type); - -#undef BEMAN_ANY_VIEW_TYPE_TRAIT - -#define BEMAN_ANY_VIEW_BOOL_TRAIT(name) \ - template \ - using name = std::bool_constant; \ - \ - template \ - inline constexpr bool name##_or_v = detected_or_t, name, RangeTraitsT>::value - -BEMAN_ANY_VIEW_BOOL_TRAIT(sized); -BEMAN_ANY_VIEW_BOOL_TRAIT(borrowed); -#if BEMAN_ANY_VIEW_USE_COPYABLE() -BEMAN_ANY_VIEW_BOOL_TRAIT(copyable); -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() -BEMAN_ANY_VIEW_BOOL_TRAIT(move_only); -#endif - -#undef BEMAN_ANY_VIEW_BOOL_TRAIT - -} // namespace detail - -struct default_range_traits {}; - -template -struct range_traits { - using iterator_concept = detail::range_concept_t; - using reference_type = std::ranges::range_reference_t; - using rvalue_reference_type = std::ranges::range_rvalue_reference_t; - using difference_type = std::ranges::range_difference_t; - - static constexpr bool sized = std::ranges::sized_range; - static constexpr bool borrowed = std::ranges::borrowed_range; -#if BEMAN_ANY_VIEW_USE_COPYABLE() - static constexpr bool copyable = std::copyable; -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - static constexpr bool move_only = not std::copyable; -#endif -}; - -} // namespace beman::any_view - -#endif // BEMAN_ANY_VIEW_RANGE_TRAITS_HPP diff --git a/tests/beman/any_view/concepts.test.cpp b/tests/beman/any_view/concepts.test.cpp index 3d60aaf..a190984 100644 --- a/tests/beman/any_view/concepts.test.cpp +++ b/tests/beman/any_view/concepts.test.cpp @@ -2,83 +2,69 @@ #include -#include "options.hpp" - #include using beman::any_view::any_view; +using enum beman::any_view::any_view_options; TEST(ConceptsTest, iterator_concept) { static_assert(std::ranges::input_range>); static_assert(not std::ranges::forward_range>); - static_assert(std::ranges::input_range>); - static_assert(not std::ranges::forward_range>); - static_assert(std::ranges::forward_range>); - static_assert(not std::ranges::bidirectional_range>); - static_assert(std::ranges::bidirectional_range>); - static_assert(not std::ranges::random_access_range>); - static_assert(std::ranges::random_access_range>); - static_assert(not std::ranges::contiguous_range>); - static_assert(std::ranges::contiguous_range>); + static_assert(std::ranges::input_range>); + static_assert(not std::ranges::forward_range>); + static_assert(std::ranges::forward_range>); + static_assert(not std::ranges::bidirectional_range>); + static_assert(std::ranges::bidirectional_range>); + static_assert(not std::ranges::random_access_range>); + static_assert(std::ranges::random_access_range>); + static_assert(not std::ranges::contiguous_range>); + static_assert(std::ranges::contiguous_range>); - static_assert(std::ranges::input_range>); - static_assert(not std::ranges::forward_range>); - static_assert(std::ranges::input_range>); - static_assert(not std::ranges::forward_range>); - static_assert(std::ranges::input_range>); - static_assert(not std::ranges::forward_range>); - static_assert(std::ranges::input_range>); - static_assert(not std::ranges::forward_range>); - static_assert(std::ranges::input_range>); - static_assert(not std::ranges::forward_range>); + static_assert(std::ranges::input_range>); + static_assert(not std::ranges::forward_range>); + static_assert(std::ranges::input_range>); + static_assert(not std::ranges::forward_range>); + static_assert(std::ranges::input_range>); + static_assert(not std::ranges::forward_range>); + static_assert(std::ranges::input_range>); + static_assert(not std::ranges::forward_range>); } TEST(ConceptsTest, sized_concept) { static_assert(not std::ranges::sized_range>); - static_assert(std::ranges::sized_range>); + static_assert(std::ranges::sized_range>); - static_assert(not std::ranges::sized_range>); - static_assert(not std::ranges::sized_range>); - static_assert(not std::ranges::sized_range>); - static_assert(not std::ranges::sized_range>); - static_assert(not std::ranges::sized_range>); - static_assert(not std::ranges::sized_range>); - static_assert(not std::ranges::sized_range>); - static_assert(not std::ranges::sized_range>); + static_assert(not std::ranges::sized_range>); + static_assert(not std::ranges::sized_range>); + static_assert(not std::ranges::sized_range>); + static_assert(not std::ranges::sized_range>); + static_assert(not std::ranges::sized_range>); + static_assert(not std::ranges::sized_range>); + static_assert(not std::ranges::sized_range>); } TEST(ConceptsTest, borrowed_concept) { static_assert(not std::ranges::borrowed_range>); - static_assert(std::ranges::borrowed_range>); + static_assert(std::ranges::borrowed_range>); - static_assert(not std::ranges::borrowed_range>); - static_assert(not std::ranges::borrowed_range>); - static_assert(not std::ranges::borrowed_range>); - static_assert(not std::ranges::borrowed_range>); - static_assert(not std::ranges::borrowed_range>); - static_assert(not std::ranges::borrowed_range>); - static_assert(not std::ranges::borrowed_range>); - static_assert(not std::ranges::borrowed_range>); + static_assert(not std::ranges::borrowed_range>); + static_assert(not std::ranges::borrowed_range>); + static_assert(not std::ranges::borrowed_range>); + static_assert(not std::ranges::borrowed_range>); + static_assert(not std::ranges::borrowed_range>); + static_assert(not std::ranges::borrowed_range>); + static_assert(not std::ranges::borrowed_range>); } TEST(ConceptsTest, copyable_concept) { -#if BEMAN_ANY_VIEW_USE_COPYABLE() static_assert(not std::copyable>); - static_assert(not std::copyable>); - static_assert(std::copyable>); -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() - static_assert(std::copyable>); - static_assert(std::copyable>); - static_assert(not std::copyable>); -#endif + static_assert(std::copyable>); - // the outcome of these options would normally depend on copyable/move_only configuration, but for testing - // purposes, other options opt-in to move-only behavior for both configured modes - static_assert(not std::copyable>); - static_assert(not std::copyable>); - static_assert(not std::copyable>); - static_assert(not std::copyable>); - static_assert(not std::copyable>); - static_assert(not std::copyable>); - static_assert(not std::copyable>); + static_assert(not std::copyable>); + static_assert(not std::copyable>); + static_assert(not std::copyable>); + static_assert(not std::copyable>); + static_assert(not std::copyable>); + static_assert(not std::copyable>); + static_assert(not std::copyable>); } diff --git a/tests/beman/any_view/constexpr.test.cpp b/tests/beman/any_view/constexpr.test.cpp index 2113851..289999b 100644 --- a/tests/beman/any_view/constexpr.test.cpp +++ b/tests/beman/any_view/constexpr.test.cpp @@ -2,49 +2,15 @@ #include -#include "options.hpp" - #include #include -#include using beman::any_view::any_view; - -#if BEMAN_ANY_VIEW_USE_ENUM() using enum beman::any_view::any_view_options; template -using proxy_any_view = any_view; -#elif BEMAN_ANY_VIEW_USE_TRAITS() -template -struct proxy_traits { - using reference_type = ValueT; -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - static constexpr bool move_only = true; -#endif -}; - -template -using proxy_any_view = any_view>; -#elif BEMAN_ANY_VIEW_USE_NAMED() -using beman::any_view::type; - -template -using proxy_any_view = any_view, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true, -#endif - }>; -#endif +using proxy_any_view = any_view; constexpr auto sum(proxy_any_view> views) { auto result = 0; @@ -86,7 +52,7 @@ TEST(ConstexprTest, sum_vector_of_iota_view) { EXPECT_EQ(22, sum(std::vector{iota(1), iota(3), iota(5)})); } -constexpr auto sort(any_view view) { +constexpr auto sort(any_view view) { std::ranges::sort(view); return std::ranges::is_sorted(view); } diff --git a/tests/beman/any_view/options.hpp b/tests/beman/any_view/options.hpp deleted file mode 100644 index 2821d4a..0000000 --- a/tests/beman/any_view/options.hpp +++ /dev/null @@ -1,124 +0,0 @@ -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -#ifndef BEMAN_ANY_VIEW_TEST_OPTIONS_HPP -#define BEMAN_ANY_VIEW_TEST_OPTIONS_HPP - -#include - -#if BEMAN_ANY_VIEW_USE_ENUM() - -#include - -using options = beman::any_view::any_view_options; - -#if BEMAN_ANY_VIEW_USE_COPYABLE() -inline constexpr auto copyable_options = options::copyable; -inline constexpr auto move_only_options = options{}; -#elif BEMAN_ANY_VIEW_USE_MOVE_ONLY() -inline constexpr auto copyable_options = options{}; -inline constexpr auto move_only_options = options::move_only; -#endif - -inline constexpr auto input_options = move_only_options | options::input; -inline constexpr auto forward_options = move_only_options | options::forward; -inline constexpr auto bidirectional_options = move_only_options | options::bidirectional; -inline constexpr auto random_access_options = move_only_options | options::random_access; -inline constexpr auto contiguous_options = move_only_options | options::contiguous; -inline constexpr auto sized_options = move_only_options | options::sized; -inline constexpr auto borrowed_options = move_only_options | options::borrowed; - -#elif BEMAN_ANY_VIEW_USE_TRAITS() - -#include - -struct copyable_options { -#if BEMAN_ANY_VIEW_USE_COPYABLE() - static constexpr bool copyable = true; -#endif -}; - -struct move_only_options { -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - static constexpr bool move_only = true; -#endif -}; - -template -struct iterator_options : move_only_options { - using iterator_concept = IterConceptT; -}; - -using input_options = iterator_options; -using forward_options = iterator_options; -using bidirectional_options = iterator_options; -using random_access_options = iterator_options; -using contiguous_options = iterator_options; - -struct sized_options : move_only_options { - static constexpr bool sized = true; -}; - -struct borrowed_options : move_only_options { - static constexpr bool borrowed = true; -}; - -template -struct inherit : OptionsT... {}; - -#elif BEMAN_ANY_VIEW_USE_NAMED() - -#include - -using beman::any_view::any_view_options; -using beman::any_view::type; - -inline constexpr auto default_reference_type = type; - -inline constexpr any_view_options copyable_options{ - .reference_type = default_reference_type, -#if BEMAN_ANY_VIEW_USE_COPYABLE() - .copyable = true, -#endif -}; - -inline constexpr any_view_options move_only_options{ - .reference_type = default_reference_type, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true, -#endif -}; - -template -inline constexpr any_view_options iterator_options{ - .reference_type = default_reference_type, - .iterator_concept = type, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true, -#endif -}; - -inline constexpr auto input_options = iterator_options; -inline constexpr auto forward_options = iterator_options; -inline constexpr auto bidirectional_options = iterator_options; -inline constexpr auto random_access_options = iterator_options; -inline constexpr auto contiguous_options = iterator_options; - -inline constexpr any_view_options sized_options{ - .reference_type = default_reference_type, - .sized = true, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true, -#endif -}; - -inline constexpr any_view_options borrowed_options{ - .reference_type = default_reference_type, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true, -#endif - .borrowed = true, -}; - -#endif - -#endif // BEMAN_ANY_VIEW_TEST_OPTIONS_HPP diff --git a/tests/beman/any_view/sfinae.test.cpp b/tests/beman/any_view/sfinae.test.cpp index 7796c44..3173c5a 100644 --- a/tests/beman/any_view/sfinae.test.cpp +++ b/tests/beman/any_view/sfinae.test.cpp @@ -2,154 +2,83 @@ #include -#include "options.hpp" - #include #include #include #include -#include -#include using beman::any_view::any_view; +using enum beman::any_view::any_view_options; TEST(SfinaeTest, istream_view) { - static_assert(std::constructible_from, std::ranges::istream_view>); - static_assert(not std::constructible_from, std::ranges::istream_view>); - static_assert(std::constructible_from, std::ranges::istream_view>); - static_assert(not std::constructible_from, std::ranges::istream_view>); - static_assert(not std::constructible_from, std::ranges::istream_view>); + static_assert(std::constructible_from, std::ranges::istream_view>); + static_assert(not std::constructible_from, std::ranges::istream_view>); + static_assert(std::constructible_from, std::ranges::istream_view>); + static_assert(not std::constructible_from, std::ranges::istream_view>); + static_assert(not std::constructible_from, std::ranges::istream_view>); // This may be surprising, but any_view makes a copy of an lvalue reference to view because of std::views::all // It limits some use-cases, but it also prevents some potential dangling when returning any_view from a function - static_assert(not std::constructible_from, std::ranges::istream_view&>); + static_assert(not std::constructible_from, std::ranges::istream_view&>); } TEST(SfinaeTest, forward_list) { - static_assert(std::constructible_from, std::forward_list>); - static_assert(not std::constructible_from, std::forward_list>); - static_assert(not std::constructible_from, std::forward_list>); - static_assert(not std::constructible_from, std::forward_list>); - static_assert(not std::constructible_from, std::forward_list>); - - static_assert(std::constructible_from, std::forward_list&>); - static_assert(std::constructible_from, std::forward_list&>); + static_assert(std::constructible_from, std::forward_list>); + static_assert(not std::constructible_from, std::forward_list>); + static_assert(not std::constructible_from, std::forward_list>); + static_assert(not std::constructible_from, std::forward_list>); + static_assert(not std::constructible_from, std::forward_list>); + + static_assert(std::constructible_from, std::forward_list&>); + static_assert(std::constructible_from, std::forward_list&>); } TEST(SfinaeTest, list) { - static_assert(std::constructible_from, std::list>); - static_assert(not std::constructible_from, std::list>); - static_assert(std::constructible_from, std::list>); - static_assert(not std::constructible_from, std::list>); - static_assert(not std::constructible_from, std::list>); - - static_assert(std::constructible_from, std::list&>); - static_assert(std::constructible_from, std::list&>); + static_assert(std::constructible_from, std::list>); + static_assert(not std::constructible_from, std::list>); + static_assert(std::constructible_from, std::list>); + static_assert(not std::constructible_from, std::list>); + static_assert(not std::constructible_from, std::list>); + + static_assert(std::constructible_from, std::list&>); + static_assert(std::constructible_from, std::list&>); } TEST(SfinaeTest, deque) { - static_assert(std::constructible_from, std::deque>); - static_assert(not std::constructible_from, std::deque>); - static_assert(std::constructible_from, std::deque>); - static_assert(not std::constructible_from, std::deque>); - static_assert(not std::constructible_from, std::deque>); - - static_assert(std::constructible_from, std::deque&>); - static_assert(std::constructible_from, std::deque&>); + static_assert(std::constructible_from, std::deque>); + static_assert(not std::constructible_from, std::deque>); + static_assert(std::constructible_from, std::deque>); + static_assert(not std::constructible_from, std::deque>); + static_assert(not std::constructible_from, std::deque>); + + static_assert(std::constructible_from, std::deque&>); + static_assert(std::constructible_from, std::deque&>); } TEST(SfinaeTest, vector) { - static_assert(std::constructible_from, std::vector>); - static_assert(std::constructible_from, std::vector>); - static_assert(not std::constructible_from, std::vector>); - static_assert(not std::constructible_from, std::vector>); + static_assert(std::constructible_from, std::vector>); + static_assert(std::constructible_from, std::vector>); + static_assert(not std::constructible_from, std::vector>); + static_assert(not std::constructible_from, std::vector>); - static_assert(std::constructible_from, std::vector&>); - static_assert(std::constructible_from, std::vector&>); + static_assert(std::constructible_from, std::vector&>); + static_assert(std::constructible_from, std::vector&>); } -template -struct traits : BaseTraitsT { - using reference_type = bool; -}; - TEST(SfinaeTest, vector_of_bool) { -#if BEMAN_ANY_VIEW_USE_ENUM() - static_assert(std::constructible_from, std::vector>); - static_assert(std::constructible_from, std::vector>); - static_assert(not std::constructible_from, std::vector>); - static_assert(not std::constructible_from, std::vector>); - - static_assert(std::constructible_from, std::vector&>); - static_assert(std::constructible_from, std::vector&>); -#elif BEMAN_ANY_VIEW_USE_TRAITS() - static_assert(std::constructible_from>, std::vector>); - static_assert(std::constructible_from>, std::vector>); - static_assert(not std::constructible_from>, std::vector>); - static_assert(not std::constructible_from>, std::vector>); - - static_assert(std::constructible_from>, std::vector&>); - static_assert(std::constructible_from>, std::vector&>); -#elif BEMAN_ANY_VIEW_USE_NAMED() - static_assert(std::constructible_from, - .iterator_concept = type, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true -#endif - }>, - std::vector>); - static_assert(std::constructible_from, - .sized = true, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true -#endif - }>, - std::vector>); - static_assert(std::constructible_from, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true -#endif - }>, - std::vector>); - static_assert(not std::constructible_from, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true, -#endif - .borrowed = true}>, - std::vector>); - static_assert(not std::constructible_from, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true, -#endif - .borrowed = true}>, - std::vector>); - - static_assert(std::constructible_from, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true, -#endif - .borrowed = true}>, - std::vector&>); - static_assert(std::constructible_from, -#if BEMAN_ANY_VIEW_USE_MOVE_ONLY() - .move_only = true, -#endif - .borrowed = true}>, - std::vector&>); -#endif + static_assert(std::constructible_from, std::vector>); + static_assert(std::constructible_from, std::vector>); + static_assert(not std::constructible_from, std::vector>); + static_assert(not std::constructible_from, std::vector>); + + static_assert(std::constructible_from, std::vector&>); + static_assert(std::constructible_from, std::vector&>); } TEST(SfinaeTest, span) { - static_assert(std::constructible_from, std::span>); - static_assert(std::constructible_from, std::span>); - static_assert(std::constructible_from, std::span>); - static_assert(std::constructible_from, std::span>); + static_assert(std::constructible_from, std::span>); + static_assert(std::constructible_from, std::span>); + static_assert(std::constructible_from, std::span>); + static_assert(std::constructible_from, std::span>); } diff --git a/tests/beman/any_view/type_traits.test.cpp b/tests/beman/any_view/type_traits.test.cpp index b9b6978..f04927b 100644 --- a/tests/beman/any_view/type_traits.test.cpp +++ b/tests/beman/any_view/type_traits.test.cpp @@ -4,9 +4,9 @@ #include -#include - using beman::any_view::any_view; +using enum beman::any_view::any_view_options; + using value = std::pair; using lvalue = std::pair; using rvalue = std::pair; @@ -18,156 +18,48 @@ TEST(TypeTraitsTest, value_type) { static_assert(std::same_as>, value>); } -#if BEMAN_ANY_VIEW_USE_ENUM() - -using enum beman::any_view::any_view_options; - -#elif BEMAN_ANY_VIEW_USE_TRAITS() - -struct value_traits { - using reference_type = value; -}; - -struct lvalue_traits { - using reference_type = lvalue; -}; - -#elif BEMAN_ANY_VIEW_USE_NAMED() - -using beman::any_view::type; - -#endif - TEST(TypeTraitsTest, reference_type) { using std::ranges::range_reference_t; static_assert(std::same_as>, value&>); static_assert(std::same_as>, const value&>); -#if BEMAN_ANY_VIEW_USE_ENUM() static_assert(std::same_as>, value>); static_assert(std::same_as>, lvalue>); -#elif BEMAN_ANY_VIEW_USE_TRAITS() - static_assert(std::same_as>, value>); - static_assert(std::same_as>, lvalue>); -#elif BEMAN_ANY_VIEW_USE_NAMED() - static_assert(std::same_as}>>, value>); - static_assert(std::same_as}>>, lvalue>); -#endif } -#if BEMAN_ANY_VIEW_USE_TRAITS() - -struct rvalue_traits { - using rvalue_reference_type = rvalue; -}; - -#endif - TEST(TypeTraitsTest, rvalue_reference_type) { using std::ranges::range_rvalue_reference_t; static_assert(std::same_as>, value&&>); static_assert(std::same_as>, const value&&>); -#if BEMAN_ANY_VIEW_USE_ENUM() static_assert(std::same_as>, value>); static_assert(std::same_as>, lvalue>); static_assert(std::same_as>, rvalue>); -#elif BEMAN_ANY_VIEW_USE_TRAITS() - static_assert(std::same_as>, value>); - static_assert(std::same_as>, lvalue>); - static_assert(std::same_as>, rvalue>); -#elif BEMAN_ANY_VIEW_USE_NAMED() - static_assert(std::same_as}>>, value>); - static_assert(std::same_as}>>, lvalue>); - static_assert( - std::same_as, .rvalue_reference_type = type}>>, - rvalue>); -#endif } -#if BEMAN_ANY_VIEW_USE_TRAITS() - -struct difference_traits { - using difference_type = short; -}; - -#endif - TEST(TypeTraitsTest, difference_type) { using std::ranges::range_difference_t; static_assert(std::same_as>, std::ptrdiff_t>); -#if BEMAN_ANY_VIEW_USE_ENUM() static_assert(std::same_as>, short>); -#elif BEMAN_ANY_VIEW_USE_TRAITS() - static_assert(std::same_as>, short>); -#elif BEMAN_ANY_VIEW_USE_NAMED() - static_assert( - std::same_as< - range_difference_t, .difference_type = type}>>, - short>); -#endif } -#if BEMAN_ANY_VIEW_USE_TRAITS() - -struct sized_traits { - static constexpr bool sized = true; -}; - -struct sized_difference_traits : sized_traits { - using difference_type = short; -}; - -#endif - TEST(TypeTraitsTest, size_type) { using std::ranges::range_size_t; -#if BEMAN_ANY_VIEW_USE_ENUM() static_assert(std::same_as>, std::size_t>); static_assert(std::same_as>, unsigned short>); -#elif BEMAN_ANY_VIEW_USE_TRAITS() - static_assert(std::same_as>, std::size_t>); - static_assert(std::same_as>, unsigned short>); -#elif BEMAN_ANY_VIEW_USE_NAMED() - static_assert( - std::same_as, .sized = true}>>, std::size_t>); - static_assert( - std::same_as< - range_size_t< - any_view, .sized = true, .difference_type = type}>>, - unsigned short>); -#endif } -#if BEMAN_ANY_VIEW_USE_TRAITS() - -struct borrowed_traits { - static constexpr bool borrowed = true; -}; - -#endif - TEST(TypeTraitsTest, borrowed_iterator_type) { using std::ranges::borrowed_iterator_t; using std::ranges::iterator_t; static_assert(std::same_as>, std::ranges::dangling>); -#if BEMAN_ANY_VIEW_USE_ENUM() static_assert(std::same_as>, iterator_t>>); -#elif BEMAN_ANY_VIEW_USE_TRAITS() - static_assert(std::same_as>, - iterator_t>>); -#elif BEMAN_ANY_VIEW_USE_NAMED() - static_assert( - std::same_as, .borrowed = true}>>, - iterator_t, .borrowed = true}>>>); -#endif }