diff --git a/CMakeLists.txt b/CMakeLists.txt index 98675d9..966e118 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,14 +11,37 @@ # Project home: https://github.com/rollbear/strong_type # +if(STRONG_TYPE_IMPORT_STD_LIBRARY) + cmake_minimum_required(VERSION 3.30) +else() + cmake_minimum_required(VERSION 3.14) +endif() + +if(STRONG_TYPE_IMPORT_STD_LIBRARY) + if("${CMAKE_GENERATOR}" STREQUAL "Visual Studio 17 2022") + # This can be done before or after project() on MSVC + # It works regardless of CMAKE_EXPERIMENTAL_CXX_IMPORT_STD + # cmake -DSTRONG_TYPE_IMPORT_STD_LIBRARY=ON src_path + set(CMAKE_CXX_SCAN_FOR_MODULES ON) + else() + # This needs to be done before selecting the languages so the project() command + # The CMAKE_EXPERIMENTAL_CXX_IMPORT_STD is required + # To build on calng you need a command line that uses Ninja points to a clang compiler and switched to use the clang libc++ not GCCs libstdc++ + # cmake -G Ninja -DCMAKE_CXX_FLAGS=-stdlib=libc++ -DSTRONG_TYPE_IMPORT_STD_LIBRARY=ON -DCMAKE_CXX_COMPILER=/usr/lib/llvm-20/bin/clang++ src_path + set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "0e5b6991-d74f-4b3d-a41c-cf096e0b2508") + set(CMAKE_CXX_MODULE_STD ON) + endif() + + # We could do C++ 26 here as well, all compilers have agreed to support the std module in C++ 20 but CMake does not support that yet + set(CMAKE_CXX_STANDARD 23) +endif() -cmake_minimum_required(VERSION 3.14) project(strong_type) include(GNUInstallDirs) include(CMakePackageConfigHelpers) -option(STRONG_TYPE_UNIT_TEST off "Decide whether to build unit tests or not") +option(STRONG_TYPE_UNIT_TEST "Decide whether to build unit tests or not" OFF) set(STRONG_TYPE_VERSION 15) set(INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include) diff --git a/include/strong_type/arithmetic.hpp b/include/strong_type/arithmetic.hpp index d1b3f8f..0307855 100644 --- a/include/strong_type/arithmetic.hpp +++ b/include/strong_type/arithmetic.hpp @@ -16,7 +16,9 @@ #include "type.hpp" +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif namespace strong { diff --git a/include/strong_type/formattable.hpp b/include/strong_type/formattable.hpp index ec0816c..edc7e86 100644 --- a/include/strong_type/formattable.hpp +++ b/include/strong_type/formattable.hpp @@ -38,8 +38,10 @@ #endif #if STRONG_HAS_STD_FORMAT +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include #endif +#endif #if STRONG_HAS_FMT_FORMAT #include "ostreamable.hpp" diff --git a/include/strong_type/hashable.hpp b/include/strong_type/hashable.hpp index 01c9ee9..474b6c1 100644 --- a/include/strong_type/hashable.hpp +++ b/include/strong_type/hashable.hpp @@ -16,7 +16,9 @@ #include "type.hpp" +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif namespace strong { diff --git a/include/strong_type/istreamable.hpp b/include/strong_type/istreamable.hpp index 56e0535..ca1e0a4 100644 --- a/include/strong_type/istreamable.hpp +++ b/include/strong_type/istreamable.hpp @@ -16,7 +16,9 @@ #include "type.hpp" +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif namespace strong { diff --git a/include/strong_type/iterator.hpp b/include/strong_type/iterator.hpp index c6cf39e..a76acec 100644 --- a/include/strong_type/iterator.hpp +++ b/include/strong_type/iterator.hpp @@ -19,7 +19,9 @@ #include "affine_point.hpp" #include "indexed.hpp" +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif #if __cplusplus >= 202002L && (((! defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 15000)) && (!defined(__GLIBCXX__) || __GLIBCXX__ >= 20230528L)) #define STRONG_TYPE_CONTIGUOUS_ITERATOR 1 @@ -57,7 +59,7 @@ namespace internal { #else using iterator_category = std::random_access_iterator_tag; #endif - using difference_type = ptrdiff_t; + using difference_type = std::ptrdiff_t; using value_type = T; using reference = T&; using pointer = T*; diff --git a/include/strong_type/ordered.hpp b/include/strong_type/ordered.hpp index b2e8e7e..db8ebd1 100644 --- a/include/strong_type/ordered.hpp +++ b/include/strong_type/ordered.hpp @@ -16,9 +16,12 @@ #include "type.hpp" +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #if __cpp_impl_three_way_comparison && __has_include() #include #endif +#endif + namespace strong { struct ordered diff --git a/include/strong_type/ordered_with.hpp b/include/strong_type/ordered_with.hpp index c44fd91..ed64dd4 100644 --- a/include/strong_type/ordered_with.hpp +++ b/include/strong_type/ordered_with.hpp @@ -16,9 +16,11 @@ #include "type.hpp" +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #if __cpp_impl_three_way_comparison && __has_include() #include #endif +#endif namespace strong { diff --git a/include/strong_type/ostreamable.hpp b/include/strong_type/ostreamable.hpp index 146ca95..e05d289 100644 --- a/include/strong_type/ostreamable.hpp +++ b/include/strong_type/ostreamable.hpp @@ -16,7 +16,9 @@ #include "type.hpp" +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif namespace strong { diff --git a/include/strong_type/range.hpp b/include/strong_type/range.hpp index c7cdf09..e40eb0f 100644 --- a/include/strong_type/range.hpp +++ b/include/strong_type/range.hpp @@ -15,8 +15,10 @@ #define STRONG_TYPE_RANGE_HPP #if __has_include() +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) # include #endif +#endif #if defined(_MSC_VER) && __cpp_lib_ranges >= 202110L # define STRONG_TYPE_HAS_RANGES #endif diff --git a/include/strong_type/type.hpp b/include/strong_type/type.hpp index 4906f34..eabaf70 100644 --- a/include/strong_type/type.hpp +++ b/include/strong_type/type.hpp @@ -14,10 +14,14 @@ #ifndef ROLLBEAR_STRONG_TYPE_TYPE_HPP_INCLUDED #define ROLLBEAR_STRONG_TYPE_TYPE_HPP_INCLUDED +#if defined(STRONG_TYPE_IMPORT_STD_LIBRARY) + import std; +#else -#include -#include -#include + #include + #include + #include +#endif #if defined(_MSC_VER) && !defined(__clang__) && _MSC_VER < 1922 #define STRONG_CONSTEXPR diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index afdba80..d443ff5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,9 +2,19 @@ if (!CMAKE_CXX_STANDARD) set(CMAKE_CXX_STANDARD 14) endif() set(CMAKE_CXX_STANDARD_REQUIRED YES) -set(CMAKE_CXX_EXTENSIONS OFF) -cmake_minimum_required(VERSION 3.22) +if(${STRONG_TYPE_IMPORT_STD_LIBRARY}) + # This is currently required to be ON for a clang module build + # https://gitlab.kitware.com/cmake/cmake/-/issues/25916 + # https://gitlab.kitware.com/cmake/cmake/-/issues/25539 + set(CMAKE_CXX_EXTENSIONS ON) +else() + set(CMAKE_CXX_EXTENSIONS OFF) +endif() + +if(NOT ${STRONG_TYPE_IMPORT_STD_LIBRARY}) + cmake_minimum_required(VERSION 3.22) +endif() find_package(Catch2 3 QUIET) if (${Catch2_FOUND}) @@ -50,6 +60,11 @@ if (NOT ${Catch2_FOUND}) add_compile_definitions(CATCH2=2) endif() +if(STRONG_TYPE_IMPORT_STD_LIBRARY) + message(STATUS "Building using import std") + add_compile_definitions(STRONG_TYPE_IMPORT_STD_LIBRARY=1) +endif() + add_executable( self_test test.cpp diff --git a/test/test.cpp b/test/test.cpp index 3e7434e..1579220 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -11,16 +11,18 @@ * Project home: https://github.com/rollbear/strong_type */ + #include "catch2.hpp" // include first to ensure there aren't any unmet header dependencies #include "strong_type/strong_type.hpp" +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include #include #include #include +#endif -#include "catch2.hpp" template using equality_compare = decltype(std::declval() == std::declval()); @@ -362,7 +364,7 @@ using ri = strong::type; static_assert(strong::type_is_v, ""); static_assert(strong::type_is_v, ""); static_assert(strong::type_is_v, ""); -static_assert(strong::type_is_v>, ""); +static_assert(strong::type_is_v>, ""); //static_assert(!strong::type_is_v, ""); //static_assert(!std::is_default_constructible{},""); static_assert(std::is_nothrow_constructible{},""); @@ -439,7 +441,7 @@ using rhi = rhandle::iterator; static_assert(strong::type_is_v, ""); static_assert(strong::type_is_v, ""); static_assert(strong::type_is_v, ""); -static_assert(strong::type_is_v>, ""); +static_assert(strong::type_is_v>, ""); static_assert(std::is_nothrow_copy_constructible{},""); static_assert(std::is_nothrow_move_constructible{},""); //static_assert(!std::is_default_constructible{},""); @@ -451,7 +453,7 @@ using crhi = rhandle::const_iterator; static_assert(strong::type_is_v, ""); static_assert(strong::type_is_v, ""); static_assert(strong::type_is_v, ""); -static_assert(strong::type_is_v>, ""); +static_assert(strong::type_is_v>, ""); static_assert(std::is_nothrow_copy_constructible{},""); static_assert(std::is_nothrow_move_constructible{},""); //static_assert(!std::is_default_constructible{},""); diff --git a/test/test_affine_point.cpp b/test/test_affine_point.cpp index f2c7248..5f87902 100644 --- a/test/test_affine_point.cpp +++ b/test/test_affine_point.cpp @@ -11,9 +11,10 @@ * Project home: https://github.com/rollbear/strong_type */ + #include "catch2.hpp" + #include -#include "catch2.hpp" TEST_CASE("affine_point types can be subtracted") { diff --git a/test/test_arithmetic.cpp b/test/test_arithmetic.cpp index 324975f..e36c801 100644 --- a/test/test_arithmetic.cpp +++ b/test/test_arithmetic.cpp @@ -11,9 +11,9 @@ * Project home: https://github.com/rollbear/strong_type */ -#include + #include "catch2.hpp" -#include "catch2.hpp" +#include namespace strong { diff --git a/test/test_bicrementable.cpp b/test/test_bicrementable.cpp index 50ea98a..707cb04 100644 --- a/test/test_bicrementable.cpp +++ b/test/test_bicrementable.cpp @@ -11,9 +11,9 @@ * Project home: https://github.com/rollbear/strong_type */ -#include + #include "catch2.hpp" -#include "catch2.hpp" +#include TEST_CASE("a bicrementable goes both ways") { diff --git a/test/test_bitarithmetic.cpp b/test/test_bitarithmetic.cpp index 735f9a7..7c942b0 100644 --- a/test/test_bitarithmetic.cpp +++ b/test/test_bitarithmetic.cpp @@ -11,9 +11,9 @@ * Project home: https://github.com/rollbear/strong_type */ -#include + #include "catch2.hpp" -#include "catch2.hpp" +#include TEST_CASE("bitarithmetic types can be bitanded") diff --git a/test/test_boolean.cpp b/test/test_boolean.cpp index 4d45a25..8280063 100644 --- a/test/test_boolean.cpp +++ b/test/test_boolean.cpp @@ -11,9 +11,9 @@ * Project home: https://github.com/rollbear/strong_type */ -#include + #include "catch2.hpp" -#include "catch2.hpp" +#include TEST_CASE("a boolean value can be tested for truth") { diff --git a/test/test_convertible_to.cpp b/test/test_convertible_to.cpp index 32a00cd..a1b49fa 100644 --- a/test/test_convertible_to.cpp +++ b/test/test_convertible_to.cpp @@ -11,9 +11,9 @@ * Project home: https://github.com/rollbear/strong_type */ -#include + #include "catch2.hpp" -#include "catch2.hpp" +#include #include "test_utils.hpp" diff --git a/test/test_decrementable.cpp b/test/test_decrementable.cpp index d8e2f23..78b7000 100644 --- a/test/test_decrementable.cpp +++ b/test/test_decrementable.cpp @@ -11,10 +11,10 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + TEST_CASE("a decrementable can be decremented") { using C = strong::type; diff --git a/test/test_difference.cpp b/test/test_difference.cpp index 09ff3a7..1689917 100644 --- a/test/test_difference.cpp +++ b/test/test_difference.cpp @@ -11,10 +11,10 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + TEST_CASE("adding difference types yields a difference type") { using U = strong::type; diff --git a/test/test_equality.cpp b/test/test_equality.cpp index dda3094..44ff0cc 100644 --- a/test/test_equality.cpp +++ b/test/test_equality.cpp @@ -11,9 +11,9 @@ * Project home: https://github.com/rollbear/strong_type */ -#include + #include "catch2.hpp" -#include "catch2.hpp" +#include TEST_CASE("values can be compared using operator==") { diff --git a/test/test_equality_with.cpp b/test/test_equality_with.cpp index f9e919b..c2c8787 100644 --- a/test/test_equality_with.cpp +++ b/test/test_equality_with.cpp @@ -11,10 +11,10 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + TEST_CASE("equality_with can compare with defined type") { using t1 = strong::type; diff --git a/test/test_hashable.cpp b/test/test_hashable.cpp index 9bc80ae..8194300 100644 --- a/test/test_hashable.cpp +++ b/test/test_hashable.cpp @@ -11,12 +11,14 @@ * Project home: https://github.com/rollbear/strong_type */ + #include "catch2.hpp" + #include #include -#include "catch2.hpp" - +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif TEST_CASE("strong::hashable can be used in unordered_set") { diff --git a/test/test_implicitly_convertible_to.cpp b/test/test_implicitly_convertible_to.cpp index f66205a..671e513 100644 --- a/test/test_implicitly_convertible_to.cpp +++ b/test/test_implicitly_convertible_to.cpp @@ -11,9 +11,9 @@ * Project home: https://github.com/rollbear/strong_type */ -#include + #include "catch2.hpp" -#include "catch2.hpp" +#include #include "test_utils.hpp" diff --git a/test/test_incrementable.cpp b/test/test_incrementable.cpp index a5a3bfa..b4883c1 100644 --- a/test/test_incrementable.cpp +++ b/test/test_incrementable.cpp @@ -11,9 +11,9 @@ * Project home: https://github.com/rollbear/strong_type */ -#include + #include "catch2.hpp" -#include "catch2.hpp" +#include TEST_CASE("an incrementable can be incremented") { diff --git a/test/test_indexed.cpp b/test/test_indexed.cpp index 92667d0..0f75f93 100644 --- a/test/test_indexed.cpp +++ b/test/test_indexed.cpp @@ -11,10 +11,10 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + #include "test_utils.hpp" TEST_CASE("indexed can be accessed using operator [] and .at()") diff --git a/test/test_invocable.cpp b/test/test_invocable.cpp index e703412..b371aa8 100644 --- a/test/test_invocable.cpp +++ b/test/test_invocable.cpp @@ -1,7 +1,7 @@ -#include - #include "catch2.hpp" +#include + namespace { using type = strong::type; diff --git a/test/test_iostreamable.cpp b/test/test_iostreamable.cpp index 0bafd77..ac7ff6a 100644 --- a/test/test_iostreamable.cpp +++ b/test/test_iostreamable.cpp @@ -11,11 +11,13 @@ * Project home: https://github.com/rollbear/strong_type */ -#include + #include "catch2.hpp" -#include "catch2.hpp" +#include +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif TEST_CASE("an iostreamable type can be both read and written using streams") { diff --git a/test/test_istreamable.cpp b/test/test_istreamable.cpp index f12621b..d5e5df2 100644 --- a/test/test_istreamable.cpp +++ b/test/test_istreamable.cpp @@ -11,11 +11,13 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif TEST_CASE("an istreamable type can be read from a istream") { diff --git a/test/test_iterator.cpp b/test/test_iterator.cpp index 0e3d622..8712f9f 100644 --- a/test/test_iterator.cpp +++ b/test/test_iterator.cpp @@ -11,13 +11,15 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include #include #include +#endif TEST_CASE("iterators work with algorithms") { diff --git a/test/test_ordered.cpp b/test/test_ordered.cpp index b1f3590..7309c76 100644 --- a/test/test_ordered.cpp +++ b/test/test_ordered.cpp @@ -11,11 +11,13 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif TEST_CASE("ordered type can be compared for ordering") { diff --git a/test/test_ordered_with.cpp b/test/test_ordered_with.cpp index 3142534..42877c2 100644 --- a/test/test_ordered_with.cpp +++ b/test/test_ordered_with.cpp @@ -11,11 +11,13 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif TEST_CASE("ordered_with") { diff --git a/test/test_ostreamable.cpp b/test/test_ostreamable.cpp index b09e1f1..c24f917 100644 --- a/test/test_ostreamable.cpp +++ b/test/test_ostreamable.cpp @@ -11,12 +11,14 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include #include +#endif TEST_CASE("an ostreamable type can be streamed using stream flags") { diff --git a/test/test_pointer.cpp b/test/test_pointer.cpp index 89ccb87..9d7de6c 100644 --- a/test/test_pointer.cpp +++ b/test/test_pointer.cpp @@ -11,11 +11,13 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif TEST_CASE("pointer types can be compared with nullptr") { diff --git a/test/test_range.cpp b/test/test_range.cpp index 17d8ea9..4aa251a 100644 --- a/test/test_range.cpp +++ b/test/test_range.cpp @@ -11,13 +11,15 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include #include #include +#endif namespace { template diff --git a/test/test_regular.cpp b/test/test_regular.cpp index 19a6ad8..4851f2b 100644 --- a/test/test_regular.cpp +++ b/test/test_regular.cpp @@ -11,11 +11,13 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif namespace { using type = strong::type; diff --git a/test/test_scalable_with.cpp b/test/test_scalable_with.cpp index 53295f9..8d0d800 100644 --- a/test/test_scalable_with.cpp +++ b/test/test_scalable_with.cpp @@ -11,10 +11,10 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + namespace { struct line { line(int x_) : x(x_) diff --git a/test/test_semiregular.cpp b/test/test_semiregular.cpp index 852b2fa..14f9acc 100644 --- a/test/test_semiregular.cpp +++ b/test/test_semiregular.cpp @@ -11,11 +11,13 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif namespace { using type = strong::type; diff --git a/test/test_type.cpp b/test/test_type.cpp index 1ee9b37..4b4dc84 100644 --- a/test/test_type.cpp +++ b/test/test_type.cpp @@ -11,14 +11,15 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + #include "test_utils.hpp" +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include - +#endif TEST_CASE("default_constructible initializes with underlying default constructor") { diff --git a/test/test_unique.cpp b/test/test_unique.cpp index 44b4a52..0cdbce4 100644 --- a/test/test_unique.cpp +++ b/test/test_unique.cpp @@ -11,11 +11,13 @@ * Project home: https://github.com/rollbear/strong_type */ -#include - #include "catch2.hpp" +#include + +#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY) #include +#endif TEST_CASE("strong::unique is movable") { diff --git a/test/test_utils.hpp b/test/test_utils.hpp index 90e8f32..5726a4d 100644 --- a/test/test_utils.hpp +++ b/test/test_utils.hpp @@ -14,7 +14,11 @@ #ifndef STRONG_TYPE_TEST_UTILS_HPP #define STRONG_TYPE_TEST_UTILS_HPP +#if defined(STRONG_TYPE_IMPORT_STD_LIBRARY) +import std; +#else #include +#endif template const T& as_const(T& t) { return t;}