sparrow 0.3.0
Loading...
Searching...
No Matches
timestamp_reference.hpp
Go to the documentation of this file.
1// Copyright 2024 Man Group Operations Limited
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or mplied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
17#if defined(__cpp_lib_format)
18# include <format>
19# include <ostream>
20#endif
21
23
24namespace sparrow
25{
31 template <class L>
33 {
34 public:
35
37 using value_type = typename L::inner_value_type;
38 using reference = typename L::inner_reference;
39 using const_reference = typename L::inner_const_reference;
40 using size_type = typename L::size_type;
41 using difference_type = std::ptrdiff_t;
42
46
49
50 bool operator==(const value_type& rhs) const;
51 auto operator<=>(const value_type& rhs) const;
52
53 private:
54
55 [[nodiscard]] L::inner_value_type value() const
56 {
57 return static_cast<const L*>(p_layout)->value(m_index);
58 }
59
60 L* p_layout = nullptr;
61 size_type m_index = size_type(0);
62#if defined(__cpp_lib_format)
63 friend std::formatter<timestamp_reference<L>>;
64#endif
65 };
66}
67
68namespace std
69
70{
71 template <typename Layout, typename T, template <typename> typename TQual, template <typename> typename UQual>
72 struct basic_common_reference<sparrow::timestamp_reference<Layout>, sparrow::timestamp<T>, TQual, UQual>
73 {
74 using type = T;
75 };
76
77 template <typename Layout, typename T, template <typename> typename TQual, template <class> class UQual>
78 struct basic_common_reference<sparrow::timestamp<T>, sparrow::timestamp_reference<Layout>, TQual, UQual>
79 {
80 using type = T;
81 };
82}
83
84namespace sparrow
85{
86 /*************************************
87 * timestamp_reference implementation *
88 *************************************/
89
90 template <typename L>
92 : p_layout(layout)
93 , m_index(index)
94 {
95 }
96
97 template <typename L>
99 {
100 p_layout->assign(std::forward<value_type>(rhs), m_index);
101 return *this;
102 }
103
104 template <typename L>
106 {
107 p_layout->assign(rhs, m_index);
108 return *this;
109 }
110
111 template <typename L>
113 {
114 const auto& value = static_cast<const L*>(p_layout)->value(m_index);
115 return value == rhs;
116 }
117
118 template <typename L>
120 {
121 return lexicographical_compare_three_way(*this, rhs);
122 }
123}
124
125#if defined(__cpp_lib_format)
126
127template <typename L>
128struct std::formatter<sparrow::timestamp_reference<L>>
129{
130 constexpr auto parse(std::format_parse_context& ctx)
131 {
132 return ctx.begin(); // Simple implementation
133 }
134
135 auto format(const sparrow::timestamp_reference<L>& ref, std::format_context& ctx) const
136 {
137 const auto& value = ref.value();
138 return std::format_to(ctx.out(), "{}", value);
139 }
140};
141
142template <typename L>
143inline std::ostream& operator<<(std::ostream& os, const sparrow::timestamp_reference<L>& value)
144{
145 os << std::format("{}", value);
146 return os;
147}
148
149#endif
Implementation of reference to inner type used for layout L.
timestamp_reference(L *layout, size_type index)
timestamp_reference< self_type > self_type
bool operator==(const value_type &rhs) const
typename self_type::inner_value_type value_type
self_type & operator=(const value_type &rhs)
typename self_type::inner_reference reference
timestamp_reference(const timestamp_reference &)=default
auto operator<=>(const value_type &rhs) const
timestamp_reference(timestamp_reference &&)=default
typename self_type::inner_const_reference const_reference
self_type & operator=(value_type &&rhs)
date::zoned_time< Duration, TimeZonePtr > timestamp
std::ostream & operator<<(std::ostream &stream, T n)
Definition large_int.hpp:93