Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/beman/any_view/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ target_sources(
detail/default_iterator.hpp
detail/default_view.hpp
detail/iterator.hpp
detail/lifetimebound.hpp
detail/no_unique_address.hpp
detail/polymorphic.hpp
detail/polymorphic_iterator.hpp
Expand Down
15 changes: 15 additions & 0 deletions include/beman/any_view/any_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <beman/any_view/concepts.hpp>
#include <beman/any_view/detail/iterator.hpp>
#include <beman/any_view/detail/lifetimebound.hpp>
#include <beman/any_view/detail/polymorphic_view.hpp>

namespace beman::any_view {
Expand Down Expand Up @@ -132,6 +133,20 @@ class any_view : public std::ranges::view_interface<any_view<ElementT, OptsV, Re
}
}

#ifdef BEMAN_ANY_VIEW_LIFETIMEBOUND
template <class RangeT>
requires(not std::ranges::enable_view<std::remove_cv_t<RangeT>>) and
ext_any_compatible_range<RangeT&, RefT, RValueRefT, DiffT, OptsV>
constexpr any_view(BEMAN_ANY_VIEW_LIFETIMEBOUND RangeT& range)
: poly(adaptor_for<std::views::all_t<RangeT&>>{.view = std::views::all(range)}) {
static_assert(std::ranges::viewable_range<RangeT&>, "range must be viewable");
if constexpr (copyable) {
static_assert(std::copyable<std::views::all_t<RangeT&>>,
"range must be convertible to copyable view if any_view is copyable");
}
}
#endif // BEMAN_ANY_VIEW_LIFETIMEBOUND

constexpr any_view() noexcept = default;

constexpr any_view(const any_view&)
Expand Down
16 changes: 16 additions & 0 deletions include/beman/any_view/detail/lifetimebound.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#ifndef BEMAN_ANY_VIEW_DETAIL_LIFETIMEBOUND_HPP
#define BEMAN_ANY_VIEW_DETAIL_LIFETIMEBOUND_HPP

#ifndef BEMAN_ANY_VIEW_LIFETIMEBOUND
#ifdef __has_cpp_attribute
#if __has_cpp_attribute(clang::lifetimebound)
#define BEMAN_ANY_VIEW_LIFETIMEBOUND [[clang::lifetimebound]]
#elif __has_cpp_attribute(msvc::lifetimebound)
#define BEMAN_ANY_VIEW_LIFETIMEBOUND [[msvc::lifetimebound]]
#endif
#endif // __has_cpp_attribute
#endif // BEMAN_ANY_VIEW_LIFETIMEBOUND

#endif // BEMAN_ANY_VIEW_DETAIL_LIFETIMEBOUND_HPP
10 changes: 7 additions & 3 deletions include/beman/any_view/detail/no_unique_address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@
#define BEMAN_ANY_VIEW_DETAIL_NO_UNIQUE_ADDRESS_HPP

#ifndef BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS
#if _MSC_VER
#ifndef __has_cpp_attribute
#define BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS
#elif __has_cpp_attribute(msvc::no_unique_address)
#define BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#else
#elif __has_cpp_attribute(no_unique_address)
#define BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS [[no_unique_address]]
#endif // _MSC_VER
#else
#define BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS
#endif // __has_cpp_attribute
#endif // BEMAN_ANY_VIEW_NO_UNIQUE_ADDRESS

#endif // BEMAN_ANY_VIEW_DETAIL_NO_UNIQUE_ADDRESS_HPP
Loading