From aa7c021962f529f3ed2f482fd6f02e5497532a8a Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Wed, 7 Jun 2023 16:41:32 +0200 Subject: project: begin restructuring --- .gitignore | 5 +- .travis.yml | 42 - .vscode/settings.json | 6 +- CMakeLists.txt | 281 ------- cmake/Modules/Conan.cmake | 554 ------------- cmake/Modules/DiscoverTests.cmake | 55 -- cmake/Modules/DiscoverTestsImpl.cmake | 39 - cmake/config.cmake.in | 4 - conanfile.py | 92 ++- examples/src/basic_usage.cpp | 39 - examples/src/basic_usage_with_read.cpp | 39 - examples/src/basic_usage_with_show.cpp | 41 - include/newtype/derivable.hpp | 32 - include/newtype/derivation_clause.hpp | 70 -- include/newtype/deriving.hpp | 21 - include/newtype/impl/new_type_iterator_types.hpp | 66 -- include/newtype/impl/new_type_storage.hpp | 139 ---- include/newtype/impl/type_traits_extensions.hpp | 853 --------------------- include/newtype/newtype.hpp | 550 ------------- include/newtype/version.hpp | 23 - source/CMakeLists.txt | 88 +++ source/examples/src/basic_usage.cpp | 39 + source/examples/src/basic_usage_with_read.cpp | 39 + source/examples/src/basic_usage_with_show.cpp | 41 + source/include/newtype/derivable.hpp | 32 + source/include/newtype/derivation_clause.hpp | 70 ++ source/include/newtype/deriving.hpp | 21 + .../newtype/impl/new_type_iterator_types.hpp | 66 ++ source/include/newtype/impl/new_type_storage.hpp | 139 ++++ .../newtype/impl/type_traits_extensions.hpp | 853 +++++++++++++++++++++ source/include/newtype/newtype.hpp | 550 +++++++++++++ source/include/newtype/version.hpp | 23 + source/test/src/arithmetic.cpp | 300 ++++++++ source/test/src/conversion_suite.cpp | 201 +++++ source/test/src/derivation_clause_suite.cpp | 312 ++++++++ source/test/src/equality_comparison_suite.cpp | 188 +++++ source/test/src/hash_suite.cpp | 69 ++ source/test/src/io_operators_suite.cpp | 121 +++ source/test/src/iterable_suite.cpp | 719 +++++++++++++++++ source/test/src/new_type_constructor_suite.cpp | 91 +++ source/test/src/relational_operators_suite.cpp | 321 ++++++++ test/include/arithmetic_suite.hpp | 11 - test/include/conversion_suite.hpp | 11 - test/include/derivation_clause_suite.hpp | 11 - test/include/equality_comparison_suite.hpp | 11 - test/include/hash_suite.hpp | 11 - test/include/io_operators_suite.hpp | 11 - test/include/iterable_suite.hpp | 11 - test/include/kawaii.hpp | 143 ---- test/include/new_type_constructor_suite.hpp | 11 - test/include/relational_operators_suite.hpp | 11 - test/src/arithmetic_suite.cpp | 330 -------- test/src/conversion_suite.cpp | 201 ----- test/src/derivation_clause_suite.cpp | 312 -------- test/src/driver.cpp | 101 --- test/src/equality_comparison_suite.cpp | 188 ----- test/src/hash_suite.cpp | 69 -- test/src/io_operators_suite.cpp | 121 --- test/src/iterable_suite.cpp | 719 ----------------- test/src/new_type_constructor_suite.cpp | 91 --- test/src/relational_operators_suite.cpp | 321 -------- test_package/CMakeLists.txt | 13 +- test_package/conanfile.py | 16 +- test_package/main.cpp | 2 +- 64 files changed, 4368 insertions(+), 5592 deletions(-) delete mode 100644 .travis.yml delete mode 100644 CMakeLists.txt delete mode 100644 cmake/Modules/Conan.cmake delete mode 100644 cmake/Modules/DiscoverTests.cmake delete mode 100644 cmake/Modules/DiscoverTestsImpl.cmake delete mode 100644 cmake/config.cmake.in delete mode 100644 examples/src/basic_usage.cpp delete mode 100644 examples/src/basic_usage_with_read.cpp delete mode 100644 examples/src/basic_usage_with_show.cpp delete mode 100644 include/newtype/derivable.hpp delete mode 100644 include/newtype/derivation_clause.hpp delete mode 100644 include/newtype/deriving.hpp delete mode 100644 include/newtype/impl/new_type_iterator_types.hpp delete mode 100644 include/newtype/impl/new_type_storage.hpp delete mode 100644 include/newtype/impl/type_traits_extensions.hpp delete mode 100644 include/newtype/newtype.hpp delete mode 100644 include/newtype/version.hpp create mode 100644 source/CMakeLists.txt create mode 100644 source/examples/src/basic_usage.cpp create mode 100644 source/examples/src/basic_usage_with_read.cpp create mode 100644 source/examples/src/basic_usage_with_show.cpp create mode 100644 source/include/newtype/derivable.hpp create mode 100644 source/include/newtype/derivation_clause.hpp create mode 100644 source/include/newtype/deriving.hpp create mode 100644 source/include/newtype/impl/new_type_iterator_types.hpp create mode 100644 source/include/newtype/impl/new_type_storage.hpp create mode 100644 source/include/newtype/impl/type_traits_extensions.hpp create mode 100644 source/include/newtype/newtype.hpp create mode 100644 source/include/newtype/version.hpp create mode 100644 source/test/src/arithmetic.cpp create mode 100644 source/test/src/conversion_suite.cpp create mode 100644 source/test/src/derivation_clause_suite.cpp create mode 100644 source/test/src/equality_comparison_suite.cpp create mode 100644 source/test/src/hash_suite.cpp create mode 100644 source/test/src/io_operators_suite.cpp create mode 100644 source/test/src/iterable_suite.cpp create mode 100644 source/test/src/new_type_constructor_suite.cpp create mode 100644 source/test/src/relational_operators_suite.cpp delete mode 100644 test/include/arithmetic_suite.hpp delete mode 100644 test/include/conversion_suite.hpp delete mode 100644 test/include/derivation_clause_suite.hpp delete mode 100644 test/include/equality_comparison_suite.hpp delete mode 100644 test/include/hash_suite.hpp delete mode 100644 test/include/io_operators_suite.hpp delete mode 100644 test/include/iterable_suite.hpp delete mode 100644 test/include/kawaii.hpp delete mode 100644 test/include/new_type_constructor_suite.hpp delete mode 100644 test/include/relational_operators_suite.hpp delete mode 100644 test/src/arithmetic_suite.cpp delete mode 100644 test/src/conversion_suite.cpp delete mode 100644 test/src/derivation_clause_suite.cpp delete mode 100644 test/src/driver.cpp delete mode 100644 test/src/equality_comparison_suite.cpp delete mode 100644 test/src/hash_suite.cpp delete mode 100644 test/src/io_operators_suite.cpp delete mode 100644 test/src/iterable_suite.cpp delete mode 100644 test/src/new_type_constructor_suite.cpp delete mode 100644 test/src/relational_operators_suite.cpp diff --git a/.gitignore b/.gitignore index 42afabf..cebfa4e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -/build \ No newline at end of file +/.cache +/build +/source/CMakeUserPresets.json +/test_package/CMakeUserPresets.json diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index f523e70..0000000 --- a/.travis.yml +++ /dev/null @@ -1,42 +0,0 @@ -os: linux -language: python -python: "3.7" -dist: bionic - -addons: - apt: - sources: - - sourceline: 'ppa:ubuntu-toolchain-r/test' - - sourceline: 'deb https://apt.kitware.com/ubuntu/ bionic main' - key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc' - packages: - - g++-9 - - cmake - - libperlio-gzip-perl - - libjson-perl - -compiler: - - gcc - -cache: - directories: - - $HOME/.conan/data - -before_install: - - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 20 - - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 20 - - sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-9 20 - - sudo update-alternatives --config gcc - - sudo update-alternatives --config g++ - - sudo update-alternatives --config gcov - -install: - - pip install conan - - conan user - - git clone git://github.com/linux-test-project/lcov.git - - cd lcov && sudo make install - - cd .. - -script: - - /usr/bin/cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=YES -DRUN_TESTS_AFTER_BUILD=YES -DENABLE_CODE_COVERAGE=YES -DPRINT_COVERAGE_REPORT=YES - - /usr/bin/cmake --build build --target all --parallel $(nproc) diff --git a/.vscode/settings.json b/.vscode/settings.json index d237db4..24f5d88 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -11,5 +11,9 @@ "C_Cpp.autoAddFileAssociations": false, // RST Configuration - "restructuredtext.confPath": "${workspaceFolder}/doc/src" + "restructuredtext.confPath": "${workspaceFolder}/doc/src", + "[python]": { + "editor.defaultFormatter": "ms-python.black-formatter" + }, + "python.formatting.provider": "none" } \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt deleted file mode 100644 index 3c29a76..0000000 --- a/CMakeLists.txt +++ /dev/null @@ -1,281 +0,0 @@ -cmake_minimum_required(VERSION "3.9.0") - -project("newtype" - VERSION "1.1.0" - LANGUAGES CXX - DESCRIPTION "A library of types and functions to create strong type aliases" -) - -include("CMakePackageConfigHelpers") - -# Project Options - -option(RUN_TESTS_AFTER_BUILD "Automatically run the unit tests after building" ON) -option(BUILD_TESTING "Build the unit tests" ON) -option(ENABLE_CODE_COVERAGE "Enable building support for code coverage report generation" ON) -option(PRINT_COVERAGE_REPORT "Print a coverage report after running the unit tests" ON) -option(GENERATE_COVERAGE_REPORT "Generate an HTML coverage report after running the unit tests" OFF) - -# 'newtype' library - -add_library("${PROJECT_NAME}" INTERFACE) - -target_include_directories("${PROJECT_NAME}" INTERFACE - $ - $ -) - -target_compile_features("${PROJECT_NAME}" INTERFACE - "cxx_std_20" -) - -install(TARGETS "${PROJECT_NAME}" - EXPORT "${PROJECT_NAME}Targets" - PUBLIC_HEADER DESTINATION "include" -) - -install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" - DESTINATION "include" -) - -# 'newtype' tests - -if(BUILD_TESTING) - enable_testing() - - if(PRINT_COVERAGE_REPORT) - find_program(LCOV_EXE NAMES "lcov") - mark_as_advanced(LCOV_EXE) - if(NOT LCOV_EXE) - message(FATAL_ERROR "lcov is required to generate code coverage reports") - endif() - endif() - - if(GENERATE_COVERAGE_REPORT) - find_program(GENHTML_EXE NAMES "genhtml") - mark_as_advanced(GENHTML_EXE) - if(NOT GENHTML_EXE) - message(FATAL_ERROR "genhtml is required to generate code coverage reports") - endif() - endif() - - include("${PROJECT_SOURCE_DIR}/cmake/Modules/DiscoverTests.cmake") - include("${PROJECT_SOURCE_DIR}/cmake/Modules/Conan.cmake") - - conan_check(REQUIRED) - conan_add_remote(NAME "fmorgner-public" URL "https://api.bintray.com/conan/fmorgner/conan-public") - conan_cmake_run(CONANFILE "conanfile.py" - OUTPUT_QUIET - BASIC_SETUP - CMAKE_TARGETS - BUILD "missing" - NO_OUTPUT_DIRS - ) - - add_executable("${PROJECT_NAME}_tests" - "${PROJECT_SOURCE_DIR}/test/src/driver.cpp" - - "${PROJECT_SOURCE_DIR}/test/src/arithmetic_suite.cpp" - "${PROJECT_SOURCE_DIR}/test/src/conversion_suite.cpp" - "${PROJECT_SOURCE_DIR}/test/src/derivation_clause_suite.cpp" - "${PROJECT_SOURCE_DIR}/test/src/equality_comparison_suite.cpp" - "${PROJECT_SOURCE_DIR}/test/src/hash_suite.cpp" - "${PROJECT_SOURCE_DIR}/test/src/io_operators_suite.cpp" - "${PROJECT_SOURCE_DIR}/test/src/iterable_suite.cpp" - "${PROJECT_SOURCE_DIR}/test/src/new_type_constructor_suite.cpp" - "${PROJECT_SOURCE_DIR}/test/src/relational_operators_suite.cpp" - ) - - target_include_directories("${PROJECT_NAME}_tests" PRIVATE - "${PROJECT_SOURCE_DIR}/test/include" - ) - - target_link_libraries("${PROJECT_NAME}_tests" - "newtype" - "CONAN_PKG::CUTE" - "CONAN_PKG::lyra" - ) - - target_compile_options("${PROJECT_NAME}_tests" PRIVATE - "-Wall" - "-Wextra" - "-Werror" - "-pedantic-errors" - $<$:--coverage> - ) - - target_link_options("${PROJECT_NAME}_tests" PRIVATE - $<$:--coverage> - ) - - set_target_properties("${PROJECT_NAME}_tests" PROPERTIES - CXX_EXTENSIONS OFF - ) - - discover_tests(TARGET "${PROJECT_NAME}_tests") - - if(RUN_TESTS_AFTER_BUILD) - add_custom_command(TARGET "${PROJECT_NAME}_tests" - POST_BUILD - DEPENDS "${PROJECT_NAME}_tests" - COMMAND "${CMAKE_CTEST_COMMAND}" - ARGS - "--output-on-failure" - WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" - COMMENT "Running unit tests" - ) - endif() - - if(ENABLE_CODE_COVERAGE AND RUN_TESTS_AFTER_BUILD) - add_custom_command(TARGET "${PROJECT_NAME}_tests" - POST_BUILD - BYPRODUCTS "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.coverage.info" - COMMAND "${LCOV_EXE}" - ARGS - "--capture" - "--base-directory" "${PROJECT_SOURCE_DIR}" - "--directory" "${PROJECT_BINARY_DIR}" - "--output-file" "${PROJECT_NAME}.coverage.info" - "--no-external" - "--exclude" "${PROJECT_SOURCE_DIR}/test/\\*" - ">/dev/null" - WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" - COMMENT "Capturing code coverage data" - ) - - if(PRINT_COVERAGE_REPORT) - add_custom_command(TARGET "${PROJECT_NAME}_tests" - POST_BUILD - COMMAND "${LCOV_EXE}" - ARGS - "--list" - "${PROJECT_NAME}.coverage.info" - WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" - COMMENT "Printing code coverage report" - ) - endif() - - if(GENERATE_COVERAGE_REPORT) - add_custom_command(TARGET "${PROJECT_NAME}_tests" - POST_BUILD - BYPRODUCTS "${PROJECT_BINARY_DIR}/coverage-report/index.html" - COMMAND "${GENHTML_EXE}" - ARGS - "--demangle-cpp" - "--highlight" - "--missed" - "--show-details" - "--output" "coverage-report" - "${PROJECT_NAME}.coverage.info" - ">/dev/null" - WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" - COMMENT "Generating code coverage report" - ) - endif() - endif() -endif() - -# 'newtype' docs - -option(BUILD_DOCS "Build the library documentation" OFF) - -if(BUILD_DOCS) - find_program(PIPENV_EXE NAMES "pipenv3" "pipenv") - mark_as_advanced(PIPENV_EXE) - if(NOT PIPENV_EXE) - message(FATAL_ERROR "Could not find pipenv") - endif() - - message(STATUS "Installing documentation dependencies via pipenv") - execute_process(COMMAND "${PIPENV_EXE}" "install" "-r" "requirements.txt" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/doc" - OUTPUT_QUIET - ERROR_QUIET - ) - - set(DOC_SOURCES - "${PROJECT_SOURCE_DIR}/doc/src/index.rst" - "${PROJECT_SOURCE_DIR}/doc/src/conf.py" - "${PROJECT_SOURCE_DIR}/examples/src/basic_usage.cpp" - "${PROJECT_SOURCE_DIR}/examples/src/basic_usage_with_show.cpp" - "${PROJECT_SOURCE_DIR}/examples/src/basic_usage_with_read.cpp" - ) - - add_custom_target("docs" - DEPENDS "${PROJECT_BINARY_DIR}/doc/html/index.html" "${PROJECT_BINARY_DIR}/doc/man/newtype.3" - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/doc" - COMMENT "Building documentation" - ) - - add_custom_command(OUTPUT "${PROJECT_BINARY_DIR}/doc/html/index.html" - COMMAND "${PIPENV_EXE}" "run" "sphinx-build" "-b" "singlehtml" "${PROJECT_SOURCE_DIR}/doc/src" "${PROJECT_BINARY_DIR}/doc/html" ">/dev/null" - DEPENDS ${DOC_SOURCES} - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/doc" - COMMENT "Compiling HTML documentation" - ) - - add_custom_command(OUTPUT "${PROJECT_BINARY_DIR}/doc/man/newtype.3" - COMMAND "${PIPENV_EXE}" "run" "sphinx-build" "-b" "man" "${PROJECT_SOURCE_DIR}/doc/src" "${PROJECT_BINARY_DIR}/doc/man" ">/dev/null" - DEPENDS ${DOC_SOURCES} - WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/doc" - COMMENT "Compiling man pages" - ) - - add_dependencies("${PROJECT_NAME}" "docs") - - install(DIRECTORY "${PROJECT_BINARY_DIR}/doc/html" - DESTINATION "share/doc/${PROJECT_NAME}" - PATTERN ".nojekyll" EXCLUDE - PATTERN ".buildinfo" EXCLUDE - PATTERN ".doctrees" EXCLUDE - PATTERN "objects.inv" EXCLUDE - ) - - install(FILES "${PROJECT_BINARY_DIR}/doc/man/${PROJECT_NAME}.3" - DESTINATION "share/man/man3" - ) -endif() - -# 'newtype' examples - -option(BUILD_EXAMPLES "Build the library examples" OFF) - -if(BUILD_EXAMPLES) - function(add_example NAME) - add_executable("ex_${NAME}" - "examples/src/${NAME}.cpp" - ) - target_link_libraries("ex_${NAME}" "${PROJECT_NAME}") - endfunction() - - add_example("basic_usage") - add_example("basic_usage_with_show") - add_example("basic_usage_with_read") -endif() - -# CMake support files - -write_basic_package_version_file( - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - COMPATIBILITY "AnyNewerVersion" -) - -configure_package_config_file( - "${PROJECT_SOURCE_DIR}/cmake/config.cmake.in" - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - INSTALL_DESTINATION "lib/cmake/${PROJECT_NAME}" -) - -install(FILES - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" - "${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" - DESTINATION "lib/cmake/${PROJECT_NAME}" -) - -install(DIRECTORY "${PROJECT_SOURCE_DIR}/doc/src/" - DESTINATION "share/doc/newtype" -) - -install(EXPORT "${PROJECT_NAME}Targets" - DESTINATION "lib/cmake/${PROJECT_NAME}" -) diff --git a/cmake/Modules/Conan.cmake b/cmake/Modules/Conan.cmake deleted file mode 100644 index aac3b9c..0000000 --- a/cmake/Modules/Conan.cmake +++ /dev/null @@ -1,554 +0,0 @@ -# The MIT License (MIT) - -# Copyright (c) 2018 JFrog - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - - - -# This file comes from: https://github.com/conan-io/cmake-conan. Please refer -# to this repository for issues and documentation. - -# Its purpose is to wrap and launch Conan C/C++ Package Manager when cmake is called. -# It will take CMake current settings (os, compiler, compiler version, architecture) -# and translate them to conan settings for installing and retrieving dependencies. - -# It is intended to facilitate developers building projects that have conan dependencies, -# but it is only necessary on the end-user side. It is not necessary to create conan -# packages, in fact it shouldn't be use for that. Check the project documentation. - - -include(CMakeParseArguments) - -function(_get_msvc_ide_version result) - set(${result} "" PARENT_SCOPE) - if(NOT MSVC_VERSION VERSION_LESS 1400 AND MSVC_VERSION VERSION_LESS 1500) - set(${result} 8 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1500 AND MSVC_VERSION VERSION_LESS 1600) - set(${result} 9 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1600 AND MSVC_VERSION VERSION_LESS 1700) - set(${result} 10 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1700 AND MSVC_VERSION VERSION_LESS 1800) - set(${result} 11 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1800 AND MSVC_VERSION VERSION_LESS 1900) - set(${result} 12 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1900 AND MSVC_VERSION VERSION_LESS 1910) - set(${result} 14 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1910 AND MSVC_VERSION VERSION_LESS 1920) - set(${result} 15 PARENT_SCOPE) - elseif(NOT MSVC_VERSION VERSION_LESS 1920 AND MSVC_VERSION VERSION_LESS 1930) - set(${result} 16 PARENT_SCOPE) - else() - message(FATAL_ERROR "Conan: Unknown MSVC compiler version [${MSVC_VERSION}]") - endif() -endfunction() - -function(conan_cmake_settings result) - #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER}) - #message(STATUS "COMPILER " ${CMAKE_CXX_COMPILER_ID}) - #message(STATUS "VERSION " ${CMAKE_CXX_COMPILER_VERSION}) - #message(STATUS "FLAGS " ${CMAKE_LANG_FLAGS}) - #message(STATUS "LIB ARCH " ${CMAKE_CXX_LIBRARY_ARCHITECTURE}) - #message(STATUS "BUILD TYPE " ${CMAKE_BUILD_TYPE}) - #message(STATUS "GENERATOR " ${CMAKE_GENERATOR}) - #message(STATUS "GENERATOR WIN64 " ${CMAKE_CL_64}) - - message(STATUS "Conan: Automatic detection of conan settings from cmake") - - parse_arguments(${ARGV}) - - if(ARGUMENTS_BUILD_TYPE) - set(_CONAN_SETTING_BUILD_TYPE ${ARGUMENTS_BUILD_TYPE}) - elseif(CMAKE_BUILD_TYPE) - set(_CONAN_SETTING_BUILD_TYPE ${CMAKE_BUILD_TYPE}) - else() - message(FATAL_ERROR "Please specify in command line CMAKE_BUILD_TYPE (-DCMAKE_BUILD_TYPE=Release)") - endif() - - string(TOUPPER ${_CONAN_SETTING_BUILD_TYPE} _CONAN_SETTING_BUILD_TYPE_UPPER) - if (_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "DEBUG") - set(_CONAN_SETTING_BUILD_TYPE "Debug") - elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELEASE") - set(_CONAN_SETTING_BUILD_TYPE "Release") - elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "RELWITHDEBINFO") - set(_CONAN_SETTING_BUILD_TYPE "RelWithDebInfo") - elseif(_CONAN_SETTING_BUILD_TYPE_UPPER STREQUAL "MINSIZEREL") - set(_CONAN_SETTING_BUILD_TYPE "MinSizeRel") - endif() - - if(ARGUMENTS_ARCH) - set(_CONAN_SETTING_ARCH ${ARGUMENTS_ARCH}) - endif() - #handle -s os setting - if(CMAKE_SYSTEM_NAME) - #use default conan os setting if CMAKE_SYSTEM_NAME is not defined - set(CONAN_SYSTEM_NAME ${CMAKE_SYSTEM_NAME}) - if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin") - set(CONAN_SYSTEM_NAME Macos) - endif() - set(CONAN_SUPPORTED_PLATFORMS Windows Linux Macos Android iOS FreeBSD WindowsStore) - list (FIND CONAN_SUPPORTED_PLATFORMS "${CONAN_SYSTEM_NAME}" _index) - if (${_index} GREATER -1) - #check if the cmake system is a conan supported one - set(_CONAN_SETTING_OS ${CONAN_SYSTEM_NAME}) - else() - message(FATAL_ERROR "cmake system ${CONAN_SYSTEM_NAME} is not supported by conan. Use one of ${CONAN_SUPPORTED_PLATFORMS}") - endif() - endif() - - get_property(_languages GLOBAL PROPERTY ENABLED_LANGUAGES) - if (";${_languages};" MATCHES ";CXX;") - set(LANGUAGE CXX) - set(USING_CXX 1) - elseif (";${_languages};" MATCHES ";C;") - set(LANGUAGE C) - set(USING_CXX 0) - else () - message(FATAL_ERROR "Conan: Neither C or C++ was detected as a language for the project. Unabled to detect compiler version.") - endif() - - if (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL GNU) - # using GCC - # TODO: Handle other params - string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) - list(GET VERSION_LIST 0 MAJOR) - list(GET VERSION_LIST 1 MINOR) - set(COMPILER_VERSION ${MAJOR}.${MINOR}) - if(${MAJOR} GREATER 4) - set(COMPILER_VERSION ${MAJOR}) - endif() - set(_CONAN_SETTING_COMPILER gcc) - set(_CONAN_SETTING_COMPILER_VERSION ${COMPILER_VERSION}) - if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) - set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) - endif () - elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL AppleClang) - # using AppleClang - string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) - list(GET VERSION_LIST 0 MAJOR) - list(GET VERSION_LIST 1 MINOR) - set(_CONAN_SETTING_COMPILER apple-clang) - set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR}) - if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) - set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) - endif () - elseif (${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL Clang) - string(REPLACE "." ";" VERSION_LIST ${CMAKE_${LANGUAGE}_COMPILER_VERSION}) - list(GET VERSION_LIST 0 MAJOR) - list(GET VERSION_LIST 1 MINOR) - set(_CONAN_SETTING_COMPILER clang) - set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}.${MINOR}) - if(APPLE) - cmake_policy(GET CMP0025 APPLE_CLANG_POLICY_ENABLED) - if(NOT APPLE_CLANG_POLICY_ENABLED) - message(STATUS "Conan: APPLE and Clang detected. Assuming apple-clang compiler. Set CMP0025 to avoid it") - set(_CONAN_SETTING_COMPILER apple-clang) - endif() - endif() - if(${_CONAN_SETTING_COMPILER} STREQUAL clang AND ${MAJOR} GREATER 7) - set(_CONAN_SETTING_COMPILER_VERSION ${MAJOR}) - endif() - if (USING_CXX) - conan_cmake_detect_unix_libcxx(_LIBCXX) - set(_CONAN_SETTING_COMPILER_LIBCXX ${_LIBCXX}) - endif () - elseif(${CMAKE_${LANGUAGE}_COMPILER_ID} STREQUAL MSVC) - set(_VISUAL "Visual Studio") - _get_msvc_ide_version(_VISUAL_VERSION) - if("${_VISUAL_VERSION}" STREQUAL "") - message(FATAL_ERROR "Conan: Visual Studio not recognized") - else() - set(_CONAN_SETTING_COMPILER ${_VISUAL}) - set(_CONAN_SETTING_COMPILER_VERSION ${_VISUAL_VERSION}) - endif() - - if(NOT _CONAN_SETTING_ARCH) - if (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "64") - set(_CONAN_SETTING_ARCH x86_64) - elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "^ARM") - message(STATUS "Conan: Using default ARM architecture from MSVC") - set(_CONAN_SETTING_ARCH armv6) - elseif (MSVC_${LANGUAGE}_ARCHITECTURE_ID MATCHES "86") - set(_CONAN_SETTING_ARCH x86) - else () - message(FATAL_ERROR "Conan: Unknown MSVC architecture [${MSVC_${LANGUAGE}_ARCHITECTURE_ID}]") - endif() - endif() - - conan_cmake_detect_vs_runtime(_vs_runtime) - message(STATUS "Conan: Detected VS runtime: ${_vs_runtime}") - set(_CONAN_SETTING_COMPILER_RUNTIME ${_vs_runtime}) - - if (CMAKE_GENERATOR_TOOLSET) - set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) - elseif(CMAKE_VS_PLATFORM_TOOLSET AND (CMAKE_GENERATOR STREQUAL "Ninja")) - set(_CONAN_SETTING_COMPILER_TOOLSET ${CMAKE_VS_PLATFORM_TOOLSET}) - endif() - else() - message(FATAL_ERROR "Conan: compiler setup not recognized") - endif() - - # If profile is defined it is used - if(CMAKE_BUILD_TYPE STREQUAL "Debug" AND ARGUMENTS_DEBUG_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_DEBUG_PROFILE}) - elseif(CMAKE_BUILD_TYPE STREQUAL "Release" AND ARGUMENTS_RELEASE_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_RELEASE_PROFILE}) - elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" AND ARGUMENTS_RELWITHDEBINFO_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_RELWITHDEBINFO_PROFILE}) - elseif(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" AND ARGUMENTS_MINSIZEREL_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_MINSIZEREL_PROFILE}) - elseif(ARGUMENTS_PROFILE) - set(_APPLIED_PROFILES ${ARGUMENTS_PROFILE}) - endif() - - foreach(ARG ${_APPLIED_PROFILES}) - set(_SETTINGS ${_SETTINGS} -pr ${ARG}) - endforeach() - - if(NOT _SETTINGS OR ARGUMENTS_PROFILE_AUTO STREQUAL "ALL") - set(ARGUMENTS_PROFILE_AUTO arch build_type compiler compiler.version - compiler.runtime compiler.libcxx compiler.toolset) - endif() - - # Automatic from CMake - foreach(ARG ${ARGUMENTS_PROFILE_AUTO}) - string(TOUPPER ${ARG} _arg_name) - string(REPLACE "." "_" _arg_name ${_arg_name}) - if(_CONAN_SETTING_${_arg_name}) - set(_SETTINGS ${_SETTINGS} -s ${ARG}=${_CONAN_SETTING_${_arg_name}}) - endif() - endforeach() - - foreach(ARG ${ARGUMENTS_SETTINGS}) - set(_SETTINGS ${_SETTINGS} -s ${ARG}) - endforeach() - - message(STATUS "Conan: Settings= ${_SETTINGS}") - - set(${result} ${_SETTINGS} PARENT_SCOPE) -endfunction() - - -function(conan_cmake_detect_unix_libcxx result) - # Take into account any -stdlib in compile options - get_directory_property(compile_options DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_OPTIONS) - - # Take into account any _GLIBCXX_USE_CXX11_ABI in compile definitions - get_directory_property(defines DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMPILE_DEFINITIONS) - foreach(define ${defines}) - if(define MATCHES "_GLIBCXX_USE_CXX11_ABI") - if(define MATCHES "^-D") - set(compile_options ${compile_options} "${define}") - else() - set(compile_options ${compile_options} "-D${define}") - endif() - endif() - endforeach() - - execute_process( - COMMAND ${CMAKE_COMMAND} -E echo "#include " - COMMAND ${CMAKE_CXX_COMPILER} -x c++ ${compile_options} -E -dM - - OUTPUT_VARIABLE string_defines - ) - - if(string_defines MATCHES "#define __GLIBCXX__") - # Allow -D_GLIBCXX_USE_CXX11_ABI=ON/OFF as argument to cmake - if(DEFINED _GLIBCXX_USE_CXX11_ABI) - if(_GLIBCXX_USE_CXX11_ABI) - set(${result} libstdc++11 PARENT_SCOPE) - return() - else() - set(${result} libstdc++ PARENT_SCOPE) - return() - endif() - endif() - - if(string_defines MATCHES "#define _GLIBCXX_USE_CXX11_ABI 1\n") - set(${result} libstdc++11 PARENT_SCOPE) - else() - # Either the compiler is missing the define because it is old, and so - # it can't use the new abi, or the compiler was configured to use the - # old abi by the user or distro (e.g. devtoolset on RHEL/CentOS) - set(${result} libstdc++ PARENT_SCOPE) - endif() - else() - set(${result} libc++ PARENT_SCOPE) - endif() -endfunction() - -function(conan_cmake_detect_vs_runtime result) - string(TOUPPER ${CMAKE_BUILD_TYPE} build_type) - set(variables CMAKE_CXX_FLAGS_${build_type} CMAKE_C_FLAGS_${build_type} CMAKE_CXX_FLAGS CMAKE_C_FLAGS) - foreach(variable ${variables}) - string(REPLACE " " ";" flags ${${variable}}) - foreach (flag ${flags}) - if(${flag} STREQUAL "/MD" OR ${flag} STREQUAL "/MDd" OR ${flag} STREQUAL "/MT" OR ${flag} STREQUAL "/MTd") - string(SUBSTRING ${flag} 1 -1 runtime) - set(${result} ${runtime} PARENT_SCOPE) - return() - endif() - endforeach() - endforeach() - if(${build_type} STREQUAL "DEBUG") - set(${result} "MDd" PARENT_SCOPE) - else() - set(${result} "MD" PARENT_SCOPE) - endif() -endfunction() - - -macro(parse_arguments) - set(options BASIC_SETUP CMAKE_TARGETS UPDATE KEEP_RPATHS NO_LOAD NO_OUTPUT_DIRS OUTPUT_QUIET NO_IMPORTS) - set(oneValueArgs CONANFILE ARCH BUILD_TYPE INSTALL_FOLDER CONAN_COMMAND) - set(multiValueArgs DEBUG_PROFILE RELEASE_PROFILE RELWITHDEBINFO_PROFILE MINSIZEREL_PROFILE - PROFILE REQUIRES OPTIONS IMPORTS SETTINGS BUILD ENV GENERATORS PROFILE_AUTO - INSTALL_ARGS) - cmake_parse_arguments(ARGUMENTS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) -endmacro() - -function(conan_cmake_install) - # Calls "conan install" - # Argument BUILD is equivalant to --build={missing, PkgName,...} or - # --build when argument is 'BUILD all' (which builds all packages from source) - # Argument CONAN_COMMAND, to specify the conan path, e.g. in case of running from source - # cmake does not identify conan as command, even if it is +x and it is in the path - parse_arguments(${ARGV}) - - if(CONAN_CMAKE_MULTI) - set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake_multi) - else() - set(ARGUMENTS_GENERATORS ${ARGUMENTS_GENERATORS} cmake) - endif() - - set(CONAN_BUILD_POLICY "") - foreach(ARG ${ARGUMENTS_BUILD}) - if(${ARG} STREQUAL "all") - set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build) - break() - else() - set(CONAN_BUILD_POLICY ${CONAN_BUILD_POLICY} --build=${ARG}) - endif() - endforeach() - if(ARGUMENTS_CONAN_COMMAND) - set(conan_command ${ARGUMENTS_CONAN_COMMAND}) - else() - set(conan_command conan) - endif() - set(CONAN_OPTIONS "") - if(ARGUMENTS_CONANFILE) - set(CONANFILE ${CMAKE_CURRENT_SOURCE_DIR}/${ARGUMENTS_CONANFILE}) - # A conan file has been specified - apply specified options as well if provided - foreach(ARG ${ARGUMENTS_OPTIONS}) - set(CONAN_OPTIONS ${CONAN_OPTIONS} -o=${ARG}) - endforeach() - else() - set(CONANFILE ".") - endif() - if(ARGUMENTS_UPDATE) - set(CONAN_INSTALL_UPDATE --update) - endif() - if(ARGUMENTS_NO_IMPORTS) - set(CONAN_INSTALL_NO_IMPORTS --no-imports) - endif() - set(CONAN_INSTALL_FOLDER "") - if(ARGUMENTS_INSTALL_FOLDER) - set(CONAN_INSTALL_FOLDER -if=${ARGUMENTS_INSTALL_FOLDER}) - endif() - foreach(ARG ${ARGUMENTS_GENERATORS}) - set(CONAN_GENERATORS ${CONAN_GENERATORS} -g=${ARG}) - endforeach() - foreach(ARG ${ARGUMENTS_ENV}) - set(CONAN_ENV_VARS ${CONAN_ENV_VARS} -e=${ARG}) - endforeach() - set(conan_args install ${CONANFILE} ${settings} ${CONAN_ENV_VARS} ${CONAN_GENERATORS} ${CONAN_BUILD_POLICY} ${CONAN_INSTALL_UPDATE} ${CONAN_INSTALL_NO_IMPORTS} ${CONAN_OPTIONS} ${CONAN_INSTALL_FOLDER} ${ARGUMENTS_INSTALL_ARGS}) - - string (REPLACE ";" " " _conan_args "${conan_args}") - message(STATUS "Conan executing: ${conan_command} ${_conan_args}") - - if(ARGUMENTS_OUTPUT_QUIET) - execute_process(COMMAND ${conan_command} ${conan_args} - RESULT_VARIABLE return_code - OUTPUT_VARIABLE conan_output - ERROR_VARIABLE conan_output - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - else() - execute_process(COMMAND ${conan_command} ${conan_args} - RESULT_VARIABLE return_code - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) - endif() - - if(NOT "${return_code}" STREQUAL "0") - message(FATAL_ERROR "Conan install failed='${return_code}'") - endif() - -endfunction() - - -function(conan_cmake_setup_conanfile) - parse_arguments(${ARGV}) - if(ARGUMENTS_CONANFILE) - get_filename_component(_CONANFILE_NAME ${ARGUMENTS_CONANFILE} NAME) - # configure_file will make sure cmake re-runs when conanfile is updated - configure_file(${ARGUMENTS_CONANFILE} ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk) - file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/${_CONANFILE_NAME}.junk) - else() - conan_cmake_generate_conanfile(${ARGV}) - endif() -endfunction() - -function(conan_cmake_generate_conanfile) - # Generate, writing in disk a conanfile.txt with the requires, options, and imports - # specified as arguments - # This will be considered as temporary file, generated in CMAKE_CURRENT_BINARY_DIR) - parse_arguments(${ARGV}) - set(_FN "${CMAKE_CURRENT_BINARY_DIR}/conanfile.txt") - - file(WRITE ${_FN} "[generators]\ncmake\n\n[requires]\n") - foreach(ARG ${ARGUMENTS_REQUIRES}) - file(APPEND ${_FN} ${ARG} "\n") - endforeach() - - file(APPEND ${_FN} ${ARG} "\n[options]\n") - foreach(ARG ${ARGUMENTS_OPTIONS}) - file(APPEND ${_FN} ${ARG} "\n") - endforeach() - - file(APPEND ${_FN} ${ARG} "\n[imports]\n") - foreach(ARG ${ARGUMENTS_IMPORTS}) - file(APPEND ${_FN} ${ARG} "\n") - endforeach() -endfunction() - - -macro(conan_load_buildinfo) - if(CONAN_CMAKE_MULTI) - set(_CONANBUILDINFO conanbuildinfo_multi.cmake) - else() - set(_CONANBUILDINFO conanbuildinfo.cmake) - endif() - if(ARGUMENTS_INSTALL_FOLDER) - set(_CONANBUILDINFOFOLDER ${ARGUMENTS_INSTALL_FOLDER}) - else() - set(_CONANBUILDINFOFOLDER ${CMAKE_CURRENT_BINARY_DIR}) - endif() - # Checks for the existence of conanbuildinfo.cmake, and loads it - # important that it is macro, so variables defined at parent scope - if(EXISTS "${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}") - message(STATUS "Conan: Loading ${_CONANBUILDINFO}") - include(${_CONANBUILDINFOFOLDER}/${_CONANBUILDINFO}) - else() - message(FATAL_ERROR "${_CONANBUILDINFO} doesn't exist in ${CMAKE_CURRENT_BINARY_DIR}") - endif() -endmacro() - - -macro(conan_cmake_run) - parse_arguments(${ARGV}) - - if(CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE AND NOT CONAN_EXPORTED - AND NOT ARGUMENTS_BUILD_TYPE) - set(CONAN_CMAKE_MULTI ON) - message(STATUS "Conan: Using cmake-multi generator") - else() - set(CONAN_CMAKE_MULTI OFF) - endif() - - if(NOT CONAN_EXPORTED) - conan_cmake_setup_conanfile(${ARGV}) - if(CONAN_CMAKE_MULTI) - foreach(CMAKE_BUILD_TYPE "Release" "Debug") - set(ENV{CONAN_IMPORT_PATH} ${CMAKE_BUILD_TYPE}) - conan_cmake_settings(settings ${ARGV}) - conan_cmake_install(SETTINGS ${settings} ${ARGV}) - endforeach() - set(CMAKE_BUILD_TYPE) - else() - conan_cmake_settings(settings ${ARGV}) - conan_cmake_install(SETTINGS ${settings} ${ARGV}) - endif() - endif() - - if (NOT ARGUMENTS_NO_LOAD) - conan_load_buildinfo() - endif() - - if(ARGUMENTS_BASIC_SETUP) - foreach(_option CMAKE_TARGETS KEEP_RPATHS NO_OUTPUT_DIRS) - if(ARGUMENTS_${_option}) - if(${_option} STREQUAL "CMAKE_TARGETS") - list(APPEND _setup_options "TARGETS") - else() - list(APPEND _setup_options ${_option}) - endif() - endif() - endforeach() - conan_basic_setup(${_setup_options}) - endif() -endmacro() - -macro(conan_check) - # Checks conan availability in PATH - # Arguments REQUIRED and VERSION are optional - # Example usage: - # conan_check(VERSION 1.0.0 REQUIRED) - message(STATUS "Conan: checking conan executable in path") - set(options REQUIRED) - set(oneValueArgs VERSION) - cmake_parse_arguments(CONAN "${options}" "${oneValueArgs}" "" ${ARGN}) - - find_program(CONAN_CMD conan) - if(NOT CONAN_CMD AND CONAN_REQUIRED) - message(FATAL_ERROR "Conan executable not found!") - endif() - message(STATUS "Conan: Found program ${CONAN_CMD}") - execute_process(COMMAND ${CONAN_CMD} --version - OUTPUT_VARIABLE CONAN_VERSION_OUTPUT - ERROR_VARIABLE CONAN_VERSION_OUTPUT) - message(STATUS "Conan: Version found ${CONAN_VERSION_OUTPUT}") - - if(DEFINED CONAN_VERSION) - string(REGEX MATCH ".*Conan version ([0-9]+\.[0-9]+\.[0-9]+)" FOO - "${CONAN_VERSION_OUTPUT}") - if(${CMAKE_MATCH_1} VERSION_LESS ${CONAN_VERSION}) - message(FATAL_ERROR "Conan outdated. Installed: ${CMAKE_MATCH_1}, \ - required: ${CONAN_VERSION}. Consider updating via 'pip \ - install conan==${CONAN_VERSION}'.") - endif() - endif() -endmacro() - -macro(conan_add_remote) - # Adds a remote - # Arguments URL and NAME are required, INDEX is optional - # Example usage: - # conan_add_remote(NAME bincrafters INDEX 1 - # URL https://api.bintray.com/conan/bincrafters/public-conan) - set(oneValueArgs URL NAME INDEX) - cmake_parse_arguments(CONAN "" "${oneValueArgs}" "" ${ARGN}) - - if(DEFINED CONAN_INDEX) - set(CONAN_INDEX_ARG "-i ${CONAN_INDEX}") - endif() - - message(STATUS "Conan: Adding ${CONAN_NAME} remote repositoy (${CONAN_URL})") - execute_process(COMMAND ${CONAN_CMD} remote add ${CONAN_NAME} ${CONAN_URL} - ${CONAN_INDEX_ARG} -f) -endmacro() diff --git a/cmake/Modules/DiscoverTests.cmake b/cmake/Modules/DiscoverTests.cmake deleted file mode 100644 index 882fbf8..0000000 --- a/cmake/Modules/DiscoverTests.cmake +++ /dev/null @@ -1,55 +0,0 @@ -#[=[ -Discover all tests in our test suites. - -This implementation is adapted vom GoogleTest.cmake -#]=] - -function(discover_tests) - set(OPTIONS "") - set(SINGLE_VALUE_KEYWORDS "TARGET") - set(MULTI_VALUE_KEYWORDS "") - - cmake_parse_arguments(DISCOVER_TESTS - "${OPTIONS}" - "${SINGLE_VALUE_KEYWORDS}" - "${MULTI_VALUE_KEYWORDS}" - ${ARGN} - ) - - if(NOT DISCOVER_TESTS_TARGET) - message(FATAL_ERROR "Missing argument TARGET") - endif() - - if(NOT TARGET "${DISCOVER_TESTS_TARGET}") - message(FATAL_ERROR "${DISCOVER_TESTS_TARGET} does not name a target known to CMake") - endif() - - set(CTEST_FILE_BASE "${CMAKE_CURRENT_BINARY_DIR}/${DISCOVER_TESTS_TARGET}") - set(CTEST_INCLUDE_FILE "${CTEST_FILE_BASE}_include.cmake") - set(CTEST_TESTS_FILE "${CTEST_FILE_BASE}_tests.cmake") - - add_custom_command(TARGET "${DISCOVER_TESTS_TARGET}" - POST_BUILD - BYPRODUCTS "${CTEST_TESTS_FILE}" - COMMAND "${CMAKE_COMMAND}" - "-D" "TEST_TARGET=${DISCOVER_TESTS_TARGET}" - "-D" "TEST_EXECUTABLE=$" - "-D" "TEST_WORKING_DIR=${CMAKE_CURRENT_BINARY_DIR}" - "-D" "CTEST_FILE=${CTEST_TESTS_FILE}" - "-P" "${PROJECT_SOURCE_DIR}/cmake/Modules/DiscoverTestsImpl.cmake" - VERBATIM - ) - - file(WRITE "${CTEST_INCLUDE_FILE}" - "if(EXISTS \"${CTEST_TESTS_FILE}\")\n" - " include(\"${CTEST_TESTS_FILE}\")\n" - "else()\n" - " add_test(${TARGET}_NOT_BUILT ${TARGET}_NOT_BUILT)\n" - "endif()\n" - ) - - set_property(DIRECTORY - APPEND - PROPERTY TEST_INCLUDE_FILES "${CTEST_INCLUDE_FILE}" - ) -endfunction() \ No newline at end of file diff --git a/cmake/Modules/DiscoverTestsImpl.cmake b/cmake/Modules/DiscoverTestsImpl.cmake deleted file mode 100644 index 893d998..0000000 --- a/cmake/Modules/DiscoverTestsImpl.cmake +++ /dev/null @@ -1,39 +0,0 @@ -#[=[ -Discover all tests in our test suites. - -This implementation is adapted vom GoogleTestAddTests.cmake -#]=] - -set(SCRIPT) - -function(add_command CMD EXE TEST) -endfunction() - -if(NOT EXISTS "${TEST_EXECUTABLE}") - message(FATAL_ERROR "The test driver ${TEST_EXECUTABLE} does not exist.") -endif() - -execute_process(COMMAND ${TEST_EXECUTABLE} "--tests" - WORKING_DIRECTORY "${TEST_WORKING_DIR}" - TIMEOUT "5" - OUTPUT_VARIABLE "TEST_LIST_OUTPUT" - RESULT_VARIABLE "TEST_LIST_RESULT" -) - -if(NOT ${TEST_LIST_RESULT} EQUAL 0) - message(FATAL_ERROR "Error while discovering tests:\n" - "Executable: ${TEST_EXECUTABLE}\n" - "Result: ${TEST_LIST_RESULT}\n" - "Output:\n" - " ${TEST_LIST_OUTPUT}\n" - ) -endif() - -string(REPLACE "\n" ";" TEST_LIST_OUTPUT "${TEST_LIST_OUTPUT}") - -foreach(LINE ${TEST_LIST_OUTPUT}) - string(REPLACE "#" ": " TEST_NAME "${LINE}") - set(SCRIPT "${SCRIPT}add_test(\"${TEST_NAME}\" \"${TEST_EXECUTABLE}\" \"${LINE}\")\n") -endforeach() - -file(WRITE "${CTEST_FILE}" "${SCRIPT}") \ No newline at end of file diff --git a/cmake/config.cmake.in b/cmake/config.cmake.in deleted file mode 100644 index f07fcfd..0000000 --- a/cmake/config.cmake.in +++ /dev/null @@ -1,4 +0,0 @@ -@PACKAGE_INIT@ - -include("${CMAKE_CURRENT_LIST_DIR}/newtypeTargets.cmake") -check_required_components("@PROJECT_NAME@") \ No newline at end of file diff --git a/conanfile.py b/conanfile.py index 000831e..990b8ac 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,50 +1,72 @@ -import re - -from conans import ConanFile, CMake -from conans.tools import load - - -def read_project_property(property): - try: - cmake_lists = load("CMakeLists.txt") - value = re.search(r"project\(.*{} \"(.*?)\"".format(property), cmake_lists, re.S).group(1) - return value.strip() - except: - return None +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.build import check_min_cppstd class NewtypeConan(ConanFile): name = "newtype" + version = "2.0.0" + license = "BSD-3-Clause" + description = "A library of types and functions to create strong type aliases" + url = "https://github.com/fmorgner/newtype" + + settings = ("os", "arch", "compiler", "build_type") + scm = { "type": "git", - "url": "https://github.com/fmorgner/newtype.git", - "revision": "auto", + "url": "auto", + "revision": "auto" + } + + options = { + "enable_docs": [False, True], } - settings = None - version = read_project_property("VERSION") - license = "BSD-3-Clause" - url = "https://github.com/fmorgner/newtype" - description = read_project_property("DESCRIPTION") - generators = "cmake" - build_requires = ( - "CUTE/2.2.6@fmorgner/stable", - "lyra/1.2.0" - ) - - def _configure_cmake(self): - cmake = CMake(self) - cmake.definitions["BUILD_TESTING"] = True - cmake.definitions["RUN_TESTS_AFTER_BUILD"] = True - cmake.configure() - return cmake + + default_options = { + "enable_docs": False, + } + + generators = [ + "CMakeDeps" + ] + + exports_sources = [ + "source/*", + "test_package/*", + "LICENSE", + ] def build(self): - cmake = self._configure_cmake() + cmake = CMake(self) + cmake.configure() cmake.build() + cmake.test() + + def build_requirements(self): + self.tool_requires("cmake/[~3.25]") + self.tool_requires("ninja/[~1.11]") + self.test_requires("catch2/[~3.3]") + + def generate(self): + toolchain = CMakeToolchain(self) + toolchain.variables["CMAKE_EXPORT_COMPILE_COMMANDS"] = True + toolchain.variables["PROJECT_VERSION"] = self.version + toolchain.variables["PROJECT_DESCRIPTION"] = self.description + toolchain.generate() + + def layout(self): + cmake_layout(self, generator="Ninja Multi-Config", src_folder="source") def package(self): - cmake = self._configure_cmake() + cmake = CMake(self) cmake.install() def package_id(self): - self.info.header_only() \ No newline at end of file + self.info.clear() + + def package_info(self): + self.cpp_info.bindirs = [] + self.cpp_info.libdirs = [] + + def validate(self): + check_min_cppstd(self, 20) diff --git a/examples/src/basic_usage.cpp b/examples/src/basic_usage.cpp deleted file mode 100644 index 35d1d2c..0000000 --- a/examples/src/basic_usage.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include - -#include - -using Width = nt::new_type; -using Height = nt::new_type; -using Area = nt::new_type; - -struct Rectangle -{ - constexpr Rectangle(Width w, Height h) - : width{w} - , height{h} - { - } - - auto constexpr area() const noexcept -> Area - { - return {width.decay() * height.decay()}; - } - -private: - Width width; - Height height; -}; - -int main() -{ - auto w{0u}, h{0u}; - - std::cin >> w >> h; - - auto width = Width{w}; - auto height = Height{h}; - - auto rect = Rectangle{width, height}; - - std::cout << rect.area().decay() << '\n'; -} \ No newline at end of file diff --git a/examples/src/basic_usage_with_read.cpp b/examples/src/basic_usage_with_read.cpp deleted file mode 100644 index 2dabe2e..0000000 --- a/examples/src/basic_usage_with_read.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include - -#include - -using Width = nt::new_type; -using Height = nt::new_type; -using Area = nt::new_type; - -struct Rectangle -{ - constexpr Rectangle(Width w, Height h) - : width{w} - , height{h} - { - } - - auto constexpr area() const noexcept -> Area - { - return {width.decay() * height.decay()}; - } - -private: - Width width; - Height height; -}; - -int main() -{ - auto width = Width{}; - auto height = Height{}; - - std::cin >> width >> height; - - auto rect = Rectangle{width, height}; - - std::cout << rect.area() << '\n'; -} \ No newline at end of file diff --git a/examples/src/basic_usage_with_show.cpp b/examples/src/basic_usage_with_show.cpp deleted file mode 100644 index 4bb68f6..0000000 --- a/examples/src/basic_usage_with_show.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include -#include -#include - -#include - -using Width = nt::new_type; -using Height = nt::new_type; -using Area = nt::new_type; - -struct Rectangle -{ - constexpr Rectangle(Width w, Height h) - : width{w} - , height{h} - { - } - - auto constexpr area() const noexcept -> Area - { - return {width.decay() * height.decay()}; - } - -private: - Width width; - Height height; -}; - -int main() -{ - auto w{0u}, h{0u}; - - std::cin >> w >> h; - - auto width = Width{w}; - auto height = Height{h}; - - auto rect = Rectangle{width, height}; - - std::cout << rect.area() << '\n'; -} \ No newline at end of file diff --git a/include/newtype/derivable.hpp b/include/newtype/derivable.hpp deleted file mode 100644 index c798c59..0000000 --- a/include/newtype/derivable.hpp +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef NEWTYPE_DERIVABLE_HPP -#define NEWTYPE_DERIVABLE_HPP - -#include "newtype/version.hpp" - -namespace nt -{ - - template - struct derivable final - { - using tag_type = DerivableTag; - }; - - inline namespace derivables - { - - auto constexpr Arithmetic = derivable{}; - auto constexpr EqBase = derivable{}; - auto constexpr Hash = derivable{}; - auto constexpr ImplicitConversion = derivable{}; - auto constexpr Indirection = derivable{}; - auto constexpr Iterable = derivable{}; - auto constexpr Read = derivable{}; - auto constexpr Relational = derivable{}; - auto constexpr Show = derivable{}; - - } // namespace derivables - -} // namespace nt - -#endif \ No newline at end of file diff --git a/include/newtype/derivation_clause.hpp b/include/newtype/derivation_clause.hpp deleted file mode 100644 index 6de70e1..0000000 --- a/include/newtype/derivation_clause.hpp +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef NEWTYPE_DERIVATION_CLAUSE_HPP -#define NEWTYPE_DERIVATION_CLAUSE_HPP - -#include "newtype/derivable.hpp" -#include "newtype/version.hpp" - -#include - -namespace nt -{ - - template - struct derivation_clause - { - constexpr derivation_clause(derivable...) noexcept - { - } - - template - auto constexpr operator()(derivable) const noexcept -> bool - { - return (std::is_same_v || ...); - } - - template - auto constexpr operator()(derivable, derivable...) const noexcept -> bool - { - return (*this)(derivable{}) && (*this)(derivable{}...); - } - - template - auto constexpr operator<(derivation_clause other) const noexcept -> bool - { - return (sizeof...(DerivableTags) < sizeof...(OtherDerivableTags)) && other(derivable{}...); - } - - template - auto constexpr operator>(derivation_clause other) const noexcept -> bool - { - return other < *this; - } - - template - auto constexpr operator==(derivation_clause other) const noexcept -> bool - { - return sizeof...(DerivableTags) == sizeof...(OtherDerivableTags) && other(derivable{}...); - } - - template - auto constexpr operator!=(derivation_clause other) const noexcept -> bool - { - return !(*this == other); - } - - template - auto constexpr operator<=(derivation_clause other) const noexcept -> bool - { - return *this < other || *this == other; - } - - template - auto constexpr operator>=(derivation_clause other) const noexcept -> bool - { - return *this > other || *this == other; - } - }; - -} // namespace nt - -#endif \ No newline at end of file diff --git a/include/newtype/deriving.hpp b/include/newtype/deriving.hpp deleted file mode 100644 index ae10bab..0000000 --- a/include/newtype/deriving.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef NEWTYPE_DERIVING_HPP -#define NEWTYPE_DERIVING_HPP - -#include "newtype/derivable.hpp" -#include "newtype/derivation_clause.hpp" -#include "newtype/version.hpp" - -#include - -namespace nt -{ - - template - auto constexpr deriving(derivable... features) noexcept -> derivation_clause - { - return {features...}; - } - -} // namespace nt - -#endif \ No newline at end of file diff --git a/include/newtype/impl/new_type_iterator_types.hpp b/include/newtype/impl/new_type_iterator_types.hpp deleted file mode 100644 index 2ea8274..0000000 --- a/include/newtype/impl/new_type_iterator_types.hpp +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef NEWTYPE_IMPL_NEW_TYPE_ITERATOR_TYPES_HPP -#define NEWTYPE_IMPL_NEW_TYPE_ITERATOR_TYPES_HPP - -#include "newtype/version.hpp" - -#include - -namespace nt::impl -{ - - template> - struct new_type_iterator - { - }; - - template - struct new_type_iterator> - { - using iterator = typename T::iterator; - }; - - template> - struct new_type_const_iterator - { - }; - - template - struct new_type_const_iterator> - { - using const_iterator = typename T::const_iterator; - }; - - template> - struct new_type_reverse_iterator - { - }; - - template - struct new_type_reverse_iterator> - { - using reverse_iterator = typename T::reverse_iterator; - }; - - template> - struct new_type_const_reverse_iterator - { - }; - - template - struct new_type_const_reverse_iterator> - { - using const_reverse_iterator = typename T::const_reverse_iterator; - }; - - template - struct new_type_iterator_types - : new_type_iterator - , new_type_const_iterator - , new_type_reverse_iterator - , new_type_const_reverse_iterator - { - }; - -} // namespace nt::impl - -#endif \ No newline at end of file diff --git a/include/newtype/impl/new_type_storage.hpp b/include/newtype/impl/new_type_storage.hpp deleted file mode 100644 index f7842af..0000000 --- a/include/newtype/impl/new_type_storage.hpp +++ /dev/null @@ -1,139 +0,0 @@ -#ifndef NEWTYPE_IMPL_NEW_TYPE_STORAGE_HPP -#define NEWTYPE_IMPL_NEW_TYPE_STORAGE_HPP - -#include "newtype/version.hpp" - -#include -#include - -namespace nt::impl -{ - - template - struct new_type_storage - { - constexpr new_type_storage() noexcept(std::is_nothrow_default_constructible_v) - : m_value{} - { - } - - constexpr new_type_storage(BaseType const & value) - : m_value{value} - { - } - - constexpr new_type_storage(BaseType && value) - : m_value{std::move(value)} - { - } - - BaseType m_value; - }; - - template> - struct new_type_constructor : new_type_storage - { - using new_type_storage::new_type_storage; - }; - - template - struct new_type_constructor : new_type_storage - { - using new_type_storage::new_type_storage; - - constexpr new_type_constructor() = delete; - }; - - template> - struct new_type_copy_constructor : new_type_constructor - { - using new_type_constructor::new_type_constructor; - - constexpr new_type_copy_constructor(new_type_copy_constructor const &) = default; - constexpr new_type_copy_constructor(new_type_copy_constructor &&) = default; - auto constexpr operator=(new_type_copy_constructor &) -> new_type_copy_constructor & = default; - auto constexpr operator=(new_type_copy_constructor &&) -> new_type_copy_constructor & = default; - }; - - template - struct new_type_copy_constructor : new_type_constructor - { - using new_type_constructor::new_type_constructor; - - constexpr new_type_copy_constructor(new_type_copy_constructor const &) = delete; - constexpr new_type_copy_constructor(new_type_copy_constructor &&) = default; - constexpr new_type_copy_constructor(BaseType const &) = delete; - auto constexpr operator=(new_type_copy_constructor &) -> new_type_copy_constructor & = default; - auto constexpr operator=(new_type_copy_constructor &&) -> new_type_copy_constructor & = default; - }; - - template> - struct new_type_move_constructor : new_type_copy_constructor - { - using new_type_copy_constructor::new_type_copy_constructor; - - constexpr new_type_move_constructor(new_type_move_constructor const &) = default; - constexpr new_type_move_constructor(new_type_move_constructor &&) = default; - auto constexpr operator=(new_type_move_constructor &) -> new_type_move_constructor & = default; - auto constexpr operator=(new_type_move_constructor &&) -> new_type_move_constructor & = default; - }; - - template - struct new_type_move_constructor : new_type_copy_constructor - { - using new_type_copy_constructor::new_type_copy_constructor; - - constexpr new_type_move_constructor(new_type_move_constructor const &) = default; - constexpr new_type_move_constructor(new_type_move_constructor &&) = delete; - constexpr new_type_move_constructor(BaseType &&) = delete; - auto constexpr operator=(new_type_move_constructor &) -> new_type_move_constructor & = default; - auto constexpr operator=(new_type_move_constructor &&) -> new_type_move_constructor & = default; - }; - - template> - struct new_type_copy_assignment : new_type_move_constructor - { - using new_type_move_constructor::new_type_move_constructor; - - constexpr new_type_copy_assignment(new_type_copy_assignment const &) = default; - constexpr new_type_copy_assignment(new_type_copy_assignment &&) = default; - auto constexpr operator=(new_type_copy_assignment &) -> new_type_copy_assignment & = default; - auto constexpr operator=(new_type_copy_assignment &&) -> new_type_copy_assignment & = default; - }; - - template - struct new_type_copy_assignment : new_type_move_constructor - { - using new_type_move_constructor::new_type_move_constructor; - - constexpr new_type_copy_assignment(new_type_copy_assignment const &) = default; - constexpr new_type_copy_assignment(new_type_copy_assignment &&) = default; - auto constexpr operator=(new_type_copy_assignment &) -> new_type_copy_assignment & = default; - auto constexpr operator=(new_type_copy_assignment &&) -> new_type_copy_assignment & = delete; - }; - - template> - struct new_type_move_assignment : new_type_copy_assignment - { - using new_type_copy_assignment::new_type_copy_assignment; - - constexpr new_type_move_assignment(new_type_move_assignment const &) = default; - constexpr new_type_move_assignment(new_type_move_assignment &&) = default; - auto constexpr operator=(new_type_move_assignment &) -> new_type_move_assignment & = default; - auto constexpr operator=(new_type_move_assignment &&) -> new_type_move_assignment & = default; - }; - - template - struct new_type_move_assignment : new_type_copy_assignment - { - using new_type_copy_assignment::new_type_copy_assignment; - - constexpr new_type_move_assignment(new_type_move_assignment const &) = default; - constexpr new_type_move_assignment(new_type_move_assignment &&) = default; - auto constexpr operator=(new_type_move_assignment &) -> new_type_move_assignment & = default; - auto constexpr operator=(new_type_move_assignment &&) -> new_type_move_assignment & = delete; - }; - -} // namespace nt::impl - -#endif diff --git a/include/newtype/impl/type_traits_extensions.hpp b/include/newtype/impl/type_traits_extensions.hpp deleted file mode 100644 index dc41649..0000000 --- a/include/newtype/impl/type_traits_extensions.hpp +++ /dev/null @@ -1,853 +0,0 @@ -#ifndef NEWTYPE_IMPL_TYPE_TRAITS_EXTENSIONS_HPP -#define NEWTYPE_IMPL_TYPE_TRAITS_EXTENSIONS_HPP - -#include "newtype/version.hpp" - -#include -#include -#include -#include - -namespace nt::impl -{ - - inline namespace equality_comparable - { - - template - struct is_equality_comparable : std::false_type - { - }; - - template - struct is_equality_comparable() == std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_equality_comparable_v = is_equality_comparable::value; - - template - struct is_nothrow_equality_comparable : std::false_type - { - }; - - template - struct is_nothrow_equality_comparable() == std::declval())>> - : std::bool_constant() == std::declval())> - { - }; - - template - auto constexpr is_nothrow_equality_comparable_v = is_nothrow_equality_comparable::value; - - template - struct is_inequality_comparable : std::false_type - { - }; - - template - struct is_inequality_comparable() != std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_inequality_comparable_v = is_inequality_comparable::value; - - template - struct is_nothrow_inequality_comparable : std::false_type - { - }; - - template - struct is_nothrow_inequality_comparable() != std::declval())>> - : std::bool_constant() != std::declval())> - { - }; - - template - auto constexpr is_nothrow_inequality_comparable_v = is_nothrow_inequality_comparable::value; - - } // namespace equality_comparable - - inline namespace relationally_comparable - { - - template - struct is_less_than_comparable : std::false_type - { - }; - - template - struct is_less_than_comparable() < std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_less_than_comparable_v = is_less_than_comparable::value; - - template - struct is_nothrow_less_than_comparable : std::false_type - { - }; - - template - struct is_nothrow_less_than_comparable() < std::declval())>> - : std::bool_constant() < std::declval())> - { - }; - - template - auto constexpr is_nothrow_less_than_comparable_v = is_nothrow_less_than_comparable::value; - - template - struct is_greater_than_comparable : std::false_type - { - }; - - template - struct is_greater_than_comparable() > std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_greater_than_comparable_v = is_greater_than_comparable::value; - - template - struct is_nothrow_greater_than_comparable : std::false_type - { - }; - - template - struct is_nothrow_greater_than_comparable() > std::declval())>> - : std::bool_constant() > std::declval())> - { - }; - - template - auto constexpr is_nothrow_greater_than_comparable_v = is_nothrow_greater_than_comparable::value; - - template - struct is_less_than_equal_to_comparable : std::false_type - { - }; - - template - struct is_less_than_equal_to_comparable() <= std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_less_than_equal_to_comparable_v = is_less_than_equal_to_comparable::value; - - template - struct is_nothrow_less_than_equal_to_comparable : std::false_type - { - }; - - template - struct is_nothrow_less_than_equal_to_comparable() <= std::declval())>> - : std::bool_constant() <= std::declval())> - { - }; - - template - auto constexpr is_nothrow_less_than_equal_to_comparable_v = is_nothrow_less_than_equal_to_comparable::value; - - template - struct is_greater_than_equal_to_comparable : std::false_type - { - }; - - template - struct is_greater_than_equal_to_comparable() >= std::declval())>> - : std::true_type - { - }; - - template - auto constexpr is_greater_than_equal_to_comparable_v = is_greater_than_equal_to_comparable::value; - - template - struct is_nothrow_greater_than_equal_to_comparable : std::false_type - { - }; - - template - struct is_nothrow_greater_than_equal_to_comparable() >= std::declval())>> - : std::bool_constant() >= std::declval())> - { - }; - - template - auto constexpr is_nothrow_greater_than_equal_to_comparable_v = is_nothrow_greater_than_equal_to_comparable::value; - } // namespace relationally_comparable - - inline namespace iostreamable - { - - template - struct is_output_streamable : std::false_type - { - }; - - template - struct is_output_streamable() << std::declval())>> - : std::true_type - { - }; - - template - auto constexpr is_output_streamable_v = is_output_streamable::value; - - template - struct is_nothrow_output_streamable : std::false_type - { - }; - - template - struct is_nothrow_output_streamable() << std::declval())>> - : std::bool_constant() << std::declval())> - { - }; - - template - auto constexpr is_nothrow_output_streamable_v = is_nothrow_output_streamable::value; - - template - struct is_input_streamable : std::false_type - { - }; - - template - struct is_input_streamable() >> std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_input_streamable_v = is_input_streamable::value; - - template - struct is_nothrow_input_streamable : std::false_type - { - }; - - template - struct is_nothrow_input_streamable() >> std::declval())>> - : std::bool_constant() >> std::declval())> - { - }; - - template - auto constexpr is_nothrow_input_streamable_v = is_nothrow_input_streamable::value; - - } // namespace iostreamable - - inline namespace arithmetic - { - - template - struct is_addable : std::false_type - { - }; - - template - struct is_addable() + std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_addable_v = is_addable::value; - - template - struct is_nothrow_addable : std::false_type - { - }; - - template - struct is_nothrow_addable() + std::declval())>> - : std::bool_constant() + std::declval())> - { - }; - - template - auto constexpr is_nothrow_addable_v = is_nothrow_addable::value; - - template - struct is_subtractable : std::false_type - { - }; - - template - struct is_subtractable() - std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_subtractable_v = is_subtractable::value; - - template - struct is_nothrow_subtractable : std::false_type - { - }; - - template - struct is_nothrow_subtractable() - std::declval())>> - : std::bool_constant() - std::declval())> - { - }; - - template - auto constexpr is_nothrow_subtractable_v = is_nothrow_subtractable::value; - - template - struct is_multipliable : std::false_type - { - }; - - template - struct is_multipliable() * std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_multipliable_v = is_multipliable::value; - - template - struct is_nothrow_multipliable : std::false_type - { - }; - - template - struct is_nothrow_multipliable() * std::declval())>> - : std::bool_constant() * std::declval())> - { - }; - - template - auto constexpr is_nothrow_multipliable_v = is_nothrow_multipliable::value; - - template - struct is_dividable : std::false_type - { - }; - - template - struct is_dividable() / std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_dividable_v = is_dividable::value; - - template - struct is_nothrow_dividable : std::false_type - { - }; - - template - struct is_nothrow_dividable() / std::declval())>> - : std::bool_constant() / std::declval())> - { - }; - - template - auto constexpr is_nothrow_dividable_v = is_nothrow_dividable::value; - - } // namespace arithmetic - - inline namespace compound_arithmetic - { - - template - struct is_add_assignable : std::false_type - { - }; - - template - struct is_add_assignable() += std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_add_assignable_v = is_add_assignable::value; - - template - struct is_nothrow_add_assignable : std::false_type - { - }; - - template - struct is_nothrow_add_assignable() += std::declval())>> - : std::bool_constant() += std::declval())> - { - }; - - template - auto constexpr is_nothrow_add_assignable_v = is_nothrow_add_assignable::value; - - template - struct is_subtract_assignable : std::false_type - { - }; - - template - struct is_subtract_assignable() -= std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_subtract_assignable_v = is_subtract_assignable::value; - - template - struct is_nothrow_subtract_assignable : std::false_type - { - }; - - template - struct is_nothrow_subtract_assignable() -= std::declval())>> - : std::bool_constant() -= std::declval())> - { - }; - - template - auto constexpr is_nothrow_subtract_assignable_v = is_nothrow_subtract_assignable::value; - - template - struct is_multiply_assignable : std::false_type - { - }; - - template - struct is_multiply_assignable() *= std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_multiply_assignable_v = is_multiply_assignable::value; - - template - struct is_nothrow_multiply_assignable : std::false_type - { - }; - - template - struct is_nothrow_multiply_assignable() *= std::declval())>> - : std::bool_constant() *= std::declval())> - { - }; - - template - auto constexpr is_nothrow_multiply_assignable_v = is_nothrow_multiply_assignable::value; - - template - struct is_divide_assignable : std::false_type - { - }; - - template - struct is_divide_assignable() /= std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_divide_assignable_v = is_divide_assignable::value; - - template - struct is_nothrow_divide_assignable : std::false_type - { - }; - - template - struct is_nothrow_divide_assignable() /= std::declval())>> - : std::bool_constant() /= std::declval())> - { - }; - - template - auto constexpr is_nothrow_divide_assignable_v = is_nothrow_divide_assignable::value; - - } // namespace compound_arithmetic - - inline namespace std_support - { - - template - struct is_hashable : std::false_type - { - }; - - template - struct is_hashable const &>()(std::declval()))>> - : std::is_same const &>()(std::declval()))> - { - }; - - template - auto constexpr is_hashable_v = is_hashable::value; - - } // namespace std_support - - inline namespace iterable_begin - { - template - struct has_free_begin : std::false_type - { - }; - - template - struct has_free_begin()))>> - : std::is_same()))>> - { - }; - - template - struct has_free_begin()))>> - : std::is_same()))>> - { - }; - - template - auto constexpr has_free_begin_v = has_free_begin::value; - - template - struct has_member_begin : std::false_type - { - }; - - template - struct has_member_begin().begin())>> - : std::is_same().begin())>> - { - }; - - template - struct has_member_begin().begin())>> - : std::is_same().begin())>> - { - }; - - template - auto constexpr has_member_begin_v = has_member_begin::value; - - template - struct has_begin : std::disjunction, has_member_begin> - { - }; - - template - auto constexpr has_begin_v = has_begin::value; - } // namespace iterable_begin - - inline namespace iterable_cbegin - { - template - struct has_free_cbegin : std::false_type - { - }; - - template - struct has_free_cbegin()))>> - : std::is_same()))>> - { - }; - - template - auto constexpr has_free_cbegin_v = has_free_cbegin::value; - - template - struct has_member_cbegin : std::false_type - { - }; - - template - struct has_member_cbegin().cbegin())>> - : std::is_same().cbegin())> - { - }; - - template - auto constexpr has_member_cbegin_v = has_member_cbegin::value; - - template - struct has_cbegin : std::disjunction, has_member_cbegin> - { - }; - - template - auto constexpr has_cbegin_v = has_cbegin::value; - } // namespace iterable_cbegin - - inline namespace iterable_rbegin - { - template - struct has_free_rbegin : std::false_type - { - }; - - template - struct has_free_rbegin()))>> - : std::is_same()))>> - { - }; - - template - struct has_free_rbegin()))>> - : std::is_same()))>> - { - }; - - template - auto constexpr has_free_rbegin_v = has_free_rbegin::value; - - template - struct has_member_rbegin : std::false_type - { - }; - - template - struct has_member_rbegin().rbegin())>> - : std::is_same().rbegin())>> - { - }; - - template - struct has_member_rbegin().rbegin())>> - : std::is_same().rbegin())>> - { - }; - - template - auto constexpr has_member_rbegin_v = has_member_rbegin::value; - - template - struct has_rbegin : std::disjunction, has_member_rbegin> - { - }; - - template - auto constexpr has_rbegin_v = has_rbegin::value; - } // namespace iterable_rbegin - - inline namespace iterable_crbegin - { - template - struct has_free_crbegin : std::false_type - { - }; - - template - struct has_free_crbegin()))>> - : std::is_same()))>> - { - }; - - template - auto constexpr has_free_crbegin_v = has_free_crbegin::value; - - template - struct has_member_crbegin : std::false_type - { - }; - - template - struct has_member_crbegin().crbegin())>> - : std::is_same().crbegin())>> - { - }; - - template - auto constexpr has_member_crbegin_v = has_member_crbegin::value; - - template - struct has_crbegin : std::disjunction, has_member_crbegin> - { - }; - - template - auto constexpr has_crbegin_v = has_crbegin::value; - } // namespace iterable_crbegin - - inline namespace iterable_end - { - template - struct has_free_end : std::false_type - { - }; - - template - struct has_free_end()))>> - : std::is_same()))>> - { - }; - - template - struct has_free_end()))>> - : std::is_same()))>> - { - }; - - template - auto constexpr has_free_end_v = has_free_end::value; - - template - struct has_member_end : std::false_type - { - }; - - template - struct has_member_end().end())>> - : std::is_same().end())>> - { - }; - - template - struct has_member_end().end())>> - : std::is_same().end())>> - { - }; - - template - auto constexpr has_member_end_v = has_member_end::value; - - template - struct has_end : std::disjunction, has_member_end> - { - }; - - template - auto constexpr has_end_v = has_end::value; - } // namespace iterable_end - - inline namespace iterable_cend - { - template - struct has_free_cend : std::false_type - { - }; - - template - struct has_free_cend()))>> - : std::is_same()))>> - { - }; - - template - auto constexpr has_free_cend_v = has_free_cend::value; - - template - struct has_member_cend : std::false_type - { - }; - - template - struct has_member_cend().cend())>> - : std::is_same().cend())> - { - }; - - template - auto constexpr has_member_cend_v = has_member_cend::value; - - template - struct has_cend : std::disjunction, has_member_cend> - { - }; - - template - auto constexpr has_cend_v = has_cend::value; - } // namespace iterable_cend - - inline namespace iterable_rend - { - template - struct has_free_rend : std::false_type - { - }; - - template - struct has_free_rend()))>> - : std::is_same()))>> - { - }; - - template - struct has_free_rend()))>> - : std::is_same()))>> - { - }; - - template - auto constexpr has_free_rend_v = has_free_rend::value; - - template - struct has_member_rend : std::false_type - { - }; - - template - struct has_member_rend().rend())>> - : std::is_same().rend())>> - { - }; - - template - struct has_member_rend().rend())>> - : std::is_same().rend())>> - { - }; - - template - auto constexpr has_member_rend_v = has_member_rend::value; - - template - struct has_rend : std::disjunction, has_member_rend> - { - }; - - template - auto constexpr has_rend_v = has_rend::value; - } // namespace iterable_rend - - inline namespace iterable_crend - { - template - struct has_free_crend : std::false_type - { - }; - - template - struct has_free_crend()))>> - : std::is_same()))>> - { - }; - - template - auto constexpr has_free_crend_v = has_free_crend::value; - - template - struct has_member_crend : std::false_type - { - }; - - template - struct has_member_crend().crend())>> - : std::is_same().crend())>> - { - }; - - template - auto constexpr has_member_crend_v = has_member_crend::value; - - template - struct has_crend : std::disjunction, has_member_crend> - { - }; - - template - auto constexpr has_crend_v = has_crend::value; - } // namespace iterable_crend - -} // namespace nt::impl - -#endif \ No newline at end of file diff --git a/include/newtype/newtype.hpp b/include/newtype/newtype.hpp deleted file mode 100644 index e2704f3..0000000 --- a/include/newtype/newtype.hpp +++ /dev/null @@ -1,550 +0,0 @@ -#ifndef NEWTYPE_NEWTYPE_HPP -#define NEWTYPE_NEWTYPE_HPP - -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" -#include "newtype/impl/new_type_iterator_types.hpp" -#include "newtype/impl/new_type_storage.hpp" -#include "newtype/impl/type_traits_extensions.hpp" -#include "newtype/version.hpp" - -#include -#include -#include -#include - -namespace nt -{ - - template - class new_type - : impl::new_type_move_assignment - , public impl::new_type_iterator_types - { - static_assert(!std::is_reference_v, "The base type must not be a reference type"); - static_assert(!std::is_void_v>, "The base type must not be possibly cv-qualified void"); - - template - auto friend operator>>(std::basic_istream &, new_type &) noexcept( - impl::is_nothrow_input_streamable_v, BaseTypeT>) - -> std::enable_if_t, BaseTypeT>, - std::basic_istream> &; - - template - auto constexpr friend - operator+=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_add_assignable_v) - -> std::enable_if_t, - new_type &>; - - template - auto constexpr friend - operator-=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_subtract_assignable_v) - -> std::enable_if_t, - new_type &>; - - template - auto constexpr friend - operator*=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_multiply_assignable_v) - -> std::enable_if_t, - new_type &>; - - template - auto constexpr friend - operator/=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_divide_assignable_v) - -> std::enable_if_t, - new_type &>; - - template - auto constexpr friend begin(new_type & obj) - -> std::enable_if_t, - typename new_type::iterator>; - - template - auto constexpr friend begin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator>; - - template - auto constexpr friend cbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator>; - - template - auto constexpr friend rbegin(new_type & obj) - -> std::enable_if_t, - typename new_type::reverse_iterator>; - - template - auto constexpr friend rbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator>; - - template - auto constexpr friend crbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator>; - - template - auto constexpr friend end(new_type & obj) - -> std::enable_if_t, - typename new_type::iterator>; - - template - auto constexpr friend end(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator>; - - template - auto constexpr friend cend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator>; - - template - auto constexpr friend rend(new_type & obj) - -> std::enable_if_t, - typename new_type::reverse_iterator>; - - template - auto constexpr friend rend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator>; - - template - auto constexpr friend crend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator>; - - using super = impl::new_type_move_assignment; - - public: - using base_type = BaseType; - using tag_type = TagType; - using derivation_clause_type = decltype(DerivationClause); - - auto constexpr static derivation_clause = DerivationClause; - - using super::super; - - constexpr new_type() noexcept(std::is_nothrow_default_constructible_v) = default; - constexpr new_type(new_type const &) noexcept(std::is_nothrow_copy_constructible_v) = default; - constexpr new_type(new_type &&) noexcept(std::is_nothrow_move_constructible_v) = default; - - auto constexpr operator=(new_type const &) noexcept(std::is_nothrow_copy_assignable_v) -> new_type & = default; - auto constexpr operator=(new_type &&) noexcept(std::is_nothrow_move_assignable_v) -> new_type & = default; - - auto constexpr decay() const noexcept(std::is_nothrow_copy_constructible_v) -> BaseType - { - return this->m_value; - } - - template * = nullptr> - constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) - { - return decay(); - } - - template * = nullptr> - explicit constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) - { - return decay(); - } - - template - auto constexpr operator->() noexcept -> std::enable_if_t - { - return std::addressof(this->m_value); - } - - template - auto constexpr operator->() const noexcept -> std::enable_if_t - { - return std::addressof(this->m_value); - } - - template * = nullptr> - auto constexpr begin() - -> std::enable_if_t, typename NewType::iterator> - { - return this->m_value.begin(); - } - - template - auto constexpr begin() const -> std::enable_if_t, - typename NewType::const_iterator> - { - return this->m_value.begin(); - } - - template - auto constexpr cbegin() const -> std::enable_if_t, - typename NewType::const_iterator> - { - return this->m_value.cbegin(); - } - - template * = nullptr> - auto constexpr rbegin() - -> std::enable_if_t, typename NewType::reverse_iterator> - { - return this->m_value.rbegin(); - } - - template - auto constexpr rbegin() const -> std::enable_if_t, - typename NewType::const_reverse_iterator> - { - return this->m_value.rbegin(); - } - - template - auto constexpr crbegin() const -> std::enable_if_t, - typename NewType::const_reverse_iterator> - { - return this->m_value.crbegin(); - } - - template * = nullptr> - auto constexpr end() - -> std::enable_if_t, typename NewType::iterator> - { - return this->m_value.end(); - } - - template - auto constexpr end() const -> std::enable_if_t, - typename NewType::const_iterator> - { - return this->m_value.end(); - } - - template - auto constexpr cend() const -> std::enable_if_t, - typename NewType::const_iterator> - { - return this->m_value.cend(); - } - - template * = nullptr> - auto constexpr rend() - -> std::enable_if_t, typename NewType::reverse_iterator> - { - return this->m_value.rend(); - } - - template - auto constexpr rend() const -> std::enable_if_t, - typename NewType::const_reverse_iterator> - { - return this->m_value.rend(); - } - - template - auto constexpr crend() const -> std::enable_if_t, - typename NewType::const_reverse_iterator> - { - return this->m_value.crend(); - } - }; - - template - auto constexpr - operator==(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() == rhs.decay(); - } - - template - auto constexpr operator==(new_type const & lhs, - BaseType const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() == rhs; - } - - template - auto constexpr - operator==(BaseType const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs == rhs.decay(); - } - - template - auto constexpr - operator!=(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() != rhs.decay(); - } - - template - auto constexpr operator!=(new_type const & lhs, - BaseType const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() != rhs; - } - - template - auto constexpr - operator!=(BaseType const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs != rhs.decay(); - } - - template - auto constexpr - operator<(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_less_than_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() < rhs.decay(); - } - - template - auto constexpr - operator>(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_greater_than_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() > rhs.decay(); - } - - template - auto constexpr - operator<=(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_less_than_equal_to_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() <= rhs.decay(); - } - - template - auto constexpr - operator>=(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_greater_than_equal_to_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() >= rhs.decay(); - } - - template - auto operator<<(std::basic_ostream & output, new_type const & source) noexcept( - impl::is_nothrow_output_streamable_v, BaseType>) - -> std::enable_if_t, BaseType>, - std::basic_ostream> & - { - return output << source.decay(); - } - - template - auto operator>>(std::basic_istream & input, new_type & target) noexcept( - impl::is_nothrow_input_streamable_v, BaseType>) - -> std::enable_if_t, BaseType>, - std::basic_istream> & - { - return input >> target.m_value; - } - - template - auto constexpr - operator+(new_type const & lhs, new_type const & rhs) noexcept( - impl::is_nothrow_addable_v && std::is_nothrow_copy_constructible_v) - -> std::enable_if_t, new_type> - { - return {lhs.decay() + rhs.decay()}; - } - - template - auto constexpr operator+=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_add_assignable_v) - -> std::enable_if_t, - new_type &> - { - lhs.m_value += rhs.m_value; - return lhs; - } - - template - auto constexpr - operator-(new_type const & lhs, new_type const & rhs) noexcept( - impl::is_nothrow_subtractable_v && std::is_nothrow_copy_constructible_v) - -> std::enable_if_t, new_type> - { - return {lhs.decay() - rhs.decay()}; - } - - template - auto constexpr - operator-=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_subtract_assignable_v) - -> std::enable_if_t, - new_type &> - { - lhs.m_value -= rhs.m_value; - return lhs; - } - - template - auto constexpr - operator*(new_type const & lhs, new_type const & rhs) noexcept( - impl::is_nothrow_multipliable_v && std::is_nothrow_copy_constructible_v) - -> std::enable_if_t, new_type> - { - return {lhs.decay() * rhs.decay()}; - } - - template - auto constexpr - operator*=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_multiply_assignable_v) - -> std::enable_if_t, - new_type &> - { - lhs.m_value *= rhs.m_value; - return lhs; - } - - template - auto constexpr - operator/(new_type const & lhs, new_type const & rhs) noexcept( - impl::is_nothrow_dividable_v && std::is_nothrow_copy_constructible_v) - -> std::enable_if_t, new_type> - { - return {lhs.decay() / rhs.decay()}; - } - - template - auto constexpr operator/=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_divide_assignable_v) - -> std::enable_if_t, - new_type &> - { - lhs.m_value /= rhs.m_value; - return lhs; - } - - template - auto constexpr begin(new_type & obj) - -> std::enable_if_t, - typename new_type::iterator> - { - return begin(obj.m_value); - } - - template - auto constexpr begin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator> - { - return begin(obj.m_value); - } - - template - auto constexpr cbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator> - { - return cbegin(obj.m_value); - } - - template - auto constexpr rbegin(new_type & obj) - -> std::enable_if_t, - typename new_type::reverse_iterator> - { - return rbegin(obj.m_value); - } - - template - auto constexpr rbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator> - { - return rbegin(obj.m_value); - } - - template - auto constexpr crbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator> - { - return crbegin(obj.m_value); - } - - template - auto constexpr end(new_type & obj) - -> std::enable_if_t, - typename new_type::iterator> - { - return end(obj.m_value); - } - - template - auto constexpr end(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator> - { - return end(obj.m_value); - } - - template - auto constexpr cend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator> - { - return cend(obj.m_value); - } - - template - auto constexpr rend(new_type & obj) - -> std::enable_if_t, - typename new_type::reverse_iterator> - { - return rend(obj.m_value); - } - - template - auto constexpr rend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator> - { - return rend(obj.m_value); - } - - template - auto constexpr crend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator> - { - return crend(obj.m_value); - } - -} // namespace nt - -namespace std -{ - template - struct hash> - { - template - auto constexpr operator()(nt::new_type const & object, - std::enable_if_t> * = nullptr) const - -> std::size_t - { - return std::hash{}(object.decay()); - } - }; -} // namespace std - -#endif diff --git a/include/newtype/version.hpp b/include/newtype/version.hpp deleted file mode 100644 index 8678514..0000000 --- a/include/newtype/version.hpp +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef NEWTYPE_VERSION_HPP -#define NEWTYPE_VERSION_HPP - -namespace nt -{ - - constexpr struct - { - int const major; - int const minor; - int const patch; - - char const * const name; - } version{ - .major = 1, - .minor = 1, - .patch = 0, - .name = "Anastasia", - }; - -} // namespace nt - -#endif \ No newline at end of file diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt new file mode 100644 index 0000000..0bd0876 --- /dev/null +++ b/source/CMakeLists.txt @@ -0,0 +1,88 @@ +cmake_minimum_required(VERSION "3.25.0") + +project("newtype" + LANGUAGES CXX + DESCRIPTION "A library of types and functions to create strong type aliases" +) + +enable_testing() + +# Project dependencies + +find_package("Catch2" "3.1" + COMPONENTS "Catch2WithMain" + REQUIRED +) + +include("Catch") + +# Project Options + +option(BUILD_EXAMPLES "Build the library examples" OFF) + +# 'newtype' library + +add_library("${PROJECT_NAME}" INTERFACE) + +target_include_directories("${PROJECT_NAME}" INTERFACE + $ + $ +) + +target_compile_features("${PROJECT_NAME}" INTERFACE + "cxx_std_20" +) + +install(TARGETS "${PROJECT_NAME}" + EXPORT "${PROJECT_NAME}Targets" + PUBLIC_HEADER DESTINATION "include" +) + +install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" + DESTINATION "include" +) + +add_library("${PROJECT_NAME}::${PROJECT_NAME}" ALIAS "${PROJECT_NAME}") + +# 'newtype' tests + +add_executable("${PROJECT_NAME}_tests" + "test/src/arithmetic.cpp" + # "test/src/conversion_suite.cpp" + # "test/src/derivation_clause_suite.cpp" + # "test/src/equality_comparison_suite.cpp" + # "test/src/hash_suite.cpp" + # "test/src/io_operators_suite.cpp" + # "test/src/iterable_suite.cpp" + # "test/src/new_type_constructor_suite.cpp" + # "test/src/relational_operators_suite.cpp" +) + +target_link_libraries("${PROJECT_NAME}_tests" + "${PROJECT_NAME}::${PROJECT_NAME}" + "Catch2::Catch2WithMain" +) + +target_compile_options("${PROJECT_NAME}_tests" PRIVATE + "$<$:-Wall>" + "$<$:-Wextra>" + "$<$:-Werror>" + "$<$:-pedantic-errors>" +) + +catch_discover_tests("${PROJECT_NAME}_tests") + +# 'newtype' examples + +if(BUILD_EXAMPLES) + function(add_example NAME) + add_executable("ex_${NAME}" + "examples/src/${NAME}.cpp" + ) + target_link_libraries("ex_${NAME}" "${PROJECT_NAME}") + endfunction() + + add_example("basic_usage") + add_example("basic_usage_with_show") + add_example("basic_usage_with_read") +endif() diff --git a/source/examples/src/basic_usage.cpp b/source/examples/src/basic_usage.cpp new file mode 100644 index 0000000..35d1d2c --- /dev/null +++ b/source/examples/src/basic_usage.cpp @@ -0,0 +1,39 @@ +#include + +#include + +using Width = nt::new_type; +using Height = nt::new_type; +using Area = nt::new_type; + +struct Rectangle +{ + constexpr Rectangle(Width w, Height h) + : width{w} + , height{h} + { + } + + auto constexpr area() const noexcept -> Area + { + return {width.decay() * height.decay()}; + } + +private: + Width width; + Height height; +}; + +int main() +{ + auto w{0u}, h{0u}; + + std::cin >> w >> h; + + auto width = Width{w}; + auto height = Height{h}; + + auto rect = Rectangle{width, height}; + + std::cout << rect.area().decay() << '\n'; +} \ No newline at end of file diff --git a/source/examples/src/basic_usage_with_read.cpp b/source/examples/src/basic_usage_with_read.cpp new file mode 100644 index 0000000..2dabe2e --- /dev/null +++ b/source/examples/src/basic_usage_with_read.cpp @@ -0,0 +1,39 @@ +#include +#include +#include + +#include + +using Width = nt::new_type; +using Height = nt::new_type; +using Area = nt::new_type; + +struct Rectangle +{ + constexpr Rectangle(Width w, Height h) + : width{w} + , height{h} + { + } + + auto constexpr area() const noexcept -> Area + { + return {width.decay() * height.decay()}; + } + +private: + Width width; + Height height; +}; + +int main() +{ + auto width = Width{}; + auto height = Height{}; + + std::cin >> width >> height; + + auto rect = Rectangle{width, height}; + + std::cout << rect.area() << '\n'; +} \ No newline at end of file diff --git a/source/examples/src/basic_usage_with_show.cpp b/source/examples/src/basic_usage_with_show.cpp new file mode 100644 index 0000000..4bb68f6 --- /dev/null +++ b/source/examples/src/basic_usage_with_show.cpp @@ -0,0 +1,41 @@ +#include +#include +#include + +#include + +using Width = nt::new_type; +using Height = nt::new_type; +using Area = nt::new_type; + +struct Rectangle +{ + constexpr Rectangle(Width w, Height h) + : width{w} + , height{h} + { + } + + auto constexpr area() const noexcept -> Area + { + return {width.decay() * height.decay()}; + } + +private: + Width width; + Height height; +}; + +int main() +{ + auto w{0u}, h{0u}; + + std::cin >> w >> h; + + auto width = Width{w}; + auto height = Height{h}; + + auto rect = Rectangle{width, height}; + + std::cout << rect.area() << '\n'; +} \ No newline at end of file diff --git a/source/include/newtype/derivable.hpp b/source/include/newtype/derivable.hpp new file mode 100644 index 0000000..c798c59 --- /dev/null +++ b/source/include/newtype/derivable.hpp @@ -0,0 +1,32 @@ +#ifndef NEWTYPE_DERIVABLE_HPP +#define NEWTYPE_DERIVABLE_HPP + +#include "newtype/version.hpp" + +namespace nt +{ + + template + struct derivable final + { + using tag_type = DerivableTag; + }; + + inline namespace derivables + { + + auto constexpr Arithmetic = derivable{}; + auto constexpr EqBase = derivable{}; + auto constexpr Hash = derivable{}; + auto constexpr ImplicitConversion = derivable{}; + auto constexpr Indirection = derivable{}; + auto constexpr Iterable = derivable{}; + auto constexpr Read = derivable{}; + auto constexpr Relational = derivable{}; + auto constexpr Show = derivable{}; + + } // namespace derivables + +} // namespace nt + +#endif \ No newline at end of file diff --git a/source/include/newtype/derivation_clause.hpp b/source/include/newtype/derivation_clause.hpp new file mode 100644 index 0000000..6de70e1 --- /dev/null +++ b/source/include/newtype/derivation_clause.hpp @@ -0,0 +1,70 @@ +#ifndef NEWTYPE_DERIVATION_CLAUSE_HPP +#define NEWTYPE_DERIVATION_CLAUSE_HPP + +#include "newtype/derivable.hpp" +#include "newtype/version.hpp" + +#include + +namespace nt +{ + + template + struct derivation_clause + { + constexpr derivation_clause(derivable...) noexcept + { + } + + template + auto constexpr operator()(derivable) const noexcept -> bool + { + return (std::is_same_v || ...); + } + + template + auto constexpr operator()(derivable, derivable...) const noexcept -> bool + { + return (*this)(derivable{}) && (*this)(derivable{}...); + } + + template + auto constexpr operator<(derivation_clause other) const noexcept -> bool + { + return (sizeof...(DerivableTags) < sizeof...(OtherDerivableTags)) && other(derivable{}...); + } + + template + auto constexpr operator>(derivation_clause other) const noexcept -> bool + { + return other < *this; + } + + template + auto constexpr operator==(derivation_clause other) const noexcept -> bool + { + return sizeof...(DerivableTags) == sizeof...(OtherDerivableTags) && other(derivable{}...); + } + + template + auto constexpr operator!=(derivation_clause other) const noexcept -> bool + { + return !(*this == other); + } + + template + auto constexpr operator<=(derivation_clause other) const noexcept -> bool + { + return *this < other || *this == other; + } + + template + auto constexpr operator>=(derivation_clause other) const noexcept -> bool + { + return *this > other || *this == other; + } + }; + +} // namespace nt + +#endif \ No newline at end of file diff --git a/source/include/newtype/deriving.hpp b/source/include/newtype/deriving.hpp new file mode 100644 index 0000000..ae10bab --- /dev/null +++ b/source/include/newtype/deriving.hpp @@ -0,0 +1,21 @@ +#ifndef NEWTYPE_DERIVING_HPP +#define NEWTYPE_DERIVING_HPP + +#include "newtype/derivable.hpp" +#include "newtype/derivation_clause.hpp" +#include "newtype/version.hpp" + +#include + +namespace nt +{ + + template + auto constexpr deriving(derivable... features) noexcept -> derivation_clause + { + return {features...}; + } + +} // namespace nt + +#endif \ No newline at end of file diff --git a/source/include/newtype/impl/new_type_iterator_types.hpp b/source/include/newtype/impl/new_type_iterator_types.hpp new file mode 100644 index 0000000..2ea8274 --- /dev/null +++ b/source/include/newtype/impl/new_type_iterator_types.hpp @@ -0,0 +1,66 @@ +#ifndef NEWTYPE_IMPL_NEW_TYPE_ITERATOR_TYPES_HPP +#define NEWTYPE_IMPL_NEW_TYPE_ITERATOR_TYPES_HPP + +#include "newtype/version.hpp" + +#include + +namespace nt::impl +{ + + template> + struct new_type_iterator + { + }; + + template + struct new_type_iterator> + { + using iterator = typename T::iterator; + }; + + template> + struct new_type_const_iterator + { + }; + + template + struct new_type_const_iterator> + { + using const_iterator = typename T::const_iterator; + }; + + template> + struct new_type_reverse_iterator + { + }; + + template + struct new_type_reverse_iterator> + { + using reverse_iterator = typename T::reverse_iterator; + }; + + template> + struct new_type_const_reverse_iterator + { + }; + + template + struct new_type_const_reverse_iterator> + { + using const_reverse_iterator = typename T::const_reverse_iterator; + }; + + template + struct new_type_iterator_types + : new_type_iterator + , new_type_const_iterator + , new_type_reverse_iterator + , new_type_const_reverse_iterator + { + }; + +} // namespace nt::impl + +#endif \ No newline at end of file diff --git a/source/include/newtype/impl/new_type_storage.hpp b/source/include/newtype/impl/new_type_storage.hpp new file mode 100644 index 0000000..f7842af --- /dev/null +++ b/source/include/newtype/impl/new_type_storage.hpp @@ -0,0 +1,139 @@ +#ifndef NEWTYPE_IMPL_NEW_TYPE_STORAGE_HPP +#define NEWTYPE_IMPL_NEW_TYPE_STORAGE_HPP + +#include "newtype/version.hpp" + +#include +#include + +namespace nt::impl +{ + + template + struct new_type_storage + { + constexpr new_type_storage() noexcept(std::is_nothrow_default_constructible_v) + : m_value{} + { + } + + constexpr new_type_storage(BaseType const & value) + : m_value{value} + { + } + + constexpr new_type_storage(BaseType && value) + : m_value{std::move(value)} + { + } + + BaseType m_value; + }; + + template> + struct new_type_constructor : new_type_storage + { + using new_type_storage::new_type_storage; + }; + + template + struct new_type_constructor : new_type_storage + { + using new_type_storage::new_type_storage; + + constexpr new_type_constructor() = delete; + }; + + template> + struct new_type_copy_constructor : new_type_constructor + { + using new_type_constructor::new_type_constructor; + + constexpr new_type_copy_constructor(new_type_copy_constructor const &) = default; + constexpr new_type_copy_constructor(new_type_copy_constructor &&) = default; + auto constexpr operator=(new_type_copy_constructor &) -> new_type_copy_constructor & = default; + auto constexpr operator=(new_type_copy_constructor &&) -> new_type_copy_constructor & = default; + }; + + template + struct new_type_copy_constructor : new_type_constructor + { + using new_type_constructor::new_type_constructor; + + constexpr new_type_copy_constructor(new_type_copy_constructor const &) = delete; + constexpr new_type_copy_constructor(new_type_copy_constructor &&) = default; + constexpr new_type_copy_constructor(BaseType const &) = delete; + auto constexpr operator=(new_type_copy_constructor &) -> new_type_copy_constructor & = default; + auto constexpr operator=(new_type_copy_constructor &&) -> new_type_copy_constructor & = default; + }; + + template> + struct new_type_move_constructor : new_type_copy_constructor + { + using new_type_copy_constructor::new_type_copy_constructor; + + constexpr new_type_move_constructor(new_type_move_constructor const &) = default; + constexpr new_type_move_constructor(new_type_move_constructor &&) = default; + auto constexpr operator=(new_type_move_constructor &) -> new_type_move_constructor & = default; + auto constexpr operator=(new_type_move_constructor &&) -> new_type_move_constructor & = default; + }; + + template + struct new_type_move_constructor : new_type_copy_constructor + { + using new_type_copy_constructor::new_type_copy_constructor; + + constexpr new_type_move_constructor(new_type_move_constructor const &) = default; + constexpr new_type_move_constructor(new_type_move_constructor &&) = delete; + constexpr new_type_move_constructor(BaseType &&) = delete; + auto constexpr operator=(new_type_move_constructor &) -> new_type_move_constructor & = default; + auto constexpr operator=(new_type_move_constructor &&) -> new_type_move_constructor & = default; + }; + + template> + struct new_type_copy_assignment : new_type_move_constructor + { + using new_type_move_constructor::new_type_move_constructor; + + constexpr new_type_copy_assignment(new_type_copy_assignment const &) = default; + constexpr new_type_copy_assignment(new_type_copy_assignment &&) = default; + auto constexpr operator=(new_type_copy_assignment &) -> new_type_copy_assignment & = default; + auto constexpr operator=(new_type_copy_assignment &&) -> new_type_copy_assignment & = default; + }; + + template + struct new_type_copy_assignment : new_type_move_constructor + { + using new_type_move_constructor::new_type_move_constructor; + + constexpr new_type_copy_assignment(new_type_copy_assignment const &) = default; + constexpr new_type_copy_assignment(new_type_copy_assignment &&) = default; + auto constexpr operator=(new_type_copy_assignment &) -> new_type_copy_assignment & = default; + auto constexpr operator=(new_type_copy_assignment &&) -> new_type_copy_assignment & = delete; + }; + + template> + struct new_type_move_assignment : new_type_copy_assignment + { + using new_type_copy_assignment::new_type_copy_assignment; + + constexpr new_type_move_assignment(new_type_move_assignment const &) = default; + constexpr new_type_move_assignment(new_type_move_assignment &&) = default; + auto constexpr operator=(new_type_move_assignment &) -> new_type_move_assignment & = default; + auto constexpr operator=(new_type_move_assignment &&) -> new_type_move_assignment & = default; + }; + + template + struct new_type_move_assignment : new_type_copy_assignment + { + using new_type_copy_assignment::new_type_copy_assignment; + + constexpr new_type_move_assignment(new_type_move_assignment const &) = default; + constexpr new_type_move_assignment(new_type_move_assignment &&) = default; + auto constexpr operator=(new_type_move_assignment &) -> new_type_move_assignment & = default; + auto constexpr operator=(new_type_move_assignment &&) -> new_type_move_assignment & = delete; + }; + +} // namespace nt::impl + +#endif diff --git a/source/include/newtype/impl/type_traits_extensions.hpp b/source/include/newtype/impl/type_traits_extensions.hpp new file mode 100644 index 0000000..dc41649 --- /dev/null +++ b/source/include/newtype/impl/type_traits_extensions.hpp @@ -0,0 +1,853 @@ +#ifndef NEWTYPE_IMPL_TYPE_TRAITS_EXTENSIONS_HPP +#define NEWTYPE_IMPL_TYPE_TRAITS_EXTENSIONS_HPP + +#include "newtype/version.hpp" + +#include +#include +#include +#include + +namespace nt::impl +{ + + inline namespace equality_comparable + { + + template + struct is_equality_comparable : std::false_type + { + }; + + template + struct is_equality_comparable() == std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_equality_comparable_v = is_equality_comparable::value; + + template + struct is_nothrow_equality_comparable : std::false_type + { + }; + + template + struct is_nothrow_equality_comparable() == std::declval())>> + : std::bool_constant() == std::declval())> + { + }; + + template + auto constexpr is_nothrow_equality_comparable_v = is_nothrow_equality_comparable::value; + + template + struct is_inequality_comparable : std::false_type + { + }; + + template + struct is_inequality_comparable() != std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_inequality_comparable_v = is_inequality_comparable::value; + + template + struct is_nothrow_inequality_comparable : std::false_type + { + }; + + template + struct is_nothrow_inequality_comparable() != std::declval())>> + : std::bool_constant() != std::declval())> + { + }; + + template + auto constexpr is_nothrow_inequality_comparable_v = is_nothrow_inequality_comparable::value; + + } // namespace equality_comparable + + inline namespace relationally_comparable + { + + template + struct is_less_than_comparable : std::false_type + { + }; + + template + struct is_less_than_comparable() < std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_less_than_comparable_v = is_less_than_comparable::value; + + template + struct is_nothrow_less_than_comparable : std::false_type + { + }; + + template + struct is_nothrow_less_than_comparable() < std::declval())>> + : std::bool_constant() < std::declval())> + { + }; + + template + auto constexpr is_nothrow_less_than_comparable_v = is_nothrow_less_than_comparable::value; + + template + struct is_greater_than_comparable : std::false_type + { + }; + + template + struct is_greater_than_comparable() > std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_greater_than_comparable_v = is_greater_than_comparable::value; + + template + struct is_nothrow_greater_than_comparable : std::false_type + { + }; + + template + struct is_nothrow_greater_than_comparable() > std::declval())>> + : std::bool_constant() > std::declval())> + { + }; + + template + auto constexpr is_nothrow_greater_than_comparable_v = is_nothrow_greater_than_comparable::value; + + template + struct is_less_than_equal_to_comparable : std::false_type + { + }; + + template + struct is_less_than_equal_to_comparable() <= std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_less_than_equal_to_comparable_v = is_less_than_equal_to_comparable::value; + + template + struct is_nothrow_less_than_equal_to_comparable : std::false_type + { + }; + + template + struct is_nothrow_less_than_equal_to_comparable() <= std::declval())>> + : std::bool_constant() <= std::declval())> + { + }; + + template + auto constexpr is_nothrow_less_than_equal_to_comparable_v = is_nothrow_less_than_equal_to_comparable::value; + + template + struct is_greater_than_equal_to_comparable : std::false_type + { + }; + + template + struct is_greater_than_equal_to_comparable() >= std::declval())>> + : std::true_type + { + }; + + template + auto constexpr is_greater_than_equal_to_comparable_v = is_greater_than_equal_to_comparable::value; + + template + struct is_nothrow_greater_than_equal_to_comparable : std::false_type + { + }; + + template + struct is_nothrow_greater_than_equal_to_comparable() >= std::declval())>> + : std::bool_constant() >= std::declval())> + { + }; + + template + auto constexpr is_nothrow_greater_than_equal_to_comparable_v = is_nothrow_greater_than_equal_to_comparable::value; + } // namespace relationally_comparable + + inline namespace iostreamable + { + + template + struct is_output_streamable : std::false_type + { + }; + + template + struct is_output_streamable() << std::declval())>> + : std::true_type + { + }; + + template + auto constexpr is_output_streamable_v = is_output_streamable::value; + + template + struct is_nothrow_output_streamable : std::false_type + { + }; + + template + struct is_nothrow_output_streamable() << std::declval())>> + : std::bool_constant() << std::declval())> + { + }; + + template + auto constexpr is_nothrow_output_streamable_v = is_nothrow_output_streamable::value; + + template + struct is_input_streamable : std::false_type + { + }; + + template + struct is_input_streamable() >> std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_input_streamable_v = is_input_streamable::value; + + template + struct is_nothrow_input_streamable : std::false_type + { + }; + + template + struct is_nothrow_input_streamable() >> std::declval())>> + : std::bool_constant() >> std::declval())> + { + }; + + template + auto constexpr is_nothrow_input_streamable_v = is_nothrow_input_streamable::value; + + } // namespace iostreamable + + inline namespace arithmetic + { + + template + struct is_addable : std::false_type + { + }; + + template + struct is_addable() + std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_addable_v = is_addable::value; + + template + struct is_nothrow_addable : std::false_type + { + }; + + template + struct is_nothrow_addable() + std::declval())>> + : std::bool_constant() + std::declval())> + { + }; + + template + auto constexpr is_nothrow_addable_v = is_nothrow_addable::value; + + template + struct is_subtractable : std::false_type + { + }; + + template + struct is_subtractable() - std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_subtractable_v = is_subtractable::value; + + template + struct is_nothrow_subtractable : std::false_type + { + }; + + template + struct is_nothrow_subtractable() - std::declval())>> + : std::bool_constant() - std::declval())> + { + }; + + template + auto constexpr is_nothrow_subtractable_v = is_nothrow_subtractable::value; + + template + struct is_multipliable : std::false_type + { + }; + + template + struct is_multipliable() * std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_multipliable_v = is_multipliable::value; + + template + struct is_nothrow_multipliable : std::false_type + { + }; + + template + struct is_nothrow_multipliable() * std::declval())>> + : std::bool_constant() * std::declval())> + { + }; + + template + auto constexpr is_nothrow_multipliable_v = is_nothrow_multipliable::value; + + template + struct is_dividable : std::false_type + { + }; + + template + struct is_dividable() / std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_dividable_v = is_dividable::value; + + template + struct is_nothrow_dividable : std::false_type + { + }; + + template + struct is_nothrow_dividable() / std::declval())>> + : std::bool_constant() / std::declval())> + { + }; + + template + auto constexpr is_nothrow_dividable_v = is_nothrow_dividable::value; + + } // namespace arithmetic + + inline namespace compound_arithmetic + { + + template + struct is_add_assignable : std::false_type + { + }; + + template + struct is_add_assignable() += std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_add_assignable_v = is_add_assignable::value; + + template + struct is_nothrow_add_assignable : std::false_type + { + }; + + template + struct is_nothrow_add_assignable() += std::declval())>> + : std::bool_constant() += std::declval())> + { + }; + + template + auto constexpr is_nothrow_add_assignable_v = is_nothrow_add_assignable::value; + + template + struct is_subtract_assignable : std::false_type + { + }; + + template + struct is_subtract_assignable() -= std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_subtract_assignable_v = is_subtract_assignable::value; + + template + struct is_nothrow_subtract_assignable : std::false_type + { + }; + + template + struct is_nothrow_subtract_assignable() -= std::declval())>> + : std::bool_constant() -= std::declval())> + { + }; + + template + auto constexpr is_nothrow_subtract_assignable_v = is_nothrow_subtract_assignable::value; + + template + struct is_multiply_assignable : std::false_type + { + }; + + template + struct is_multiply_assignable() *= std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_multiply_assignable_v = is_multiply_assignable::value; + + template + struct is_nothrow_multiply_assignable : std::false_type + { + }; + + template + struct is_nothrow_multiply_assignable() *= std::declval())>> + : std::bool_constant() *= std::declval())> + { + }; + + template + auto constexpr is_nothrow_multiply_assignable_v = is_nothrow_multiply_assignable::value; + + template + struct is_divide_assignable : std::false_type + { + }; + + template + struct is_divide_assignable() /= std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_divide_assignable_v = is_divide_assignable::value; + + template + struct is_nothrow_divide_assignable : std::false_type + { + }; + + template + struct is_nothrow_divide_assignable() /= std::declval())>> + : std::bool_constant() /= std::declval())> + { + }; + + template + auto constexpr is_nothrow_divide_assignable_v = is_nothrow_divide_assignable::value; + + } // namespace compound_arithmetic + + inline namespace std_support + { + + template + struct is_hashable : std::false_type + { + }; + + template + struct is_hashable const &>()(std::declval()))>> + : std::is_same const &>()(std::declval()))> + { + }; + + template + auto constexpr is_hashable_v = is_hashable::value; + + } // namespace std_support + + inline namespace iterable_begin + { + template + struct has_free_begin : std::false_type + { + }; + + template + struct has_free_begin()))>> + : std::is_same()))>> + { + }; + + template + struct has_free_begin()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_begin_v = has_free_begin::value; + + template + struct has_member_begin : std::false_type + { + }; + + template + struct has_member_begin().begin())>> + : std::is_same().begin())>> + { + }; + + template + struct has_member_begin().begin())>> + : std::is_same().begin())>> + { + }; + + template + auto constexpr has_member_begin_v = has_member_begin::value; + + template + struct has_begin : std::disjunction, has_member_begin> + { + }; + + template + auto constexpr has_begin_v = has_begin::value; + } // namespace iterable_begin + + inline namespace iterable_cbegin + { + template + struct has_free_cbegin : std::false_type + { + }; + + template + struct has_free_cbegin()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_cbegin_v = has_free_cbegin::value; + + template + struct has_member_cbegin : std::false_type + { + }; + + template + struct has_member_cbegin().cbegin())>> + : std::is_same().cbegin())> + { + }; + + template + auto constexpr has_member_cbegin_v = has_member_cbegin::value; + + template + struct has_cbegin : std::disjunction, has_member_cbegin> + { + }; + + template + auto constexpr has_cbegin_v = has_cbegin::value; + } // namespace iterable_cbegin + + inline namespace iterable_rbegin + { + template + struct has_free_rbegin : std::false_type + { + }; + + template + struct has_free_rbegin()))>> + : std::is_same()))>> + { + }; + + template + struct has_free_rbegin()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_rbegin_v = has_free_rbegin::value; + + template + struct has_member_rbegin : std::false_type + { + }; + + template + struct has_member_rbegin().rbegin())>> + : std::is_same().rbegin())>> + { + }; + + template + struct has_member_rbegin().rbegin())>> + : std::is_same().rbegin())>> + { + }; + + template + auto constexpr has_member_rbegin_v = has_member_rbegin::value; + + template + struct has_rbegin : std::disjunction, has_member_rbegin> + { + }; + + template + auto constexpr has_rbegin_v = has_rbegin::value; + } // namespace iterable_rbegin + + inline namespace iterable_crbegin + { + template + struct has_free_crbegin : std::false_type + { + }; + + template + struct has_free_crbegin()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_crbegin_v = has_free_crbegin::value; + + template + struct has_member_crbegin : std::false_type + { + }; + + template + struct has_member_crbegin().crbegin())>> + : std::is_same().crbegin())>> + { + }; + + template + auto constexpr has_member_crbegin_v = has_member_crbegin::value; + + template + struct has_crbegin : std::disjunction, has_member_crbegin> + { + }; + + template + auto constexpr has_crbegin_v = has_crbegin::value; + } // namespace iterable_crbegin + + inline namespace iterable_end + { + template + struct has_free_end : std::false_type + { + }; + + template + struct has_free_end()))>> + : std::is_same()))>> + { + }; + + template + struct has_free_end()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_end_v = has_free_end::value; + + template + struct has_member_end : std::false_type + { + }; + + template + struct has_member_end().end())>> + : std::is_same().end())>> + { + }; + + template + struct has_member_end().end())>> + : std::is_same().end())>> + { + }; + + template + auto constexpr has_member_end_v = has_member_end::value; + + template + struct has_end : std::disjunction, has_member_end> + { + }; + + template + auto constexpr has_end_v = has_end::value; + } // namespace iterable_end + + inline namespace iterable_cend + { + template + struct has_free_cend : std::false_type + { + }; + + template + struct has_free_cend()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_cend_v = has_free_cend::value; + + template + struct has_member_cend : std::false_type + { + }; + + template + struct has_member_cend().cend())>> + : std::is_same().cend())> + { + }; + + template + auto constexpr has_member_cend_v = has_member_cend::value; + + template + struct has_cend : std::disjunction, has_member_cend> + { + }; + + template + auto constexpr has_cend_v = has_cend::value; + } // namespace iterable_cend + + inline namespace iterable_rend + { + template + struct has_free_rend : std::false_type + { + }; + + template + struct has_free_rend()))>> + : std::is_same()))>> + { + }; + + template + struct has_free_rend()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_rend_v = has_free_rend::value; + + template + struct has_member_rend : std::false_type + { + }; + + template + struct has_member_rend().rend())>> + : std::is_same().rend())>> + { + }; + + template + struct has_member_rend().rend())>> + : std::is_same().rend())>> + { + }; + + template + auto constexpr has_member_rend_v = has_member_rend::value; + + template + struct has_rend : std::disjunction, has_member_rend> + { + }; + + template + auto constexpr has_rend_v = has_rend::value; + } // namespace iterable_rend + + inline namespace iterable_crend + { + template + struct has_free_crend : std::false_type + { + }; + + template + struct has_free_crend()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_crend_v = has_free_crend::value; + + template + struct has_member_crend : std::false_type + { + }; + + template + struct has_member_crend().crend())>> + : std::is_same().crend())>> + { + }; + + template + auto constexpr has_member_crend_v = has_member_crend::value; + + template + struct has_crend : std::disjunction, has_member_crend> + { + }; + + template + auto constexpr has_crend_v = has_crend::value; + } // namespace iterable_crend + +} // namespace nt::impl + +#endif \ No newline at end of file diff --git a/source/include/newtype/newtype.hpp b/source/include/newtype/newtype.hpp new file mode 100644 index 0000000..e2704f3 --- /dev/null +++ b/source/include/newtype/newtype.hpp @@ -0,0 +1,550 @@ +#ifndef NEWTYPE_NEWTYPE_HPP +#define NEWTYPE_NEWTYPE_HPP + +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" +#include "newtype/impl/new_type_iterator_types.hpp" +#include "newtype/impl/new_type_storage.hpp" +#include "newtype/impl/type_traits_extensions.hpp" +#include "newtype/version.hpp" + +#include +#include +#include +#include + +namespace nt +{ + + template + class new_type + : impl::new_type_move_assignment + , public impl::new_type_iterator_types + { + static_assert(!std::is_reference_v, "The base type must not be a reference type"); + static_assert(!std::is_void_v>, "The base type must not be possibly cv-qualified void"); + + template + auto friend operator>>(std::basic_istream &, new_type &) noexcept( + impl::is_nothrow_input_streamable_v, BaseTypeT>) + -> std::enable_if_t, BaseTypeT>, + std::basic_istream> &; + + template + auto constexpr friend + operator+=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_add_assignable_v) + -> std::enable_if_t, + new_type &>; + + template + auto constexpr friend + operator-=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_subtract_assignable_v) + -> std::enable_if_t, + new_type &>; + + template + auto constexpr friend + operator*=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_multiply_assignable_v) + -> std::enable_if_t, + new_type &>; + + template + auto constexpr friend + operator/=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_divide_assignable_v) + -> std::enable_if_t, + new_type &>; + + template + auto constexpr friend begin(new_type & obj) + -> std::enable_if_t, + typename new_type::iterator>; + + template + auto constexpr friend begin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + + template + auto constexpr friend cbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + + template + auto constexpr friend rbegin(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator>; + + template + auto constexpr friend rbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + + template + auto constexpr friend crbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + + template + auto constexpr friend end(new_type & obj) + -> std::enable_if_t, + typename new_type::iterator>; + + template + auto constexpr friend end(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + + template + auto constexpr friend cend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + + template + auto constexpr friend rend(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator>; + + template + auto constexpr friend rend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + + template + auto constexpr friend crend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + + using super = impl::new_type_move_assignment; + + public: + using base_type = BaseType; + using tag_type = TagType; + using derivation_clause_type = decltype(DerivationClause); + + auto constexpr static derivation_clause = DerivationClause; + + using super::super; + + constexpr new_type() noexcept(std::is_nothrow_default_constructible_v) = default; + constexpr new_type(new_type const &) noexcept(std::is_nothrow_copy_constructible_v) = default; + constexpr new_type(new_type &&) noexcept(std::is_nothrow_move_constructible_v) = default; + + auto constexpr operator=(new_type const &) noexcept(std::is_nothrow_copy_assignable_v) -> new_type & = default; + auto constexpr operator=(new_type &&) noexcept(std::is_nothrow_move_assignable_v) -> new_type & = default; + + auto constexpr decay() const noexcept(std::is_nothrow_copy_constructible_v) -> BaseType + { + return this->m_value; + } + + template * = nullptr> + constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) + { + return decay(); + } + + template * = nullptr> + explicit constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) + { + return decay(); + } + + template + auto constexpr operator->() noexcept -> std::enable_if_t + { + return std::addressof(this->m_value); + } + + template + auto constexpr operator->() const noexcept -> std::enable_if_t + { + return std::addressof(this->m_value); + } + + template * = nullptr> + auto constexpr begin() + -> std::enable_if_t, typename NewType::iterator> + { + return this->m_value.begin(); + } + + template + auto constexpr begin() const -> std::enable_if_t, + typename NewType::const_iterator> + { + return this->m_value.begin(); + } + + template + auto constexpr cbegin() const -> std::enable_if_t, + typename NewType::const_iterator> + { + return this->m_value.cbegin(); + } + + template * = nullptr> + auto constexpr rbegin() + -> std::enable_if_t, typename NewType::reverse_iterator> + { + return this->m_value.rbegin(); + } + + template + auto constexpr rbegin() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.rbegin(); + } + + template + auto constexpr crbegin() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.crbegin(); + } + + template * = nullptr> + auto constexpr end() + -> std::enable_if_t, typename NewType::iterator> + { + return this->m_value.end(); + } + + template + auto constexpr end() const -> std::enable_if_t, + typename NewType::const_iterator> + { + return this->m_value.end(); + } + + template + auto constexpr cend() const -> std::enable_if_t, + typename NewType::const_iterator> + { + return this->m_value.cend(); + } + + template * = nullptr> + auto constexpr rend() + -> std::enable_if_t, typename NewType::reverse_iterator> + { + return this->m_value.rend(); + } + + template + auto constexpr rend() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.rend(); + } + + template + auto constexpr crend() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.crend(); + } + }; + + template + auto constexpr + operator==(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() == rhs.decay(); + } + + template + auto constexpr operator==(new_type const & lhs, + BaseType const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() == rhs; + } + + template + auto constexpr + operator==(BaseType const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs == rhs.decay(); + } + + template + auto constexpr + operator!=(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() != rhs.decay(); + } + + template + auto constexpr operator!=(new_type const & lhs, + BaseType const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() != rhs; + } + + template + auto constexpr + operator!=(BaseType const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs != rhs.decay(); + } + + template + auto constexpr + operator<(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_less_than_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() < rhs.decay(); + } + + template + auto constexpr + operator>(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_greater_than_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() > rhs.decay(); + } + + template + auto constexpr + operator<=(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_less_than_equal_to_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() <= rhs.decay(); + } + + template + auto constexpr + operator>=(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_greater_than_equal_to_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() >= rhs.decay(); + } + + template + auto operator<<(std::basic_ostream & output, new_type const & source) noexcept( + impl::is_nothrow_output_streamable_v, BaseType>) + -> std::enable_if_t, BaseType>, + std::basic_ostream> & + { + return output << source.decay(); + } + + template + auto operator>>(std::basic_istream & input, new_type & target) noexcept( + impl::is_nothrow_input_streamable_v, BaseType>) + -> std::enable_if_t, BaseType>, + std::basic_istream> & + { + return input >> target.m_value; + } + + template + auto constexpr + operator+(new_type const & lhs, new_type const & rhs) noexcept( + impl::is_nothrow_addable_v && std::is_nothrow_copy_constructible_v) + -> std::enable_if_t, new_type> + { + return {lhs.decay() + rhs.decay()}; + } + + template + auto constexpr operator+=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_add_assignable_v) + -> std::enable_if_t, + new_type &> + { + lhs.m_value += rhs.m_value; + return lhs; + } + + template + auto constexpr + operator-(new_type const & lhs, new_type const & rhs) noexcept( + impl::is_nothrow_subtractable_v && std::is_nothrow_copy_constructible_v) + -> std::enable_if_t, new_type> + { + return {lhs.decay() - rhs.decay()}; + } + + template + auto constexpr + operator-=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_subtract_assignable_v) + -> std::enable_if_t, + new_type &> + { + lhs.m_value -= rhs.m_value; + return lhs; + } + + template + auto constexpr + operator*(new_type const & lhs, new_type const & rhs) noexcept( + impl::is_nothrow_multipliable_v && std::is_nothrow_copy_constructible_v) + -> std::enable_if_t, new_type> + { + return {lhs.decay() * rhs.decay()}; + } + + template + auto constexpr + operator*=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_multiply_assignable_v) + -> std::enable_if_t, + new_type &> + { + lhs.m_value *= rhs.m_value; + return lhs; + } + + template + auto constexpr + operator/(new_type const & lhs, new_type const & rhs) noexcept( + impl::is_nothrow_dividable_v && std::is_nothrow_copy_constructible_v) + -> std::enable_if_t, new_type> + { + return {lhs.decay() / rhs.decay()}; + } + + template + auto constexpr operator/=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_divide_assignable_v) + -> std::enable_if_t, + new_type &> + { + lhs.m_value /= rhs.m_value; + return lhs; + } + + template + auto constexpr begin(new_type & obj) + -> std::enable_if_t, + typename new_type::iterator> + { + return begin(obj.m_value); + } + + template + auto constexpr begin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator> + { + return begin(obj.m_value); + } + + template + auto constexpr cbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator> + { + return cbegin(obj.m_value); + } + + template + auto constexpr rbegin(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator> + { + return rbegin(obj.m_value); + } + + template + auto constexpr rbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return rbegin(obj.m_value); + } + + template + auto constexpr crbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return crbegin(obj.m_value); + } + + template + auto constexpr end(new_type & obj) + -> std::enable_if_t, + typename new_type::iterator> + { + return end(obj.m_value); + } + + template + auto constexpr end(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator> + { + return end(obj.m_value); + } + + template + auto constexpr cend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator> + { + return cend(obj.m_value); + } + + template + auto constexpr rend(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator> + { + return rend(obj.m_value); + } + + template + auto constexpr rend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return rend(obj.m_value); + } + + template + auto constexpr crend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return crend(obj.m_value); + } + +} // namespace nt + +namespace std +{ + template + struct hash> + { + template + auto constexpr operator()(nt::new_type const & object, + std::enable_if_t> * = nullptr) const + -> std::size_t + { + return std::hash{}(object.decay()); + } + }; +} // namespace std + +#endif diff --git a/source/include/newtype/version.hpp b/source/include/newtype/version.hpp new file mode 100644 index 0000000..8678514 --- /dev/null +++ b/source/include/newtype/version.hpp @@ -0,0 +1,23 @@ +#ifndef NEWTYPE_VERSION_HPP +#define NEWTYPE_VERSION_HPP + +namespace nt +{ + + constexpr struct + { + int const major; + int const minor; + int const patch; + + char const * const name; + } version{ + .major = 1, + .minor = 1, + .patch = 0, + .name = "Anastasia", + }; + +} // namespace nt + +#endif \ No newline at end of file diff --git a/source/test/src/arithmetic.cpp b/source/test/src/arithmetic.cpp new file mode 100644 index 0000000..5048393 --- /dev/null +++ b/source/test/src/arithmetic.cpp @@ -0,0 +1,300 @@ +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" +#include "newtype/impl/type_traits_extensions.hpp" +#include "newtype/newtype.hpp" + +#include + +#include + +SCENARIO("Addition", "[arithmetic]") +{ + struct addable_type + { + auto constexpr operator+(addable_type const &) const -> addable_type + { + return {}; + }; + }; + + GIVEN("A new_type instance not deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is not addable") + { + REQUIRE(!nt::impl::is_addable_v); + } + } + + GIVEN("A new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is addable") + { + REQUIRE(nt::impl::is_addable_v); + } + } + + GIVEN("A new_type over a non-addable class type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is not addable") + { + REQUIRE(!nt::impl::is_addable_v == nt::impl::is_addable_v); + } + } + + GIVEN("A new_type over an addable class type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is addable") + { + REQUIRE(nt::impl::is_addable_v == nt::impl::is_addable_v); + } + } + + GIVEN("A new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("addition produces the same type") + { + REQUIRE(std::is_same_v() + std::declval())>); + } + } + + GIVEN("Two objects of a new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + auto lhs = type_alias{24}; + auto rhs = type_alias{18}; + + THEN("addition produces the correct result with respect to the base type") + { + REQUIRE((lhs + rhs).decay() == 24 + 18); + } + } +} + +SCENARIO("Subtraction", "[arithmetic]") +{ + struct subtractable_type + { + auto constexpr operator-(subtractable_type const &) const -> subtractable_type + { + return {}; + }; + }; + + GIVEN("A new_type not deriving nt::arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is not subtractable") + { + REQUIRE(!nt::impl::is_subtractable_v); + } + } + + GIVEN("A new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is subtractable") + { + REQUIRE(nt::impl::is_subtractable_v); + } + } + + GIVEN("A new_type over a non-subtractable class type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is not addable") + { + REQUIRE(!nt::impl::is_subtractable_v); + } + } + + GIVEN("A new_type over a subtractable class type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is subtractable") + { + REQUIRE(nt::impl::is_subtractable_v); + } + } + + GIVEN("A new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("subtraction produces the same type") + { + REQUIRE(std::is_same_v() - std::declval())>); + } + } + + GIVEN("Two objects of a new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + auto lhs = type_alias{24}; + auto rhs = type_alias{18}; + + THEN("subtraction produces the correct result with respect to the base type") + { + REQUIRE((lhs - rhs).decay() == 24 - 18); + } + } +} + +SCENARIO("Multiplication", "[arithmetic]") +{ + struct multipliable_type + { + auto constexpr operator*(multipliable_type const &) const -> multipliable_type + { + return {}; + }; + }; + + GIVEN("A new_type not deriving nt::arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is not multipliable") + { + REQUIRE(!nt::impl::is_multipliable_v); + } + } + + GIVEN("A new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is multipliable") + { + REQUIRE(nt::impl::is_multipliable_v); + } + } + + GIVEN("A new_type over a non-multipliable class type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is not multipliable") + { + REQUIRE(!nt::impl::is_multipliable_v); + } + } + + GIVEN("A new_type over a multipliable class type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is multipliable") + { + REQUIRE(nt::impl::is_multipliable_v); + } + } + + GIVEN("A new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("multiplication produces the same type") + { + REQUIRE(std::is_same_v() * std::declval())>); + } + } + + GIVEN("Two objects of a new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + auto lhs = type_alias{24}; + auto rhs = type_alias{18}; + + THEN("multiplication produces the correct result with respect to the base type") + { + REQUIRE((lhs * rhs).decay() == 24 * 18); + } + } +} + +SCENARIO("Division", "[arithmetic]") +{ + struct dividable_type + { + auto constexpr operator/(dividable_type const &) const -> dividable_type + { + return {}; + }; + }; + + GIVEN("A new_type not deriving nt::arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is not divisible") + { + REQUIRE(!nt::impl::is_dividable_v); + } + } + + GIVEN("A new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is divisible") + { + REQUIRE(nt::impl::is_dividable_v); + } + } + + GIVEN("A new_type over a non-divisible class type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is not divisible") + { + REQUIRE(!nt::impl::is_dividable_v); + } + } + + GIVEN("A new_type over a divisible class type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("it is divisible") + { + REQUIRE(nt::impl::is_dividable_v); + } + } + + GIVEN("A new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + + THEN("division produces the same type") + { + REQUIRE(std::is_same_v() / std::declval())>); + } + } + + GIVEN("Two objects of a new_type deriving nt::Arithmetic") + { + using type_alias = nt::new_type; + auto lhs = type_alias{30}; + auto rhs = type_alias{15}; + + THEN("division produces the correct result with respect to the base type") + { + REQUIRE((lhs / rhs).decay() == 30 / 15); + } + } +} diff --git a/source/test/src/conversion_suite.cpp b/source/test/src/conversion_suite.cpp new file mode 100644 index 0000000..cbe2463 --- /dev/null +++ b/source/test/src/conversion_suite.cpp @@ -0,0 +1,201 @@ +#include "conversion_suite.hpp" + +#include "kawaii.hpp" +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" +#include "newtype/newtype.hpp" + +#include + +#include +#include +#include +#include +#include +#include +#include + +inline namespace traits_extensions +{ + + template + struct is_implicitly_convertible : std::false_type + { + }; + + template + struct is_implicitly_convertible() = std::declval())>> : std::true_type + { + }; + + template + auto constexpr is_implicitly_convertible_v = is_implicitly_convertible::value; + +} // namespace traits_extensions + +inline namespace ddt_support +{ + + template + struct datum + { + T value; + cute::test_failure failure; + }; + + template + auto generate_test_set(std::size_t size) -> std::vector> + { + auto device = std::random_device{}; + auto generator = std::mt19937{device()}; + auto distribution = [&] { + auto min = std::numeric_limits::min(); + auto max = std::numeric_limits::max(); + if constexpr (std::is_floating_point_v) + { + return std::uniform_real_distribution(min, max); + } + else + { + return std::uniform_int_distribution(min, max); + } + }(); + + auto data = std::vector>{}; + generate_n(std::back_inserter(data), size, [&] { + auto point = distribution(generator); + return datum{point, DDT()}; + }); + return data; + } + +} // namespace ddt_support + +inline namespace implicit_conversion_tests +{ + + template + auto a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type() -> void + { + using type_alias = nt::new_type; + ASSERT(!(is_implicitly_convertible_v)); + } + + template + auto a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type() -> void + { + using type_alias = nt::new_type; + ASSERT((is_implicitly_convertible_v)); + } + +} // namespace implicit_conversion_tests + +inline namespace decay_tests +{ + + template + auto decay_on_a_new__type_has_a_return_type_equal_to_the_base_type() -> void + { + using type_alias = nt::new_type; + ASSERT((std::is_same_v().decay())>)); + } + + template + auto decay_on_a_new__type_returns_the_underlying_value() -> void + { + using type_alias = nt::new_type; + auto data = generate_test_set(2 << 16); + for_each(begin(data), end(data), [](auto & test) { ASSERT_EQUAL_DDT(test.value, type_alias{test.value}.decay(), test.failure); }); + } + +} // namespace decay_tests + +inline namespace decay_noexcept_tests +{ + + auto decay_on_a_new__type_is_noexcept_if_the_base_type_can_be_copied_without_throwing() -> void + { + static_assert(std::is_nothrow_copy_constructible_v, "Sanity check"); + using type_alias = nt::new_type; + ASSERT(noexcept(type_alias{}.decay())); + } + + auto decay_on_a_new__type_is_not_noexcept_if_the_base_type_can_be_not_copied_without_throwing() -> void + { + struct strange_type + { + strange_type() = default; + strange_type(strange_type const &) noexcept(false) + { + } + }; + + static_assert(!std::is_nothrow_copy_constructible_v, "Sanity check"); + using type_alias = nt::new_type; + ASSERT(!noexcept(type_alias{}.decay())); + } + +} // namespace decay_noexcept_tests + +inline namespace conversion_operator_noexcept_tests +{ + + auto new__type_conversion_operator_is_noexcept_if_the_base_type_can_be_copied_without_throwing() -> void + { + static_assert(std::is_nothrow_copy_constructible_v, "Sanity check"); + using type_alias = nt::new_type; + ASSERT(noexcept(static_cast(type_alias{}))); + } + + auto new__type_conversion_operator_is_not_noexcept_if_the_base_type_can_not_be_copied_without_throwing() -> void + { + struct strange_type + { + strange_type() = default; + strange_type(strange_type const &) noexcept(false) + { + } + }; + + static_assert(!std::is_nothrow_copy_constructible_v, "Sanity check"); + using type_alias = nt::new_type; + ASSERT(!noexcept(static_cast(type_alias{}))); + } + +} // namespace conversion_operator_noexcept_tests + +auto conversion_suite() -> std::pair +{ + return {{ + /// Implicit Conversion Tests + KAWAII(a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type), + KAWAII(a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type), + KAWAII(a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type), + KAWAII(a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type), + KAWAII(a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type), + KAWAII(a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type), + KAWAII(a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type), + KAWAII(a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type), + KAWAII(a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type), + KAWAII(a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type), + + /// Decay Tests + KAWAII(decay_on_a_new__type_has_a_return_type_equal_to_the_base_type), + KAWAII(decay_on_a_new__type_has_a_return_type_equal_to_the_base_type), + KAWAII(decay_on_a_new__type_has_a_return_type_equal_to_the_base_type), + KAWAII(decay_on_a_new__type_has_a_return_type_equal_to_the_base_type), + KAWAII(decay_on_a_new__type_has_a_return_type_equal_to_the_base_type), + KAWAII(decay_on_a_new__type_returns_the_underlying_value), + KAWAII(decay_on_a_new__type_returns_the_underlying_value), + KAWAII(decay_on_a_new__type_returns_the_underlying_value), + + /// Decay noexcept Tests + KAWAII(decay_on_a_new__type_is_noexcept_if_the_base_type_can_be_copied_without_throwing), + KAWAII(decay_on_a_new__type_is_not_noexcept_if_the_base_type_can_be_not_copied_without_throwing), + + /// Conversion Operator noexcept Tests + KAWAII(new__type_conversion_operator_is_noexcept_if_the_base_type_can_be_copied_without_throwing), + KAWAII(new__type_conversion_operator_is_not_noexcept_if_the_base_type_can_not_be_copied_without_throwing), + }, + "Conversion Tests"}; +} \ No newline at end of file diff --git a/source/test/src/derivation_clause_suite.cpp b/source/test/src/derivation_clause_suite.cpp new file mode 100644 index 0000000..86a34ab --- /dev/null +++ b/source/test/src/derivation_clause_suite.cpp @@ -0,0 +1,312 @@ +#include "derivation_clause_suite.hpp" + +#include "kawaii.hpp" +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" + +#include + +#include + +inline namespace subset_tests +{ + + auto an_empty_derivation_clause_does_not_contain_any_derivable() -> void + { + auto derivation_clause = nt::deriving(); + ASSERT(!derivation_clause(nt::Show)); + } + + auto a_derivation_clause_containing_only_show_does_not_contain_eqbase() -> void + { + auto derivation_clause = deriving(nt::Show); + ASSERT(!derivation_clause(nt::EqBase)); + } + + auto a_derivation_clause_containing_only_show_does_contain_show() -> void + { + auto derivation_clause = deriving(nt::Show); + ASSERT(derivation_clause(nt::Show)); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_does_contain_show() -> void + { + auto derivation_clause = deriving(nt::Show, nt::EqBase); + ASSERT(derivation_clause(nt::Show)); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_does_contain_both_show_and_eqbase() -> void + { + auto derivation_clause = deriving(nt::Show, nt::EqBase); + ASSERT(derivation_clause(nt::Show, nt::EqBase)); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_arithmetic() -> void + { + auto derivation_clause = deriving(nt::Show, nt::EqBase); + ASSERT(!derivation_clause(nt::Arithmetic)); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_both_show_and_arithmetic() -> void + { + auto derivation_clause = deriving(nt::Show, nt::EqBase); + ASSERT(!derivation_clause(nt::Show, nt::Arithmetic)); + } + +} // namespace subset_tests + +inline namespace less_than_tests +{ + + auto a_derivation_clause_containing_only_show_compares_less_than_one_containing_show_and_eqbase() -> void + { + auto only_show = deriving(nt::Show); + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + + ASSERT(only_show < show_and_eqbase); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_show_and_eqbase() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); + + ASSERT(!(show_and_eqbase < also_show_and_eqbase)); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_eqbase_and_show() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto eqbase_and_show = deriving(nt::EqBase, nt::Show); + + ASSERT(!(show_and_eqbase < eqbase_and_show)); + } + + auto a_derivation_clause_containing_only_show_does_not_compare_less_than_one_containing_only_eqbase() -> void + { + auto show = deriving(nt::Show); + auto eqbase = deriving(nt::EqBase); + + ASSERT(!(show < eqbase)); + } + +} // namespace less_than_tests + +inline namespace greater_than_tests +{ + + auto a_derivation_clause_containing_only_show_and_eqbase_compares_greater_than_one_containing_only_show() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto show = deriving(nt::Show); + + ASSERT(show_and_eqbase > show); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_show_and_eqbase() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); + + ASSERT(!(show_and_eqbase > also_show_and_eqbase)); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_eqbase_and_show() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto eqbase_and_show = deriving(nt::EqBase, nt::Show); + + ASSERT(!(show_and_eqbase > eqbase_and_show)); + } + + auto a_derivation_clause_containing_only_show_does_not_compare_greater_than_one_containing_only_eqbase() -> void + { + auto show = deriving(nt::Show); + auto eqbase = deriving(nt::EqBase); + + ASSERT(!(show > eqbase)); + } + +} // namespace greater_than_tests + +inline namespace eqbaseuals_tests +{ + + auto a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_show_and_eqbase() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); + + ASSERT_EQUAL(show_and_eqbase, also_show_and_eqbase); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_eqbase_and_show() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto eqbase_and_show = deriving(nt::EqBase, nt::Show); + + ASSERT_EQUAL(show_and_eqbase, eqbase_and_show); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto arithmetic = deriving(nt::Arithmetic); + + ASSERT(!(show_and_eqbase == arithmetic)); + } + + auto a_derivation_clause_containing_only_show_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void + { + auto show = deriving(nt::Show); + auto arithmetic = deriving(nt::Arithmetic); + + ASSERT(!(show == arithmetic)); + } + +} // namespace eqbaseuals_tests + +inline namespace not_eqbaseuals_tests +{ + + auto a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_show_and_eqbase() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); + + ASSERT(!(show_and_eqbase != also_show_and_eqbase)); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_eqbase_and_show() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto eqbase_and_show = deriving(nt::EqBase, nt::Show); + + ASSERT(!(show_and_eqbase != eqbase_and_show)); + } + + auto a_derivation_clause_containing_only_eqbase_and_show_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void + { + auto eqbase_and_show = deriving(nt::EqBase, nt::Show); + auto arithmetic = deriving(nt::Arithmetic); + + ASSERT(eqbase_and_show != arithmetic); + } + + auto a_derivation_clause_containing_only_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void + { + auto eqbase = deriving(nt::EqBase); + auto arithmetic = deriving(nt::Arithmetic); + + ASSERT(eqbase != arithmetic); + } + +} // namespace not_eqbaseuals_tests + +inline namespace less_than_or_eqbaseual_tests +{ + + auto a_derivation_clause_containing_only_show_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase() -> void + { + auto only_show = deriving(nt::Show); + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + + ASSERT(only_show <= show_and_eqbase); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); + + ASSERT(show_and_eqbase <= also_show_and_eqbase); + } + + auto a_derivation_clause_containing_only_arithmetic_is_neither_less_than_nor_eqbaseual_to_on_containing_only_show_and_eqbase() -> void + { + auto arithmetic = deriving(nt::Arithmetic); + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + + ASSERT(!(arithmetic <= show_and_eqbase)); + } + +} // namespace less_than_or_eqbaseual_tests + +inline namespace greater_than_or_eqbaseual_tests +{ + + auto a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show() -> void + { + auto only_show = deriving(nt::Show); + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + + ASSERT(show_and_eqbase >= only_show); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show_and_eqbase() -> void + { + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); + + ASSERT(show_and_eqbase >= also_show_and_eqbase); + } + + auto a_derivation_clause_containing_only_show_and_eqbase_is_neither_greater_than_nor_eqbaseual_to_on_containing_only_arithmetic() -> void + { + auto arithmetic = deriving(nt::Arithmetic); + auto show_and_eqbase = deriving(nt::Show, nt::EqBase); + + ASSERT(!(show_and_eqbase >= arithmetic)); + } + +} // namespace greater_than_or_eqbaseual_tests + +auto derivation_clause_suite() -> std::pair +{ + return { + { + /// Subset tests + KAWAII(an_empty_derivation_clause_does_not_contain_any_derivable), + KAWAII(a_derivation_clause_containing_only_show_does_not_contain_eqbase), + KAWAII(a_derivation_clause_containing_only_show_does_contain_show), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_contain_show), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_contain_both_show_and_eqbase), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_arithmetic), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_both_show_and_arithmetic), + + /// Less-than tests + KAWAII(a_derivation_clause_containing_only_show_compares_less_than_one_containing_show_and_eqbase), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_show_and_eqbase), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_eqbase_and_show), + KAWAII(a_derivation_clause_containing_only_show_does_not_compare_less_than_one_containing_only_eqbase), + + /// Greater-than tests + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_compares_greater_than_one_containing_only_show), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_show_and_eqbase), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_eqbase_and_show), + KAWAII(a_derivation_clause_containing_only_show_does_not_compare_greater_than_one_containing_only_eqbase), + + /// Equals tests + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_show_and_eqbase), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_eqbase_and_show), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic), + KAWAII(a_derivation_clause_containing_only_show_is_not_eqbaseual_to_one_containing_only_arithmetic), + + /// Not-Equals tests + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_show_and_eqbase), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_eqbase_and_show), + KAWAII(a_derivation_clause_containing_only_eqbase_and_show_is_not_eqbaseual_to_one_containing_only_arithmetic), + KAWAII(a_derivation_clause_containing_only_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic), + + /// Less-than or Equals tests + KAWAII(a_derivation_clause_containing_only_show_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase), + KAWAII(a_derivation_clause_containing_only_arithmetic_is_neither_less_than_nor_eqbaseual_to_on_containing_only_show_and_eqbase), + + /// Greater-than or Equals tests + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show_and_eqbase), + KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_neither_greater_than_nor_eqbaseual_to_on_containing_only_arithmetic), + }, + "Derivation Clause Tests"}; +} \ No newline at end of file diff --git a/source/test/src/equality_comparison_suite.cpp b/source/test/src/equality_comparison_suite.cpp new file mode 100644 index 0000000..4e484f4 --- /dev/null +++ b/source/test/src/equality_comparison_suite.cpp @@ -0,0 +1,188 @@ +#include "equality_comparison_suite.hpp" + +#include "kawaii.hpp" +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" +#include "newtype/newtype.hpp" + +#include + +#include +#include +#include + +inline namespace basic_equality_comparsion_tests +{ + + auto two_instances_of_the_same_new__type_with_the_same_value_compare_equal() -> void + { + using type_alias = nt::new_type; + + auto constexpr lhs = type_alias{42}; + auto constexpr rhs = type_alias{42}; + + ASSERT_EQUAL(lhs, rhs); + } + + auto two_instances_of_the_same_new__type_with_the_same_value_do_not_compare_not_equal() -> void + { + using type_alias = nt::new_type; + + auto constexpr lhs = type_alias{42}; + auto constexpr rhs = type_alias{42}; + + ASSERT(!(lhs != rhs)); + } + + auto two_instances_of_the_same_new__type_with_differing_values_do_compare_not_equal() -> void + { + using type_alias = nt::new_type; + + auto constexpr lhs = type_alias{42}; + auto constexpr rhs = type_alias{43}; + + ASSERT_NOT_EQUAL_TO(lhs, rhs); + } + + auto two_instances_of_the_same_new__type_with_differing_values_do_not_compare_equal() -> void + { + using type_alias = nt::new_type; + + auto constexpr lhs = type_alias{42}; + auto constexpr rhs = type_alias{43}; + + ASSERT(!(lhs == rhs)); + } + +} // namespace basic_equality_comparsion_tests + +inline namespace equality_comparsion_noexcept_tests +{ + + auto equality_comparison_on_a_new__type_is_noexcept_if_the_base_type_is_noexcept_comparable() -> void + { + using type_alias = nt::new_type; + static_assert(noexcept(std::declval() == std::declval()), "Sanity Check"); + ASSERT(noexcept(std::declval() == std::declval())); + } + + auto equality_comparison_on_a_new__type_is_not_noexcept_if_the_base_type_is_not_noexcept_comparable() -> void + { + struct strange_type + { + auto constexpr operator==(strange_type const &) const noexcept(false) -> bool + { + return false; + } + }; + + using type_alias = nt::new_type; + static_assert(!noexcept(std::declval() == std::declval()), "Sanity Check"); + ASSERT(!noexcept(std::declval() == std::declval())); + } + + auto inequality_comparison_on_a_new__type_is_noexcept_if_the_base_type_is_noexcept_comparable() -> void + { + using type_alias = nt::new_type; + static_assert(noexcept(std::declval() != std::declval()), "Sanity Check"); + ASSERT(noexcept(std::declval() != std::declval())); + } + + auto inequality_comparison_on_a_new__type_is_not_noexcept_if_the_base_type_is_not_noexcept_comparable() -> void + { + struct strange_type + { + auto constexpr operator!=(strange_type const &) const noexcept(false) -> bool + { + return false; + } + }; + + using type_alias = nt::new_type; + static_assert(!noexcept(std::declval() != std::declval()), "Sanity Check"); + ASSERT(!noexcept(std::declval() != std::declval())); + } + +} // namespace equality_comparsion_noexcept_tests + +inline namespace equality_comparison_return_type_tests +{ + + auto equality_comparsion_of_two_new__type_instances_returns_bool() -> void + { + using type_alias = nt::new_type; + ASSERT((std::is_same_v() == std::declval())>)); + } + + auto inequality_comparsion_of_two_new__type_instances_returns_bool() -> void + { + using type_alias = nt::new_type; + ASSERT((std::is_same_v() != std::declval())>)); + } + +} // namespace equality_comparison_return_type_tests + +inline namespace base_type_equality_comparison_tests +{ + + auto an_instance_of_a_new__type_compares_equal_to_an_instance_of_its_base_type_with_the_same_value() -> void + { + using type_alias = nt::new_type; + auto lhs = type_alias{42}; + auto rhs = 42; + ASSERT_EQUAL(lhs, rhs); + } + + auto an_instance_of_the_base_type_of_a_new__type_compares_equal_to_an_instance_of_the_new__type_with_the_same_value() -> void + { + using type_alias = nt::new_type; + auto lhs = 42; + auto rhs = type_alias{42}; + ASSERT_EQUAL(lhs, rhs); + } + + auto an_instance_of_a_new__type_compares_not_equal_to_an_instance_of_its_base_type_with_a_differing_value() -> void + { + using type_alias = nt::new_type; + auto lhs = type_alias{42}; + auto rhs = 43; + ASSERT(lhs != rhs); + } + + auto an_instance_of_the_base_type_of_a_new__type_compares_not_equal_to_an_instance_of_the_new__type_with_a_differing_value() -> void + { + using type_alias = nt::new_type; + auto lhs = 43; + auto rhs = type_alias{42}; + ASSERT(lhs != rhs); + } + +} // namespace base_type_equality_comparison_tests + +auto equality_comparison_suite() -> std::pair +{ + return {{ + // Basic Equality Comparison Tests + KAWAII(two_instances_of_the_same_new__type_with_the_same_value_compare_equal), + KAWAII(two_instances_of_the_same_new__type_with_the_same_value_do_not_compare_not_equal), + KAWAII(two_instances_of_the_same_new__type_with_differing_values_do_compare_not_equal), + KAWAII(two_instances_of_the_same_new__type_with_differing_values_do_not_compare_equal), + + // Equality Comparison noexcept Tests + KAWAII(equality_comparison_on_a_new__type_is_noexcept_if_the_base_type_is_noexcept_comparable), + KAWAII(equality_comparison_on_a_new__type_is_not_noexcept_if_the_base_type_is_not_noexcept_comparable), + KAWAII(inequality_comparison_on_a_new__type_is_noexcept_if_the_base_type_is_noexcept_comparable), + KAWAII(inequality_comparison_on_a_new__type_is_not_noexcept_if_the_base_type_is_not_noexcept_comparable), + + // Equality Comparison Return Type Tests + KAWAII(equality_comparsion_of_two_new__type_instances_returns_bool), + KAWAII(inequality_comparsion_of_two_new__type_instances_returns_bool), + + // Base-type Equality Comparison Tests + KAWAII(an_instance_of_a_new__type_compares_equal_to_an_instance_of_its_base_type_with_the_same_value), + KAWAII(an_instance_of_the_base_type_of_a_new__type_compares_equal_to_an_instance_of_the_new__type_with_the_same_value), + KAWAII(an_instance_of_a_new__type_compares_not_equal_to_an_instance_of_its_base_type_with_a_differing_value), + KAWAII(an_instance_of_the_base_type_of_a_new__type_compares_not_equal_to_an_instance_of_the_new__type_with_a_differing_value), + }, + "Equality Comparison Tests"}; +} \ No newline at end of file diff --git a/source/test/src/hash_suite.cpp b/source/test/src/hash_suite.cpp new file mode 100644 index 0000000..b482414 --- /dev/null +++ b/source/test/src/hash_suite.cpp @@ -0,0 +1,69 @@ +#include "hash_suite.hpp" + +#include "kawaii.hpp" +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" +#include "newtype/impl/type_traits_extensions.hpp" +#include "newtype/newtype.hpp" + +#include + +#include + +inline namespace hashable_tests +{ + + auto a_new__type_that_does_not_include_hash_in_its_derivation_clause_is_not_hashable() -> void + { + using type_alias = nt::new_type; + ASSERT(!nt::impl::is_hashable_v); + } + + auto a_new__type_that_does_include_hash_in_its_derivation_clause_is_hashable() -> void + { + static_assert(nt::impl::is_hashable_v, "Sanity Check"); + using type_alias = nt::new_type; + ASSERT(nt::impl::is_hashable_v); + } + + auto a_new__type_that_does_include_hash_in_its_derivation_clause_but_whose_base_type_is_not_hashable_is_also_not_hashable() -> void + { + struct not_hashable + { + }; + + static_assert(!nt::impl::is_hashable_v, "Sanity Check"); + using type_alias = nt::new_type; + ASSERT(!nt::impl::is_hashable_v); + } + +} // namespace hashable_tests + +inline namespace usage_tests +{ + + auto a_new__type_that_is_hashable_can_be_used_in_an_unordered__map() -> void + { + static_assert(nt::impl::is_hashable_v, "Sanity Check"); + using type_alias = nt::new_type; + + auto map = std::unordered_map{}; + map[type_alias{42}] = 43; + ASSERT_EQUAL(43, map[type_alias{42}]); + } + +} // namespace usage_tests + +auto hash_suite() -> std::pair +{ + return {{ + // Hashable Tests + KAWAII(a_new__type_that_does_not_include_hash_in_its_derivation_clause_is_not_hashable), + KAWAII(a_new__type_that_does_include_hash_in_its_derivation_clause_is_hashable), + KAWAII(a_new__type_that_does_include_hash_in_its_derivation_clause_but_whose_base_type_is_not_hashable_is_also_not_hashable), + + // Usage Tests + KAWAII(a_new__type_that_is_hashable_can_be_used_in_an_unordered__map), + }, + "std::hash Support Tests"}; +} \ No newline at end of file diff --git a/source/test/src/io_operators_suite.cpp b/source/test/src/io_operators_suite.cpp new file mode 100644 index 0000000..4e146a7 --- /dev/null +++ b/source/test/src/io_operators_suite.cpp @@ -0,0 +1,121 @@ +#include "io_operators_suite.hpp" + +#include "kawaii.hpp" +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" +#include "newtype/newtype.hpp" + +#include + +#include +#include +#include +#include +#include + +inline namespace traits_extensions +{ + + template + struct has_stream_input : std::false_type + { + }; + + template + struct has_stream_input() >> std::declval())>> : std::true_type + { + }; + + template + auto constexpr has_stream_input_v = has_stream_input::value; + + template + struct has_stream_output : std::false_type + { + }; + + template + struct has_stream_output() << std::declval())>> : std::true_type + { + }; + + template + auto constexpr has_stream_output_v = has_stream_output::value; + +} // namespace traits_extensions + +inline namespace stream_input_operator_tests +{ + + auto a_new__type_has_the_stream_input_operator_if_the_derivation_clause_contains_read() -> void + { + using type_alias = nt::new_type; + ASSERT(has_stream_input_v); + } + + auto a_new__type_does_not_have_the_stream_input_operator_if_the_derivation_clause_does_not_contain_read() -> void + { + using type_alias = nt::new_type; + ASSERT(!has_stream_input_v); + } + + auto a_instance_of_a_new__type_can_be_read_from_an_istream_if_the_base_type_can_be_read_from_an_istream() -> void + { + static_assert(has_stream_input_v, "Sanity Check"); + using type_alias = nt::new_type; + + auto obj = type_alias{}; + auto input = std::istringstream{"42"}; + + input >> obj; + + ASSERT_EQUAL(42, obj.decay()); + } + +} // namespace stream_input_operator_tests + +inline namespace stream_output_operator_tests +{ + + auto a_new__type_has_the_stream_output_operator_if_the_derivation_clause_contains_show() -> void + { + using type_alias = nt::new_type; + ASSERT(has_stream_output_v); + } + + auto a_new__type_does_not_have_the_stream_output_operator_if_the_derivation_clause_does_not_contain_show() -> void + { + using type_alias = nt::new_type; + ASSERT(!has_stream_output_v); + } + + auto a_instance_of_a_new__type_can_be_written_to_an_ostream_if_the_base_type_can_be_written_to_an_ostream() -> void + { + static_assert(has_stream_output_v, "Sanity Check"); + using type_alias = nt::new_type; + + auto obj = type_alias{42}; + auto output = std::ostringstream{}; + + output << obj; + + ASSERT_EQUAL("42", output.str()); + } + +} // namespace stream_output_operator_tests + +auto io_operators_suite() -> std::pair +{ + return {{ + // Stream Input Operator Tests + KAWAII(a_new__type_has_the_stream_input_operator_if_the_derivation_clause_contains_read), + KAWAII(a_new__type_does_not_have_the_stream_input_operator_if_the_derivation_clause_does_not_contain_read), + KAWAII(a_instance_of_a_new__type_can_be_read_from_an_istream_if_the_base_type_can_be_read_from_an_istream), + + // Stream Ouput Operator Tests + KAWAII(a_new__type_has_the_stream_output_operator_if_the_derivation_clause_contains_show), + KAWAII(a_new__type_does_not_have_the_stream_output_operator_if_the_derivation_clause_does_not_contain_show), + KAWAII(a_instance_of_a_new__type_can_be_written_to_an_ostream_if_the_base_type_can_be_written_to_an_ostream), + }, + "I/O Operators Tests"}; +} \ No newline at end of file diff --git a/source/test/src/iterable_suite.cpp b/source/test/src/iterable_suite.cpp new file mode 100644 index 0000000..add4696 --- /dev/null +++ b/source/test/src/iterable_suite.cpp @@ -0,0 +1,719 @@ +#include "iterable_suite.hpp" + +#include "kawaii.hpp" +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" +#include "newtype/impl/type_traits_extensions.hpp" +#include "newtype/newtype.hpp" + +#include + +#include +#include +#include +#include + +namespace +{ + + struct with_member + { + using iterator = char *; + using const_iterator = char const *; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; + + auto begin() -> iterator; + auto begin() const -> const_iterator; + auto cbegin() const -> const_iterator; + auto rbegin() -> reverse_iterator; + auto rbegin() const -> const_reverse_iterator; + auto crbegin() const -> const_reverse_iterator; + + auto end() -> iterator; + auto end() const -> const_iterator; + auto cend() const -> const_iterator; + auto rend() -> reverse_iterator; + auto rend() const -> const_reverse_iterator; + auto crend() const -> const_reverse_iterator; + }; + + struct with_free + { + using iterator = char *; + using const_iterator = char const *; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; + }; + + auto begin(with_free &) -> with_free::iterator + { + return {}; + } + + auto begin(with_free const &) -> with_free::const_iterator + { + return {}; + } + + auto cbegin(with_free const &) -> with_free::const_iterator + { + return {}; + } + + auto rbegin(with_free &) -> with_free::reverse_iterator + { + return {}; + } + + auto rbegin(with_free const &) -> with_free::const_reverse_iterator + { + return {}; + } + + auto crbegin(with_free const &) -> with_free::const_reverse_iterator + { + return {}; + } + + auto end(with_free &) -> with_free::iterator + { + return {}; + } + + auto end(with_free const &) -> with_free::const_iterator + { + return {}; + } + + auto cend(with_free const &) -> with_free::const_iterator + { + return {}; + } + + auto rend(with_free &) -> with_free::reverse_iterator + { + return {}; + } + + auto rend(with_free const &) -> with_free::const_reverse_iterator + { + return {}; + } + + auto crend(with_free const &) -> with_free::const_reverse_iterator + { + return {}; + } + +} // namespace + +inline namespace combined_enablement_tests +{ + + auto a_new__type_not_deriving_iterable_has_no_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_begin_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_constant_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_begin_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_cbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cbegin_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rbegin_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_constant_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rbegin_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_crbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crbegin_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_end() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_end_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_constant_end() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_end_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_cend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cend_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rend_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_constant_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rend_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_crend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crend_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_begin_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_begin_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cbegin_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rbegin_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rbegin_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crbegin_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_end() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_end_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_end() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_end_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cend_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rend_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rend_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crend_v)); + } + +} // namespace combined_enablement_tests + +inline namespace member_enablement_tests +{ + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_begin_v)); + } + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_begin_v)); + } + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_cbegin_v)); + } + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_rbegin_v)); + } + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_rbegin_v)); + } + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_crbegin_v)); + } + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_end() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_end_v)); + } + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_end() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_end_v)); + } + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_cend_v)); + } + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_rend_v)); + } + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_rend_v)); + } + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_crend_v)); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_begin_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_begin_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_cbegin_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_rbegin_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_rbegin_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_crbegin_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_end() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_end_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_end() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_end_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_cend_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_rend_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_rend_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_crend_v); + } + +} // namespace member_enablement_tests + +inline namespace free_enablement_tests +{ + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_begin_v)); + } + + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_begin_v)); + } + + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_cbegin_v)); + } + + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_rbegin_v)); + } + + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_rbegin_v)); + } + + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_crbegin_v)); + } + + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_end() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_end_v)); + } + + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_end() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_end_v)); + } + + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_cend_v)); + } + + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_rend_v)); + } + + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_rend_v)); + } + + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_crend_v)); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_begin_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_begin_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_cbegin_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_rbegin_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_rbegin_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_crbegin_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_end() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_end_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_end() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_end_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_cend_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_rend_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_rend_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_crend_v); + } + +} // namespace free_enablement_tests + +inline namespace semantic_tests +{ + + auto a_non_const_object_of_iterable_new__type_can_be_used_in_value_range_for() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto object = type_alias{{1, 2, 3}}; + for (auto e : object) + { + (void)e; + } + ASSERT(true); + } + + auto a_const_object_of_iterable_new__type_can_be_used_in_value_range_for() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto const object = type_alias{{1, 2, 3}}; + for (auto e : object) + { + (void)e; + } + ASSERT(true); + } + + auto a_non_const_object_of_iterable_new__type_can_be_used_in_reference_range_for() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto object = type_alias{{1, 2, 3}}; + for (auto & e : object) + { + (void)e; + } + ASSERT(true); + } + + auto a_const_object_of_iterable_new__type_can_be_used_in_const_reference_range_for() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto const object = type_alias{{1, 2, 3}}; + for (auto const & e : object) + { + (void)e; + } + ASSERT(true); + } + + auto applying_accumulate_to_an_interable_new__type_yields_the_same_result_as_when_applied_to_the_base_type() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto const nt_object = type_alias{{1, 2, 3}}; + auto const bt_object = type_alias::base_type{1, 2, 3}; + + auto nt_result = std::accumulate(std::cbegin(nt_object), std::cend(nt_object), 0); + auto bt_result = std::accumulate(std::cbegin(bt_object), std::cend(bt_object), 0); + + ASSERT_EQUAL(bt_result, nt_result); + } + + auto iterating_over_an_iterable_new__type_yields_the_elements_in_the_same_order_as_when_iterating_the_base_type() -> void + { + using std::cbegin, std::cend, std::equal; + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto const nt_object = type_alias{{1, 2, 3}}; + auto const bt_object = type_alias::base_type{1, 2, 3}; + + ASSERT(equal(cbegin(nt_object), cend(nt_object), cbegin(bt_object), cend(bt_object))); + } + +} // namespace semantic_tests + +auto iterable_suite() -> std::pair +{ + return {{ + /// Combined Enablement Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_begin), + KAWAII(a_new__type_not_deriving_iterable_has_no_constant_begin), + KAWAII(a_new__type_not_deriving_iterable_has_no_cbegin), + KAWAII(a_new__type_not_deriving_iterable_has_no_rbegin), + KAWAII(a_new__type_not_deriving_iterable_has_no_constant_rbegin), + KAWAII(a_new__type_not_deriving_iterable_has_no_crbegin), + KAWAII(a_new__type_not_deriving_iterable_has_no_end), + KAWAII(a_new__type_not_deriving_iterable_has_no_constant_end), + KAWAII(a_new__type_not_deriving_iterable_has_no_cend), + KAWAII(a_new__type_not_deriving_iterable_has_no_rend), + KAWAII(a_new__type_not_deriving_iterable_has_no_constant_rend), + KAWAII(a_new__type_not_deriving_iterable_has_no_crend), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_begin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_begin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cbegin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rbegin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rbegin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crbegin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_end), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_end), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cend), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rend), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rend), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crend), + + /// Member Enablement Tests + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_begin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_begin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cbegin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rbegin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rbegin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crbegin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_end), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_end), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cend), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rend), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rend), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crend), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_begin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_begin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cbegin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rbegin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rbegin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crbegin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_end), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_end), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cend), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rend), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rend), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crend), + + /// Free Enablement Tests + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_begin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_begin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cbegin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rbegin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rbegin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crbegin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_end), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_end), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cend), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rend), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rend), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crend), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_begin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_begin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cbegin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rbegin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rbegin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crbegin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_end), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_end), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cend), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rend), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rend), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crend), + + /// Semantic Tests + KAWAII(a_non_const_object_of_iterable_new__type_can_be_used_in_value_range_for), + KAWAII(a_const_object_of_iterable_new__type_can_be_used_in_value_range_for), + KAWAII(a_non_const_object_of_iterable_new__type_can_be_used_in_reference_range_for), + KAWAII(a_const_object_of_iterable_new__type_can_be_used_in_const_reference_range_for), + KAWAII(applying_accumulate_to_an_interable_new__type_yields_the_same_result_as_when_applied_to_the_base_type), + KAWAII(iterating_over_an_iterable_new__type_yields_the_elements_in_the_same_order_as_when_iterating_the_base_type), + }, + + "Iterable Tests"}; +} \ No newline at end of file diff --git a/source/test/src/new_type_constructor_suite.cpp b/source/test/src/new_type_constructor_suite.cpp new file mode 100644 index 0000000..fc3e9f6 --- /dev/null +++ b/source/test/src/new_type_constructor_suite.cpp @@ -0,0 +1,91 @@ +#include "new_type_constructor_suite.hpp" + +#include "kawaii.hpp" +#include "newtype/derivable.hpp" +#include "newtype/newtype.hpp" + +#include + +#include + +inline namespace constructor_tests +{ + + struct not_default_constructible + { + not_default_constructible() = delete; + }; + + auto a_new__type_based_on_a_type_that_is_default_constructible_is_default_constructible_too() -> void + { + using nt_float = nt::new_type; + + ASSERT(std::is_default_constructible_v); + } + + auto a_new__type_based_on_a_type_that_is_not_default_constructible_is_not_default_constructible_too() -> void + { + using nt_not_default_constructible = nt::new_type; + + ASSERT(!std::is_default_constructible_v); + } + + template + auto a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type() -> void + { + using nt_old = nt::new_type; + + ASSERT((std::is_constructible_v)); + } + + auto a_new__type_instance_can_be_copy_constructed_if_the_base_type_can_be_copy_constructed() -> void + { + using type_alias = nt::new_type; + ASSERT((std::is_copy_constructible_v)); + } + + auto a_new__type_instance_can_not_be_copy_constructed_if_the_base_type_can_not_be_copy_constructed() -> void + { + struct not_copy_constructible + { + not_copy_constructible() = default; + not_copy_constructible(not_copy_constructible const &) = delete; + not_copy_constructible(not_copy_constructible &&) = default; + auto operator=(not_copy_constructible const &) -> not_copy_constructible & = default; + auto operator=(not_copy_constructible &&) -> not_copy_constructible & = default; + }; + + using type_alias = nt::new_type; + ASSERT(!(std::is_copy_constructible_v)); + } + +} // namespace constructor_tests + +auto new_type_constructor_suite() -> std::pair +{ + return {{ + KAWAII(a_new__type_based_on_a_type_that_is_default_constructible_is_default_constructible_too), + KAWAII(a_new__type_based_on_a_type_that_is_not_default_constructible_is_not_default_constructible_too), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), + KAWAII(a_new__type_instance_can_be_copy_constructed_if_the_base_type_can_be_copy_constructed), + KAWAII(a_new__type_instance_can_not_be_copy_constructed_if_the_base_type_can_not_be_copy_constructed), + }, + "new_type Constructor Tests"}; +} \ No newline at end of file diff --git a/source/test/src/relational_operators_suite.cpp b/source/test/src/relational_operators_suite.cpp new file mode 100644 index 0000000..64fcba0 --- /dev/null +++ b/source/test/src/relational_operators_suite.cpp @@ -0,0 +1,321 @@ +#include "relational_operators_suite.hpp" + +#include "kawaii.hpp" +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" +#include "newtype/newtype.hpp" + +#include + +#include +#include +#include + +inline namespace traits_extensions +{ + + template + struct has_less_than : std::false_type + { + }; + + template + struct has_less_than() < std::declval())>> : std::true_type + { + }; + + template + auto constexpr has_less_than_v = has_less_than::value; + + template + struct has_greater_than : std::false_type + { + }; + + template + struct has_greater_than() > std::declval())>> : std::true_type + { + }; + + template + auto constexpr has_greater_than_v = has_greater_than::value; + + template + struct has_less_than_equal_to : std::false_type + { + }; + + template + struct has_less_than_equal_to() <= std::declval())>> : std::true_type + { + }; + + template + auto constexpr has_less_than_equal_to_v = has_less_than_equal_to::value; + + template + struct has_greater_than_equal_to : std::false_type + { + }; + + template + struct has_greater_than_equal_to() >= std::declval())>> : std::true_type + { + }; + + template + auto constexpr has_greater_than_equal_to_v = has_greater_than_equal_to::value; + +} // namespace traits_extensions + +inline namespace relational_operator_presence_tests +{ + + auto an_instance_of_new__type_has_less_than_if_its_derivation_clause_contains_relational() -> void + { + using type_alias = nt::new_type; + ASSERT(has_less_than_v); + } + + auto an_instance_of_new__type_does_not_have_less_than_if_its_derivation_clause_does_not_contain_relational() -> void + { + using type_alias = nt::new_type; + ASSERT(!has_less_than_v); + } + + auto an_instance_of_new__type_has_greater_than_if_its_derivation_clause_contains_relational() -> void + { + using type_alias = nt::new_type; + ASSERT(has_greater_than_v); + } + + auto an_instance_of_new__type_does_not_have_greater_than_if_its_derivation_clause_does_not_contain_relational() -> void + { + using type_alias = nt::new_type; + ASSERT(!has_greater_than_v); + } + + auto an_instance_of_new__type_has_less_than_or_equal_to_if_its_derivation_clause_contains_relational() -> void + { + using type_alias = nt::new_type; + ASSERT(has_less_than_equal_to_v); + } + + auto an_instance_of_new__type_does_not_have_less_than_or_equal_to_if_its_derivation_clause_does_not_contain_relational() -> void + { + using type_alias = nt::new_type; + ASSERT(!has_less_than_equal_to_v); + } + + auto an_instance_of_new__type_has_greater_than_or_equal_to_if_its_derivation_clause_contains_relational() -> void + { + using type_alias = nt::new_type; + ASSERT(has_greater_than_equal_to_v); + } + + auto an_instance_of_new__type_does_not_have_greater_than_or_equal_to_if_its_derivation_clause_does_not_contain_relational() -> void + { + using type_alias = nt::new_type; + ASSERT(!has_greater_than_equal_to_v); + } + +} // namespace relational_operator_presence_tests + +inline namespace less_than_tests +{ + + auto two_instances_of_the_same_new__type_compare_less_than_if_both_contained_values_would_compare_less_than() -> void + { + using type_alias = nt::new_type; + auto constexpr lhs{21}; + auto constexpr rhs{42}; + static_assert(lhs < rhs, "Sanity Check"); + ASSERT_LESS(type_alias{lhs}, type_alias{rhs}); + } + + auto two_instances_of_the_same_new__type_do_not_compare_less_than_if_both_contained_values_would_not_compare_less_than() -> void + { + using type_alias = nt::new_type; + auto constexpr lhs{44}; + auto constexpr rhs{42}; + static_assert(!(lhs < rhs), "Sanity Check"); + ASSERT(!(type_alias{lhs} < type_alias{rhs})); + } + + auto two_instances_of_the_same_new__type_compare_less_than_or_equal_if_both_contained_values_would_compare_less_than_or_equal() -> void + { + using type_alias = nt::new_type; + auto constexpr lhs{33}; + auto constexpr rhs{42}; + static_assert(lhs <= rhs, "Sanity Check"); + ASSERT_LESS_EQUAL(type_alias{lhs}, type_alias{rhs}); + } + + auto two_instances_of_the_same_new__type_do_not_compare_less_than_or_equal_if_both_contained_values_would_not_compare_less_than_or_equal() + -> void + { + using type_alias = nt::new_type; + auto constexpr lhs{87}; + auto constexpr rhs{42}; + static_assert(!(lhs < rhs), "Sanity Check"); + ASSERT(!(type_alias{lhs} < type_alias{rhs})); + } + +} // namespace less_than_tests + +inline namespace greater_than_tests +{ + + auto two_instances_of_the_same_new__type_compare_greater_than_if_both_contained_values_would_compare_greater_than() -> void + { + using type_alias = nt::new_type; + auto constexpr lhs{42}; + auto constexpr rhs{21}; + static_assert(lhs > rhs, "Sanity Check"); + ASSERT_GREATER(type_alias{lhs}, type_alias{rhs}); + } + + auto two_instances_of_the_same_new__type_do_not_compare_greater_than_if_both_contained_values_would_not_compare_greater_than() -> void + { + using type_alias = nt::new_type; + auto constexpr lhs{42}; + auto constexpr rhs{44}; + static_assert(!(lhs > rhs), "Sanity Check"); + ASSERT(!(type_alias{lhs} > type_alias{rhs})); + } + + auto two_instances_of_the_same_new__type_compare_greater_than_or_equal_if_both_contained_values_would_compare_greater_than_or_equal() -> void + { + using type_alias = nt::new_type; + auto constexpr lhs{42}; + auto constexpr rhs{33}; + static_assert(lhs >= rhs, "Sanity Check"); + ASSERT_GREATER_EQUAL(type_alias{lhs}, type_alias{rhs}); + } + + auto + two_instances_of_the_same_new__type_do_not_compare_greater_than_or_equal_if_both_contained_values_would_not_compare_greater_than_or_equal() + -> void + { + using type_alias = nt::new_type; + auto constexpr lhs{42}; + auto constexpr rhs{87}; + static_assert(!(lhs > rhs), "Sanity Check"); + ASSERT(!(type_alias{lhs} > type_alias{rhs})); + } + +} // namespace greater_than_tests + +inline namespace relational_operator_noexcept_tests +{ + + struct strange_type + { + auto constexpr operator<(strange_type const & other) const noexcept(false) -> bool; + auto constexpr operator>(strange_type const & other) const noexcept(false) -> bool; + auto constexpr operator<=(strange_type const & other) const noexcept(false) -> bool; + auto constexpr operator>=(strange_type const & other) const noexcept(false) -> bool; + }; + + auto less_than_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept() -> void + { + using type_alias = nt::new_type; + static_assert(noexcept(std::declval() < std::declval()), "Sanity Check"); + ASSERT(noexcept(std::declval() < std::declval())); + } + + auto less_than_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept() -> void + { + using type_alias = nt::new_type; + static_assert(!noexcept(std::declval() < std::declval()), "Sanity Check"); + ASSERT(!noexcept(std::declval() < std::declval())); + } + + auto less_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept() -> void + { + using type_alias = nt::new_type; + static_assert(noexcept(std::declval() <= std::declval()), "Sanity Check"); + ASSERT(noexcept(std::declval() <= std::declval())); + } + + auto less_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept() + -> void + { + using type_alias = nt::new_type; + static_assert(!noexcept(std::declval() <= std::declval()), "Sanity Check"); + ASSERT(!noexcept(std::declval() <= std::declval())); + } + + auto greater_than_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept() -> void + { + using type_alias = nt::new_type; + static_assert(noexcept(std::declval() > std::declval()), "Sanity Check"); + ASSERT(noexcept(std::declval() > std::declval())); + } + + auto greater_than_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept() -> void + { + using type_alias = nt::new_type; + static_assert(!noexcept(std::declval() > std::declval()), "Sanity Check"); + ASSERT(!noexcept(std::declval() > std::declval())); + } + + auto greater_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept() -> void + { + using type_alias = nt::new_type; + static_assert(noexcept(std::declval() >= std::declval()), "Sanity Check"); + ASSERT(noexcept(std::declval() >= std::declval())); + } + + auto greater_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept() + -> void + { + using type_alias = nt::new_type; + static_assert(!noexcept(std::declval() >= std::declval()), "Sanity Check"); + ASSERT(!noexcept(std::declval() >= std::declval())); + } + +} // namespace relational_operator_noexcept_tests + +auto relational_operators_suite() -> std::pair +{ + return { + { + // clang-format off + + // Relational Operator Presensence Tests + KAWAII(an_instance_of_new__type_has_less_than_if_its_derivation_clause_contains_relational), + KAWAII(an_instance_of_new__type_does_not_have_less_than_if_its_derivation_clause_does_not_contain_relational), + KAWAII(an_instance_of_new__type_has_greater_than_if_its_derivation_clause_contains_relational), + KAWAII(an_instance_of_new__type_does_not_have_greater_than_if_its_derivation_clause_does_not_contain_relational), + KAWAII(an_instance_of_new__type_has_less_than_or_equal_to_if_its_derivation_clause_contains_relational), + KAWAII(an_instance_of_new__type_does_not_have_less_than_or_equal_to_if_its_derivation_clause_does_not_contain_relational), + KAWAII(an_instance_of_new__type_has_greater_than_or_equal_to_if_its_derivation_clause_contains_relational), + KAWAII(an_instance_of_new__type_does_not_have_greater_than_or_equal_to_if_its_derivation_clause_does_not_contain_relational), + + // Less-than Comparison Tests + KAWAII(two_instances_of_the_same_new__type_compare_less_than_if_both_contained_values_would_compare_less_than), + KAWAII(two_instances_of_the_same_new__type_do_not_compare_less_than_if_both_contained_values_would_not_compare_less_than), + KAWAII(two_instances_of_the_same_new__type_compare_less_than_or_equal_if_both_contained_values_would_compare_less_than_or_equal), + KAWAII(two_instances_of_the_same_new__type_do_not_compare_less_than_or_equal_if_both_contained_values_would_not_compare_less_than_or_equal), + + // Greater-than Comparison Tests + KAWAII(two_instances_of_the_same_new__type_compare_greater_than_if_both_contained_values_would_compare_greater_than), + KAWAII(two_instances_of_the_same_new__type_do_not_compare_greater_than_if_both_contained_values_would_not_compare_greater_than), + KAWAII(two_instances_of_the_same_new__type_compare_greater_than_or_equal_if_both_contained_values_would_compare_greater_than_or_equal), + KAWAII(two_instances_of_the_same_new__type_do_not_compare_greater_than_or_equal_if_both_contained_values_would_not_compare_greater_than_or_equal), + + // Relational Operators noexcept Tests + KAWAII(less_than_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept), + KAWAII(less_than_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept), + KAWAII(less_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept), + KAWAII(less_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept), + KAWAII(greater_than_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept), + KAWAII(greater_than_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept), + KAWAII(greater_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept), + KAWAII(greater_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept), + + // clang-format on + }, + "Relational Operators Tests"}; +} \ No newline at end of file diff --git a/test/include/arithmetic_suite.hpp b/test/include/arithmetic_suite.hpp deleted file mode 100644 index 1eb4af8..0000000 --- a/test/include/arithmetic_suite.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NEWTYPE_TEST_ARITHMETIC_SUITE_HPP -#define NEWTYPE_TEST_ARITHMETIC_SUITE_HPP - -#include - -#include -#include - -auto arithmetic_suite() -> std::pair; - -#endif \ No newline at end of file diff --git a/test/include/conversion_suite.hpp b/test/include/conversion_suite.hpp deleted file mode 100644 index 8b9c337..0000000 --- a/test/include/conversion_suite.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NEWTYPE_TEST_CONVERSION_SUITE_HPP -#define NEWTYPE_TEST_CONVERSION_SUITE_HPP - -#include - -#include -#include - -auto conversion_suite() -> std::pair; - -#endif \ No newline at end of file diff --git a/test/include/derivation_clause_suite.hpp b/test/include/derivation_clause_suite.hpp deleted file mode 100644 index b5ef5c2..0000000 --- a/test/include/derivation_clause_suite.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NEWTYPE_TEST_DERIVATION_CLAUSE_SUITE_HPP -#define NEWTYPE_TEST_DERIVATION_CLAUSE_SUITE_HPP - -#include - -#include -#include - -auto derivation_clause_suite() -> std::pair; - -#endif \ No newline at end of file diff --git a/test/include/equality_comparison_suite.hpp b/test/include/equality_comparison_suite.hpp deleted file mode 100644 index 80abbe7..0000000 --- a/test/include/equality_comparison_suite.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NEWTYPE_TEST_EQUALITY_COMPARISON_SUITE_HPP -#define NEWTYPE_TEST_EQUALITY_COMPARISON_SUITE_HPP - -#include - -#include -#include - -auto equality_comparison_suite() -> std::pair; - -#endif \ No newline at end of file diff --git a/test/include/hash_suite.hpp b/test/include/hash_suite.hpp deleted file mode 100644 index 0ef51bc..0000000 --- a/test/include/hash_suite.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NEWTYPE_TEST_HASH_SUITE_HPP -#define NEWTYPE_TEST_HASH_SUITE_HPP - -#include - -#include -#include - -auto hash_suite() -> std::pair; - -#endif \ No newline at end of file diff --git a/test/include/io_operators_suite.hpp b/test/include/io_operators_suite.hpp deleted file mode 100644 index c7af2ee..0000000 --- a/test/include/io_operators_suite.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NEWTYPE_TEST_IO_OPERATORS_SUITE_HPP -#define NEWTYPE_TEST_IO_OPERATORS_SUITE_HPP - -#include - -#include -#include - -auto io_operators_suite() -> std::pair; - -#endif \ No newline at end of file diff --git a/test/include/iterable_suite.hpp b/test/include/iterable_suite.hpp deleted file mode 100644 index c2bbc6e..0000000 --- a/test/include/iterable_suite.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NEWTYPE_TEST_ITERABLE_SUITE_HPP -#define NEWTYPE_TEST_ITERABLE_SUITE_HPP - -#include - -#include -#include - -auto iterable_suite() -> std::pair; - -#endif \ No newline at end of file diff --git a/test/include/kawaii.hpp b/test/include/kawaii.hpp deleted file mode 100644 index 9084b56..0000000 --- a/test/include/kawaii.hpp +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef NEWTYPE_TEST_KAWAII_HPP -#define NEWTYPE_TEST_KAWAII_HPP - -#include - -#include -#include -#include -#include -#include -#include -#include - -namespace nt::test -{ - - namespace impl - { - auto constexpr prepositions = std::array{"a", "an", "and", "as", "at", "by", "for", "in", "of", "on", "or", "the", "to"}; - auto constexpr keywords = std::array{"noexcept"}; - auto constexpr type_names = std::array{"new_type", "derivation_clause", "unordered_map"}; - - auto inline replace_template_argument_syntax(std::string const & name) -> std::string - { - using namespace std::string_literals; - - auto template_argument_start = find(cbegin(name), cend(name), '<'); - - if (template_argument_start == cend(name)) - { - return name; - } - - auto replaced{""s}; - - copy(cbegin(name), template_argument_start, back_inserter(replaced)); - - replaced += " [ T = "; - - auto template_argument_end = find(template_argument_start, cend(name), '>'); - - copy(template_argument_start + 1, template_argument_end, back_inserter(replaced)); - - return replaced + " ]"; - } - - auto inline is_prefix(std::string const & suspect, std::string const & of) -> bool - { - if (suspect.size() > of.size()) - { - return false; - } - return equal(cbegin(suspect), cend(suspect), cbegin(of)); - } - - auto inline is_type_name_prefix(std::string const & suspect) -> bool - { - return std::any_of(cbegin(type_names), cend(type_names), [&](auto type_name) { return is_prefix(suspect, type_name); }); - } - - auto inline wordify(std::string const & name) - { - using namespace std::string_literals; - using namespace impl; - - auto stream = std::stringstream{name}; - auto output{""s}; - - while (stream) - { - auto current_char = static_cast(stream.get()); - - if (current_char == '_') - { - if (stream.peek() != '_') - { - output += ' '; - } - else - { - output += current_char; - stream.ignore(); - } - } - else if (current_char != EOF) - { - output += current_char; - } - } - - return output; - } - - auto inline titelize(std::string const & name) -> std::string - { - using namespace std::string_literals; - - auto stream = std::istringstream{name}; - auto buffer{""s}; - auto word{""s}; - auto first{false}; - - while (stream >> word && word != "[") - { - auto is_preposition = std::find(cbegin(prepositions), cend(prepositions), word) != cend(prepositions); - auto is_keyword = std::find(cbegin(keywords), cend(keywords), word) != cend(keywords); - auto is_type_name = std::find(cbegin(type_names), cend(type_names), word) != cend(type_names); - if ((!(is_preposition || is_keyword) || buffer.empty()) && !is_type_name) - { - word.front() = std::toupper(word.front()); - } - buffer += (first ? "" : " ") + word; - first = false; - } - - auto rest{""s}; - - if (stream) - { - buffer += " " + word; - std::getline(stream, rest); - } - - return buffer + rest; - } - - } // namespace impl - - auto inline go_full_kawaii(std::string kowai) -> std::string - { - using namespace impl; - - auto template_free = replace_template_argument_syntax(kowai); - auto wordified = wordify(template_free); - - return titelize(wordified); - } - -} // namespace nt::test - -#define KAWAII(name) cute::test((&name), nt::test::go_full_kawaii(#name)) - -#endif \ No newline at end of file diff --git a/test/include/new_type_constructor_suite.hpp b/test/include/new_type_constructor_suite.hpp deleted file mode 100644 index 38c3cba..0000000 --- a/test/include/new_type_constructor_suite.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NEWTYPE_TEST_NEW_TYPE_SUITE_HPP -#define NEWTYPE_TEST_NEW_TYPE_SUITE_HPP - -#include - -#include -#include - -auto new_type_constructor_suite() -> std::pair; - -#endif \ No newline at end of file diff --git a/test/include/relational_operators_suite.hpp b/test/include/relational_operators_suite.hpp deleted file mode 100644 index 259834b..0000000 --- a/test/include/relational_operators_suite.hpp +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NEWTYPE_TEST_RELATIONAL_OPERATORS_SUITE_HPP -#define NEWTYPE_TEST_RELATIONAL_OPERATORS_SUITE_HPP - -#include - -#include -#include - -auto relational_operators_suite() -> std::pair; - -#endif \ No newline at end of file diff --git a/test/src/arithmetic_suite.cpp b/test/src/arithmetic_suite.cpp deleted file mode 100644 index 0d8cfa8..0000000 --- a/test/src/arithmetic_suite.cpp +++ /dev/null @@ -1,330 +0,0 @@ -#include "arithmetic_suite.hpp" - -#include "kawaii.hpp" -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" -#include "newtype/impl/type_traits_extensions.hpp" -#include "newtype/newtype.hpp" - -#include - -#include - -namespace -{ - - struct addable_type - { - auto constexpr operator+(addable_type const &) const -> addable_type - { - return {}; - }; - }; - - struct subtractable_type - { - auto constexpr operator-(subtractable_type const &) const -> subtractable_type - { - return {}; - }; - }; - - struct multipliable_type - { - auto constexpr operator*(multipliable_type const &)const -> multipliable_type - { - return {}; - }; - }; - - struct dividable_type - { - auto constexpr operator/(dividable_type const &) const -> dividable_type - { - return {}; - }; - }; - -} // namespace - -inline namespace addition_tests -{ - - auto a_new__type_not_deriving_arithmetic_is_not_addable_with_instances_of_itself() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::is_addable_v)); - } - - auto a_new__type_deriving_arithmetic_is_addable_with_instances_of_itself() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::is_addable_v); - } - - template - auto a_new__type_deriving_arithmetic_is_addable_with_instances_of_itself_if_the_base_type_is_addable() -> void - { - static_assert(nt::impl::is_addable_v, "Sanity Check"); - using type_alias = nt::new_type; - ASSERT_EQUAL(nt::impl::is_addable_v, nt::impl::is_addable_v); - } - - auto addition_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_same_v() + std::declval())>)); - } - - auto addition_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type() -> void - { - using type_alias = nt::new_type; - auto lhs = type_alias{24}; - auto rhs = type_alias{18}; - ASSERT_EQUAL(24 + 18, (lhs + rhs).decay()); - } - -} // namespace addition_tests - -inline namespace subtraction_tests -{ - - auto a_new__type_not_deriving_arithmetic_is_not_subtractable_with_instances_of_itself() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::is_subtractable_v)); - } - - auto a_new__type_deriving_arithmetic_is_subtractable_with_instances_of_itself() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::is_subtractable_v); - } - - template - auto a_new__type_deriving_arithmetic_is_subtractable_with_instances_of_itself_if_the_base_type_is_subtractable() -> void - { - static_assert(nt::impl::is_subtractable_v, "Sanity Check"); - using type_alias = nt::new_type; - ASSERT_EQUAL(nt::impl::is_subtractable_v, nt::impl::is_subtractable_v); - } - - auto subtraction_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_same_v() - std::declval())>)); - } - - auto subtraction_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type() -> void - { - using type_alias = nt::new_type; - auto lhs = type_alias{24}; - auto rhs = type_alias{18}; - ASSERT_EQUAL(24 - 18, (lhs - rhs).decay()); - } - -} // namespace subtraction_tests - -inline namespace multiplication_tests -{ - - auto a_new__type_not_deriving_arithmetic_is_not_multipliable_with_instances_of_itself() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::is_multipliable_v)); - } - - auto a_new__type_deriving_arithmetic_is_multipliable_with_instances_of_itself() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::is_multipliable_v); - } - - template - auto a_new__type_deriving_arithmetic_is_multipliable_with_instances_of_itself_if_the_base_type_is_multipliable() -> void - { - static_assert(nt::impl::is_multipliable_v, "Sanity Check"); - using type_alias = nt::new_type; - ASSERT_EQUAL(nt::impl::is_multipliable_v, nt::impl::is_multipliable_v); - } - - auto multiplication_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_same_v() * std::declval())>)); - } - - auto multiplication_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type() -> void - { - using type_alias = nt::new_type; - auto lhs = type_alias{24}; - auto rhs = type_alias{18}; - ASSERT_EQUAL(24 * 18, (lhs * rhs).decay()); - } - -} // namespace multiplication_tests - -inline namespace division_tests -{ - - auto a_new__type_not_deriving_arithmetic_is_not_dividable_with_instances_of_itself() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::is_dividable_v)); - } - - auto a_new__type_deriving_arithmetic_is_dividable_with_instances_of_itself() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::is_dividable_v); - } - - template - auto a_new__type_deriving_arithmetic_is_dividable_with_instances_of_itself_if_the_base_type_is_dividable() -> void - { - static_assert(nt::impl::is_dividable_v, "Sanity Check"); - using type_alias = nt::new_type; - ASSERT_EQUAL(nt::impl::is_dividable_v, nt::impl::is_dividable_v); - } - - auto division_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_same_v() / std::declval())>)); - } - - auto division_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type() -> void - { - using type_alias = nt::new_type; - auto lhs = type_alias{24}; - auto rhs = type_alias{2}; - ASSERT_EQUAL(24 / 2, (lhs / rhs).decay()); - } - -} // namespace division_tests - -inline namespace compound_arithmetic -{ - - auto addition_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_same_v() += std::declval())>)); - } - - auto addition_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type() - -> void - { - using type_alias = nt::new_type; - auto elhs = 42; - auto erhs = 18; - auto lhs = type_alias{elhs}; - auto rhs = type_alias{erhs}; - ASSERT_EQUAL(elhs += erhs, (lhs += rhs).decay()); - } - - auto subtraction_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_same_v() -= std::declval())>)); - } - - auto subtraction_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type() - -> void - { - using type_alias = nt::new_type; - auto elhs = 42; - auto erhs = 18; - auto lhs = type_alias{elhs}; - auto rhs = type_alias{erhs}; - ASSERT_EQUAL(elhs -= erhs, (lhs -= rhs).decay()); - } - - auto multiplication_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_same_v() *= std::declval())>)); - } - - auto multiplication_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type() - -> void - { - using type_alias = nt::new_type; - auto elhs = 42; - auto erhs = 18; - auto lhs = type_alias{elhs}; - auto rhs = type_alias{erhs}; - ASSERT_EQUAL(elhs *= erhs, (lhs *= rhs).decay()); - } - - auto division_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_same_v() /= std::declval())>)); - } - - auto division_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type() - -> void - { - using type_alias = nt::new_type; - auto elhs = 42; - auto erhs = 18; - auto lhs = type_alias{elhs}; - auto rhs = type_alias{erhs}; - ASSERT_EQUAL(elhs /= erhs, (lhs /= rhs).decay()); - } - -} // namespace compound_arithmetic - -auto arithmetic_suite() -> std::pair -{ - return { - { - // clang-format off - - /// Addition Tests - KAWAII(a_new__type_not_deriving_arithmetic_is_not_addable_with_instances_of_itself), - KAWAII(a_new__type_deriving_arithmetic_is_addable_with_instances_of_itself), - KAWAII(a_new__type_deriving_arithmetic_is_addable_with_instances_of_itself_if_the_base_type_is_addable), - KAWAII(a_new__type_deriving_arithmetic_is_addable_with_instances_of_itself_if_the_base_type_is_addable), - KAWAII(addition_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type), - KAWAII(addition_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type), - - /// Subtraction Tests - KAWAII(a_new__type_not_deriving_arithmetic_is_not_subtractable_with_instances_of_itself), - KAWAII(a_new__type_deriving_arithmetic_is_subtractable_with_instances_of_itself), - KAWAII(a_new__type_deriving_arithmetic_is_subtractable_with_instances_of_itself_if_the_base_type_is_subtractable), - KAWAII(a_new__type_deriving_arithmetic_is_subtractable_with_instances_of_itself_if_the_base_type_is_subtractable), - KAWAII(subtraction_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type), - KAWAII(subtraction_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type), - - /// Multiplication Tests - KAWAII(a_new__type_not_deriving_arithmetic_is_not_multipliable_with_instances_of_itself), - KAWAII(a_new__type_deriving_arithmetic_is_multipliable_with_instances_of_itself), - KAWAII(a_new__type_deriving_arithmetic_is_multipliable_with_instances_of_itself_if_the_base_type_is_multipliable), - KAWAII(a_new__type_deriving_arithmetic_is_multipliable_with_instances_of_itself_if_the_base_type_is_multipliable), - KAWAII(multiplication_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type), - KAWAII(multiplication_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type), - - /// Division Tests - KAWAII(a_new__type_not_deriving_arithmetic_is_not_dividable_with_instances_of_itself), - KAWAII(a_new__type_deriving_arithmetic_is_dividable_with_instances_of_itself), - KAWAII(a_new__type_deriving_arithmetic_is_dividable_with_instances_of_itself_if_the_base_type_is_dividable), - KAWAII(a_new__type_deriving_arithmetic_is_dividable_with_instances_of_itself_if_the_base_type_is_dividable), - KAWAII(division_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type), - KAWAII(division_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type), - - /// Compound Arithmetic Tests - KAWAII(addition_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type), - KAWAII(addition_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type), - KAWAII(subtraction_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type), - KAWAII(subtraction_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type), - KAWAII(multiplication_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type), - KAWAII(multiplication_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type), - KAWAII(division_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_an_instance_of_the_same_new__type), - KAWAII(division_assignment_of_two_instances_of_a_new__type_deriving_arithmetic_produces_the_correct_value_with_respect_to_the_base_type), - - // clang-format on - }, - "Arithmetic Operators Tests"}; -} \ No newline at end of file diff --git a/test/src/conversion_suite.cpp b/test/src/conversion_suite.cpp deleted file mode 100644 index cbe2463..0000000 --- a/test/src/conversion_suite.cpp +++ /dev/null @@ -1,201 +0,0 @@ -#include "conversion_suite.hpp" - -#include "kawaii.hpp" -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" -#include "newtype/newtype.hpp" - -#include - -#include -#include -#include -#include -#include -#include -#include - -inline namespace traits_extensions -{ - - template - struct is_implicitly_convertible : std::false_type - { - }; - - template - struct is_implicitly_convertible() = std::declval())>> : std::true_type - { - }; - - template - auto constexpr is_implicitly_convertible_v = is_implicitly_convertible::value; - -} // namespace traits_extensions - -inline namespace ddt_support -{ - - template - struct datum - { - T value; - cute::test_failure failure; - }; - - template - auto generate_test_set(std::size_t size) -> std::vector> - { - auto device = std::random_device{}; - auto generator = std::mt19937{device()}; - auto distribution = [&] { - auto min = std::numeric_limits::min(); - auto max = std::numeric_limits::max(); - if constexpr (std::is_floating_point_v) - { - return std::uniform_real_distribution(min, max); - } - else - { - return std::uniform_int_distribution(min, max); - } - }(); - - auto data = std::vector>{}; - generate_n(std::back_inserter(data), size, [&] { - auto point = distribution(generator); - return datum{point, DDT()}; - }); - return data; - } - -} // namespace ddt_support - -inline namespace implicit_conversion_tests -{ - - template - auto a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type() -> void - { - using type_alias = nt::new_type; - ASSERT(!(is_implicitly_convertible_v)); - } - - template - auto a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type() -> void - { - using type_alias = nt::new_type; - ASSERT((is_implicitly_convertible_v)); - } - -} // namespace implicit_conversion_tests - -inline namespace decay_tests -{ - - template - auto decay_on_a_new__type_has_a_return_type_equal_to_the_base_type() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_same_v().decay())>)); - } - - template - auto decay_on_a_new__type_returns_the_underlying_value() -> void - { - using type_alias = nt::new_type; - auto data = generate_test_set(2 << 16); - for_each(begin(data), end(data), [](auto & test) { ASSERT_EQUAL_DDT(test.value, type_alias{test.value}.decay(), test.failure); }); - } - -} // namespace decay_tests - -inline namespace decay_noexcept_tests -{ - - auto decay_on_a_new__type_is_noexcept_if_the_base_type_can_be_copied_without_throwing() -> void - { - static_assert(std::is_nothrow_copy_constructible_v, "Sanity check"); - using type_alias = nt::new_type; - ASSERT(noexcept(type_alias{}.decay())); - } - - auto decay_on_a_new__type_is_not_noexcept_if_the_base_type_can_be_not_copied_without_throwing() -> void - { - struct strange_type - { - strange_type() = default; - strange_type(strange_type const &) noexcept(false) - { - } - }; - - static_assert(!std::is_nothrow_copy_constructible_v, "Sanity check"); - using type_alias = nt::new_type; - ASSERT(!noexcept(type_alias{}.decay())); - } - -} // namespace decay_noexcept_tests - -inline namespace conversion_operator_noexcept_tests -{ - - auto new__type_conversion_operator_is_noexcept_if_the_base_type_can_be_copied_without_throwing() -> void - { - static_assert(std::is_nothrow_copy_constructible_v, "Sanity check"); - using type_alias = nt::new_type; - ASSERT(noexcept(static_cast(type_alias{}))); - } - - auto new__type_conversion_operator_is_not_noexcept_if_the_base_type_can_not_be_copied_without_throwing() -> void - { - struct strange_type - { - strange_type() = default; - strange_type(strange_type const &) noexcept(false) - { - } - }; - - static_assert(!std::is_nothrow_copy_constructible_v, "Sanity check"); - using type_alias = nt::new_type; - ASSERT(!noexcept(static_cast(type_alias{}))); - } - -} // namespace conversion_operator_noexcept_tests - -auto conversion_suite() -> std::pair -{ - return {{ - /// Implicit Conversion Tests - KAWAII(a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type), - KAWAII(a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type), - KAWAII(a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type), - KAWAII(a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type), - KAWAII(a_new__type_without_deriving_implicit_conversion_is_not_implicitly_convertible_to_the_base_type), - KAWAII(a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type), - KAWAII(a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type), - KAWAII(a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type), - KAWAII(a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type), - KAWAII(a_new__type_with_deriving_implicit_conversion_is_implicitly_convertible_to_the_base_type), - - /// Decay Tests - KAWAII(decay_on_a_new__type_has_a_return_type_equal_to_the_base_type), - KAWAII(decay_on_a_new__type_has_a_return_type_equal_to_the_base_type), - KAWAII(decay_on_a_new__type_has_a_return_type_equal_to_the_base_type), - KAWAII(decay_on_a_new__type_has_a_return_type_equal_to_the_base_type), - KAWAII(decay_on_a_new__type_has_a_return_type_equal_to_the_base_type), - KAWAII(decay_on_a_new__type_returns_the_underlying_value), - KAWAII(decay_on_a_new__type_returns_the_underlying_value), - KAWAII(decay_on_a_new__type_returns_the_underlying_value), - - /// Decay noexcept Tests - KAWAII(decay_on_a_new__type_is_noexcept_if_the_base_type_can_be_copied_without_throwing), - KAWAII(decay_on_a_new__type_is_not_noexcept_if_the_base_type_can_be_not_copied_without_throwing), - - /// Conversion Operator noexcept Tests - KAWAII(new__type_conversion_operator_is_noexcept_if_the_base_type_can_be_copied_without_throwing), - KAWAII(new__type_conversion_operator_is_not_noexcept_if_the_base_type_can_not_be_copied_without_throwing), - }, - "Conversion Tests"}; -} \ No newline at end of file diff --git a/test/src/derivation_clause_suite.cpp b/test/src/derivation_clause_suite.cpp deleted file mode 100644 index 86a34ab..0000000 --- a/test/src/derivation_clause_suite.cpp +++ /dev/null @@ -1,312 +0,0 @@ -#include "derivation_clause_suite.hpp" - -#include "kawaii.hpp" -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" - -#include - -#include - -inline namespace subset_tests -{ - - auto an_empty_derivation_clause_does_not_contain_any_derivable() -> void - { - auto derivation_clause = nt::deriving(); - ASSERT(!derivation_clause(nt::Show)); - } - - auto a_derivation_clause_containing_only_show_does_not_contain_eqbase() -> void - { - auto derivation_clause = deriving(nt::Show); - ASSERT(!derivation_clause(nt::EqBase)); - } - - auto a_derivation_clause_containing_only_show_does_contain_show() -> void - { - auto derivation_clause = deriving(nt::Show); - ASSERT(derivation_clause(nt::Show)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_contain_show() -> void - { - auto derivation_clause = deriving(nt::Show, nt::EqBase); - ASSERT(derivation_clause(nt::Show)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_contain_both_show_and_eqbase() -> void - { - auto derivation_clause = deriving(nt::Show, nt::EqBase); - ASSERT(derivation_clause(nt::Show, nt::EqBase)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_arithmetic() -> void - { - auto derivation_clause = deriving(nt::Show, nt::EqBase); - ASSERT(!derivation_clause(nt::Arithmetic)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_both_show_and_arithmetic() -> void - { - auto derivation_clause = deriving(nt::Show, nt::EqBase); - ASSERT(!derivation_clause(nt::Show, nt::Arithmetic)); - } - -} // namespace subset_tests - -inline namespace less_than_tests -{ - - auto a_derivation_clause_containing_only_show_compares_less_than_one_containing_show_and_eqbase() -> void - { - auto only_show = deriving(nt::Show); - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(only_show < show_and_eqbase); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(!(show_and_eqbase < also_show_and_eqbase)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_eqbase_and_show() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto eqbase_and_show = deriving(nt::EqBase, nt::Show); - - ASSERT(!(show_and_eqbase < eqbase_and_show)); - } - - auto a_derivation_clause_containing_only_show_does_not_compare_less_than_one_containing_only_eqbase() -> void - { - auto show = deriving(nt::Show); - auto eqbase = deriving(nt::EqBase); - - ASSERT(!(show < eqbase)); - } - -} // namespace less_than_tests - -inline namespace greater_than_tests -{ - - auto a_derivation_clause_containing_only_show_and_eqbase_compares_greater_than_one_containing_only_show() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto show = deriving(nt::Show); - - ASSERT(show_and_eqbase > show); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(!(show_and_eqbase > also_show_and_eqbase)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_eqbase_and_show() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto eqbase_and_show = deriving(nt::EqBase, nt::Show); - - ASSERT(!(show_and_eqbase > eqbase_and_show)); - } - - auto a_derivation_clause_containing_only_show_does_not_compare_greater_than_one_containing_only_eqbase() -> void - { - auto show = deriving(nt::Show); - auto eqbase = deriving(nt::EqBase); - - ASSERT(!(show > eqbase)); - } - -} // namespace greater_than_tests - -inline namespace eqbaseuals_tests -{ - - auto a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT_EQUAL(show_and_eqbase, also_show_and_eqbase); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_eqbase_and_show() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto eqbase_and_show = deriving(nt::EqBase, nt::Show); - - ASSERT_EQUAL(show_and_eqbase, eqbase_and_show); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto arithmetic = deriving(nt::Arithmetic); - - ASSERT(!(show_and_eqbase == arithmetic)); - } - - auto a_derivation_clause_containing_only_show_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void - { - auto show = deriving(nt::Show); - auto arithmetic = deriving(nt::Arithmetic); - - ASSERT(!(show == arithmetic)); - } - -} // namespace eqbaseuals_tests - -inline namespace not_eqbaseuals_tests -{ - - auto a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(!(show_and_eqbase != also_show_and_eqbase)); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_eqbase_and_show() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto eqbase_and_show = deriving(nt::EqBase, nt::Show); - - ASSERT(!(show_and_eqbase != eqbase_and_show)); - } - - auto a_derivation_clause_containing_only_eqbase_and_show_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void - { - auto eqbase_and_show = deriving(nt::EqBase, nt::Show); - auto arithmetic = deriving(nt::Arithmetic); - - ASSERT(eqbase_and_show != arithmetic); - } - - auto a_derivation_clause_containing_only_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic() -> void - { - auto eqbase = deriving(nt::EqBase); - auto arithmetic = deriving(nt::Arithmetic); - - ASSERT(eqbase != arithmetic); - } - -} // namespace not_eqbaseuals_tests - -inline namespace less_than_or_eqbaseual_tests -{ - - auto a_derivation_clause_containing_only_show_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase() -> void - { - auto only_show = deriving(nt::Show); - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(only_show <= show_and_eqbase); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(show_and_eqbase <= also_show_and_eqbase); - } - - auto a_derivation_clause_containing_only_arithmetic_is_neither_less_than_nor_eqbaseual_to_on_containing_only_show_and_eqbase() -> void - { - auto arithmetic = deriving(nt::Arithmetic); - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(!(arithmetic <= show_and_eqbase)); - } - -} // namespace less_than_or_eqbaseual_tests - -inline namespace greater_than_or_eqbaseual_tests -{ - - auto a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show() -> void - { - auto only_show = deriving(nt::Show); - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(show_and_eqbase >= only_show); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show_and_eqbase() -> void - { - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - auto also_show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(show_and_eqbase >= also_show_and_eqbase); - } - - auto a_derivation_clause_containing_only_show_and_eqbase_is_neither_greater_than_nor_eqbaseual_to_on_containing_only_arithmetic() -> void - { - auto arithmetic = deriving(nt::Arithmetic); - auto show_and_eqbase = deriving(nt::Show, nt::EqBase); - - ASSERT(!(show_and_eqbase >= arithmetic)); - } - -} // namespace greater_than_or_eqbaseual_tests - -auto derivation_clause_suite() -> std::pair -{ - return { - { - /// Subset tests - KAWAII(an_empty_derivation_clause_does_not_contain_any_derivable), - KAWAII(a_derivation_clause_containing_only_show_does_not_contain_eqbase), - KAWAII(a_derivation_clause_containing_only_show_does_contain_show), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_contain_show), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_contain_both_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_arithmetic), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_contain_both_show_and_arithmetic), - - /// Less-than tests - KAWAII(a_derivation_clause_containing_only_show_compares_less_than_one_containing_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_less_than_one_containing_eqbase_and_show), - KAWAII(a_derivation_clause_containing_only_show_does_not_compare_less_than_one_containing_only_eqbase), - - /// Greater-than tests - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_compares_greater_than_one_containing_only_show), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_does_not_compare_greater_than_one_containing_only_eqbase_and_show), - KAWAII(a_derivation_clause_containing_only_show_does_not_compare_greater_than_one_containing_only_eqbase), - - /// Equals tests - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_eqbaseual_to_one_containing_only_eqbase_and_show), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic), - KAWAII(a_derivation_clause_containing_only_show_is_not_eqbaseual_to_one_containing_only_arithmetic), - - /// Not-Equals tests - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_not_not_eqbaseual_to_one_containing_only_eqbase_and_show), - KAWAII(a_derivation_clause_containing_only_eqbase_and_show_is_not_eqbaseual_to_one_containing_only_arithmetic), - KAWAII(a_derivation_clause_containing_only_eqbase_is_not_eqbaseual_to_one_containing_only_arithmetic), - - /// Less-than or Equals tests - KAWAII(a_derivation_clause_containing_only_show_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_less_than_or_eqbaseual_to_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_arithmetic_is_neither_less_than_nor_eqbaseual_to_on_containing_only_show_and_eqbase), - - /// Greater-than or Equals tests - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_greater_than_or_eqbaseual_to_one_containing_only_show_and_eqbase), - KAWAII(a_derivation_clause_containing_only_show_and_eqbase_is_neither_greater_than_nor_eqbaseual_to_on_containing_only_arithmetic), - }, - "Derivation Clause Tests"}; -} \ No newline at end of file diff --git a/test/src/driver.cpp b/test/src/driver.cpp deleted file mode 100644 index a0e8904..0000000 --- a/test/src/driver.cpp +++ /dev/null @@ -1,101 +0,0 @@ -#include "arithmetic_suite.hpp" -#include "conversion_suite.hpp" -#include "derivation_clause_suite.hpp" -#include "equality_comparison_suite.hpp" -#include "hash_suite.hpp" -#include "io_operators_suite.hpp" -#include "iterable_suite.hpp" -#include "new_type_constructor_suite.hpp" -#include "relational_operators_suite.hpp" - -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -using suite_list = std::vector>; - -auto get_test_selectors(suite_list const & suites) -> std::vector -{ - auto selectors = std::vector{}; - - for_each(cbegin(suites), cend(suites), [&](auto descriptor) { - auto const & [suite, name] = descriptor; - transform(cbegin(suite), cend(suite), std::back_inserter(selectors), [&, name = name](auto test) { return name + "#" + test.name(); }); - }); - - return selectors; -} - -auto do_run_tests(suite_list const & suites, int argc, char ** argv) -> bool -{ - auto listener = cute::tap_listener<>{}; - auto runner = cute::makeRunner(listener, argc, argv); - - return accumulate(cbegin(suites), cend(suites), true, [&](auto accumulator, auto const & descriptor) { - auto const & [suite, name] = descriptor; - return accumulator && runner(suite, name.c_str()); - }); -} - -int main(int argc, char ** argv) -{ - auto suites = std::vector{ - derivation_clause_suite(), - new_type_constructor_suite(), - conversion_suite(), - equality_comparison_suite(), - relational_operators_suite(), - io_operators_suite(), - arithmetic_suite(), - hash_suite(), - iterable_suite(), - }; - - auto selectors = get_test_selectors(suites); - - auto list_tests{false}; - auto list_suites{false}; - auto show_help{false}; - auto selected_tests = std::vector{}; - - auto cli = lyra::cli_parser() | // - lyra::opt(list_tests)["-t"]["--tests"]("List all registered tests") | // - lyra::opt(list_suites)["-s"]["--suites"]("List all registered suites") | // - lyra::arg(selected_tests, "test selector")("A pattern to select a specific test") | // - lyra::help(show_help); - auto result = cli.parse({argc, argv}); - - if (list_tests) - { - copy(cbegin(selectors), cend(selectors), std::ostream_iterator{std::cout, "\n"}); - } - if (list_suites) - { - transform(cbegin(suites), cend(suites), std::ostream_iterator{std::cout, "\n"}, [](auto descriptor) { - auto const & [_, name] = descriptor; - return name; - }); - } - else if (!result || show_help) - { - std::cout << cli; - } - else - { - return do_run_tests(suites, argc, argv) ? EXIT_SUCCESS : EXIT_FAILURE; - } -} \ No newline at end of file diff --git a/test/src/equality_comparison_suite.cpp b/test/src/equality_comparison_suite.cpp deleted file mode 100644 index 4e484f4..0000000 --- a/test/src/equality_comparison_suite.cpp +++ /dev/null @@ -1,188 +0,0 @@ -#include "equality_comparison_suite.hpp" - -#include "kawaii.hpp" -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" -#include "newtype/newtype.hpp" - -#include - -#include -#include -#include - -inline namespace basic_equality_comparsion_tests -{ - - auto two_instances_of_the_same_new__type_with_the_same_value_compare_equal() -> void - { - using type_alias = nt::new_type; - - auto constexpr lhs = type_alias{42}; - auto constexpr rhs = type_alias{42}; - - ASSERT_EQUAL(lhs, rhs); - } - - auto two_instances_of_the_same_new__type_with_the_same_value_do_not_compare_not_equal() -> void - { - using type_alias = nt::new_type; - - auto constexpr lhs = type_alias{42}; - auto constexpr rhs = type_alias{42}; - - ASSERT(!(lhs != rhs)); - } - - auto two_instances_of_the_same_new__type_with_differing_values_do_compare_not_equal() -> void - { - using type_alias = nt::new_type; - - auto constexpr lhs = type_alias{42}; - auto constexpr rhs = type_alias{43}; - - ASSERT_NOT_EQUAL_TO(lhs, rhs); - } - - auto two_instances_of_the_same_new__type_with_differing_values_do_not_compare_equal() -> void - { - using type_alias = nt::new_type; - - auto constexpr lhs = type_alias{42}; - auto constexpr rhs = type_alias{43}; - - ASSERT(!(lhs == rhs)); - } - -} // namespace basic_equality_comparsion_tests - -inline namespace equality_comparsion_noexcept_tests -{ - - auto equality_comparison_on_a_new__type_is_noexcept_if_the_base_type_is_noexcept_comparable() -> void - { - using type_alias = nt::new_type; - static_assert(noexcept(std::declval() == std::declval()), "Sanity Check"); - ASSERT(noexcept(std::declval() == std::declval())); - } - - auto equality_comparison_on_a_new__type_is_not_noexcept_if_the_base_type_is_not_noexcept_comparable() -> void - { - struct strange_type - { - auto constexpr operator==(strange_type const &) const noexcept(false) -> bool - { - return false; - } - }; - - using type_alias = nt::new_type; - static_assert(!noexcept(std::declval() == std::declval()), "Sanity Check"); - ASSERT(!noexcept(std::declval() == std::declval())); - } - - auto inequality_comparison_on_a_new__type_is_noexcept_if_the_base_type_is_noexcept_comparable() -> void - { - using type_alias = nt::new_type; - static_assert(noexcept(std::declval() != std::declval()), "Sanity Check"); - ASSERT(noexcept(std::declval() != std::declval())); - } - - auto inequality_comparison_on_a_new__type_is_not_noexcept_if_the_base_type_is_not_noexcept_comparable() -> void - { - struct strange_type - { - auto constexpr operator!=(strange_type const &) const noexcept(false) -> bool - { - return false; - } - }; - - using type_alias = nt::new_type; - static_assert(!noexcept(std::declval() != std::declval()), "Sanity Check"); - ASSERT(!noexcept(std::declval() != std::declval())); - } - -} // namespace equality_comparsion_noexcept_tests - -inline namespace equality_comparison_return_type_tests -{ - - auto equality_comparsion_of_two_new__type_instances_returns_bool() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_same_v() == std::declval())>)); - } - - auto inequality_comparsion_of_two_new__type_instances_returns_bool() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_same_v() != std::declval())>)); - } - -} // namespace equality_comparison_return_type_tests - -inline namespace base_type_equality_comparison_tests -{ - - auto an_instance_of_a_new__type_compares_equal_to_an_instance_of_its_base_type_with_the_same_value() -> void - { - using type_alias = nt::new_type; - auto lhs = type_alias{42}; - auto rhs = 42; - ASSERT_EQUAL(lhs, rhs); - } - - auto an_instance_of_the_base_type_of_a_new__type_compares_equal_to_an_instance_of_the_new__type_with_the_same_value() -> void - { - using type_alias = nt::new_type; - auto lhs = 42; - auto rhs = type_alias{42}; - ASSERT_EQUAL(lhs, rhs); - } - - auto an_instance_of_a_new__type_compares_not_equal_to_an_instance_of_its_base_type_with_a_differing_value() -> void - { - using type_alias = nt::new_type; - auto lhs = type_alias{42}; - auto rhs = 43; - ASSERT(lhs != rhs); - } - - auto an_instance_of_the_base_type_of_a_new__type_compares_not_equal_to_an_instance_of_the_new__type_with_a_differing_value() -> void - { - using type_alias = nt::new_type; - auto lhs = 43; - auto rhs = type_alias{42}; - ASSERT(lhs != rhs); - } - -} // namespace base_type_equality_comparison_tests - -auto equality_comparison_suite() -> std::pair -{ - return {{ - // Basic Equality Comparison Tests - KAWAII(two_instances_of_the_same_new__type_with_the_same_value_compare_equal), - KAWAII(two_instances_of_the_same_new__type_with_the_same_value_do_not_compare_not_equal), - KAWAII(two_instances_of_the_same_new__type_with_differing_values_do_compare_not_equal), - KAWAII(two_instances_of_the_same_new__type_with_differing_values_do_not_compare_equal), - - // Equality Comparison noexcept Tests - KAWAII(equality_comparison_on_a_new__type_is_noexcept_if_the_base_type_is_noexcept_comparable), - KAWAII(equality_comparison_on_a_new__type_is_not_noexcept_if_the_base_type_is_not_noexcept_comparable), - KAWAII(inequality_comparison_on_a_new__type_is_noexcept_if_the_base_type_is_noexcept_comparable), - KAWAII(inequality_comparison_on_a_new__type_is_not_noexcept_if_the_base_type_is_not_noexcept_comparable), - - // Equality Comparison Return Type Tests - KAWAII(equality_comparsion_of_two_new__type_instances_returns_bool), - KAWAII(inequality_comparsion_of_two_new__type_instances_returns_bool), - - // Base-type Equality Comparison Tests - KAWAII(an_instance_of_a_new__type_compares_equal_to_an_instance_of_its_base_type_with_the_same_value), - KAWAII(an_instance_of_the_base_type_of_a_new__type_compares_equal_to_an_instance_of_the_new__type_with_the_same_value), - KAWAII(an_instance_of_a_new__type_compares_not_equal_to_an_instance_of_its_base_type_with_a_differing_value), - KAWAII(an_instance_of_the_base_type_of_a_new__type_compares_not_equal_to_an_instance_of_the_new__type_with_a_differing_value), - }, - "Equality Comparison Tests"}; -} \ No newline at end of file diff --git a/test/src/hash_suite.cpp b/test/src/hash_suite.cpp deleted file mode 100644 index b482414..0000000 --- a/test/src/hash_suite.cpp +++ /dev/null @@ -1,69 +0,0 @@ -#include "hash_suite.hpp" - -#include "kawaii.hpp" -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" -#include "newtype/impl/type_traits_extensions.hpp" -#include "newtype/newtype.hpp" - -#include - -#include - -inline namespace hashable_tests -{ - - auto a_new__type_that_does_not_include_hash_in_its_derivation_clause_is_not_hashable() -> void - { - using type_alias = nt::new_type; - ASSERT(!nt::impl::is_hashable_v); - } - - auto a_new__type_that_does_include_hash_in_its_derivation_clause_is_hashable() -> void - { - static_assert(nt::impl::is_hashable_v, "Sanity Check"); - using type_alias = nt::new_type; - ASSERT(nt::impl::is_hashable_v); - } - - auto a_new__type_that_does_include_hash_in_its_derivation_clause_but_whose_base_type_is_not_hashable_is_also_not_hashable() -> void - { - struct not_hashable - { - }; - - static_assert(!nt::impl::is_hashable_v, "Sanity Check"); - using type_alias = nt::new_type; - ASSERT(!nt::impl::is_hashable_v); - } - -} // namespace hashable_tests - -inline namespace usage_tests -{ - - auto a_new__type_that_is_hashable_can_be_used_in_an_unordered__map() -> void - { - static_assert(nt::impl::is_hashable_v, "Sanity Check"); - using type_alias = nt::new_type; - - auto map = std::unordered_map{}; - map[type_alias{42}] = 43; - ASSERT_EQUAL(43, map[type_alias{42}]); - } - -} // namespace usage_tests - -auto hash_suite() -> std::pair -{ - return {{ - // Hashable Tests - KAWAII(a_new__type_that_does_not_include_hash_in_its_derivation_clause_is_not_hashable), - KAWAII(a_new__type_that_does_include_hash_in_its_derivation_clause_is_hashable), - KAWAII(a_new__type_that_does_include_hash_in_its_derivation_clause_but_whose_base_type_is_not_hashable_is_also_not_hashable), - - // Usage Tests - KAWAII(a_new__type_that_is_hashable_can_be_used_in_an_unordered__map), - }, - "std::hash Support Tests"}; -} \ No newline at end of file diff --git a/test/src/io_operators_suite.cpp b/test/src/io_operators_suite.cpp deleted file mode 100644 index 4e146a7..0000000 --- a/test/src/io_operators_suite.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include "io_operators_suite.hpp" - -#include "kawaii.hpp" -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" -#include "newtype/newtype.hpp" - -#include - -#include -#include -#include -#include -#include - -inline namespace traits_extensions -{ - - template - struct has_stream_input : std::false_type - { - }; - - template - struct has_stream_input() >> std::declval())>> : std::true_type - { - }; - - template - auto constexpr has_stream_input_v = has_stream_input::value; - - template - struct has_stream_output : std::false_type - { - }; - - template - struct has_stream_output() << std::declval())>> : std::true_type - { - }; - - template - auto constexpr has_stream_output_v = has_stream_output::value; - -} // namespace traits_extensions - -inline namespace stream_input_operator_tests -{ - - auto a_new__type_has_the_stream_input_operator_if_the_derivation_clause_contains_read() -> void - { - using type_alias = nt::new_type; - ASSERT(has_stream_input_v); - } - - auto a_new__type_does_not_have_the_stream_input_operator_if_the_derivation_clause_does_not_contain_read() -> void - { - using type_alias = nt::new_type; - ASSERT(!has_stream_input_v); - } - - auto a_instance_of_a_new__type_can_be_read_from_an_istream_if_the_base_type_can_be_read_from_an_istream() -> void - { - static_assert(has_stream_input_v, "Sanity Check"); - using type_alias = nt::new_type; - - auto obj = type_alias{}; - auto input = std::istringstream{"42"}; - - input >> obj; - - ASSERT_EQUAL(42, obj.decay()); - } - -} // namespace stream_input_operator_tests - -inline namespace stream_output_operator_tests -{ - - auto a_new__type_has_the_stream_output_operator_if_the_derivation_clause_contains_show() -> void - { - using type_alias = nt::new_type; - ASSERT(has_stream_output_v); - } - - auto a_new__type_does_not_have_the_stream_output_operator_if_the_derivation_clause_does_not_contain_show() -> void - { - using type_alias = nt::new_type; - ASSERT(!has_stream_output_v); - } - - auto a_instance_of_a_new__type_can_be_written_to_an_ostream_if_the_base_type_can_be_written_to_an_ostream() -> void - { - static_assert(has_stream_output_v, "Sanity Check"); - using type_alias = nt::new_type; - - auto obj = type_alias{42}; - auto output = std::ostringstream{}; - - output << obj; - - ASSERT_EQUAL("42", output.str()); - } - -} // namespace stream_output_operator_tests - -auto io_operators_suite() -> std::pair -{ - return {{ - // Stream Input Operator Tests - KAWAII(a_new__type_has_the_stream_input_operator_if_the_derivation_clause_contains_read), - KAWAII(a_new__type_does_not_have_the_stream_input_operator_if_the_derivation_clause_does_not_contain_read), - KAWAII(a_instance_of_a_new__type_can_be_read_from_an_istream_if_the_base_type_can_be_read_from_an_istream), - - // Stream Ouput Operator Tests - KAWAII(a_new__type_has_the_stream_output_operator_if_the_derivation_clause_contains_show), - KAWAII(a_new__type_does_not_have_the_stream_output_operator_if_the_derivation_clause_does_not_contain_show), - KAWAII(a_instance_of_a_new__type_can_be_written_to_an_ostream_if_the_base_type_can_be_written_to_an_ostream), - }, - "I/O Operators Tests"}; -} \ No newline at end of file diff --git a/test/src/iterable_suite.cpp b/test/src/iterable_suite.cpp deleted file mode 100644 index add4696..0000000 --- a/test/src/iterable_suite.cpp +++ /dev/null @@ -1,719 +0,0 @@ -#include "iterable_suite.hpp" - -#include "kawaii.hpp" -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" -#include "newtype/impl/type_traits_extensions.hpp" -#include "newtype/newtype.hpp" - -#include - -#include -#include -#include -#include - -namespace -{ - - struct with_member - { - using iterator = char *; - using const_iterator = char const *; - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = std::reverse_iterator; - - auto begin() -> iterator; - auto begin() const -> const_iterator; - auto cbegin() const -> const_iterator; - auto rbegin() -> reverse_iterator; - auto rbegin() const -> const_reverse_iterator; - auto crbegin() const -> const_reverse_iterator; - - auto end() -> iterator; - auto end() const -> const_iterator; - auto cend() const -> const_iterator; - auto rend() -> reverse_iterator; - auto rend() const -> const_reverse_iterator; - auto crend() const -> const_reverse_iterator; - }; - - struct with_free - { - using iterator = char *; - using const_iterator = char const *; - using reverse_iterator = std::reverse_iterator; - using const_reverse_iterator = std::reverse_iterator; - }; - - auto begin(with_free &) -> with_free::iterator - { - return {}; - } - - auto begin(with_free const &) -> with_free::const_iterator - { - return {}; - } - - auto cbegin(with_free const &) -> with_free::const_iterator - { - return {}; - } - - auto rbegin(with_free &) -> with_free::reverse_iterator - { - return {}; - } - - auto rbegin(with_free const &) -> with_free::const_reverse_iterator - { - return {}; - } - - auto crbegin(with_free const &) -> with_free::const_reverse_iterator - { - return {}; - } - - auto end(with_free &) -> with_free::iterator - { - return {}; - } - - auto end(with_free const &) -> with_free::const_iterator - { - return {}; - } - - auto cend(with_free const &) -> with_free::const_iterator - { - return {}; - } - - auto rend(with_free &) -> with_free::reverse_iterator - { - return {}; - } - - auto rend(with_free const &) -> with_free::const_reverse_iterator - { - return {}; - } - - auto crend(with_free const &) -> with_free::const_reverse_iterator - { - return {}; - } - -} // namespace - -inline namespace combined_enablement_tests -{ - - auto a_new__type_not_deriving_iterable_has_no_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_begin_v)); - } - - auto a_new__type_not_deriving_iterable_has_no_constant_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_begin_v)); - } - - auto a_new__type_not_deriving_iterable_has_no_cbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_cbegin_v)); - } - - auto a_new__type_not_deriving_iterable_has_no_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rbegin_v)); - } - - auto a_new__type_not_deriving_iterable_has_no_constant_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rbegin_v)); - } - - auto a_new__type_not_deriving_iterable_has_no_crbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_crbegin_v)); - } - - auto a_new__type_not_deriving_iterable_has_no_end() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_end_v)); - } - - auto a_new__type_not_deriving_iterable_has_no_constant_end() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_end_v)); - } - - auto a_new__type_not_deriving_iterable_has_no_cend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_cend_v)); - } - - auto a_new__type_not_deriving_iterable_has_no_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rend_v)); - } - - auto a_new__type_not_deriving_iterable_has_no_constant_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rend_v)); - } - - auto a_new__type_not_deriving_iterable_has_no_crend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_crend_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_begin_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_begin_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_cbegin_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rbegin_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rbegin_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_crbegin_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_end() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_end_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_end() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_end_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_cend_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rend_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rend_v)); - } - - auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_crend_v)); - } - -} // namespace combined_enablement_tests - -inline namespace member_enablement_tests -{ - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_begin_v)); - } - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_begin_v)); - } - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_cbegin_v)); - } - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_rbegin_v)); - } - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_rbegin_v)); - } - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_crbegin_v)); - } - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_end() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_end_v)); - } - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_end() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_end_v)); - } - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_cend_v)); - } - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_rend_v)); - } - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_rend_v)); - } - - auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_member_crend_v)); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_begin_v); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_begin_v); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_cbegin_v); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_rbegin_v); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_rbegin_v); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_crbegin_v); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_end() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_end_v); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_end() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_end_v); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cend() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_cend_v); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_rend_v); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_rend_v); - } - - auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crend() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_crend_v); - } - -} // namespace member_enablement_tests - -inline namespace free_enablement_tests -{ - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_begin_v)); - } - - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_begin_v)); - } - - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_cbegin_v)); - } - - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_rbegin_v)); - } - - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_rbegin_v)); - } - - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_crbegin_v)); - } - - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_end() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_end_v)); - } - - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_end() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_end_v)); - } - - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_cend_v)); - } - - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_rend_v)); - } - - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_rend_v)); - } - - auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crend() -> void - { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_free_crend_v)); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_begin_v); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_begin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_begin_v); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_cbegin_v); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_rbegin_v); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_rbegin_v); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crbegin() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_crbegin_v); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_end() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_end_v); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_end() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_end_v); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cend() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_cend_v); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_rend_v); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rend() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_rend_v); - } - - auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crend() -> void - { - using type_alias = nt::new_type; - ASSERT(nt::impl::has_free_crend_v); - } - -} // namespace free_enablement_tests - -inline namespace semantic_tests -{ - - auto a_non_const_object_of_iterable_new__type_can_be_used_in_value_range_for() -> void - { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto object = type_alias{{1, 2, 3}}; - for (auto e : object) - { - (void)e; - } - ASSERT(true); - } - - auto a_const_object_of_iterable_new__type_can_be_used_in_value_range_for() -> void - { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto const object = type_alias{{1, 2, 3}}; - for (auto e : object) - { - (void)e; - } - ASSERT(true); - } - - auto a_non_const_object_of_iterable_new__type_can_be_used_in_reference_range_for() -> void - { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto object = type_alias{{1, 2, 3}}; - for (auto & e : object) - { - (void)e; - } - ASSERT(true); - } - - auto a_const_object_of_iterable_new__type_can_be_used_in_const_reference_range_for() -> void - { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto const object = type_alias{{1, 2, 3}}; - for (auto const & e : object) - { - (void)e; - } - ASSERT(true); - } - - auto applying_accumulate_to_an_interable_new__type_yields_the_same_result_as_when_applied_to_the_base_type() -> void - { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto const nt_object = type_alias{{1, 2, 3}}; - auto const bt_object = type_alias::base_type{1, 2, 3}; - - auto nt_result = std::accumulate(std::cbegin(nt_object), std::cend(nt_object), 0); - auto bt_result = std::accumulate(std::cbegin(bt_object), std::cend(bt_object), 0); - - ASSERT_EQUAL(bt_result, nt_result); - } - - auto iterating_over_an_iterable_new__type_yields_the_elements_in_the_same_order_as_when_iterating_the_base_type() -> void - { - using std::cbegin, std::cend, std::equal; - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto const nt_object = type_alias{{1, 2, 3}}; - auto const bt_object = type_alias::base_type{1, 2, 3}; - - ASSERT(equal(cbegin(nt_object), cend(nt_object), cbegin(bt_object), cend(bt_object))); - } - -} // namespace semantic_tests - -auto iterable_suite() -> std::pair -{ - return {{ - /// Combined Enablement Tests - KAWAII(a_new__type_not_deriving_iterable_has_no_begin), - KAWAII(a_new__type_not_deriving_iterable_has_no_constant_begin), - KAWAII(a_new__type_not_deriving_iterable_has_no_cbegin), - KAWAII(a_new__type_not_deriving_iterable_has_no_rbegin), - KAWAII(a_new__type_not_deriving_iterable_has_no_constant_rbegin), - KAWAII(a_new__type_not_deriving_iterable_has_no_crbegin), - KAWAII(a_new__type_not_deriving_iterable_has_no_end), - KAWAII(a_new__type_not_deriving_iterable_has_no_constant_end), - KAWAII(a_new__type_not_deriving_iterable_has_no_cend), - KAWAII(a_new__type_not_deriving_iterable_has_no_rend), - KAWAII(a_new__type_not_deriving_iterable_has_no_constant_rend), - KAWAII(a_new__type_not_deriving_iterable_has_no_crend), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_begin), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_begin), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cbegin), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rbegin), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rbegin), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crbegin), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_end), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_end), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cend), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rend), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rend), - KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crend), - - /// Member Enablement Tests - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_begin), - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_begin), - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cbegin), - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rbegin), - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rbegin), - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crbegin), - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_end), - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_end), - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cend), - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rend), - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rend), - KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crend), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_begin), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_begin), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cbegin), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rbegin), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rbegin), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crbegin), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_end), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_end), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cend), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rend), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rend), - KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crend), - - /// Free Enablement Tests - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_begin), - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_begin), - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cbegin), - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rbegin), - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rbegin), - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crbegin), - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_end), - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_end), - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cend), - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rend), - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rend), - KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crend), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_begin), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_begin), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cbegin), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rbegin), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rbegin), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crbegin), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_end), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_end), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cend), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rend), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rend), - KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crend), - - /// Semantic Tests - KAWAII(a_non_const_object_of_iterable_new__type_can_be_used_in_value_range_for), - KAWAII(a_const_object_of_iterable_new__type_can_be_used_in_value_range_for), - KAWAII(a_non_const_object_of_iterable_new__type_can_be_used_in_reference_range_for), - KAWAII(a_const_object_of_iterable_new__type_can_be_used_in_const_reference_range_for), - KAWAII(applying_accumulate_to_an_interable_new__type_yields_the_same_result_as_when_applied_to_the_base_type), - KAWAII(iterating_over_an_iterable_new__type_yields_the_elements_in_the_same_order_as_when_iterating_the_base_type), - }, - - "Iterable Tests"}; -} \ No newline at end of file diff --git a/test/src/new_type_constructor_suite.cpp b/test/src/new_type_constructor_suite.cpp deleted file mode 100644 index fc3e9f6..0000000 --- a/test/src/new_type_constructor_suite.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "new_type_constructor_suite.hpp" - -#include "kawaii.hpp" -#include "newtype/derivable.hpp" -#include "newtype/newtype.hpp" - -#include - -#include - -inline namespace constructor_tests -{ - - struct not_default_constructible - { - not_default_constructible() = delete; - }; - - auto a_new__type_based_on_a_type_that_is_default_constructible_is_default_constructible_too() -> void - { - using nt_float = nt::new_type; - - ASSERT(std::is_default_constructible_v); - } - - auto a_new__type_based_on_a_type_that_is_not_default_constructible_is_not_default_constructible_too() -> void - { - using nt_not_default_constructible = nt::new_type; - - ASSERT(!std::is_default_constructible_v); - } - - template - auto a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type() -> void - { - using nt_old = nt::new_type; - - ASSERT((std::is_constructible_v)); - } - - auto a_new__type_instance_can_be_copy_constructed_if_the_base_type_can_be_copy_constructed() -> void - { - using type_alias = nt::new_type; - ASSERT((std::is_copy_constructible_v)); - } - - auto a_new__type_instance_can_not_be_copy_constructed_if_the_base_type_can_not_be_copy_constructed() -> void - { - struct not_copy_constructible - { - not_copy_constructible() = default; - not_copy_constructible(not_copy_constructible const &) = delete; - not_copy_constructible(not_copy_constructible &&) = default; - auto operator=(not_copy_constructible const &) -> not_copy_constructible & = default; - auto operator=(not_copy_constructible &&) -> not_copy_constructible & = default; - }; - - using type_alias = nt::new_type; - ASSERT(!(std::is_copy_constructible_v)); - } - -} // namespace constructor_tests - -auto new_type_constructor_suite() -> std::pair -{ - return {{ - KAWAII(a_new__type_based_on_a_type_that_is_default_constructible_is_default_constructible_too), - KAWAII(a_new__type_based_on_a_type_that_is_not_default_constructible_is_not_default_constructible_too), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_based_on_a_fundamental_type_can_be_constructed_with_a_value_of_fundamental_type), - KAWAII(a_new__type_instance_can_be_copy_constructed_if_the_base_type_can_be_copy_constructed), - KAWAII(a_new__type_instance_can_not_be_copy_constructed_if_the_base_type_can_not_be_copy_constructed), - }, - "new_type Constructor Tests"}; -} \ No newline at end of file diff --git a/test/src/relational_operators_suite.cpp b/test/src/relational_operators_suite.cpp deleted file mode 100644 index 64fcba0..0000000 --- a/test/src/relational_operators_suite.cpp +++ /dev/null @@ -1,321 +0,0 @@ -#include "relational_operators_suite.hpp" - -#include "kawaii.hpp" -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" -#include "newtype/newtype.hpp" - -#include - -#include -#include -#include - -inline namespace traits_extensions -{ - - template - struct has_less_than : std::false_type - { - }; - - template - struct has_less_than() < std::declval())>> : std::true_type - { - }; - - template - auto constexpr has_less_than_v = has_less_than::value; - - template - struct has_greater_than : std::false_type - { - }; - - template - struct has_greater_than() > std::declval())>> : std::true_type - { - }; - - template - auto constexpr has_greater_than_v = has_greater_than::value; - - template - struct has_less_than_equal_to : std::false_type - { - }; - - template - struct has_less_than_equal_to() <= std::declval())>> : std::true_type - { - }; - - template - auto constexpr has_less_than_equal_to_v = has_less_than_equal_to::value; - - template - struct has_greater_than_equal_to : std::false_type - { - }; - - template - struct has_greater_than_equal_to() >= std::declval())>> : std::true_type - { - }; - - template - auto constexpr has_greater_than_equal_to_v = has_greater_than_equal_to::value; - -} // namespace traits_extensions - -inline namespace relational_operator_presence_tests -{ - - auto an_instance_of_new__type_has_less_than_if_its_derivation_clause_contains_relational() -> void - { - using type_alias = nt::new_type; - ASSERT(has_less_than_v); - } - - auto an_instance_of_new__type_does_not_have_less_than_if_its_derivation_clause_does_not_contain_relational() -> void - { - using type_alias = nt::new_type; - ASSERT(!has_less_than_v); - } - - auto an_instance_of_new__type_has_greater_than_if_its_derivation_clause_contains_relational() -> void - { - using type_alias = nt::new_type; - ASSERT(has_greater_than_v); - } - - auto an_instance_of_new__type_does_not_have_greater_than_if_its_derivation_clause_does_not_contain_relational() -> void - { - using type_alias = nt::new_type; - ASSERT(!has_greater_than_v); - } - - auto an_instance_of_new__type_has_less_than_or_equal_to_if_its_derivation_clause_contains_relational() -> void - { - using type_alias = nt::new_type; - ASSERT(has_less_than_equal_to_v); - } - - auto an_instance_of_new__type_does_not_have_less_than_or_equal_to_if_its_derivation_clause_does_not_contain_relational() -> void - { - using type_alias = nt::new_type; - ASSERT(!has_less_than_equal_to_v); - } - - auto an_instance_of_new__type_has_greater_than_or_equal_to_if_its_derivation_clause_contains_relational() -> void - { - using type_alias = nt::new_type; - ASSERT(has_greater_than_equal_to_v); - } - - auto an_instance_of_new__type_does_not_have_greater_than_or_equal_to_if_its_derivation_clause_does_not_contain_relational() -> void - { - using type_alias = nt::new_type; - ASSERT(!has_greater_than_equal_to_v); - } - -} // namespace relational_operator_presence_tests - -inline namespace less_than_tests -{ - - auto two_instances_of_the_same_new__type_compare_less_than_if_both_contained_values_would_compare_less_than() -> void - { - using type_alias = nt::new_type; - auto constexpr lhs{21}; - auto constexpr rhs{42}; - static_assert(lhs < rhs, "Sanity Check"); - ASSERT_LESS(type_alias{lhs}, type_alias{rhs}); - } - - auto two_instances_of_the_same_new__type_do_not_compare_less_than_if_both_contained_values_would_not_compare_less_than() -> void - { - using type_alias = nt::new_type; - auto constexpr lhs{44}; - auto constexpr rhs{42}; - static_assert(!(lhs < rhs), "Sanity Check"); - ASSERT(!(type_alias{lhs} < type_alias{rhs})); - } - - auto two_instances_of_the_same_new__type_compare_less_than_or_equal_if_both_contained_values_would_compare_less_than_or_equal() -> void - { - using type_alias = nt::new_type; - auto constexpr lhs{33}; - auto constexpr rhs{42}; - static_assert(lhs <= rhs, "Sanity Check"); - ASSERT_LESS_EQUAL(type_alias{lhs}, type_alias{rhs}); - } - - auto two_instances_of_the_same_new__type_do_not_compare_less_than_or_equal_if_both_contained_values_would_not_compare_less_than_or_equal() - -> void - { - using type_alias = nt::new_type; - auto constexpr lhs{87}; - auto constexpr rhs{42}; - static_assert(!(lhs < rhs), "Sanity Check"); - ASSERT(!(type_alias{lhs} < type_alias{rhs})); - } - -} // namespace less_than_tests - -inline namespace greater_than_tests -{ - - auto two_instances_of_the_same_new__type_compare_greater_than_if_both_contained_values_would_compare_greater_than() -> void - { - using type_alias = nt::new_type; - auto constexpr lhs{42}; - auto constexpr rhs{21}; - static_assert(lhs > rhs, "Sanity Check"); - ASSERT_GREATER(type_alias{lhs}, type_alias{rhs}); - } - - auto two_instances_of_the_same_new__type_do_not_compare_greater_than_if_both_contained_values_would_not_compare_greater_than() -> void - { - using type_alias = nt::new_type; - auto constexpr lhs{42}; - auto constexpr rhs{44}; - static_assert(!(lhs > rhs), "Sanity Check"); - ASSERT(!(type_alias{lhs} > type_alias{rhs})); - } - - auto two_instances_of_the_same_new__type_compare_greater_than_or_equal_if_both_contained_values_would_compare_greater_than_or_equal() -> void - { - using type_alias = nt::new_type; - auto constexpr lhs{42}; - auto constexpr rhs{33}; - static_assert(lhs >= rhs, "Sanity Check"); - ASSERT_GREATER_EQUAL(type_alias{lhs}, type_alias{rhs}); - } - - auto - two_instances_of_the_same_new__type_do_not_compare_greater_than_or_equal_if_both_contained_values_would_not_compare_greater_than_or_equal() - -> void - { - using type_alias = nt::new_type; - auto constexpr lhs{42}; - auto constexpr rhs{87}; - static_assert(!(lhs > rhs), "Sanity Check"); - ASSERT(!(type_alias{lhs} > type_alias{rhs})); - } - -} // namespace greater_than_tests - -inline namespace relational_operator_noexcept_tests -{ - - struct strange_type - { - auto constexpr operator<(strange_type const & other) const noexcept(false) -> bool; - auto constexpr operator>(strange_type const & other) const noexcept(false) -> bool; - auto constexpr operator<=(strange_type const & other) const noexcept(false) -> bool; - auto constexpr operator>=(strange_type const & other) const noexcept(false) -> bool; - }; - - auto less_than_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept() -> void - { - using type_alias = nt::new_type; - static_assert(noexcept(std::declval() < std::declval()), "Sanity Check"); - ASSERT(noexcept(std::declval() < std::declval())); - } - - auto less_than_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept() -> void - { - using type_alias = nt::new_type; - static_assert(!noexcept(std::declval() < std::declval()), "Sanity Check"); - ASSERT(!noexcept(std::declval() < std::declval())); - } - - auto less_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept() -> void - { - using type_alias = nt::new_type; - static_assert(noexcept(std::declval() <= std::declval()), "Sanity Check"); - ASSERT(noexcept(std::declval() <= std::declval())); - } - - auto less_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept() - -> void - { - using type_alias = nt::new_type; - static_assert(!noexcept(std::declval() <= std::declval()), "Sanity Check"); - ASSERT(!noexcept(std::declval() <= std::declval())); - } - - auto greater_than_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept() -> void - { - using type_alias = nt::new_type; - static_assert(noexcept(std::declval() > std::declval()), "Sanity Check"); - ASSERT(noexcept(std::declval() > std::declval())); - } - - auto greater_than_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept() -> void - { - using type_alias = nt::new_type; - static_assert(!noexcept(std::declval() > std::declval()), "Sanity Check"); - ASSERT(!noexcept(std::declval() > std::declval())); - } - - auto greater_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept() -> void - { - using type_alias = nt::new_type; - static_assert(noexcept(std::declval() >= std::declval()), "Sanity Check"); - ASSERT(noexcept(std::declval() >= std::declval())); - } - - auto greater_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept() - -> void - { - using type_alias = nt::new_type; - static_assert(!noexcept(std::declval() >= std::declval()), "Sanity Check"); - ASSERT(!noexcept(std::declval() >= std::declval())); - } - -} // namespace relational_operator_noexcept_tests - -auto relational_operators_suite() -> std::pair -{ - return { - { - // clang-format off - - // Relational Operator Presensence Tests - KAWAII(an_instance_of_new__type_has_less_than_if_its_derivation_clause_contains_relational), - KAWAII(an_instance_of_new__type_does_not_have_less_than_if_its_derivation_clause_does_not_contain_relational), - KAWAII(an_instance_of_new__type_has_greater_than_if_its_derivation_clause_contains_relational), - KAWAII(an_instance_of_new__type_does_not_have_greater_than_if_its_derivation_clause_does_not_contain_relational), - KAWAII(an_instance_of_new__type_has_less_than_or_equal_to_if_its_derivation_clause_contains_relational), - KAWAII(an_instance_of_new__type_does_not_have_less_than_or_equal_to_if_its_derivation_clause_does_not_contain_relational), - KAWAII(an_instance_of_new__type_has_greater_than_or_equal_to_if_its_derivation_clause_contains_relational), - KAWAII(an_instance_of_new__type_does_not_have_greater_than_or_equal_to_if_its_derivation_clause_does_not_contain_relational), - - // Less-than Comparison Tests - KAWAII(two_instances_of_the_same_new__type_compare_less_than_if_both_contained_values_would_compare_less_than), - KAWAII(two_instances_of_the_same_new__type_do_not_compare_less_than_if_both_contained_values_would_not_compare_less_than), - KAWAII(two_instances_of_the_same_new__type_compare_less_than_or_equal_if_both_contained_values_would_compare_less_than_or_equal), - KAWAII(two_instances_of_the_same_new__type_do_not_compare_less_than_or_equal_if_both_contained_values_would_not_compare_less_than_or_equal), - - // Greater-than Comparison Tests - KAWAII(two_instances_of_the_same_new__type_compare_greater_than_if_both_contained_values_would_compare_greater_than), - KAWAII(two_instances_of_the_same_new__type_do_not_compare_greater_than_if_both_contained_values_would_not_compare_greater_than), - KAWAII(two_instances_of_the_same_new__type_compare_greater_than_or_equal_if_both_contained_values_would_compare_greater_than_or_equal), - KAWAII(two_instances_of_the_same_new__type_do_not_compare_greater_than_or_equal_if_both_contained_values_would_not_compare_greater_than_or_equal), - - // Relational Operators noexcept Tests - KAWAII(less_than_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept), - KAWAII(less_than_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept), - KAWAII(less_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept), - KAWAII(less_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept), - KAWAII(greater_than_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept), - KAWAII(greater_than_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept), - KAWAII(greater_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_noexcept_if_comparison_of_the_base_type_is_noexcept), - KAWAII(greater_than_equal_to_comparison_of_two_intances_of_the_same_new__type_is_not_noexcept_if_comparison_of_the_base_type_is_not_noexcept), - - // clang-format on - }, - "Relational Operators Tests"}; -} \ No newline at end of file diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index 1aafacf..f511e49 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -1,10 +1,13 @@ -cmake_minimum_required(VERSION "3.0") +cmake_minimum_required(VERSION "3.25") project("TestPackage" CXX) -set(CMAKE_CXX_STANDARD "20") +find_package("newtype") -include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") -conan_basic_setup() +add_executable("${PROJECT_NAME}" + "main.cpp" +) -add_executable("test_package" "main.cpp") \ No newline at end of file +target_link_libraries("${PROJECT_NAME}" PRIVATE + "newtype::newtype" +) diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 0b12b5f..ae8c241 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -1,11 +1,12 @@ import os -from conans import ConanFile, CMake +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout class NewtypeTestConan(ConanFile): - settings = None - requires = "newtype/[~=1.0]@fmorgner/stable" - generators = "cmake" + settings = ("os", "arch", "compiler", "build_type") + requires = "newtype/[~2.0]" + generators = "CMakeDeps", "CMakeToolchain" def build(self): cmake = CMake(self) @@ -13,5 +14,8 @@ class NewtypeTestConan(ConanFile): cmake.build() def test(self): - os.chdir("bin") - self.run(".%stest_package" % os.sep) \ No newline at end of file + os.chdir(self.build_folder) + self.run(".%sTestPackage" % os.sep) + + def layout(self): + cmake_layout(self, generator="Ninja Multi-Config") diff --git a/test_package/main.cpp b/test_package/main.cpp index 95fe763..d2efe04 100644 --- a/test_package/main.cpp +++ b/test_package/main.cpp @@ -1,4 +1,4 @@ -#include "newtype/new_type.hpp" +#include "newtype/newtype.hpp" #include -- cgit v1.2.3