Skip to content

Commit

Permalink
rename defines and enable module and std module in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthapz committed Oct 27, 2024
1 parent ae92a79 commit c388069
Show file tree
Hide file tree
Showing 36 changed files with 275 additions and 97 deletions.
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
16 changes: 10 additions & 6 deletions examples/html_entities_map.cpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
#ifdef EXAMPLES_USE_MODULE
#ifdef FROZEN_USE_STD_MODULE
import std;
#else
#include <cstdint>
#include <utility>
#endif

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

#include <cinttypes>
#include <utility>

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
12 changes: 8 additions & 4 deletions examples/pixel_art.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ g++ $0 -std=c++14 -Iinclude && ./a.out && rm -f a.out && qiv panda.ppm 1up.ppm
exit
#else

#ifdef EXAMPLES_USE_MODULE
#ifdef FROZEN_USE_STD_MODULE
import std;
#else
#include <array>
#include <fstream>
#endif

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

#include <array>
#include <fstream>

constexpr frozen::map<char, std::array<char, 3>, 5> Tans{
{'R', {(char)0xFF, (char)0x00, (char)0x00}},
{'G', {(char)0x00, (char)0xFF, (char)0x00}},
Expand Down
2 changes: 1 addition & 1 deletion examples/static_assert.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef EXAMPLES_USE_MODULE
#ifdef FROZEN_USE_MODULE
import frozen;
#else
#include <frozen/set.h>
Expand Down
10 changes: 7 additions & 3 deletions examples/value_modification.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#ifdef EXAMPLES_USE_MODULE
#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>
#endif

#include <iostream>

/// MAYBE_CONSTINIT expands to `constinit` if available.
#if __cpp_constinit
#define MAYBE_CONSTINIT constinit
Expand Down
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: 1 addition & 1 deletion include/frozen/bits/algorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "frozen/bits/basic_types.h"

#ifndef FROZEN_DONT_INCLUDE_STL
#ifndef FROZEN_USE_STD_MODULE
#include <limits>
#include <tuple>
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/frozen/bits/basic_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

#include "frozen/bits/exceptions.h"

#ifndef FROZEN_DONT_INCLUDE_STL
#ifndef FROZEN_USE_STD_MODULE
#include <array>
#include <utility>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion include/frozen/bits/constexpr_assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifndef FROZEN_LETITGO_CONSTEXPR_ASSERT_H
#define FROZEN_LETITGO_CONSTEXPR_ASSERT_H

#ifndef FROZEN_DONT_INCLUDE_STL
#ifndef FROZEN_USE_STD_MODULE
#include <cassert>
#endif

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

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

Expand Down
2 changes: 1 addition & 1 deletion include/frozen/bits/elsa_std.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "elsa.h"
#include "hash_string.h"

#ifndef FROZEN_DONT_INCLUDE_STL
#ifndef FROZEN_USE_STD_MODULE
#ifdef FROZEN_LETITGO_HAS_STRING_VIEW
#include <string_view>
#endif
Expand Down
4 changes: 2 additions & 2 deletions include/frozen/bits/exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

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

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

#else

#ifndef FROZEN_DONT_INCLUDE_STL
#ifndef FROZEN_USE_STD_MODULE
#include <stdexcept>
#endif
#define FROZEN_THROW_OR_ABORT(err) throw err
Expand Down
2 changes: 1 addition & 1 deletion include/frozen/bits/hash_string.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef FROZEN_LETITGO_BITS_HASH_STRING_H
#define FROZEN_LETITGO_BITS_HASH_STRING_H

#ifndef FROZEN_DONT_INCLUDE_STL
#ifndef FROZEN_USE_STD_MODULE
#include <cstddef>
#endif

Expand Down
2 changes: 1 addition & 1 deletion include/frozen/bits/mpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifndef FROZEN_LETITGO_BITS_MPL_H
#define FROZEN_LETITGO_BITS_MPL_H

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

Expand Down
2 changes: 1 addition & 1 deletion include/frozen/bits/pmh.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "frozen/bits/algorithms.h"
#include "frozen/bits/basic_types.h"

#ifndef FROZEN_DONT_INCLUDE_STL
#ifndef FROZEN_USE_STD_MODULE
#include <array>
#include <cstddef>
#include <cstdint>
Expand Down
2 changes: 1 addition & 1 deletion include/frozen/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "frozen/bits/mpl.h"
#include "frozen/bits/version.h"

#ifndef FROZEN_DONT_INCLUDE_STL
#ifndef FROZEN_USE_STD_MODULE
#include <iterator>
#include <utility>
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/frozen/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "frozen/bits/algorithms.h"
#include "frozen/bits/version.h"

#ifndef FROZEN_DONT_INCLUDE_STL
#ifndef FROZEN_USE_STD_MODULE
#include <cstdint>
#include <type_traits>
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/frozen/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "frozen/bits/version.h"
#include "frozen/bits/defines.h"

#ifndef FROZEN_DONT_INCLUDE_STL
#ifndef FROZEN_USE_STD_MODULE
#include <iterator>
#include <utility>
#endif
Expand Down
2 changes: 1 addition & 1 deletion include/frozen/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "frozen/bits/version.h"
#include "frozen/bits/defines.h"

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

Expand Down
2 changes: 1 addition & 1 deletion include/frozen/unordered_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "frozen/bits/version.h"
#include "frozen/random.h"

#ifndef FROZEN_DONT_INCLUDE_STL
#ifndef FROZEN_USE_STD_MODULE
#include <tuple>
#include <functional>
#include <utility>
Expand Down
2 changes: 1 addition & 1 deletion include/frozen/unordered_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "frozen/bits/version.h"
#include "frozen/random.h"

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

Expand Down
9 changes: 8 additions & 1 deletion module/frozen.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,27 @@
* under the License.
*/

module;

#include <cassert>

export module frozen;

#ifdef FROZEN_DONT_INCLUDE_STL
#ifdef FROZEN_USE_STD_MODULE
import std;
#endif

extern "C++" {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Winclude-angled-in-module-purview"
#include <frozen/algorithm.h>
#include <frozen/map.h>
#include <frozen/random.h>
#include <frozen/set.h>
#include <frozen/string.h>
#include <frozen/unordered_set.h>
#include <frozen/unordered_map.h>
#pragma clang diagnostic pop
}

export namespace frozen {
Expand Down
4 changes: 4 additions & 0 deletions tests/no_exceptions.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#ifdef FROZEN_USE_MODULE
import frozen;
#else
#include <frozen/unordered_map.h>
#endif

#include <csignal>
#include <cstdlib>
Expand Down
12 changes: 9 additions & 3 deletions tests/test_algorithms.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// include catch before import std to avoid STL issues
#include "bench.hpp"
#include "catch.hpp"

#ifdef FROZEN_USE_STD_MODULE
import std;
#else
#include <algorithm>
#include <frozen/bits/algorithms.h>
#include <iostream>
#endif

#include "bench.hpp"
#include "catch.hpp"
#include <frozen/bits/algorithms.h>

TEST_CASE("next_highest_power_of_two", "[algorithm]") {
REQUIRE(frozen::bits::next_highest_power_of_two(1) == 1);
Expand Down
21 changes: 18 additions & 3 deletions tests/test_elsa_std.cpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
// include catch before import std to avoid STL issues
#include "catch.hpp"

#ifdef FROZEN_USE_STD_MODULE
import std;
#endif

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

#ifdef FROZEN_LETITGO_HAS_STRING_VIEW

#ifndef FROZEN_USE_MODULE
#include <frozen/bits/elsa_std.h>
#include <frozen/map.h>
#include <frozen/set.h>
#include <frozen/unordered_map.h>
#include <frozen/unordered_set.h>
#endif

#include "catch.hpp"

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

#ifdef FROZEN_LETITGO_HAS_CONSTEXPR_STRING

#ifndef FROZEN_USE_STD_MODULE
#include <string>
#endif

using StringTypes = std::tuple<std::string_view, std::string>;

Expand Down
Loading

0 comments on commit c388069

Please sign in to comment.