Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add C++20 module #165

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
build/
.xmake
tests/test_main
tests/*.o
*.*~
Expand Down
1 change: 1 addition & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
indent_type = "Spaces"
13 changes: 9 additions & 4 deletions examples/enum_to_string.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <cstdio> // for std::puts

/* ELF Relocations */

#define ELF_RELOC(name, value) name = value,
Expand Down Expand Up @@ -57,12 +55,19 @@ ELF_RELOC(R_386_NUM, 43)

#ifndef SWITCH_VERSION

#ifdef FROZEN_VERSION
#include "frozen/map.h"
#ifdef FROZEN_USE_STD_MODULE
import std;
#else
#include <cstdio>
#include <map>
#endif

#ifdef FROZEN_USE_MODULE
import frozen;
#else
#include "frozen/map.h"
#endif

#ifdef FROZEN_VERSION
constexpr
frozen::map<RELOC_i386, const char*, 41>
Expand Down
20 changes: 13 additions & 7 deletions examples/enum_to_string_hash.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include <cstdio> // for std::puts

/* ELF Relocations */

#define ELF_RELOC(name, value) name = value,
Expand Down Expand Up @@ -55,15 +53,23 @@ ELF_RELOC(R_386_IRELATIVE, 42)
ELF_RELOC(R_386_NUM, 43)
};

#ifdef FROZEN_VERSION
#include "frozen/unordered_map.h"
#ifdef FROZEN_USE_STD_MODULE
import std;
#else
#include <cstdio>
#include <unordered_map>
#endif

#ifdef FROZEN_USE_MODULE
import frozen;
#else
#include <frozen/unordered_map.h>
#endif
#include <frozen/bits/elsa.h> // this is not exported by the module
namespace frozen {
template <> struct elsa<RELOC_i386> : elsa<int> {
};
}
#else
#include <unordered_map>
#endif

#ifdef FROZEN_VERSION
constexpr
Expand Down
15 changes: 12 additions & 3 deletions examples/html_entities_map.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#ifdef FROZEN_USE_STD_MODULE
import std;
#else
#include <cstdint>
#include <utility>
#endif

#include <cinttypes>
#ifdef FROZEN_USE_MODULE
import frozen;
#else
#include <frozen/unordered_map.h>
#include <frozen/string.h>
#endif

struct codes_t
{
uint32_t iCodepoint1;
uint32_t iCodepoint2{0};
std::uint32_t iCodepoint1;
std::uint32_t iCodepoint2{0};
};

static constexpr std::pair<frozen::string, codes_t> s_Entities[]
Expand Down
11 changes: 10 additions & 1 deletion examples/pixel_art.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@ g++ $0 -std=c++14 -Iinclude && ./a.out && rm -f a.out && qiv panda.ppm 1up.ppm
exit
#else

#ifdef FROZEN_USE_STD_MODULE
import std;
#else
#include <array>
#include <frozen/map.h>
#include <fstream>
#endif

#ifdef FROZEN_USE_MODULE
import frozen;
#else
#include <frozen/map.h>
#endif

constexpr frozen::map<char, std::array<char, 3>, 5> Tans{
{'R', {(char)0xFF, (char)0x00, (char)0x00}},
Expand Down
4 changes: 4 additions & 0 deletions examples/static_assert.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef FROZEN_USE_MODULE
import frozen;
#else
#include <frozen/set.h>
#endif

static constexpr frozen::set<unsigned, 3> supported_sizes = {
1, 2, 4
Expand Down
13 changes: 11 additions & 2 deletions examples/value_modification.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
#ifdef FROZEN_USE_STD_MODULE
import std;
#else
#include <iostream>
#endif

#ifdef FROZEN_USE_MODULE
import frozen;
#else
#include <frozen/set.h>
#include <frozen/string.h>
#include <frozen/unordered_map.h>
#include <iostream>
#endif

/// MAYBE_CONSTINIT expands to `constinit` if available.
#if __cpp_constinit
Expand Down Expand Up @@ -34,4 +43,4 @@ int main() {
auto range = fruits.equal_range("n_apples");
range.first->second = 1337;
std::cout << "n_apples: " << fruits.at("n_apples") << std::endl;
}
}
2 changes: 1 addition & 1 deletion include/frozen/algorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ template <std::size_t size> class boyer_moore_searcher {
if (size == 0)
return { first, first };

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

RandomAccessIterator iter = first + size - 1;
Expand Down
2 changes: 2 additions & 0 deletions include/frozen/bits/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@

#include "frozen/bits/basic_types.h"

#ifndef FROZEN_USE_STD_MODULE
#include <limits>
#include <tuple>
#endif

namespace frozen {

Expand Down
2 changes: 2 additions & 0 deletions include/frozen/bits/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@

#include "frozen/bits/exceptions.h"

#ifndef FROZEN_USE_STD_MODULE
#include <array>
#include <utility>
#include <string>
#include <type_traits>
#endif

namespace frozen {

Expand Down
2 changes: 2 additions & 0 deletions include/frozen/bits/constexpr_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#ifndef FROZEN_LETITGO_CONSTEXPR_ASSERT_H
#define FROZEN_LETITGO_CONSTEXPR_ASSERT_H

#ifndef FROZEN_USE_STD_MODULE
#include <cassert>
#endif

#ifdef _MSC_VER

Expand Down
2 changes: 2 additions & 0 deletions include/frozen/bits/elsa.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#ifndef FROZEN_LETITGO_ELSA_H
#define FROZEN_LETITGO_ELSA_H

#ifndef FROZEN_USE_STD_MODULE
#include <type_traits>
#endif

namespace frozen {

Expand Down
2 changes: 2 additions & 0 deletions include/frozen/bits/elsa_std.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#include "elsa.h"
#include "hash_string.h"

#ifndef FROZEN_USE_STD_MODULE
#ifdef FROZEN_LETITGO_HAS_STRING_VIEW
#include <string_view>
#endif
#include <string>
#endif

namespace frozen {

Expand Down
4 changes: 4 additions & 0 deletions include/frozen/bits/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@

#if defined(FROZEN_NO_EXCEPTIONS) || (defined(_MSC_VER) && !defined(_CPPUNWIND)) || (!defined(_MSC_VER) && !defined(__cpp_exceptions))

#ifndef FROZEN_USE_STD_MODULE
#include <cstdlib>
#endif
#define FROZEN_THROW_OR_ABORT(_) std::abort()

#else

#ifndef FROZEN_USE_STD_MODULE
#include <stdexcept>
#endif
#define FROZEN_THROW_OR_ABORT(err) throw err


Expand Down
4 changes: 3 additions & 1 deletion include/frozen/bits/hash_string.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef FROZEN_LETITGO_BITS_HASH_STRING_H
#define FROZEN_LETITGO_BITS_HASH_STRING_H

#ifndef FROZEN_USE_STD_MODULE
#include <cstddef>
#endif

namespace frozen {

Expand All @@ -25,4 +27,4 @@ constexpr std::size_t hash_string(const String& value, std::size_t seed) {

} // namespace frozen

#endif // FROZEN_LETITGO_BITS_HASH_STRING_H
#endif // FROZEN_LETITGO_BITS_HASH_STRING_H
2 changes: 2 additions & 0 deletions include/frozen/bits/mpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#ifndef FROZEN_LETITGO_BITS_MPL_H
#define FROZEN_LETITGO_BITS_MPL_H

#ifndef FROZEN_USE_STD_MODULE
#include <utility>
#endif

namespace frozen {

Expand Down
2 changes: 2 additions & 0 deletions include/frozen/bits/pmh.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
#include "frozen/bits/algorithms.h"
#include "frozen/bits/basic_types.h"

#ifndef FROZEN_USE_STD_MODULE
#include <array>
#include <cstddef>
#include <cstdint>
#include <limits>
#endif

namespace frozen {

Expand Down
2 changes: 2 additions & 0 deletions include/frozen/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
#include "frozen/bits/mpl.h"
#include "frozen/bits/version.h"

#ifndef FROZEN_USE_STD_MODULE
#include <iterator>
#include <utility>
#endif

namespace frozen {

Expand Down
2 changes: 2 additions & 0 deletions include/frozen/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
#include "frozen/bits/algorithms.h"
#include "frozen/bits/version.h"

#ifndef FROZEN_USE_STD_MODULE
#include <cstdint>
#include <type_traits>
#endif

namespace frozen {
template <class UIntType, UIntType a, UIntType c, UIntType m>
Expand Down
2 changes: 2 additions & 0 deletions include/frozen/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
#include "frozen/bits/version.h"
#include "frozen/bits/defines.h"

#ifndef FROZEN_USE_STD_MODULE
#include <iterator>
#include <utility>
#endif

namespace frozen {

Expand Down
2 changes: 2 additions & 0 deletions include/frozen/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
#include "frozen/bits/version.h"
#include "frozen/bits/defines.h"

#ifndef FROZEN_USE_STD_MODULE
#include <cstddef>
#include <functional>

#ifdef FROZEN_LETITGO_HAS_STRING_VIEW
#include <string_view>
#endif
#endif

namespace frozen {

Expand Down
2 changes: 2 additions & 0 deletions include/frozen/unordered_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@
#include "frozen/bits/version.h"
#include "frozen/random.h"

#ifndef FROZEN_USE_STD_MODULE
#include <tuple>
#include <functional>
#include <utility>
#endif

namespace frozen {

Expand Down
2 changes: 2 additions & 0 deletions include/frozen/unordered_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#include "frozen/bits/version.h"
#include "frozen/random.h"

#ifndef FROZEN_USE_STD_MODULE
#include <utility>
#endif

namespace frozen {

Expand Down
Loading