sparrow 1.3.0
Loading...
Searching...
No Matches
bool8_array.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 implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#pragma once
16
19
20namespace sparrow
21{
38 using bool8_array = primitive_array<int8_t, simple_extension<"arrow.bool8">, bool>;
39
40
41}
42
43#if defined(__cpp_lib_format)
44# include <format>
45
46// Formatter specialization for bool8_array
47template <>
48struct std::formatter<sparrow::bool8_array>
49{
50 constexpr auto parse(std::format_parse_context& ctx)
51 {
52 return ctx.begin();
53 }
54
55 auto format(const sparrow::bool8_array& ar, std::format_context& ctx) const
56 {
57 std::format_to(ctx.out(), "Bool8 array [{}]: [", ar.size());
58 for (std::size_t i = 0; i < ar.size(); ++i)
59 {
60 if (i > 0)
61 {
62 std::format_to(ctx.out(), ", ");
63 }
64 const auto elem = ar[i];
65 if (elem.has_value())
66 {
67 std::format_to(ctx.out(), "{}", static_cast<bool>(elem.value()) ? "true" : "false");
68 }
69 else
70 {
71 std::format_to(ctx.out(), "null");
72 }
73 }
74 return std::format_to(ctx.out(), "]");
75 }
76};
77
78namespace sparrow
79{
80 inline std::ostream& operator<<(std::ostream& os, const bool8_array& value)
81 {
82 os << std::format("{}", value);
83 return os;
84 }
85}
86
87#endif
std::ostream & operator<<(std::ostream &os, const nullval_t &)
primitive_array_impl< T, Ext, T2 > primitive_array
Array of values of whose type has fixed binary size.
primitive_array< int8_t, simple_extension<"arrow.bool8">, bool > bool8_array
Bool8 array using 8-bit storage for boolean values.