Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions include/strong_type/arithmetic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#include "type.hpp"

#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY)
#include <limits>
#endif

namespace strong
{
Expand Down
2 changes: 2 additions & 0 deletions include/strong_type/formattable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@
#endif

#if STRONG_HAS_STD_FORMAT
#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY)
#include <format>
#endif
#endif

#if STRONG_HAS_FMT_FORMAT
#include "ostreamable.hpp"
Expand Down
2 changes: 2 additions & 0 deletions include/strong_type/hashable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#include "type.hpp"

#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY)
#include <functional>
#endif

namespace strong
{
Expand Down
2 changes: 2 additions & 0 deletions include/strong_type/istreamable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#include "type.hpp"

#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY)
#include <istream>
#endif

namespace strong
{
Expand Down
4 changes: 3 additions & 1 deletion include/strong_type/iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
#include "affine_point.hpp"
#include "indexed.hpp"

#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY)
#include <iterator>
#endif

#if __cplusplus >= 202002L && (((! defined(_LIBCPP_VERSION) || _LIBCPP_VERSION >= 15000)) && (!defined(__GLIBCXX__) || __GLIBCXX__ >= 20230528L))
#define STRONG_TYPE_CONTIGUOUS_ITERATOR 1
Expand Down Expand Up @@ -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*;
Expand Down
3 changes: 3 additions & 0 deletions include/strong_type/ordered.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@

#include "type.hpp"

#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY)
#if __cpp_impl_three_way_comparison && __has_include(<compare>)
#include <compare>
#endif
#endif

namespace strong
{
struct ordered
Expand Down
2 changes: 2 additions & 0 deletions include/strong_type/ordered_with.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

#include "type.hpp"

#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY)
#if __cpp_impl_three_way_comparison && __has_include(<compare>)
#include <compare>
#endif
#endif

namespace strong
{
Expand Down
2 changes: 2 additions & 0 deletions include/strong_type/ostreamable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

#include "type.hpp"

#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY)
#include <ostream>
#endif

namespace strong
{
Expand Down
2 changes: 2 additions & 0 deletions include/strong_type/range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
#define STRONG_TYPE_RANGE_HPP

#if __has_include(<ranges>)
#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY)
# include <ranges>
#endif
#endif
#if defined(_MSC_VER) && __cpp_lib_ranges >= 202110L
# define STRONG_TYPE_HAS_RANGES
#endif
Expand Down
10 changes: 7 additions & 3 deletions include/strong_type/type.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <type_traits>
#include <initializer_list>
#include <utility>
#include <type_traits>
#include <initializer_list>
#include <utility>
#endif

#if defined(_MSC_VER) && !defined(__clang__) && _MSC_VER < 1922
#define STRONG_CONSTEXPR
Expand Down
19 changes: 17 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <iomanip>
#include <unordered_set>
#include <memory>
#include <algorithm>
#endif

#include "catch2.hpp"

template <typename T, typename U>
using equality_compare = decltype(std::declval<const T&>() == std::declval<const U&>());
Expand Down Expand Up @@ -362,7 +364,7 @@ using ri = strong::type<int*, struct ipt, strong::iterator>;
static_assert(strong::type_is_v<ri, strong::iterator>, "");
static_assert(strong::type_is_v<ri, strong::equality>, "");
static_assert(strong::type_is_v<ri, strong::pointer>, "");
static_assert(strong::type_is_v<ri, strong::affine_point<intptr_t>>, "");
static_assert(strong::type_is_v<ri, strong::affine_point<std::intptr_t>>, "");
//static_assert(!strong::type_is_v<ri, strong::regular>, "");
//static_assert(!std::is_default_constructible<ri>{},"");
static_assert(std::is_nothrow_constructible<ri, int*>{},"");
Expand Down Expand Up @@ -439,7 +441,7 @@ using rhi = rhandle::iterator;
static_assert(strong::type_is_v<rhi, strong::iterator>, "");
static_assert(strong::type_is_v<rhi, strong::pointer>, "");
static_assert(strong::type_is_v<rhi, strong::equality>, "");
static_assert(strong::type_is_v<rhi, strong::affine_point<intptr_t>>, "");
static_assert(strong::type_is_v<rhi, strong::affine_point<std::intptr_t>>, "");
static_assert(std::is_nothrow_copy_constructible<rhi>{},"");
static_assert(std::is_nothrow_move_constructible<rhi>{},"");
//static_assert(!std::is_default_constructible<rhi>{},"");
Expand All @@ -451,7 +453,7 @@ using crhi = rhandle::const_iterator;
static_assert(strong::type_is_v<crhi, strong::iterator>, "");
static_assert(strong::type_is_v<crhi, strong::pointer>, "");
static_assert(strong::type_is_v<crhi, strong::equality>, "");
static_assert(strong::type_is_v<crhi, strong::affine_point<intptr_t>>, "");
static_assert(strong::type_is_v<crhi, strong::affine_point<std::intptr_t>>, "");
static_assert(std::is_nothrow_copy_constructible<crhi>{},"");
static_assert(std::is_nothrow_move_constructible<crhi>{},"");
//static_assert(!std::is_default_constructible<crhi>{},"");
Expand Down
3 changes: 2 additions & 1 deletion test/test_affine_point.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include "catch2.hpp"

#include <strong_type/affine_point.hpp>

#include "catch2.hpp"

TEST_CASE("affine_point types can be subtracted")
{
Expand Down
4 changes: 2 additions & 2 deletions test/test_arithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include <strong_type/arithmetic.hpp>
#include "catch2.hpp"

#include "catch2.hpp"
#include <strong_type/arithmetic.hpp>

namespace strong
{
Expand Down
4 changes: 2 additions & 2 deletions test/test_bicrementable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include <strong_type/bicrementable.hpp>
#include "catch2.hpp"

#include "catch2.hpp"
#include <strong_type/bicrementable.hpp>

TEST_CASE("a bicrementable goes both ways")
{
Expand Down
4 changes: 2 additions & 2 deletions test/test_bitarithmetic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include <strong_type/bitarithmetic.hpp>
#include "catch2.hpp"

#include "catch2.hpp"
#include <strong_type/bitarithmetic.hpp>


TEST_CASE("bitarithmetic types can be bitanded")
Expand Down
4 changes: 2 additions & 2 deletions test/test_boolean.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include <strong_type/boolean.hpp>
#include "catch2.hpp"

#include "catch2.hpp"
#include <strong_type/boolean.hpp>

TEST_CASE("a boolean value can be tested for truth")
{
Expand Down
4 changes: 2 additions & 2 deletions test/test_convertible_to.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include <strong_type/convertible_to.hpp>
#include "catch2.hpp"

#include "catch2.hpp"
#include <strong_type/convertible_to.hpp>

#include "test_utils.hpp"

Expand Down
4 changes: 2 additions & 2 deletions test/test_decrementable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include <strong_type/decrementable.hpp>

#include "catch2.hpp"

#include <strong_type/decrementable.hpp>

TEST_CASE("a decrementable can be decremented")
{
using C = strong::type<int, struct i_, strong::decrementable>;
Expand Down
4 changes: 2 additions & 2 deletions test/test_difference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include <strong_type/difference.hpp>

#include "catch2.hpp"

#include <strong_type/difference.hpp>

TEST_CASE("adding difference types yields a difference type")
{
using U = strong::type<int, struct u_, strong::difference>;
Expand Down
4 changes: 2 additions & 2 deletions test/test_equality.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include <strong_type/equality.hpp>
#include "catch2.hpp"

#include "catch2.hpp"
#include <strong_type/equality.hpp>

TEST_CASE("values can be compared using operator==")
{
Expand Down
4 changes: 2 additions & 2 deletions test/test_equality_with.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include <strong_type/equality_with.hpp>

#include "catch2.hpp"

#include <strong_type/equality_with.hpp>

TEST_CASE("equality_with can compare with defined type")
{
using t1 = strong::type<int, struct t1_>;
Expand Down
6 changes: 4 additions & 2 deletions test/test_hashable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include "catch2.hpp"

#include <strong_type/hashable.hpp>
#include <strong_type/regular.hpp>

#include "catch2.hpp"

#if !defined(STRONG_TYPE_IMPORT_STD_LIBRARY)
#include <unordered_set>
#endif

TEST_CASE("strong::hashable can be used in unordered_set")
{
Expand Down
4 changes: 2 additions & 2 deletions test/test_implicitly_convertible_to.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
* Project home: https://github.com/rollbear/strong_type
*/

#include <strong_type/implicitly_convertible_to.hpp>
#include "catch2.hpp"

#include "catch2.hpp"
#include <strong_type/implicitly_convertible_to.hpp>

#include "test_utils.hpp"

Expand Down
Loading