diff --git a/.gitignore b/.gitignore index 81801b5c..a1e88a5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +build/ +.xmake tests/test_main tests/*.o *.*~ diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 00000000..394e8846 --- /dev/null +++ b/.stylua.toml @@ -0,0 +1 @@ +indent_type = "Spaces" diff --git a/examples/enum_to_string.cpp b/examples/enum_to_string.cpp index a602400d..5ffca081 100644 --- a/examples/enum_to_string.cpp +++ b/examples/enum_to_string.cpp @@ -1,5 +1,3 @@ -#include // for std::puts - /* ELF Relocations */ #define ELF_RELOC(name, value) name = value, @@ -57,12 +55,21 @@ ELF_RELOC(R_386_NUM, 43) #ifndef SWITCH_VERSION -#ifdef FROZEN_VERSION -#include "frozen/map.h" +#ifdef FROZEN_STD_MODULE +import std; #else +#include #include #endif +#ifdef FROZEN_VERSION +#ifdef FROZEN_MODULE +import frozen; +#else +#include "frozen/map.h" +#endif +#endif + #ifdef FROZEN_VERSION constexpr frozen::map diff --git a/examples/enum_to_string_hash.cpp b/examples/enum_to_string_hash.cpp index 18b0b69d..6fe6f0b7 100644 --- a/examples/enum_to_string_hash.cpp +++ b/examples/enum_to_string_hash.cpp @@ -1,5 +1,3 @@ -#include // for std::puts - /* ELF Relocations */ #define ELF_RELOC(name, value) name = value, @@ -55,14 +53,26 @@ ELF_RELOC(R_386_IRELATIVE, 42) ELF_RELOC(R_386_NUM, 43) }; +#ifdef FROZEN_STD_MODULE +import std; +#else +#include +#include +#endif + #ifdef FROZEN_VERSION -#include "frozen/unordered_map.h" +#include // this is not exported by the module + +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#endif + namespace frozen { template <> struct elsa : elsa { }; } -#else -#include #endif #ifdef FROZEN_VERSION diff --git a/examples/html_entities_map.cpp b/examples/html_entities_map.cpp index ac7d9226..ee4f98c5 100644 --- a/examples/html_entities_map.cpp +++ b/examples/html_entities_map.cpp @@ -1,12 +1,21 @@ +#ifdef FROZEN_STD_MODULE +import std; +#else +#include +#include +#endif -#include +#ifdef FROZEN_MODULE +import frozen; +#else #include #include +#endif struct codes_t { - uint32_t iCodepoint1; - uint32_t iCodepoint2{0}; + std::uint32_t iCodepoint1; + std::uint32_t iCodepoint2{0}; }; static constexpr std::pair s_Entities[] diff --git a/examples/pixel_art.cpp b/examples/pixel_art.cpp index 003ffe94..49e12361 100644 --- a/examples/pixel_art.cpp +++ b/examples/pixel_art.cpp @@ -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_STD_MODULE +import std; +#else #include -#include #include +#endif + +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#endif constexpr frozen::map, 5> Tans{ {'R', {(char)0xFF, (char)0x00, (char)0x00}}, diff --git a/examples/static_assert.cpp b/examples/static_assert.cpp index 08992926..294df164 100644 --- a/examples/static_assert.cpp +++ b/examples/static_assert.cpp @@ -1,4 +1,8 @@ +#ifdef FROZEN_MODULE +import frozen; +#else #include +#endif static constexpr frozen::set supported_sizes = { 1, 2, 4 diff --git a/examples/value_modification.cpp b/examples/value_modification.cpp index 2584efd2..25569a68 100644 --- a/examples/value_modification.cpp +++ b/examples/value_modification.cpp @@ -1,7 +1,16 @@ +#ifdef FROZEN_STD_MODULE +import std; +#else +#include +#endif + +#ifdef FROZEN_MODULE +import frozen; +#else #include #include #include -#include +#endif /// MAYBE_CONSTINIT expands to `constinit` if available. #if __cpp_constinit @@ -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; -} \ No newline at end of file +} diff --git a/include/frozen/algorithm.h b/include/frozen/algorithm.h index 3abd529b..ffa2d988 100644 --- a/include/frozen/algorithm.h +++ b/include/frozen/algorithm.h @@ -167,7 +167,7 @@ template 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; diff --git a/include/frozen/bits/algorithms.h b/include/frozen/bits/algorithms.h index 4efa61b2..524be261 100644 --- a/include/frozen/bits/algorithms.h +++ b/include/frozen/bits/algorithms.h @@ -25,8 +25,10 @@ #include "frozen/bits/basic_types.h" +#ifndef FROZEN_STD_MODULE #include #include +#endif namespace frozen { diff --git a/include/frozen/bits/basic_types.h b/include/frozen/bits/basic_types.h index 2d776047..75aced60 100644 --- a/include/frozen/bits/basic_types.h +++ b/include/frozen/bits/basic_types.h @@ -26,10 +26,12 @@ #include "frozen/bits/exceptions.h" #include "frozen/bits/constexpr_assert.h" +#ifndef FROZEN_STD_MODULE #include #include #include #include +#endif namespace frozen { diff --git a/include/frozen/bits/constexpr_assert.h b/include/frozen/bits/constexpr_assert.h index bd0bb10e..295a0a59 100644 --- a/include/frozen/bits/constexpr_assert.h +++ b/include/frozen/bits/constexpr_assert.h @@ -23,8 +23,10 @@ #ifndef FROZEN_LETITGO_CONSTEXPR_ASSERT_H #define FROZEN_LETITGO_CONSTEXPR_ASSERT_H +#ifndef FROZEN_STD_MODULE #include #include +#endif inline void constexpr_assert_failed() {} diff --git a/include/frozen/bits/defines.h b/include/frozen/bits/defines.h index 839f4e83..7327d97c 100644 --- a/include/frozen/bits/defines.h +++ b/include/frozen/bits/defines.h @@ -29,13 +29,23 @@ // Code taken from https://stackoverflow.com/questions/43639122/which-values-can-msvc-lang-have #if defined(FROZEN_LETITGO_IS_MSVC) - #if _MSVC_LANG > 201402 + #if _MSVC_LANG > 201703L + #define FROZEN_LETITGO_HAS_CXX20 1 + #else + #define FROZEN_LETITGO_HAS_CXX20 0 + #endif + #if _MSVC_LANG > 201402L #define FROZEN_LETITGO_HAS_CXX17 1 #else /* _MSVC_LANG > 201402 */ #define FROZEN_LETITGO_HAS_CXX17 0 #endif /* _MSVC_LANG > 201402 */ #else /* _MSVC_LANG etc. */ - #if __cplusplus > 201402 + #if __cplusplus > 201703L + #define FROZEN_LETITGO_HAS_CXX20 1 + #else /* __cplusplus > 201402 */ + #define FROZEN_LETITGO_HAS_CXX20 0 + #endif /* __cplusplus > 201402 */ + #if __cplusplus > 201402L #define FROZEN_LETITGO_HAS_CXX17 1 #else /* __cplusplus > 201402 */ #define FROZEN_LETITGO_HAS_CXX17 0 @@ -51,6 +61,12 @@ #endif #endif +#if FROZEN_LETITGO_HAS_CXX20 && __has_include() + #if defined(_cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907 + #define FROZEN_LETITGO_HAS_THREE_WAY_COMPARISON + #endif +#endif + #ifdef __cpp_char8_t #define FROZEN_LETITGO_HAS_CHAR8T #endif diff --git a/include/frozen/bits/elsa.h b/include/frozen/bits/elsa.h index 6c9ecb78..39b92eb0 100644 --- a/include/frozen/bits/elsa.h +++ b/include/frozen/bits/elsa.h @@ -23,7 +23,9 @@ #ifndef FROZEN_LETITGO_ELSA_H #define FROZEN_LETITGO_ELSA_H +#ifndef FROZEN_STD_MODULE #include +#endif namespace frozen { diff --git a/include/frozen/bits/elsa_std.h b/include/frozen/bits/elsa_std.h index df1a9cfc..0407c904 100644 --- a/include/frozen/bits/elsa_std.h +++ b/include/frozen/bits/elsa_std.h @@ -5,10 +5,12 @@ #include "elsa.h" #include "hash_string.h" +#ifndef FROZEN_STD_MODULE #ifdef FROZEN_LETITGO_HAS_STRING_VIEW #include #endif #include +#endif namespace frozen { diff --git a/include/frozen/bits/exceptions.h b/include/frozen/bits/exceptions.h index b43e3e6b..0bba267d 100644 --- a/include/frozen/bits/exceptions.h +++ b/include/frozen/bits/exceptions.h @@ -25,12 +25,16 @@ #if defined(FROZEN_NO_EXCEPTIONS) || (defined(_MSC_VER) && !defined(_CPPUNWIND)) || (!defined(_MSC_VER) && !defined(__cpp_exceptions)) +#ifndef FROZEN_STD_MODULE #include +#endif #define FROZEN_THROW_OR_ABORT(_) std::abort() #else +#ifndef FROZEN_STD_MODULE #include +#endif #define FROZEN_THROW_OR_ABORT(err) throw err diff --git a/include/frozen/bits/hash_string.h b/include/frozen/bits/hash_string.h index b2f7e90e..5ad8c619 100644 --- a/include/frozen/bits/hash_string.h +++ b/include/frozen/bits/hash_string.h @@ -1,7 +1,9 @@ #ifndef FROZEN_LETITGO_BITS_HASH_STRING_H #define FROZEN_LETITGO_BITS_HASH_STRING_H +#ifndef FROZEN_STD_MODULE #include +#endif namespace frozen { @@ -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 \ No newline at end of file +#endif // FROZEN_LETITGO_BITS_HASH_STRING_H diff --git a/include/frozen/bits/mpl.h b/include/frozen/bits/mpl.h index 8f87f99c..befd6329 100644 --- a/include/frozen/bits/mpl.h +++ b/include/frozen/bits/mpl.h @@ -23,7 +23,9 @@ #ifndef FROZEN_LETITGO_BITS_MPL_H #define FROZEN_LETITGO_BITS_MPL_H +#ifndef FROZEN_STD_MODULE #include +#endif namespace frozen { diff --git a/include/frozen/bits/pmh.h b/include/frozen/bits/pmh.h index fbdf664b..b7a6ab06 100644 --- a/include/frozen/bits/pmh.h +++ b/include/frozen/bits/pmh.h @@ -27,10 +27,12 @@ #include "frozen/bits/algorithms.h" #include "frozen/bits/basic_types.h" +#ifndef FROZEN_STD_MODULE #include #include #include #include +#endif namespace frozen { diff --git a/include/frozen/map.h b/include/frozen/map.h index cb3e3a28..888f0434 100644 --- a/include/frozen/map.h +++ b/include/frozen/map.h @@ -29,8 +29,10 @@ #include "frozen/bits/mpl.h" #include "frozen/bits/version.h" +#ifndef FROZEN_STD_MODULE #include #include +#endif namespace frozen { diff --git a/include/frozen/random.h b/include/frozen/random.h index 727133bb..20ea2722 100644 --- a/include/frozen/random.h +++ b/include/frozen/random.h @@ -26,8 +26,10 @@ #include "frozen/bits/algorithms.h" #include "frozen/bits/version.h" +#ifndef FROZEN_STD_MODULE #include #include +#endif namespace frozen { template diff --git a/include/frozen/set.h b/include/frozen/set.h index edf1ad17..375cd986 100644 --- a/include/frozen/set.h +++ b/include/frozen/set.h @@ -28,8 +28,10 @@ #include "frozen/bits/version.h" #include "frozen/bits/defines.h" +#ifndef FROZEN_STD_MODULE #include #include +#endif namespace frozen { diff --git a/include/frozen/string.h b/include/frozen/string.h index 12334eff..d833e77e 100644 --- a/include/frozen/string.h +++ b/include/frozen/string.h @@ -28,6 +28,7 @@ #include "frozen/bits/version.h" #include "frozen/bits/defines.h" +#ifndef FROZEN_STD_MODULE #include #include @@ -35,6 +36,11 @@ #include #endif +#ifdef FROZEN_LETITGO_HAS_THREE_WAY_COMPARISON +#include +#endif +#endif + namespace frozen { template @@ -55,7 +61,7 @@ class basic_string { constexpr basic_string(std::basic_string_view data) : data_(data.data()), size_(data.size()) {} - explicit constexpr operator std::basic_string_view() const { + constexpr explicit operator std::basic_string_view() const { return std::basic_string_view(data_, size_); } #endif @@ -68,7 +74,32 @@ class basic_string { constexpr chr_t operator[](std::size_t i) const { return data_[i]; } - constexpr bool operator==(basic_string other) const { +#ifdef FROZEN_LETITGO_HAS_THREE_WAY_COMPARISON + constexpr std::weak_ordering operator<=>(const basic_string &other) const { + bool equal = true; + if(size_ == other.size_) + for (std::size_t i = 0; i < size_; ++i) + if (data_[i] != other.data_[i]) { + equal = false; + break; + } + + if(equal) return std::weak_ordering::equivalent; + + unsigned i = 0; + while (i < size() && i < other.size()) { + if ((*this)[i] < other[i]) { + return std::weak_ordering::less; + } + if ((*this)[i] > other[i]) { + return std::weak_ordering::greater; + } + ++i; + } + return size() < other.size() ? std::weak_ordering::less : std::weak_ordering::greater; + } +#else + constexpr bool operator==(const basic_string &other) const { if (size_ != other.size_) return false; for (std::size_t i = 0; i < size_; ++i) @@ -77,6 +108,10 @@ class basic_string { return true; } + friend constexpr bool operator!=(const basic_string &lhs, const basic_string &rhs) { + return !(lhs == rhs); + } + constexpr bool operator<(const basic_string &other) const { unsigned i = 0; while (i < size() && i < other.size()) { @@ -100,6 +135,7 @@ class basic_string { friend constexpr bool operator<=(const basic_string& lhs, const basic_string& rhs) { return !(lhs > rhs); } +#endif constexpr const chr_t *data() const { return data_; } constexpr const chr_t *begin() const { return data(); } diff --git a/include/frozen/unordered_map.h b/include/frozen/unordered_map.h index 24053852..83d34cc2 100644 --- a/include/frozen/unordered_map.h +++ b/include/frozen/unordered_map.h @@ -27,12 +27,14 @@ #include "frozen/bits/elsa.h" #include "frozen/bits/exceptions.h" #include "frozen/bits/pmh.h" -#include "frozen/bits/version.h" #include "frozen/random.h" -#include +#ifndef FROZEN_STD_MODULE +#include #include #include +#include +#endif namespace frozen { diff --git a/include/frozen/unordered_set.h b/include/frozen/unordered_set.h index 482034bd..dfeb0efb 100644 --- a/include/frozen/unordered_set.h +++ b/include/frozen/unordered_set.h @@ -29,7 +29,9 @@ #include "frozen/bits/version.h" #include "frozen/random.h" +#ifndef FROZEN_STD_MODULE #include +#endif namespace frozen { diff --git a/module/frozen.cppm b/module/frozen.cppm new file mode 100644 index 00000000..71dc07b8 --- /dev/null +++ b/module/frozen.cppm @@ -0,0 +1,98 @@ +/* + * Frozen + * Copyright 2016 QuarksLab + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +module; + + +#ifndef FROZEN_STD_MODULE +#if defined(__cpp_modules) && __cpp_modules >= 201907L && defined(__cpp_lib_modules) && __cpp_lib_modules >= 202207L +#define FROZEN_STD_MODULE +#endif +#endif + +#ifdef FROZEN_STD_MODULE +import std; +#endif + +#include +#include +#include +#include +#include +#include +#include + +export module frozen; + +export namespace frozen { + // exposed internals + namespace bits { + using frozen::bits::pmh_tables; + using frozen::bits::carray; + using frozen::bits::cvector; + } + + using frozen::elsa; + using frozen::anna; + + /* algorithm */ + using frozen::search; + using frozen::knuth_morris_pratt_searcher; + using frozen::make_knuth_morris_pratt_searcher; + using frozen::boyer_moore_searcher; + using frozen::make_boyer_moore_searcher; + + /* map */ + using frozen::map; + using frozen::make_map; + + /* random */ + using frozen::linear_congruential_engine; + using frozen::minstd_rand0; + using frozen::minstd_rand; + using frozen::default_prg_t; + + /* set */ + using frozen::set; + using frozen::make_set; + + /* string */ + using frozen::basic_string; + using frozen::string; + using frozen::wstring; + using frozen::u8string; + using frozen::u16string; + using frozen::u32string; + + namespace string_literals { + using frozen::string_literals::operator""_s; + } + + /* unordered_map */ + using frozen::unordered_map; + using frozen::make_unordered_map; + + /* unordered_set */ + using frozen::unordered_set; + using frozen::make_unordered_set; +} + diff --git a/tests/no_exceptions.cpp b/tests/no_exceptions.cpp index ee270d6e..832bc513 100644 --- a/tests/no_exceptions.cpp +++ b/tests/no_exceptions.cpp @@ -1,8 +1,12 @@ -#include - #include #include +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#endif + // https://discourse.cmake.org/t/tests-that-are-meant-to-abort/537/3 // This is a hack to implement death tests in CTest. extern "C" void error_test_handle_abort(int) { std::_Exit(EXIT_FAILURE); } diff --git a/tests/test_algorithms.cpp b/tests/test_algorithms.cpp index b0ecc83f..6e03afe1 100644 --- a/tests/test_algorithms.cpp +++ b/tests/test_algorithms.cpp @@ -1,9 +1,15 @@ +// include catch before import std to avoid STL issues +#include "bench.hpp" +#include "catch.hpp" + +#ifdef FROZEN_STD_MODULE +import std; +#else #include -#include #include +#endif -#include "bench.hpp" -#include "catch.hpp" +#include TEST_CASE("next_highest_power_of_two", "[algorithm]") { REQUIRE(frozen::bits::next_highest_power_of_two(1) == 1); diff --git a/tests/test_elsa_std.cpp b/tests/test_elsa_std.cpp index 58387263..a18b77bb 100644 --- a/tests/test_elsa_std.cpp +++ b/tests/test_elsa_std.cpp @@ -1,20 +1,35 @@ +// include catch before import std to avoid STL issues +#include "catch.hpp" + +#ifdef FROZEN_STD_MODULE +import std; +#endif + +#ifdef FROZEN_MODULE +import frozen; +#else #include +#endif #ifdef FROZEN_LETITGO_HAS_STRING_VIEW - +#ifndef FROZEN_MODULE #include #include #include #include #include +#endif -#include "catch.hpp" - +#ifndef FROZEN_STD_MODULE #include +#include +#endif #ifdef FROZEN_LETITGO_HAS_CONSTEXPR_STRING +#ifndef FROZEN_STD_MODULE #include +#endif using StringTypes = std::tuple; diff --git a/tests/test_map.cpp b/tests/test_map.cpp index 98be136f..b6617cc5 100644 --- a/tests/test_map.cpp +++ b/tests/test_map.cpp @@ -1,11 +1,21 @@ +// include catch before import std to avoid STL issues +#include "bench.hpp" +#include "catch.hpp" + +#ifdef FROZEN_STD_MODULE +import std; +#else #include -#include #include #include #include +#endif -#include "bench.hpp" -#include "catch.hpp" +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#endif TEST_CASE("empty frozen map", "[map]") { constexpr frozen::map ze_map{}; diff --git a/tests/test_rand.cpp b/tests/test_rand.cpp index eac94ec5..c4ac178d 100644 --- a/tests/test_rand.cpp +++ b/tests/test_rand.cpp @@ -1,10 +1,20 @@ +// include catch before import std to avoid STL issues +#include "bench.hpp" +#include "catch.hpp" + +#ifdef FROZEN_STD_MODULE +import std; +#else #include -#include #include #include +#endif -#include "bench.hpp" -#include "catch.hpp" +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#endif TEST_CASE("linear_congruential_engine", "[random]") { diff --git a/tests/test_set.cpp b/tests/test_set.cpp index fbbd4033..1fc78849 100644 --- a/tests/test_set.cpp +++ b/tests/test_set.cpp @@ -1,11 +1,21 @@ +// include catch before import std to avoid STL issues +#include "bench.hpp" +#include "catch.hpp" + +#ifdef FROZEN_STD_MODULE +import std; +#else #include -#include #include #include #include +#endif -#include "bench.hpp" -#include "catch.hpp" +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#endif TEST_CASE("empty frozen set", "[set]") { constexpr frozen::set ze_set{}; diff --git a/tests/test_str.cpp b/tests/test_str.cpp index 551e0502..b7d45b5d 100644 --- a/tests/test_str.cpp +++ b/tests/test_str.cpp @@ -1,16 +1,24 @@ -#include -#include +// include catch before import std to avoid STL issues +#include "catch.hpp" + +#ifdef FROZEN_STD_MODULE +import std; +#else #include -#include #ifdef FROZEN_LETITGO_HAS_STRING_VIEW #include #include #include #endif +#endif -#include "bench.hpp" -#include "catch.hpp" +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#include +#endif using namespace frozen::string_literals; using namespace std::literals; diff --git a/tests/test_str_set.cpp b/tests/test_str_set.cpp index cae019d9..f71f5f1a 100644 --- a/tests/test_str_set.cpp +++ b/tests/test_str_set.cpp @@ -1,11 +1,21 @@ -#include -#include +// include catch before import std to avoid STL issues +#include "bench.hpp" +#include "catch.hpp" + +#ifdef FROZEN_STD_MODULE +import std; +#else #include #include #include +#endif -#include "bench.hpp" -#include "catch.hpp" +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#include +#endif TEST_CASE("tripleton int frozen ordered set", "[set]") { constexpr frozen::set ze_set{"1", "2", "3"}; diff --git a/tests/test_unordered_map.cpp b/tests/test_unordered_map.cpp index ccc44713..d8e09983 100644 --- a/tests/test_unordered_map.cpp +++ b/tests/test_unordered_map.cpp @@ -1,15 +1,26 @@ -#include -#include -#include +// include catch before import std to avoid STL issues +#include "bench.hpp" +#include "catch.hpp" + +#ifdef FROZEN_STD_MODULE +import std; +#else #include #include #include - #include #include +#endif + +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#include +#endif + +#include -#include "bench.hpp" -#include "catch.hpp" TEST_CASE("singleton frozen unordered map", "[unordered map]") { constexpr frozen::unordered_map ze_map{{1, 2.}}; @@ -260,7 +271,7 @@ struct case_insensitive { template <> struct frozen::elsa { constexpr std::size_t operator()(case_insensitive const &value, std::size_t seed) const { - char tmp[3]; + char tmp[3] = {}; for(size_t i = 0; i < 3; ++i) tmp[i] = tolower(value.data[i]); return frozen::elsa<>()(frozen::string(tmp, 3), seed); diff --git a/tests/test_unordered_map_str.cpp b/tests/test_unordered_map_str.cpp index 35bb9dba..83cdbd31 100644 --- a/tests/test_unordered_map_str.cpp +++ b/tests/test_unordered_map_str.cpp @@ -1,10 +1,20 @@ -#include -#include +// include catch before import std to avoid STL issues +#include "bench.hpp" +#include "catch.hpp" + +#ifdef FROZEN_STD_MODULE +import std; +#else #include #include +#endif -#include "bench.hpp" -#include "catch.hpp" +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#include +#endif TEST_CASE("frozen::unordered_map <> std::unordered_map", "[unordered_map]") { diff --git a/tests/test_unordered_set.cpp b/tests/test_unordered_set.cpp index 7d863502..18e957da 100644 --- a/tests/test_unordered_set.cpp +++ b/tests/test_unordered_set.cpp @@ -1,12 +1,23 @@ -#include -#include -#include +// include catch before import std to avoid STL issues +#include "bench.hpp" +#include "catch.hpp" + +#ifdef FROZEN_STD_MODULE +import std; +#else #include #include #include +#endif -#include "bench.hpp" -#include "catch.hpp" +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#include +#endif + +#include TEST_CASE("singleton frozen unordered set", "[unordered set]") { constexpr frozen::unordered_set ze_set{1}; diff --git a/tests/test_unordered_str_set.cpp b/tests/test_unordered_str_set.cpp index 840b9762..0bfb4936 100644 --- a/tests/test_unordered_str_set.cpp +++ b/tests/test_unordered_str_set.cpp @@ -1,11 +1,21 @@ -#include -#include +// include catch before import std to avoid STL issues +#include "bench.hpp" +#include "catch.hpp" + +#ifdef FROZEN_STD_MODULE +import std; +#else #include #include #include +#endif -#include "bench.hpp" -#include "catch.hpp" +#ifdef FROZEN_MODULE +import frozen; +#else +#include +#include +#endif TEST_CASE("tripleton int frozen unordered set", "[unordered set]") { constexpr frozen::unordered_set ze_set{"1", "2", "3"}; diff --git a/xmake.lua b/xmake.lua new file mode 100644 index 00000000..dc801662 --- /dev/null +++ b/xmake.lua @@ -0,0 +1,135 @@ +set_xmakever("3.0.4") +set_project("frozen") + +set_version("1.1.0", { build = "%Y%m%d%H%M" }) + +option("modules", { defines = "FROZEN_MODULE", default = false }) +option("std_module", { defines = "FROZEN_STD_MODULE", default = false }) +option("tests", { default = false }) +option("benchmark", { default = false }) + +target("frozen", function() + if get_config("modules") then + set_kind("static") + if get_config("std_module") then + set_languages("c++23") + else + set_languages("c++20") + end + else + set_kind("headeronly") + set_languages("c++17") + end + + add_includedirs("include", { public = true }) + add_headerfiles("include/(frozen/**.h)") + + add_options("modules", "std_module") + + if get_config("modules") then + add_files("module/frozen.cppm", { public = true }) + end +end) + +if get_config("benchmark") then + add_requires("benchmark") + target("frozen.benchmark", function() + set_kind("binary") + set_languages("c++17") + + add_files("benchmarks/**.cpp") + + if not get_config("benchmark_str_search") then + remove_files("benchmarks/bench_str_search.cpp") + end + + add_packages("benchmark") + + add_deps("frozen") + end) +end + +if get_config("tests") then + target("frozen.tests", function() + set_kind("binary") + if get_config("modules") then + if get_config("std_module") then + set_languages("c++23") + else + set_languages("c++20") + end + else + set_languages("c++17") + end + add_rules("mode.coverage") + add_files("tests/**.cpp") + remove_files("tests/no_exceptions.cpp") + + add_cxxflags("/W3", "/WX", { tools = { "cl", "clang_cl" } }) + add_cxxflags("-Wall", "-Wextra", "-Wpedantic", "-Werror", "-Wshadow", { tools = { "cl", "clang_cl" } }) + + if is_plat("windows") then + add_cxxflags("/W3", "/WX", { tools = "icc" }) + else + add_cxxflags("-Wall", "-Werror", { tools = "icc" }) + end + + add_options("modules", "std_module") + add_deps("frozen") + end) + + target("frozen.tests.noexcept", function() + set_kind("binary") + if get_config("modules") then + if get_config("std_module") then + set_languages("c++23") + else + set_languages("c++20") + end + else + set_languages("c++17") + end + add_rules("mode.coverage") + set_basename("test_no_exceptions") + + add_files("tests/no_exceptions.cpp") + + add_cxxflags("/W3", "/WX", { tools = { "cl", "clang_cl" } }) + add_cxxflags("-Wall", "-Wextra", "-Wpedantic", "-Werror", "-Wshadow", { tools = { "cl", "clang_cl" } }) + + if is_plat("windows") then + add_cxxflags("/W3", "/WX", { tools = { "icc" } }) + else + add_cxxflags("-Wall", "-Werror", { tools = { "icc" } }) + end + + add_options("modules", "std_module") + add_deps("frozen") + end) + + for _, example in ipairs(os.files("examples/*.cpp")) do + target("frozen.example." .. path.basename(example), function() + set_kind("binary") + if get_config("modules") then + if get_config("std_module") then + set_languages("c++23") + else + set_languages("c++20") + end + else + set_languages("c++17") + end + + add_files(example) + + add_deps("frozen") + + add_options("modules", "std_module") + + if path.basename(example) == "html_entities_map" then + add_cxxflags("-fconstexpr-steps=123456789", { tools = { "clangxx", "clang" } }) + add_cxxflags("-fconstexpr-ops-limit=12345678910", { tools = { "gxx", "gcc" } }) + end + end) + end +end