GeoDesk for C++
Fast and storage-efficient spatial database engine for OpenStreetMap features
Loading...
Searching...
No Matches
streamable.h
Go to the documentation of this file.
1// Copyright (c) 2025 Clarisma / GeoDesk contributors
2// SPDX-License-Identifier: LGPL-3.0-only
3
4#pragma once
5#include <iosfwd> // forward declares std::ostream
6#include <concepts> // std::same_as
7
8namespace clarisma
9{
10
12template<typename T>
13concept OstreamFormattable =
14 requires (const T& t, std::ostream& os)
15{
16 { t.template format<std::ostream>(os) } -> std::same_as<void>;
17};
18
22template<typename T>
23 requires OstreamFormattable<T>
24std::ostream& operator<<(std::ostream& os, const T& value)
25{
26 value.template format<std::ostream>(os);
27 return os;
28}
29
30} // namespace clarisma
31
32/*
33
34#pragma once
35#include <concepts>
36#include <cstddef>
37#include <type_traits>
38
39namespace clarisma {
40
41class Buffer;
42
44template<typename S>
45concept NotBufferLike =
46 !std::is_base_of_v<Buffer, std::remove_reference_t<S>>;
47
50template<typename S>
51concept StreamLike =
52 requires (S& s)
53{
54 // std::ostream-like: write(const char*, streamsize)
55 s.write(static_cast<const char*>(nullptr), 0);
56} ||
57requires (S& s)
58{
59 // byte-sink-like: write(const void*, size_t)
60 s.write(static_cast<const void*>(nullptr), std::size_t{});
61};
62
64template<typename T, typename S>
65concept FormatsWith =
66 requires (const T& t, S& s)
67{
68 { t.template format<S>(s) } -> std::same_as<void>;
69};
70
74template<typename Stream, typename T>
75 requires NotBufferLike<Stream> && StreamLike<Stream> &&
76 FormatsWith<T, Stream>
77Stream& operator<<(Stream& s, const T& value)
78{
79 value.template format<Stream>(s);
80 return s;
81}
82
83} // namespace clarisma
84
85*/
Definition Arena.h:17
Buffer & operator<<(Buffer &buf, std::string_view s)
Definition Buffer.h:198