Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:14:02

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___RANGES_SINGLE_VIEW_H
0011 #define _LIBCPP___RANGES_SINGLE_VIEW_H
0012 
0013 #include <__concepts/constructible.h>
0014 #include <__config>
0015 #include <__cstddef/ptrdiff_t.h>
0016 #include <__cstddef/size_t.h>
0017 #include <__ranges/movable_box.h>
0018 #include <__ranges/range_adaptor.h>
0019 #include <__ranges/view_interface.h>
0020 #include <__type_traits/decay.h>
0021 #include <__type_traits/is_object.h>
0022 #include <__utility/forward.h>
0023 #include <__utility/in_place.h>
0024 #include <__utility/move.h>
0025 
0026 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0027 #  pragma GCC system_header
0028 #endif
0029 
0030 _LIBCPP_PUSH_MACROS
0031 #include <__undef_macros>
0032 
0033 _LIBCPP_BEGIN_NAMESPACE_STD
0034 
0035 #if _LIBCPP_STD_VER >= 20
0036 
0037 namespace ranges {
0038 #  if _LIBCPP_STD_VER >= 23
0039 template <move_constructible _Tp>
0040 #  else
0041 template <copy_constructible _Tp>
0042 #  endif
0043   requires is_object_v<_Tp>
0044 class _LIBCPP_ABI_LLVM18_NO_UNIQUE_ADDRESS single_view : public view_interface<single_view<_Tp>> {
0045   _LIBCPP_NO_UNIQUE_ADDRESS __movable_box<_Tp> __value_;
0046 
0047 public:
0048   _LIBCPP_HIDE_FROM_ABI single_view()
0049     requires default_initializable<_Tp>
0050   = default;
0051 
0052   _LIBCPP_HIDE_FROM_ABI constexpr explicit single_view(const _Tp& __t)
0053 #  if _LIBCPP_STD_VER >= 23
0054     requires copy_constructible<_Tp>
0055 #  endif
0056       : __value_(in_place, __t) {
0057   }
0058 
0059   _LIBCPP_HIDE_FROM_ABI constexpr explicit single_view(_Tp&& __t) : __value_(in_place, std::move(__t)) {}
0060 
0061   template <class... _Args>
0062     requires constructible_from<_Tp, _Args...>
0063   _LIBCPP_HIDE_FROM_ABI constexpr explicit single_view(in_place_t, _Args&&... __args)
0064       : __value_{in_place, std::forward<_Args>(__args)...} {}
0065 
0066   _LIBCPP_HIDE_FROM_ABI constexpr _Tp* begin() noexcept { return data(); }
0067 
0068   _LIBCPP_HIDE_FROM_ABI constexpr const _Tp* begin() const noexcept { return data(); }
0069 
0070   _LIBCPP_HIDE_FROM_ABI constexpr _Tp* end() noexcept { return data() + 1; }
0071 
0072   _LIBCPP_HIDE_FROM_ABI constexpr const _Tp* end() const noexcept { return data() + 1; }
0073 
0074   _LIBCPP_HIDE_FROM_ABI static constexpr bool empty() noexcept { return false; }
0075 
0076   _LIBCPP_HIDE_FROM_ABI static constexpr size_t size() noexcept { return 1; }
0077 
0078   _LIBCPP_HIDE_FROM_ABI constexpr _Tp* data() noexcept { return __value_.operator->(); }
0079 
0080   _LIBCPP_HIDE_FROM_ABI constexpr const _Tp* data() const noexcept { return __value_.operator->(); }
0081 };
0082 
0083 template <class _Tp>
0084 single_view(_Tp) -> single_view<_Tp>;
0085 
0086 namespace views {
0087 namespace __single_view {
0088 
0089 struct __fn : __range_adaptor_closure<__fn> {
0090   template <class _Range>
0091   [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Range&& __range) const
0092       noexcept(noexcept(single_view<decay_t<_Range&&>>(std::forward<_Range>(__range))))
0093           -> decltype(single_view<decay_t<_Range&&>>(std::forward<_Range>(__range))) {
0094     return single_view<decay_t<_Range&&>>(std::forward<_Range>(__range));
0095   }
0096 };
0097 } // namespace __single_view
0098 
0099 inline namespace __cpo {
0100 inline constexpr auto single = __single_view::__fn{};
0101 } // namespace __cpo
0102 
0103 } // namespace views
0104 } // namespace ranges
0105 
0106 #endif // _LIBCPP_STD_VER >= 20
0107 
0108 _LIBCPP_END_NAMESPACE_STD
0109 
0110 _LIBCPP_POP_MACROS
0111 
0112 #endif // _LIBCPP___RANGES_SINGLE_VIEW_H