LILAC
Language to language Interop LAyer Compiler
Loading...
Searching...
No Matches
char.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024 Yeong-won Seo
3 *
4 * This file is part of LILAC.
5 *
6 * LILAC is free software: you can redistribute it and/or modify it under
7 * the terms of the GNU General Public License as published by the Free
8 * Software Foundation, either version 3, or (at your option) any later
9 * version.
10 *
11 * LILAC is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#pragma once
21
22#include <ostream>
23#include <array>
24
25namespace lilac::shared
26{
27 constexpr int MaxIntrinIndent = 255;
28
29 template<typename T, T e, size_t N>
31 {
32 constexpr __FilledString() noexcept
33 {
34 for (size_t i = 0; i < N; ++i)
35 V[i] = e;
36 V[N] = 0;
37 }
38
39 T V[N + 1];
40 };
41
42 template<int... Ts>
44 {
45 template<int N>
47 {
48 static constexpr auto V = __FilledString<char, '\t', N>();
49 static constexpr const char* P = V.V;
50 };
51
52 static constexpr std::array<const char*, sizeof...(Ts)> Vs = { __Indentation<Ts>::P... };
53 };
54
55 template<int... Ts>
56 constexpr const char* __GetIndentation(int c, std::integer_sequence<int, Ts...>)
57 {
58 return __IndentationVector<Ts...>::Vs[c];
59 }
60
75 constexpr const char* GetIndent(int c = 1)
76 {
77 return __GetIndentation(c, std::make_integer_sequence<int, MaxIntrinIndent>{});
78 }
79
83 inline std::ostream& endl(std::ostream& __os)
84 {
85 return __os.put('\n');
86 }
87}
std::ostream & endl(std::ostream &__os)
Write a newline on stream.
Definition char.h:83
constexpr const char * __GetIndentation(int c, std::integer_sequence< int, Ts... >)
Definition char.h:56
constexpr int MaxIntrinIndent
Definition char.h:27
constexpr const char * GetIndent(int c=1)
Gets an indentation string with specified length.
Definition char.h:75
constexpr __FilledString() noexcept
Definition char.h:32
static constexpr const char * P
Definition char.h:49
static constexpr std::array< const char *, sizeof...(Ts)> Vs
Definition char.h:52