Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:41

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