Skip to content

Commit c7d2bb2

Browse files
committed
implement c++20 module
1 parent 61dce5a commit c7d2bb2

38 files changed

+496
-65
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
build/
2+
.xmake
13
tests/test_main
24
tests/*.o
35
*.*~

.stylua.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
indent_type = "Spaces"

examples/enum_to_string.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <cstdio> // for std::puts
2-
31
/* ELF Relocations */
42

53
#define ELF_RELOC(name, value) name = value,
@@ -57,12 +55,21 @@ ELF_RELOC(R_386_NUM, 43)
5755

5856
#ifndef SWITCH_VERSION
5957

60-
#ifdef FROZEN_VERSION
61-
#include "frozen/map.h"
58+
#ifdef FROZEN_STD_MODULE
59+
import std;
6260
#else
61+
#include <cstdio>
6362
#include <map>
6463
#endif
6564

65+
#ifdef FROZEN_VERSION
66+
#ifdef FROZEN_MODULE
67+
import frozen;
68+
#else
69+
#include "frozen/map.h"
70+
#endif
71+
#endif
72+
6673
#ifdef FROZEN_VERSION
6774
constexpr
6875
frozen::map<RELOC_i386, const char*, 41>

examples/enum_to_string_hash.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include <cstdio> // for std::puts
2-
31
/* ELF Relocations */
42

53
#define ELF_RELOC(name, value) name = value,
@@ -55,14 +53,26 @@ ELF_RELOC(R_386_IRELATIVE, 42)
5553
ELF_RELOC(R_386_NUM, 43)
5654
};
5755

56+
#ifdef FROZEN_STD_MODULE
57+
import std;
58+
#else
59+
#include <cstdio>
60+
#include <unordered_map>
61+
#endif
62+
5863
#ifdef FROZEN_VERSION
59-
#include "frozen/unordered_map.h"
64+
#include <frozen/bits/elsa.h> // this is not exported by the module
65+
66+
#ifdef FROZEN_MODULE
67+
import frozen;
68+
#else
69+
#include <frozen/unordered_map.h>
70+
#endif
71+
6072
namespace frozen {
6173
template <> struct elsa<RELOC_i386> : elsa<int> {
6274
};
6375
}
64-
#else
65-
#include <unordered_map>
6676
#endif
6777

6878
#ifdef FROZEN_VERSION

examples/html_entities_map.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
1+
#ifdef FROZEN_STD_MODULE
2+
import std;
3+
#else
4+
#include <cstdint>
5+
#include <utility>
6+
#endif
17

2-
#include <cinttypes>
8+
#ifdef FROZEN_MODULE
9+
import frozen;
10+
#else
311
#include <frozen/unordered_map.h>
412
#include <frozen/string.h>
13+
#endif
514

615
struct codes_t
716
{
8-
uint32_t iCodepoint1;
9-
uint32_t iCodepoint2{0};
17+
std::uint32_t iCodepoint1;
18+
std::uint32_t iCodepoint2{0};
1019
};
1120

1221
static constexpr std::pair<frozen::string, codes_t> s_Entities[]

examples/pixel_art.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ g++ $0 -std=c++14 -Iinclude && ./a.out && rm -f a.out && qiv panda.ppm 1up.ppm
33
exit
44
#else
55

6+
#ifdef FROZEN_STD_MODULE
7+
import std;
8+
#else
69
#include <array>
7-
#include <frozen/map.h>
810
#include <fstream>
11+
#endif
12+
13+
#ifdef FROZEN_MODULE
14+
import frozen;
15+
#else
16+
#include <frozen/map.h>
17+
#endif
918

1019
constexpr frozen::map<char, std::array<char, 3>, 5> Tans{
1120
{'R', {(char)0xFF, (char)0x00, (char)0x00}},

examples/static_assert.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
#ifdef FROZEN_MODULE
2+
import frozen;
3+
#else
14
#include <frozen/set.h>
5+
#endif
26

37
static constexpr frozen::set<unsigned, 3> supported_sizes = {
48
1, 2, 4

examples/value_modification.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
#ifdef FROZEN_STD_MODULE
2+
import std;
3+
#else
4+
#include <iostream>
5+
#endif
6+
7+
#ifdef FROZEN_MODULE
8+
import frozen;
9+
#else
110
#include <frozen/set.h>
211
#include <frozen/string.h>
312
#include <frozen/unordered_map.h>
4-
#include <iostream>
13+
#endif
514

615
/// MAYBE_CONSTINIT expands to `constinit` if available.
716
#if __cpp_constinit
@@ -34,4 +43,4 @@ int main() {
3443
auto range = fruits.equal_range("n_apples");
3544
range.first->second = 1337;
3645
std::cout << "n_apples: " << fruits.at("n_apples") << std::endl;
37-
}
46+
}

include/frozen/algorithm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ template <std::size_t size> class boyer_moore_searcher {
167167
if (size == 0)
168168
return { first, first };
169169

170-
if (size > size_t(last - first))
170+
if (size > std::size_t(last - first))
171171
return { last, last };
172172

173173
RandomAccessIterator iter = first + size - 1;

include/frozen/bits/algorithms.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@
2525

2626
#include "frozen/bits/basic_types.h"
2727

28+
#ifndef FROZEN_STD_MODULE
2829
#include <limits>
2930
#include <tuple>
31+
#endif
3032

3133
namespace frozen {
3234

0 commit comments

Comments
 (0)