From ba8705bf7c55ace1f422ac7157d874e126b321d5 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 14:01:34 -0500 Subject: [PATCH 01/38] Make line endings consistent --- CML.cmake | 47 ++++++++++++++++++++------------------- CMakeLists.txt | 31 +++++++++++++------------- README.md | 2 -- tests/CMakeLists.txt | 20 ++--------------- tests/main/CMakeLists.txt | 6 ++--- 5 files changed, 45 insertions(+), 61 deletions(-) diff --git a/CML.cmake b/CML.cmake index accf019..f134a5d 100644 --- a/CML.cmake +++ b/CML.cmake @@ -1,6 +1,6 @@ -# -*- cmake -*- ----------------------------------------------------------- +# -------------------------------------------------------------------------- # @@COPYRIGHT@@ -#*------------------------------------------------------------------------- +# -------------------------------------------------------------------------- set(main_HEADERS cml/cml.h @@ -10,7 +10,7 @@ set(main_HEADERS cml/util.h cml/vector.h cml/version.h - ) +) set(common_HEADERS cml/common/array_size_of.h @@ -25,7 +25,7 @@ set(common_HEADERS cml/common/temporary.h cml/common/traits.h cml/common/type_util.h - ) +) set(common_mpl_HEADERS cml/common/mpl/are_convertible.h @@ -47,7 +47,7 @@ set(common_mpl_HEADERS cml/common/mpl/rebind.h cml/common/mpl/type_map.h cml/common/mpl/type_table.h - ) +) set(scalar_HEADERS cml/scalar/binary_ops.h @@ -56,7 +56,7 @@ set(scalar_HEADERS cml/scalar/promotion.h cml/scalar/traits.h cml/scalar/unary_ops.h - ) +) set(storage_HEADERS cml/storage/allocated_selector.h @@ -67,7 +67,7 @@ set(storage_HEADERS cml/storage/resize.h cml/storage/selectors.h cml/storage/type_util.h - ) +) set(vector_HEADERS cml/vector/binary_node.h @@ -133,13 +133,13 @@ set(vector_HEADERS cml/vector/vector.h cml/vector/writable_vector.h cml/vector/writable_vector.tpp - ) +) set(vector_detail_HEADERS cml/vector/detail/check_or_resize.h cml/vector/detail/combined_size_of.h cml/vector/detail/resize.h - ) +) set(matrix_HEADERS cml/matrix/array_size_of.h @@ -207,7 +207,7 @@ set(matrix_HEADERS cml/matrix/vector_product.tpp cml/matrix/writable_matrix.h cml/matrix/writable_matrix.tpp - ) +) set(matrix_detail_HEADERS cml/matrix/detail/apply.h @@ -222,7 +222,7 @@ set(matrix_detail_HEADERS cml/matrix/detail/lu.tpp cml/matrix/detail/resize.h cml/matrix/detail/transpose.h - ) +) set(quaternion_HEADERS cml/quaternion/binary_node.h @@ -275,7 +275,7 @@ set(quaternion_HEADERS cml/quaternion/unary_ops.h cml/quaternion/writable_quaternion.h cml/quaternion/writable_quaternion.tpp - ) +) set(mathlib_HEADERS cml/mathlib/axis_order.h @@ -288,7 +288,7 @@ set(mathlib_HEADERS cml/mathlib/mathlib.h cml/mathlib/random_unit.h cml/mathlib/random_unit.tpp - ) +) set(mathlib_vector_HEADERS cml/mathlib/vector/angle.h @@ -303,7 +303,7 @@ set(mathlib_vector_HEADERS cml/mathlib/vector/rotation.tpp cml/mathlib/vector/transform.h cml/mathlib/vector/transform.tpp - ) +) set(mathlib_matrix_HEADERS cml/mathlib/matrix/basis.h @@ -328,14 +328,14 @@ set(mathlib_matrix_HEADERS cml/mathlib/matrix/transform.tpp cml/mathlib/matrix/translation.h cml/mathlib/matrix/translation.tpp - ) +) set(mathlib_quaternion_HEADERS cml/mathlib/quaternion/basis.h cml/mathlib/quaternion/basis.tpp cml/mathlib/quaternion/rotation.h cml/mathlib/quaternion/rotation.tpp - ) +) set(util_HEADERS cml/util/matrix_print.h @@ -345,7 +345,7 @@ set(util_HEADERS cml/util/vector_hash.h cml/util/vector_print.h cml/util/vector_print.tpp - ) +) set(all_headers ${main_HEADERS} @@ -363,15 +363,15 @@ set(all_headers ${mathlib_vector_HEADERS} ${mathlib_matrix_HEADERS} ${mathlib_quaternion_HEADERS} - ) +) add_library(cml INTERFACE) target_compile_options(cml INTERFACE $<$:/permissive->) target_compile_features(cml INTERFACE - cxx_reference_qualified_functions - cxx_constexpr - cxx_defaulted_functions - ) + cxx_reference_qualified_functions + cxx_constexpr + cxx_defaulted_functions +) target_include_directories(cml INTERFACE $) target_include_directories(cml INTERFACE $/include>) @@ -394,4 +394,5 @@ if(${CMAKE_GENERATOR} MATCHES "Visual Studio") source_group("${_header_group}mathlib\\quaternion" FILES ${mathlib_quaternion_HEADERS}) source_group("${_header_group}\\util" FILES ${util_HEADERS}) endif() -add_custom_target(cml-dev SOURCES ${all_headers}) + +add_custom_target(cml-dev SOURCES ${all_headers}) \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 878b871..d07a797 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ -# -*- cmake -*- ----------------------------------------------------------- +# -------------------------------------------------------------------------- # @@COPYRIGHT@@ -#*------------------------------------------------------------------------- +# -------------------------------------------------------------------------- # Set the minimum CMake version: cmake_minimum_required(VERSION 3.15) @@ -23,20 +23,21 @@ include(CMLBuildMacros) # Figure out which version of CML is being built by parsing CML/version.h (this # is from the root Boost.CMake CMakeLists.txt file): cml_version_from_file( - ${CML_ROOT}/cml/version.h # Path to version.h - "CML_VERSION" # The macro name to find - CML_VERSION_MAJOR # Parsed major version - CML_VERSION_MINOR # Parsed minor version - CML_VERSION_PATCH # Parsed patch version - CML_VERSION # String MM.mm.pp - ) + ${CML_ROOT}/cml/version.h # Path to version.h + "CML_VERSION" # The macro name to find + CML_VERSION_MAJOR # Parsed major version + CML_VERSION_MINOR # Parsed minor version + CML_VERSION_PATCH # Parsed patch version + CML_VERSION # String MM.mm.pp +) message(STATUS "Building CML ${CML_VERSION}") -# Create the CML interface library: +# Create the CML interface library: include(CML.cmake) # Build tests if requested: option(CML_BUILD_TESTING "Build CML tests" OFF) + if(CML_BUILD_TESTING) enable_testing() add_subdirectory(tests) @@ -55,9 +56,9 @@ install(TARGETS cml DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT cml-targets) install(EXPORT cml-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cml FILE cml-targets.cmake) install(DIRECTORY cml DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*") install(FILES - ${CMAKE_CURRENT_BINARY_DIR}/cml-config-version.cmake - CMake/cml-config.cmake - DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cml - ) + ${CMAKE_CURRENT_BINARY_DIR}/cml-config-version.cmake + CMake/cml-config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cml +) - export(EXPORT cml-targets FILE cml-config.cmake) \ No newline at end of file +export(EXPORT cml-targets FILE cml-config.cmake) \ No newline at end of file diff --git a/README.md b/README.md index 663c57e..55fa949 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,9 @@ For CML version 1, please see https://github.com/demianmnave/CML1. The Configurable Math Library (CML) is released under the [Boost Software License, Version 1.0.](http://www.boost.org/LICENSE_1_0.txt). - ## Status [![Build status](https://ci.appveyor.com/api/projects/status/r3l3xnhxe8djjimg/branch/master?svg=true)](https://ci.appveyor.com/project/demianmnave/cml/branch/master) -[![Build Status](https://travis-ci.com/demianmnave/CML.svg?branch=master)](https://travis-ci.com/github/demianmnave/CML) ## Using the CML diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a8f8f53..842edfc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,30 +1,14 @@ -# -*- cmake -*- ----------------------------------------------------------- +# -------------------------------------------------------------------------- # @@COPYRIGHT@@ -#*------------------------------------------------------------------------- +# -------------------------------------------------------------------------- -# Need the test macros: include(CMLTestMacros) -# Catch-based test runner: add_subdirectory(main) - -# Common functionality tests: add_subdirectory(common) - -# Storage tests: add_subdirectory(storage) - -# cml::vector<> tests: add_subdirectory(vector) - -# cml::matrix<> tests: add_subdirectory(matrix) - -# cml::quaternion<> tests: add_subdirectory(quaternion) - -# mathlib tests: add_subdirectory(mathlib) - -# util tests: add_subdirectory(util) \ No newline at end of file diff --git a/tests/main/CMakeLists.txt b/tests/main/CMakeLists.txt index 31a3a38..b685aae 100644 --- a/tests/main/CMakeLists.txt +++ b/tests/main/CMakeLists.txt @@ -1,6 +1,6 @@ -# -*- cmake -*- ----------------------------------------------------------- +# -------------------------------------------------------------------------- # @@COPYRIGHT@@ -#*------------------------------------------------------------------------- +# -------------------------------------------------------------------------- project(CMLTestMain) @@ -8,5 +8,5 @@ add_library(cml_test_main STATIC catch_main.cpp catch.hpp catch_runner.h) target_include_directories(cml_test_main PUBLIC ${CMAKE_CURRENT_LIST_DIR} PRIVATE ${CML_ROOT} - ) +) set_target_properties(cml_test_main PROPERTIES FOLDER "CML-Tests") \ No newline at end of file From c87bb1c7994b44da5fbe83c76f651b1c01a86d84 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 17:37:48 -0500 Subject: [PATCH 02/38] Delete unnecessary files from the CMake directory --- .travis.yml | 29 - CMake/CMLTestMacros.cmake | 30 - CMake/FindBoost.cmake | 1893 ------------------------------------- 3 files changed, 1952 deletions(-) delete mode 100644 .travis.yml delete mode 100644 CMake/CMLTestMacros.cmake delete mode 100644 CMake/FindBoost.cmake diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e8296aa..0000000 --- a/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: cpp - -branches: - only: - - master - - develop - -matrix: - include: - - - os: osx - osx_image: xcode11.6 - - - os: osx - osx_image: xcode12.5 - -before_install: - - if [ ${TRAVIS_OS_NAME} == "linux" ]; then - eval "${MATRIX_EVAL}"; - fi - -before_script: - - mkdir build - - cd build - -script: - - cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_STANDARD=11 -DCML_BUILD_TESTING:Bool=ON .. - - cmake --build . --config Release -- -j2 - - ctest -V -C Release diff --git a/CMake/CMLTestMacros.cmake b/CMake/CMLTestMacros.cmake deleted file mode 100644 index 0def331..0000000 --- a/CMake/CMLTestMacros.cmake +++ /dev/null @@ -1,30 +0,0 @@ -# -*- cmake -*- ----------------------------------------------------------- -# @@COPYRIGHT@@ -#*------------------------------------------------------------------------- - -# Macro to add a single-file test to the build, using ${_Name}.cpp as the -# test source. The executable name and test title will be set to -# ${_Name}_test. -macro(cml_add_test - _Name # The test basename, e.g. my -> my_test - ) - - # Define the executable name: - set(ExecName "${_Name}") - - # Define the test name: - if(DEFINED CML_CURRENT_TEST_GROUP) - set(TestName "CML:${CML_CURRENT_TEST_GROUP}:${_Name}") - else() - message(FATAL_ERROR "CML_CURRENT_TEST_GROUP must be defined") - endif() - - # Setup the build target: - add_executable(${ExecName} ${_Name}.cpp) - set_target_properties(${ExecName} PROPERTIES - FOLDER "CML-Tests/${CML_CURRENT_TEST_GROUP}") - target_link_libraries(${ExecName} cml cml_test_main) - - # Setup the test: - add_test(NAME ${TestName} COMMAND ${ExecName}) -endmacro() \ No newline at end of file diff --git a/CMake/FindBoost.cmake b/CMake/FindBoost.cmake deleted file mode 100644 index c8ab419..0000000 --- a/CMake/FindBoost.cmake +++ /dev/null @@ -1,1893 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# FindBoost -# --------- -# -# Find Boost include dirs and libraries -# -# Use this module by invoking find_package with the form:: -# -# find_package(Boost -# [version] [EXACT] # Minimum or EXACT version e.g. 1.36.0 -# [REQUIRED] # Fail with error if Boost is not found -# [COMPONENTS ...] # Boost libraries by their canonical name -# ) # e.g. "date_time" for "libboost_date_time" -# -# This module finds headers and requested component libraries OR a CMake -# package configuration file provided by a "Boost CMake" build. For the -# latter case skip to the "Boost CMake" section below. For the former -# case results are reported in variables:: -# -# Boost_FOUND - True if headers and requested libraries were found -# Boost_INCLUDE_DIRS - Boost include directories -# Boost_LIBRARY_DIRS - Link directories for Boost libraries -# Boost_LIBRARIES - Boost component libraries to be linked -# Boost__FOUND - True if component was found ( is upper-case) -# Boost__LIBRARY - Libraries to link for component (may include -# target_link_libraries debug/optimized keywords) -# Boost_VERSION - BOOST_VERSION value from boost/version.hpp -# Boost_LIB_VERSION - Version string appended to library filenames -# Boost_MAJOR_VERSION - Boost major version number (X in X.y.z) -# Boost_MINOR_VERSION - Boost minor version number (Y in x.Y.z) -# Boost_SUBMINOR_VERSION - Boost subminor version number (Z in x.y.Z) -# Boost_LIB_DIAGNOSTIC_DEFINITIONS (Windows) -# - Pass to add_definitions() to have diagnostic -# information about Boost's automatic linking -# displayed during compilation -# -# This module reads hints about search locations from variables:: -# -# BOOST_ROOT - Preferred installation prefix -# (or BOOSTROOT) -# BOOST_INCLUDEDIR - Preferred include directory e.g. /include -# BOOST_LIBRARYDIR - Preferred library directory e.g. /lib -# Boost_NO_SYSTEM_PATHS - Set to ON to disable searching in locations not -# specified by these hint variables. Default is OFF. -# Boost_ADDITIONAL_VERSIONS -# - List of Boost versions not known to this module -# (Boost install locations may contain the version) -# -# and saves search results persistently in CMake cache entries:: -# -# Boost_INCLUDE_DIR - Directory containing Boost headers -# Boost_LIBRARY_DIR_RELEASE - Directory containing release Boost libraries -# Boost_LIBRARY_DIR_DEBUG - Directory containing debug Boost libraries -# Boost__LIBRARY_DEBUG - Component library debug variant -# Boost__LIBRARY_RELEASE - Component library release variant -# -# The following :prop_tgt:`IMPORTED` targets are also defined:: -# -# Boost::boost - Target for header-only dependencies -# (Boost include directory) -# Boost:: - Target for specific component dependency -# (shared or static library); is lower- -# case -# Boost::diagnostic_definitions - interface target to enable diagnostic -# information about Boost's automatic linking -# during compilation (adds BOOST_LIB_DIAGNOSTIC) -# Boost::disable_autolinking - interface target to disable automatic -# linking with MSVC (adds BOOST_ALL_NO_LIB) -# Boost::dynamic_linking - interface target to enable dynamic linking -# linking with MSVC (adds BOOST_ALL_DYN_LINK) -# -# Implicit dependencies such as Boost::filesystem requiring -# Boost::system will be automatically detected and satisfied, even -# if system is not specified when using find_package and if -# Boost::system is not added to target_link_libraries. If using -# Boost::thread, then Thread::Thread will also be added automatically. -# -# It is important to note that the imported targets behave differently -# than variables created by this module: multiple calls to -# find_package(Boost) in the same directory or sub-directories with -# different options (e.g. static or shared) will not override the -# values of the targets created by the first call. -# -# Users may set these hints or results as cache entries. Projects -# should not read these entries directly but instead use the above -# result variables. Note that some hint names start in upper-case -# "BOOST". One may specify these as environment variables if they are -# not specified as CMake variables or cache entries. -# -# This module first searches for the Boost header files using the above -# hint variables (excluding BOOST_LIBRARYDIR) and saves the result in -# Boost_INCLUDE_DIR. Then it searches for requested component libraries -# using the above hints (excluding BOOST_INCLUDEDIR and -# Boost_ADDITIONAL_VERSIONS), "lib" directories near Boost_INCLUDE_DIR, -# and the library name configuration settings below. It saves the -# library directories in Boost_LIBRARY_DIR_DEBUG and -# Boost_LIBRARY_DIR_RELEASE and individual library -# locations in Boost__LIBRARY_DEBUG and Boost__LIBRARY_RELEASE. -# When one changes settings used by previous searches in the same build -# tree (excluding environment variables) this module discards previous -# search results affected by the changes and searches again. -# -# Boost libraries come in many variants encoded in their file name. -# Users or projects may tell this module which variant to find by -# setting variables:: -# -# Boost_USE_MULTITHREADED - Set to OFF to use the non-multithreaded -# libraries ('mt' tag). Default is ON. -# Boost_USE_STATIC_LIBS - Set to ON to force the use of the static -# libraries. Default is OFF. -# Boost_USE_STATIC_RUNTIME - Set to ON or OFF to specify whether to use -# libraries linked statically to the C++ runtime -# ('s' tag). Default is platform dependent. -# Boost_USE_DEBUG_RUNTIME - Set to ON or OFF to specify whether to use -# libraries linked to the MS debug C++ runtime -# ('g' tag). Default is ON. -# Boost_USE_DEBUG_PYTHON - Set to ON to use libraries compiled with a -# debug Python build ('y' tag). Default is OFF. -# Boost_USE_STLPORT - Set to ON to use libraries compiled with -# STLPort ('p' tag). Default is OFF. -# Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS -# - Set to ON to use libraries compiled with -# STLPort deprecated "native iostreams" -# ('n' tag). Default is OFF. -# Boost_COMPILER - Set to the compiler-specific library suffix -# (e.g. "-gcc43"). Default is auto-computed -# for the C++ compiler in use. A list may be -# used if multiple compatible suffixes should -# be tested for, in decreasing order of -# preference. -# Boost_THREADAPI - Suffix for "thread" component library name, -# such as "pthread" or "win32". Names with -# and without this suffix will both be tried. -# Boost_NAMESPACE - Alternate namespace used to build boost with -# e.g. if set to "myboost", will search for -# myboost_thread instead of boost_thread. -# -# Other variables one may set to control this module are:: -# -# Boost_DEBUG - Set to ON to enable debug output from FindBoost. -# Please enable this before filing any bug report. -# Boost_DETAILED_FAILURE_MSG -# - Set to ON to add detailed information to the -# failure message even when the REQUIRED option -# is not given to the find_package call. -# Boost_REALPATH - Set to ON to resolve symlinks for discovered -# libraries to assist with packaging. For example, -# the "system" component library may be resolved to -# "/usr/lib/libboost_system.so.1.42.0" instead of -# "/usr/lib/libboost_system.so". This does not -# affect linking and should not be enabled unless -# the user needs this information. -# Boost_LIBRARY_DIR - Default value for Boost_LIBRARY_DIR_RELEASE and -# Boost_LIBRARY_DIR_DEBUG. -# -# On Visual Studio and Borland compilers Boost headers request automatic -# linking to corresponding libraries. This requires matching libraries -# to be linked explicitly or available in the link library search path. -# In this case setting Boost_USE_STATIC_LIBS to OFF may not achieve -# dynamic linking. Boost automatic linking typically requests static -# libraries with a few exceptions (such as Boost.Python). Use:: -# -# add_definitions(${Boost_LIB_DIAGNOSTIC_DEFINITIONS}) -# -# to ask Boost to report information about automatic linking requests. -# -# Example to find Boost headers only:: -# -# find_package(Boost 1.36.0) -# if(Boost_FOUND) -# include_directories(${Boost_INCLUDE_DIRS}) -# add_executable(foo foo.cc) -# endif() -# -# Example to find Boost libraries and use imported targets:: -# -# find_package(Boost 1.56 REQUIRED COMPONENTS -# date_time filesystem iostreams) -# add_executable(foo foo.cc) -# target_link_libraries(foo Boost::date_time Boost::filesystem -# Boost::iostreams) -# -# Example to find Boost headers and some *static* libraries:: -# -# set(Boost_USE_STATIC_LIBS ON) # only find static libs -# set(Boost_USE_MULTITHREADED ON) -# set(Boost_USE_STATIC_RUNTIME OFF) -# find_package(Boost 1.36.0 COMPONENTS date_time filesystem system ...) -# if(Boost_FOUND) -# include_directories(${Boost_INCLUDE_DIRS}) -# add_executable(foo foo.cc) -# target_link_libraries(foo ${Boost_LIBRARIES}) -# endif() -# -# Boost CMake -# ^^^^^^^^^^^ -# -# If Boost was built using the boost-cmake project it provides a package -# configuration file for use with find_package's Config mode. This -# module looks for the package configuration file called -# BoostConfig.cmake or boost-config.cmake and stores the result in cache -# entry "Boost_DIR". If found, the package configuration file is loaded -# and this module returns with no further action. See documentation of -# the Boost CMake package configuration for details on what it provides. -# -# Set Boost_NO_BOOST_CMAKE to ON to disable the search for boost-cmake. - -#------------------------------------------------------------------------------- -# Before we go searching, check whether boost-cmake is available, unless the -# user specifically asked NOT to search for boost-cmake. -# -# If Boost_DIR is set, this behaves as any find_package call would. If not, -# it looks at BOOST_ROOT and BOOSTROOT to find Boost. -# -if (NOT Boost_NO_BOOST_CMAKE) - # If Boost_DIR is not set, look for BOOSTROOT and BOOST_ROOT as alternatives, - # since these are more conventional for Boost. - if ("$ENV{Boost_DIR}" STREQUAL "") - if (NOT "$ENV{BOOST_ROOT}" STREQUAL "") - set(ENV{Boost_DIR} $ENV{BOOST_ROOT}) - elseif (NOT "$ENV{BOOSTROOT}" STREQUAL "") - set(ENV{Boost_DIR} $ENV{BOOSTROOT}) - endif() - endif() - - # Do the same find_package call but look specifically for the CMake version. - # Note that args are passed in the Boost_FIND_xxxxx variables, so there is no - # need to delegate them to this find_package call. - find_package(Boost QUIET NO_MODULE) - mark_as_advanced(Boost_DIR) - - # If we found boost-cmake, then we're done. Print out what we found. - # Otherwise let the rest of the module try to find it. - if (Boost_FOUND) - message("Boost ${Boost_FIND_VERSION} found.") - if (Boost_FIND_COMPONENTS) - message("Found Boost components:") - message(" ${Boost_FIND_COMPONENTS}") - endif() - return() - endif() -endif() - - -#------------------------------------------------------------------------------- -# FindBoost functions & macros -# - -############################################ -# -# Check the existence of the libraries. -# -############################################ -# This macro was taken directly from the FindQt4.cmake file that is included -# with the CMake distribution. This is NOT my work. All work was done by the -# original authors of the FindQt4.cmake file. Only minor modifications were -# made to remove references to Qt and make this file more generally applicable -# And ELSE/ENDIF pairs were removed for readability. -######################################################################### - -macro(_Boost_ADJUST_LIB_VARS basename) - if(Boost_INCLUDE_DIR ) - if(Boost_${basename}_LIBRARY_DEBUG AND Boost_${basename}_LIBRARY_RELEASE) - # if the generator supports configuration types then set - # optimized and debug libraries, or if the CMAKE_BUILD_TYPE has a value - if(CMAKE_CONFIGURATION_TYPES OR CMAKE_BUILD_TYPE) - set(Boost_${basename}_LIBRARY optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG}) - else() - # if there are no configuration types and CMAKE_BUILD_TYPE has no value - # then just use the release libraries - set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} ) - endif() - # FIXME: This probably should be set for both cases - set(Boost_${basename}_LIBRARIES optimized ${Boost_${basename}_LIBRARY_RELEASE} debug ${Boost_${basename}_LIBRARY_DEBUG}) - endif() - - # if only the release version was found, set the debug variable also to the release version - if(Boost_${basename}_LIBRARY_RELEASE AND NOT Boost_${basename}_LIBRARY_DEBUG) - set(Boost_${basename}_LIBRARY_DEBUG ${Boost_${basename}_LIBRARY_RELEASE}) - set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE}) - set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE}) - endif() - - # if only the debug version was found, set the release variable also to the debug version - if(Boost_${basename}_LIBRARY_DEBUG AND NOT Boost_${basename}_LIBRARY_RELEASE) - set(Boost_${basename}_LIBRARY_RELEASE ${Boost_${basename}_LIBRARY_DEBUG}) - set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_DEBUG}) - set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_DEBUG}) - endif() - - # If the debug & release library ends up being the same, omit the keywords - if(${Boost_${basename}_LIBRARY_RELEASE} STREQUAL ${Boost_${basename}_LIBRARY_DEBUG}) - set(Boost_${basename}_LIBRARY ${Boost_${basename}_LIBRARY_RELEASE} ) - set(Boost_${basename}_LIBRARIES ${Boost_${basename}_LIBRARY_RELEASE} ) - endif() - - if(Boost_${basename}_LIBRARY AND Boost_${basename}_HEADER) - set(Boost_${basename}_FOUND ON) - endif() - - endif() - # Make variables changeable to the advanced user - mark_as_advanced( - Boost_${basename}_LIBRARY_RELEASE - Boost_${basename}_LIBRARY_DEBUG - ) -endmacro() - -# Detect changes in used variables. -# Compares the current variable value with the last one. -# In short form: -# v != v_LAST -> CHANGED = 1 -# v is defined, v_LAST not -> CHANGED = 1 -# v is not defined, but v_LAST is -> CHANGED = 1 -# otherwise -> CHANGED = 0 -# CHANGED is returned in variable named ${changed_var} -macro(_Boost_CHANGE_DETECT changed_var) - set(${changed_var} 0) - foreach(v ${ARGN}) - if(DEFINED _Boost_COMPONENTS_SEARCHED) - if(${v}) - if(_${v}_LAST) - string(COMPARE NOTEQUAL "${${v}}" "${_${v}_LAST}" _${v}_CHANGED) - else() - set(_${v}_CHANGED 1) - endif() - elseif(_${v}_LAST) - set(_${v}_CHANGED 1) - endif() - if(_${v}_CHANGED) - set(${changed_var} 1) - endif() - else() - set(_${v}_CHANGED 0) - endif() - endforeach() -endmacro() - -# -# Find the given library (var). -# Use 'build_type' to support different lib paths for RELEASE or DEBUG builds -# -macro(_Boost_FIND_LIBRARY var build_type) - - find_library(${var} ${ARGN}) - - if(${var}) - # If this is the first library found then save Boost_LIBRARY_DIR_[RELEASE,DEBUG]. - if(NOT Boost_LIBRARY_DIR_${build_type}) - get_filename_component(_dir "${${var}}" PATH) - set(Boost_LIBRARY_DIR_${build_type} "${_dir}" CACHE PATH "Boost library directory ${build_type}" FORCE) - endif() - elseif(_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT) - # Try component-specific hints but do not save Boost_LIBRARY_DIR_[RELEASE,DEBUG]. - find_library(${var} HINTS ${_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT} ${ARGN}) - endif() - - # If Boost_LIBRARY_DIR_[RELEASE,DEBUG] is known then search only there. - if(Boost_LIBRARY_DIR_${build_type}) - set(_boost_LIBRARY_SEARCH_DIRS_${build_type} ${Boost_LIBRARY_DIR_${build_type}} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " Boost_LIBRARY_DIR_${build_type} = ${Boost_LIBRARY_DIR_${build_type}}" - " _boost_LIBRARY_SEARCH_DIRS_${build_type} = ${_boost_LIBRARY_SEARCH_DIRS_${build_type}}") - endif() - endif() -endmacro() - -#------------------------------------------------------------------------------- - -# -# Runs compiler with "-dumpversion" and parses major/minor -# version with a regex. -# -function(_Boost_COMPILER_DUMPVERSION _OUTPUT_VERSION) - - exec_program(${CMAKE_CXX_COMPILER} - ARGS ${CMAKE_CXX_COMPILER_ARG1} -dumpversion - OUTPUT_VARIABLE _boost_COMPILER_VERSION - ) - string(REGEX REPLACE "([0-9])\\.([0-9])(\\.[0-9])?" "\\1\\2" - _boost_COMPILER_VERSION ${_boost_COMPILER_VERSION}) - - set(${_OUTPUT_VERSION} ${_boost_COMPILER_VERSION} PARENT_SCOPE) -endfunction() - -# -# Take a list of libraries with "thread" in it -# and prepend duplicates with "thread_${Boost_THREADAPI}" -# at the front of the list -# -function(_Boost_PREPEND_LIST_WITH_THREADAPI _output) - set(_orig_libnames ${ARGN}) - string(REPLACE "thread" "thread_${Boost_THREADAPI}" _threadapi_libnames "${_orig_libnames}") - set(${_output} ${_threadapi_libnames} ${_orig_libnames} PARENT_SCOPE) -endfunction() - -# -# If a library is found, replace its cache entry with its REALPATH -# -function(_Boost_SWAP_WITH_REALPATH _library _docstring) - if(${_library}) - get_filename_component(_boost_filepathreal ${${_library}} REALPATH) - unset(${_library} CACHE) - set(${_library} ${_boost_filepathreal} CACHE FILEPATH "${_docstring}") - endif() -endfunction() - -function(_Boost_CHECK_SPELLING _var) - if(${_var}) - string(TOUPPER ${_var} _var_UC) - message(FATAL_ERROR "ERROR: ${_var} is not the correct spelling. The proper spelling is ${_var_UC}.") - endif() -endfunction() - -# Guesses Boost's compiler prefix used in built library names -# Returns the guess by setting the variable pointed to by _ret -function(_Boost_GUESS_COMPILER_PREFIX _ret) - if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" - OR CMAKE_CXX_COMPILER MATCHES "icl" - OR CMAKE_CXX_COMPILER MATCHES "icpc") - if(WIN32) - set (_boost_COMPILER "-iw") - else() - set (_boost_COMPILER "-il") - endif() - elseif (GHSMULTI) - set(_boost_COMPILER "-ghs") - elseif("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC") - if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) - set(_boost_COMPILER "-vc141;-vc140") - elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19) - set(_boost_COMPILER "-vc140") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18) - set(_boost_COMPILER "-vc120") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17) - set(_boost_COMPILER "-vc110") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) - set(_boost_COMPILER "-vc100") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15) - set(_boost_COMPILER "-vc90") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14) - set(_boost_COMPILER "-vc80") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.10) - set(_boost_COMPILER "-vc71") - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13) # Good luck! - set(_boost_COMPILER "-vc7") # yes, this is correct - else() # VS 6.0 Good luck! - set(_boost_COMPILER "-vc6") # yes, this is correct - endif() - elseif (BORLAND) - set(_boost_COMPILER "-bcb") - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro") - set(_boost_COMPILER "-sw") - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "XL") - set(_boost_COMPILER "-xlc") - elseif (MINGW) - if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34) - set(_boost_COMPILER "-mgw") # no GCC version encoding prior to 1.34 - else() - _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION) - set(_boost_COMPILER "-mgw${_boost_COMPILER_VERSION}") - endif() - elseif (UNIX) - if (CMAKE_COMPILER_IS_GNUCXX) - if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34) - set(_boost_COMPILER "-gcc") # no GCC version encoding prior to 1.34 - else() - _Boost_COMPILER_DUMPVERSION(_boost_COMPILER_VERSION) - # Determine which version of GCC we have. - if(APPLE) - if(Boost_MINOR_VERSION) - if(${Boost_MINOR_VERSION} GREATER 35) - # In Boost 1.36.0 and newer, the mangled compiler name used - # on Mac OS X/Darwin is "xgcc". - set(_boost_COMPILER "-xgcc${_boost_COMPILER_VERSION}") - else() - # In Boost <= 1.35.0, there is no mangled compiler name for - # the Mac OS X/Darwin version of GCC. - set(_boost_COMPILER "") - endif() - else() - # We don't know the Boost version, so assume it's - # pre-1.36.0. - set(_boost_COMPILER "") - endif() - else() - set(_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}") - endif() - endif() - endif () - else() - # TODO at least Boost_DEBUG here? - set(_boost_COMPILER "") - endif() - set(${_ret} ${_boost_COMPILER} PARENT_SCOPE) -endfunction() - -# -# Get component dependencies. Requires the dependencies to have been -# defined for the Boost release version. -# -# component - the component to check -# _ret - list of library dependencies -# -function(_Boost_COMPONENT_DEPENDENCIES component _ret) - # Note: to add a new Boost release, run - # - # % cmake -DBOOST_DIR=/path/to/boost/source -P Utilities/Scripts/BoostScanDeps.cmake - # - # The output may be added in a new block below. If it's the same as - # the previous release, simply update the version range of the block - # for the previous release. Also check if any new components have - # been added, and add any new components to - # _Boost_COMPONENT_HEADERS. - # - # This information was originally generated by running - # BoostScanDeps.cmake against every boost release to date supported - # by FindBoost: - # - # % for version in /path/to/boost/sources/* - # do - # cmake -DBOOST_DIR=$version -P Utilities/Scripts/BoostScanDeps.cmake - # done - # - # The output was then updated by search and replace with these regexes: - # - # - Strip message(STATUS) prefix dashes - # s;^-- ;; - # - Indent - # s;^set(; set(;; - # - Add conditionals - # s;Scanning /path/to/boost/sources/boost_\(.*\)_\(.*\)_\(.*); elseif(NOT Boost_VERSION VERSION_LESS \10\20\3 AND Boost_VERSION VERSION_LESS xxxx); - # - # This results in the logic seen below, but will require the xxxx - # replacing with the following Boost release version (or the next - # minor version to be released, e.g. 1.59 was the latest at the time - # of writing, making 1.60 the next, so 106000 is the needed version - # number). Identical consecutive releases were then merged together - # by updating the end range of the first block and removing the - # following redundant blocks. - # - # Running the script against all historical releases should be - # required only if the BoostScanDeps.cmake script logic is changed. - # The addition of a new release should only require it to be run - # against the new release. - set(_Boost_IMPORTED_TARGETS TRUE) - if(NOT Boost_VERSION VERSION_LESS 103300 AND Boost_VERSION VERSION_LESS 103500) - set(_Boost_IOSTREAMS_DEPENDENCIES regex thread) - set(_Boost_REGEX_DEPENDENCIES thread) - set(_Boost_WAVE_DEPENDENCIES filesystem thread) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 103500 AND Boost_VERSION VERSION_LESS 103600) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_WAVE_DEPENDENCIES filesystem system thread) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 103600 AND Boost_VERSION VERSION_LESS 103800) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_WAVE_DEPENDENCIES filesystem system thread) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 103800 AND Boost_VERSION VERSION_LESS 104300) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_THREAD_DEPENDENCIES date_time) - set(_Boost_WAVE_DEPENDENCIES filesystem system thread date_time) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 104300 AND Boost_VERSION VERSION_LESS 104400) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_THREAD_DEPENDENCIES date_time) - set(_Boost_WAVE_DEPENDENCIES filesystem system thread date_time) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 104400 AND Boost_VERSION VERSION_LESS 104500) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random serialization) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_THREAD_DEPENDENCIES date_time) - set(_Boost_WAVE_DEPENDENCIES serialization filesystem system thread date_time) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 104500 AND Boost_VERSION VERSION_LESS 104700) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_THREAD_DEPENDENCIES date_time) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread date_time) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 104700 AND Boost_VERSION VERSION_LESS 104800) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_THREAD_DEPENDENCIES date_time) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread date_time) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 104800 AND Boost_VERSION VERSION_LESS 105000) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l random) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_THREAD_DEPENDENCIES date_time) - set(_Boost_TIMER_DEPENDENCIES chrono system) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread date_time) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 105000 AND Boost_VERSION VERSION_LESS 105300) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_THREAD_DEPENDENCIES chrono system date_time) - set(_Boost_TIMER_DEPENDENCIES chrono system) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 105300 AND Boost_VERSION VERSION_LESS 105400) - set(_Boost_ATOMIC_DEPENDENCIES thread chrono system date_time) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic) - set(_Boost_TIMER_DEPENDENCIES chrono system) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 105400 AND Boost_VERSION VERSION_LESS 105500) - set(_Boost_ATOMIC_DEPENDENCIES thread chrono system date_time) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic) - set(_Boost_TIMER_DEPENDENCIES chrono system) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 105500 AND Boost_VERSION VERSION_LESS 105600) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_COROUTINE_DEPENDENCIES context system) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l regex random) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic) - set(_Boost_TIMER_DEPENDENCIES chrono system) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 105600 AND Boost_VERSION VERSION_LESS 105900) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_COROUTINE_DEPENDENCIES context system) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_RANDOM_DEPENDENCIES system) - set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic) - set(_Boost_TIMER_DEPENDENCIES chrono system) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 105900 AND Boost_VERSION VERSION_LESS 106000) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_COROUTINE_DEPENDENCIES context system) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_LOG_DEPENDENCIES log_setup date_time system filesystem thread regex chrono atomic) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_RANDOM_DEPENDENCIES system) - set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic) - set(_Boost_TIMER_DEPENDENCIES chrono system) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 106000 AND Boost_VERSION VERSION_LESS 106100) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_COROUTINE_DEPENDENCIES context system) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_RANDOM_DEPENDENCIES system) - set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic) - set(_Boost_TIMER_DEPENDENCIES chrono system) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 106100 AND Boost_VERSION VERSION_LESS 106200) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_CONTEXT_DEPENDENCIES thread chrono system date_time) - set(_Boost_COROUTINE_DEPENDENCIES context system) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_RANDOM_DEPENDENCIES system) - set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 106200 AND Boost_VERSION VERSION_LESS 106300) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_CONTEXT_DEPENDENCIES thread chrono system date_time) - set(_Boost_COROUTINE_DEPENDENCIES context system) - set(_Boost_FIBER_DEPENDENCIES context thread chrono system date_time) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_RANDOM_DEPENDENCIES system) - set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - elseif(NOT Boost_VERSION VERSION_LESS 106300 AND Boost_VERSION VERSION_LESS 106500) - set(_Boost_CHRONO_DEPENDENCIES system) - set(_Boost_CONTEXT_DEPENDENCIES thread chrono system date_time) - set(_Boost_COROUTINE_DEPENDENCIES context system) - set(_Boost_COROUTINE2_DEPENDENCIES context fiber thread chrono system date_time) - set(_Boost_FIBER_DEPENDENCIES context thread chrono system date_time) - set(_Boost_FILESYSTEM_DEPENDENCIES system) - set(_Boost_IOSTREAMS_DEPENDENCIES regex) - set(_Boost_LOG_DEPENDENCIES date_time log_setup system filesystem thread regex chrono atomic) - set(_Boost_MATH_DEPENDENCIES math_c99 math_c99f math_c99l math_tr1 math_tr1f math_tr1l atomic) - set(_Boost_MPI_DEPENDENCIES serialization) - set(_Boost_MPI_PYTHON_DEPENDENCIES python mpi serialization) - set(_Boost_RANDOM_DEPENDENCIES system) - set(_Boost_THREAD_DEPENDENCIES chrono system date_time atomic) - set(_Boost_WAVE_DEPENDENCIES filesystem system serialization thread chrono date_time atomic) - set(_Boost_WSERIALIZATION_DEPENDENCIES serialization) - else() - message(WARNING "Imported targets not available for Boost version ${Boost_VERSION}") - set(_Boost_IMPORTED_TARGETS FALSE) - endif() - - string(TOUPPER ${component} uppercomponent) - set(${_ret} ${_Boost_${uppercomponent}_DEPENDENCIES} PARENT_SCOPE) - set(_Boost_IMPORTED_TARGETS ${_Boost_IMPORTED_TARGETS} PARENT_SCOPE) - - string(REGEX REPLACE ";" " " _boost_DEPS_STRING "${_Boost_${uppercomponent}_DEPENDENCIES}") - if (NOT _boost_DEPS_STRING) - set(_boost_DEPS_STRING "(none)") - endif() - # message(STATUS "Dependencies for Boost::${component}: ${_boost_DEPS_STRING}") -endfunction() - -# -# Get component headers. This is the primary header (or headers) for -# a given component, and is used to check that the headers are present -# as well as the library itself as an extra sanity check of the build -# environment. -# -# component - the component to check -# _hdrs -# -function(_Boost_COMPONENT_HEADERS component _hdrs) - # Note: new boost components will require adding here. The header - # must be present in all versions of Boost providing a library. - set(_Boost_ATOMIC_HEADERS "boost/atomic.hpp") - set(_Boost_CHRONO_HEADERS "boost/chrono.hpp") - set(_Boost_CONTAINER_HEADERS "boost/container/container_fwd.hpp") - set(_Boost_CONTEXT_HEADERS "boost/context/all.hpp") - set(_Boost_COROUTINE_HEADERS "boost/coroutine/all.hpp") - set(_Boost_EXCEPTION_HEADERS "boost/exception/exception.hpp") - set(_Boost_DATE_TIME_HEADERS "boost/date_time/date.hpp") - set(_Boost_FIBER_HEADERS "boost/fiber/all.hpp") - set(_Boost_FILESYSTEM_HEADERS "boost/filesystem/path.hpp") - set(_Boost_GRAPH_HEADERS "boost/graph/adjacency_list.hpp") - set(_Boost_GRAPH_PARALLEL_HEADERS "boost/graph/adjacency_list.hpp") - set(_Boost_IOSTREAMS_HEADERS "boost/iostreams/stream.hpp") - set(_Boost_LOCALE_HEADERS "boost/locale.hpp") - set(_Boost_LOG_HEADERS "boost/log/core.hpp") - set(_Boost_LOG_SETUP_HEADERS "boost/log/detail/setup_config.hpp") - set(_Boost_MATH_HEADERS "boost/math_fwd.hpp") - set(_Boost_MATH_C99_HEADERS "boost/math/tr1.hpp") - set(_Boost_MATH_C99F_HEADERS "boost/math/tr1.hpp") - set(_Boost_MATH_C99L_HEADERS "boost/math/tr1.hpp") - set(_Boost_MATH_TR1_HEADERS "boost/math/tr1.hpp") - set(_Boost_MATH_TR1F_HEADERS "boost/math/tr1.hpp") - set(_Boost_MATH_TR1L_HEADERS "boost/math/tr1.hpp") - set(_Boost_MPI_HEADERS "boost/mpi.hpp") - set(_Boost_MPI_PYTHON_HEADERS "boost/mpi/python/config.hpp") - set(_Boost_PRG_EXEC_MONITOR_HEADERS "boost/test/prg_exec_monitor.hpp") - set(_Boost_PROGRAM_OPTIONS_HEADERS "boost/program_options.hpp") - set(_Boost_PYTHON_HEADERS "boost/python.hpp") - set(_Boost_RANDOM_HEADERS "boost/random.hpp") - set(_Boost_REGEX_HEADERS "boost/regex.hpp") - set(_Boost_SERIALIZATION_HEADERS "boost/serialization/serialization.hpp") - set(_Boost_SIGNALS_HEADERS "boost/signals.hpp") - set(_Boost_SYSTEM_HEADERS "boost/system/config.hpp") - set(_Boost_TEST_EXEC_MONITOR_HEADERS "boost/test/test_exec_monitor.hpp") - set(_Boost_THREAD_HEADERS "boost/thread.hpp") - set(_Boost_TIMER_HEADERS "boost/timer.hpp") - set(_Boost_TYPE_ERASURE_HEADERS "boost/type_erasure/config.hpp") - set(_Boost_UNIT_TEST_FRAMEWORK_HEADERS "boost/test/framework.hpp") - set(_Boost_WAVE_HEADERS "boost/wave.hpp") - set(_Boost_WSERIALIZATION_HEADERS "boost/archive/text_wiarchive.hpp") - if(WIN32) - set(_Boost_BZIP2_HEADERS "boost/iostreams/filter/bzip2.hpp") - set(_Boost_ZLIB_HEADERS "boost/iostreams/filter/zlib.hpp") - endif() - - string(TOUPPER ${component} uppercomponent) - set(${_hdrs} ${_Boost_${uppercomponent}_HEADERS} PARENT_SCOPE) - - string(REGEX REPLACE ";" " " _boost_HDRS_STRING "${_Boost_${uppercomponent}_HEADERS}") - if (NOT _boost_HDRS_STRING) - set(_boost_HDRS_STRING "(none)") - endif() - # message(STATUS "Headers for Boost::${component}: ${_boost_HDRS_STRING}") -endfunction() - -# -# Determine if any missing dependencies require adding to the component list. -# -# Sets _Boost_${COMPONENT}_DEPENDENCIES for each required component, -# plus _Boost_IMPORTED_TARGETS (TRUE if imported targets should be -# defined; FALSE if dependency information is unavailable). -# -# componentvar - the component list variable name -# extravar - the indirect dependency list variable name -# -# -function(_Boost_MISSING_DEPENDENCIES componentvar extravar) - # _boost_unprocessed_components - list of components requiring processing - # _boost_processed_components - components already processed (or currently being processed) - # _boost_new_components - new components discovered for future processing - # - list(APPEND _boost_unprocessed_components ${${componentvar}}) - - while(_boost_unprocessed_components) - list(APPEND _boost_processed_components ${_boost_unprocessed_components}) - foreach(component ${_boost_unprocessed_components}) - string(TOUPPER ${component} uppercomponent) - set(${_ret} ${_Boost_${uppercomponent}_DEPENDENCIES} PARENT_SCOPE) - _Boost_COMPONENT_DEPENDENCIES("${component}" _Boost_${uppercomponent}_DEPENDENCIES) - set(_Boost_${uppercomponent}_DEPENDENCIES ${_Boost_${uppercomponent}_DEPENDENCIES} PARENT_SCOPE) - set(_Boost_IMPORTED_TARGETS ${_Boost_IMPORTED_TARGETS} PARENT_SCOPE) - foreach(componentdep ${_Boost_${uppercomponent}_DEPENDENCIES}) - list(FIND _boost_processed_components "${componentdep}" _boost_component_found) - list(FIND _boost_new_components "${componentdep}" _boost_component_new) - if (_boost_component_found EQUAL -1 AND _boost_component_new EQUAL -1) - list(APPEND _boost_new_components ${componentdep}) - endif() - endforeach() - endforeach() - set(_boost_unprocessed_components ${_boost_new_components}) - unset(_boost_new_components) - endwhile() - set(_boost_extra_components ${_boost_processed_components}) - if(_boost_extra_components AND ${componentvar}) - list(REMOVE_ITEM _boost_extra_components ${${componentvar}}) - endif() - set(${componentvar} ${_boost_processed_components} PARENT_SCOPE) - set(${extravar} ${_boost_extra_components} PARENT_SCOPE) -endfunction() - -# -# Update library search directory hint variable with paths used by prebuilt boost binaries. -# -# Prebuilt windows binaries (https://sourceforge.net/projects/boost/files/boost-binaries/) -# have library directories named using MSVC compiler version and architecture. -# This function would append corresponding directories if MSVC is a current compiler, -# so having `BOOST_ROOT` would be enough to specify to find everything. -# -function(_Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS componentlibvar basedir) - if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC") - if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(_arch_suffix 64) - else() - set(_arch_suffix 32) - endif() - if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.10) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.1) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-14.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-12.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 17) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-11.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 16) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-10.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 15) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-9.0) - elseif(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 14) - list(APPEND ${componentlibvar} ${basedir}/lib${_arch_suffix}-msvc-8.0) - endif() - set(${componentlibvar} ${${componentlibvar}} PARENT_SCOPE) - endif() -endfunction() - -# -# End functions/macros -# -#------------------------------------------------------------------------------- - -#------------------------------------------------------------------------------- -# main. -#------------------------------------------------------------------------------- - - -# If the user sets Boost_LIBRARY_DIR, use it as the default for both -# configurations. -if(NOT Boost_LIBRARY_DIR_RELEASE AND Boost_LIBRARY_DIR) - set(Boost_LIBRARY_DIR_RELEASE "${Boost_LIBRARY_DIR}") -endif() -if(NOT Boost_LIBRARY_DIR_DEBUG AND Boost_LIBRARY_DIR) - set(Boost_LIBRARY_DIR_DEBUG "${Boost_LIBRARY_DIR}") -endif() - -if(NOT DEFINED Boost_USE_MULTITHREADED) - set(Boost_USE_MULTITHREADED TRUE) -endif() -if(NOT DEFINED Boost_USE_DEBUG_RUNTIME) - set(Boost_USE_DEBUG_RUNTIME TRUE) -endif() - -# Check the version of Boost against the requested version. -if(Boost_FIND_VERSION AND NOT Boost_FIND_VERSION_MINOR) - message(SEND_ERROR "When requesting a specific version of Boost, you must provide at least the major and minor version numbers, e.g., 1.34") -endif() - -if(Boost_FIND_VERSION_EXACT) - # The version may appear in a directory with or without the patch - # level, even when the patch level is non-zero. - set(_boost_TEST_VERSIONS - "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}.${Boost_FIND_VERSION_PATCH}" - "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}") -else() - # The user has not requested an exact version. Among known - # versions, find those that are acceptable to the user request. - # - # Note: When adding a new Boost release, also update the dependency - # information in _Boost_COMPONENT_DEPENDENCIES and - # _Boost_COMPONENT_HEADERS. See the instructions at the top of - # _Boost_COMPONENT_DEPENDENCIES. - set(_Boost_KNOWN_VERSIONS ${Boost_ADDITIONAL_VERSIONS} - "1.64.0" "1.64" "1.63.0" "1.63" "1.62.0" "1.62" "1.61.0" "1.61" "1.60.0" "1.60" - "1.59.0" "1.59" "1.58.0" "1.58" "1.57.0" "1.57" "1.56.0" "1.56" "1.55.0" "1.55" - "1.54.0" "1.54" "1.53.0" "1.53" "1.52.0" "1.52" "1.51.0" "1.51" - "1.50.0" "1.50" "1.49.0" "1.49" "1.48.0" "1.48" "1.47.0" "1.47" "1.46.1" - "1.46.0" "1.46" "1.45.0" "1.45" "1.44.0" "1.44" "1.43.0" "1.43" "1.42.0" "1.42" - "1.41.0" "1.41" "1.40.0" "1.40" "1.39.0" "1.39" "1.38.0" "1.38" "1.37.0" "1.37" - "1.36.1" "1.36.0" "1.36" "1.35.1" "1.35.0" "1.35" "1.34.1" "1.34.0" - "1.34" "1.33.1" "1.33.0" "1.33") - - set(_boost_TEST_VERSIONS) - if(Boost_FIND_VERSION) - set(_Boost_FIND_VERSION_SHORT "${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}") - # Select acceptable versions. - foreach(version ${_Boost_KNOWN_VERSIONS}) - if(NOT "${version}" VERSION_LESS "${Boost_FIND_VERSION}") - # This version is high enough. - list(APPEND _boost_TEST_VERSIONS "${version}") - elseif("${version}.99" VERSION_EQUAL "${_Boost_FIND_VERSION_SHORT}.99") - # This version is a short-form for the requested version with - # the patch level dropped. - list(APPEND _boost_TEST_VERSIONS "${version}") - endif() - endforeach() - else() - # Any version is acceptable. - set(_boost_TEST_VERSIONS "${_Boost_KNOWN_VERSIONS}") - endif() -endif() - -# The reason that we failed to find Boost. This will be set to a -# user-friendly message when we fail to find some necessary piece of -# Boost. -set(Boost_ERROR_REASON) - -if(Boost_DEBUG) - # Output some of their choices - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Boost_USE_MULTITHREADED = ${Boost_USE_MULTITHREADED}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Boost_USE_STATIC_LIBS = ${Boost_USE_STATIC_LIBS}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Boost_USE_STATIC_RUNTIME = ${Boost_USE_STATIC_RUNTIME}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Boost_ADDITIONAL_VERSIONS = ${Boost_ADDITIONAL_VERSIONS}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Boost_NO_SYSTEM_PATHS = ${Boost_NO_SYSTEM_PATHS}") -endif() - -# Supply Boost_LIB_DIAGNOSTIC_DEFINITIONS as a convenience target. It -# will only contain any interface definitions on WIN32, but is created -# on all platforms to keep end user code free from platform dependent -# code. Also provide convenience targets to disable autolinking and -# enable dynamic linking. -if(NOT TARGET Boost::diagnostic_definitions) - add_library(Boost::diagnostic_definitions INTERFACE IMPORTED) - add_library(Boost::disable_autolinking INTERFACE IMPORTED) - add_library(Boost::dynamic_linking INTERFACE IMPORTED) -endif() -if(WIN32) - # In windows, automatic linking is performed, so you do not have - # to specify the libraries. If you are linking to a dynamic - # runtime, then you can choose to link to either a static or a - # dynamic Boost library, the default is to do a static link. You - # can alter this for a specific library "whatever" by defining - # BOOST_WHATEVER_DYN_LINK to force Boost library "whatever" to be - # linked dynamically. Alternatively you can force all Boost - # libraries to dynamic link by defining BOOST_ALL_DYN_LINK. - - # This feature can be disabled for Boost library "whatever" by - # defining BOOST_WHATEVER_NO_LIB, or for all of Boost by defining - # BOOST_ALL_NO_LIB. - - # If you want to observe which libraries are being linked against - # then defining BOOST_LIB_DIAGNOSTIC will cause the auto-linking - # code to emit a #pragma message each time a library is selected - # for linking. - set(Boost_LIB_DIAGNOSTIC_DEFINITIONS "-DBOOST_LIB_DIAGNOSTIC") - set_target_properties(Boost::diagnostic_definitions PROPERTIES - INTERFACE_COMPILE_DEFINITIONS "BOOST_LIB_DIAGNOSTIC") - set_target_properties(Boost::disable_autolinking PROPERTIES - INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_NO_LIB") - set_target_properties(Boost::dynamic_linking PROPERTIES - INTERFACE_COMPILE_DEFINITIONS "BOOST_ALL_DYN_LINK") -endif() - -_Boost_CHECK_SPELLING(Boost_ROOT) -_Boost_CHECK_SPELLING(Boost_LIBRARYDIR) -_Boost_CHECK_SPELLING(Boost_INCLUDEDIR) - -# Collect environment variable inputs as hints. Do not consider changes. -foreach(v BOOSTROOT BOOST_ROOT BOOST_INCLUDEDIR BOOST_LIBRARYDIR) - set(_env $ENV{${v}}) - if(_env) - file(TO_CMAKE_PATH "${_env}" _ENV_${v}) - else() - set(_ENV_${v} "") - endif() -endforeach() -if(NOT _ENV_BOOST_ROOT AND _ENV_BOOSTROOT) - set(_ENV_BOOST_ROOT "${_ENV_BOOSTROOT}") -endif() - -# Collect inputs and cached results. Detect changes since the last run. -if(NOT BOOST_ROOT AND BOOSTROOT) - set(BOOST_ROOT "${BOOSTROOT}") -endif() -set(_Boost_VARS_DIR - BOOST_ROOT - Boost_NO_SYSTEM_PATHS - ) - -if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Declared as CMake or Environmental Variables:") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " BOOST_ROOT = ${BOOST_ROOT}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " BOOST_INCLUDEDIR = ${BOOST_INCLUDEDIR}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " BOOST_LIBRARYDIR = ${BOOST_LIBRARYDIR}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_TEST_VERSIONS = ${_boost_TEST_VERSIONS}") -endif() - -# ------------------------------------------------------------------------ -# Search for Boost include DIR -# ------------------------------------------------------------------------ - -set(_Boost_VARS_INC BOOST_INCLUDEDIR Boost_INCLUDE_DIR Boost_ADDITIONAL_VERSIONS) -_Boost_CHANGE_DETECT(_Boost_CHANGE_INCDIR ${_Boost_VARS_DIR} ${_Boost_VARS_INC}) -# Clear Boost_INCLUDE_DIR if it did not change but other input affecting the -# location did. We will find a new one based on the new inputs. -if(_Boost_CHANGE_INCDIR AND NOT _Boost_INCLUDE_DIR_CHANGED) - unset(Boost_INCLUDE_DIR CACHE) -endif() - -if(NOT Boost_INCLUDE_DIR) - set(_boost_INCLUDE_SEARCH_DIRS "") - if(BOOST_INCLUDEDIR) - list(APPEND _boost_INCLUDE_SEARCH_DIRS ${BOOST_INCLUDEDIR}) - elseif(_ENV_BOOST_INCLUDEDIR) - list(APPEND _boost_INCLUDE_SEARCH_DIRS ${_ENV_BOOST_INCLUDEDIR}) - endif() - - if( BOOST_ROOT ) - list(APPEND _boost_INCLUDE_SEARCH_DIRS ${BOOST_ROOT}/include ${BOOST_ROOT}) - elseif( _ENV_BOOST_ROOT ) - list(APPEND _boost_INCLUDE_SEARCH_DIRS ${_ENV_BOOST_ROOT}/include ${_ENV_BOOST_ROOT}) - endif() - - if( Boost_NO_SYSTEM_PATHS) - list(APPEND _boost_INCLUDE_SEARCH_DIRS NO_CMAKE_SYSTEM_PATH NO_SYSTEM_ENVIRONMENT_PATH) - else() - if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC") - foreach(ver ${_Boost_KNOWN_VERSIONS}) - string(REPLACE "." "_" ver "${ver}") - list(APPEND _boost_INCLUDE_SEARCH_DIRS PATHS "C:/local/boost_${ver}") - endforeach() - endif() - list(APPEND _boost_INCLUDE_SEARCH_DIRS PATHS - C:/boost/include - C:/boost - /sw/local/include - ) - endif() - - # Try to find Boost by stepping backwards through the Boost versions - # we know about. - # Build a list of path suffixes for each version. - set(_boost_PATH_SUFFIXES) - foreach(_boost_VER ${_boost_TEST_VERSIONS}) - # Add in a path suffix, based on the required version, ideally - # we could read this from version.hpp, but for that to work we'd - # need to know the include dir already - set(_boost_BOOSTIFIED_VERSION) - - # Transform 1.35 => 1_35 and 1.36.0 => 1_36_0 - if(_boost_VER MATCHES "([0-9]+)\\.([0-9]+)\\.([0-9]+)") - set(_boost_BOOSTIFIED_VERSION - "${CMAKE_MATCH_1}_${CMAKE_MATCH_2}_${CMAKE_MATCH_3}") - elseif(_boost_VER MATCHES "([0-9]+)\\.([0-9]+)") - set(_boost_BOOSTIFIED_VERSION - "${CMAKE_MATCH_1}_${CMAKE_MATCH_2}") - endif() - - list(APPEND _boost_PATH_SUFFIXES - "boost-${_boost_BOOSTIFIED_VERSION}" - "boost_${_boost_BOOSTIFIED_VERSION}" - "boost/boost-${_boost_BOOSTIFIED_VERSION}" - "boost/boost_${_boost_BOOSTIFIED_VERSION}" - ) - - endforeach() - - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Include debugging info:") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " _boost_INCLUDE_SEARCH_DIRS = ${_boost_INCLUDE_SEARCH_DIRS}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - " _boost_PATH_SUFFIXES = ${_boost_PATH_SUFFIXES}") - endif() - - # Look for a standard boost header file. - find_path(Boost_INCLUDE_DIR - NAMES boost/config.hpp - HINTS ${_boost_INCLUDE_SEARCH_DIRS} - PATH_SUFFIXES ${_boost_PATH_SUFFIXES} - ) -endif() - -# ------------------------------------------------------------------------ -# Extract version information from version.hpp -# ------------------------------------------------------------------------ - -# Set Boost_FOUND based only on header location and version. -# It will be updated below for component libraries. -if(Boost_INCLUDE_DIR) - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "location of version.hpp: ${Boost_INCLUDE_DIR}/boost/version.hpp") - endif() - - # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp - set(Boost_VERSION 0) - set(Boost_LIB_VERSION "") - file(STRINGS "${Boost_INCLUDE_DIR}/boost/version.hpp" _boost_VERSION_HPP_CONTENTS REGEX "#define BOOST_(LIB_)?VERSION ") - set(_Boost_VERSION_REGEX "([0-9]+)") - set(_Boost_LIB_VERSION_REGEX "\"([0-9_]+)\"") - foreach(v VERSION LIB_VERSION) - if("${_boost_VERSION_HPP_CONTENTS}" MATCHES "#define BOOST_${v} ${_Boost_${v}_REGEX}") - set(Boost_${v} "${CMAKE_MATCH_1}") - endif() - endforeach() - unset(_boost_VERSION_HPP_CONTENTS) - - math(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000") - math(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000") - math(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100") - - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} - "Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}\nBoost include path: ${Boost_INCLUDE_DIR}") - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "version.hpp reveals boost " - "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") - endif() - - if(Boost_FIND_VERSION) - # Set Boost_FOUND based on requested version. - set(_Boost_VERSION "${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") - if("${_Boost_VERSION}" VERSION_LESS "${Boost_FIND_VERSION}") - set(Boost_FOUND 0) - set(_Boost_VERSION_AGE "old") - elseif(Boost_FIND_VERSION_EXACT AND - NOT "${_Boost_VERSION}" VERSION_EQUAL "${Boost_FIND_VERSION}") - set(Boost_FOUND 0) - set(_Boost_VERSION_AGE "new") - else() - set(Boost_FOUND 1) - endif() - if(NOT Boost_FOUND) - # State that we found a version of Boost that is too new or too old. - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} - "\nDetected version of Boost is too ${_Boost_VERSION_AGE}. Requested version was ${Boost_FIND_VERSION_MAJOR}.${Boost_FIND_VERSION_MINOR}") - if (Boost_FIND_VERSION_PATCH) - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} - ".${Boost_FIND_VERSION_PATCH}") - endif () - if (NOT Boost_FIND_VERSION_EXACT) - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} " (or newer)") - endif () - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} ".") - endif () - else() - # Caller will accept any Boost version. - set(Boost_FOUND 1) - endif() -else() - set(Boost_FOUND 0) - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} - "Unable to find the Boost header files. Please set BOOST_ROOT to the root directory containing Boost or BOOST_INCLUDEDIR to the directory containing Boost's headers.") -endif() - -# ------------------------------------------------------------------------ -# Prefix initialization -# ------------------------------------------------------------------------ - -set(Boost_LIB_PREFIX "") -if ( (GHSMULTI AND Boost_USE_STATIC_LIBS) OR - (WIN32 AND Boost_USE_STATIC_LIBS AND NOT CYGWIN) ) - set(Boost_LIB_PREFIX "lib") -endif() - -if ( NOT Boost_NAMESPACE ) - set(Boost_NAMESPACE "boost") -endif() - -# ------------------------------------------------------------------------ -# Suffix initialization and compiler suffix detection. -# ------------------------------------------------------------------------ - -set(_Boost_VARS_NAME - Boost_NAMESPACE - Boost_COMPILER - Boost_THREADAPI - Boost_USE_DEBUG_PYTHON - Boost_USE_MULTITHREADED - Boost_USE_STATIC_LIBS - Boost_USE_STATIC_RUNTIME - Boost_USE_STLPORT - Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS - ) -_Boost_CHANGE_DETECT(_Boost_CHANGE_LIBNAME ${_Boost_VARS_NAME}) - -# Setting some more suffixes for the library -if (Boost_COMPILER) - set(_boost_COMPILER ${Boost_COMPILER}) - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "using user-specified Boost_COMPILER = ${_boost_COMPILER}") - endif() -else() - # Attempt to guess the compiler suffix - # NOTE: this is not perfect yet, if you experience any issues - # please report them and use the Boost_COMPILER variable - # to work around the problems. - _Boost_GUESS_COMPILER_PREFIX(_boost_COMPILER) - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "guessed _boost_COMPILER = ${_boost_COMPILER}") - endif() -endif() - -set (_boost_MULTITHREADED "-mt") -if( NOT Boost_USE_MULTITHREADED ) - set (_boost_MULTITHREADED "") -endif() -if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_MULTITHREADED = ${_boost_MULTITHREADED}") -endif() - -#====================== -# Systematically build up the Boost ABI tag -# http://boost.org/doc/libs/1_41_0/more/getting_started/windows.html#library-naming -set( _boost_RELEASE_ABI_TAG "-") -set( _boost_DEBUG_ABI_TAG "-") -# Key Use this library when: -# s linking statically to the C++ standard library and -# compiler runtime support libraries. -if(Boost_USE_STATIC_RUNTIME) - set( _boost_RELEASE_ABI_TAG "${_boost_RELEASE_ABI_TAG}s") - set( _boost_DEBUG_ABI_TAG "${_boost_DEBUG_ABI_TAG}s") -endif() -# g using debug versions of the standard and runtime -# support libraries -if(WIN32 AND Boost_USE_DEBUG_RUNTIME) - if("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC" - OR "${CMAKE_CXX_COMPILER}" MATCHES "icl" - OR "${CMAKE_CXX_COMPILER}" MATCHES "icpc") - string(CONCAT _boost_DEBUG_ABI_TAG ${_boost_DEBUG_ABI_TAG} "g") - endif() -endif() -# y using special debug build of python -if(Boost_USE_DEBUG_PYTHON) - string(CONCAT _boost_DEBUG_ABI_TAG ${_boost_DEBUG_ABI_TAG} "y") -endif() -# d using a debug version of your code -string(CONCAT _boost_DEBUG_ABI_TAG ${_boost_DEBUG_ABI_TAG} "d") -# p using the STLport standard library rather than the -# default one supplied with your compiler -if(Boost_USE_STLPORT) - string(CONCAT _boost_RELEASE_ABI_TAG ${_boost_RELEASE_ABI_TAG} "p") - string(CONCAT _boost_DEBUG_ABI_TAG ${_boost_DEBUG_ABI_TAG} "p") -endif() -# n using the STLport deprecated "native iostreams" feature -if(Boost_USE_STLPORT_DEPRECATED_NATIVE_IOSTREAMS) - string(CONCAT _boost_RELEASE_ABI_TAG ${_boost_RELEASE_ABI_TAG} "n") - string(CONCAT _boost_DEBUG_ABI_TAG ${_boost_DEBUG_ABI_TAG} "n") -endif() - -if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_RELEASE_ABI_TAG = ${_boost_RELEASE_ABI_TAG}") - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_DEBUG_ABI_TAG = ${_boost_DEBUG_ABI_TAG}") -endif() - -# ------------------------------------------------------------------------ -# Begin finding boost libraries -# ------------------------------------------------------------------------ - -set(_Boost_VARS_LIB "") -foreach(c DEBUG RELEASE) - set(_Boost_VARS_LIB_${c} BOOST_LIBRARYDIR Boost_LIBRARY_DIR_${c}) - list(APPEND _Boost_VARS_LIB ${_Boost_VARS_LIB_${c}}) - _Boost_CHANGE_DETECT(_Boost_CHANGE_LIBDIR_${c} ${_Boost_VARS_DIR} ${_Boost_VARS_LIB_${c}} Boost_INCLUDE_DIR) - # Clear Boost_LIBRARY_DIR_${c} if it did not change but other input affecting the - # location did. We will find a new one based on the new inputs. - if(_Boost_CHANGE_LIBDIR_${c} AND NOT _Boost_LIBRARY_DIR_${c}_CHANGED) - unset(Boost_LIBRARY_DIR_${c} CACHE) - endif() - - # If Boost_LIBRARY_DIR_[RELEASE,DEBUG] is set, prefer its value. - if(Boost_LIBRARY_DIR_${c}) - set(_boost_LIBRARY_SEARCH_DIRS_${c} ${Boost_LIBRARY_DIR_${c}} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH) - else() - set(_boost_LIBRARY_SEARCH_DIRS_${c} "") - if(BOOST_LIBRARYDIR) - list(APPEND _boost_LIBRARY_SEARCH_DIRS_${c} ${BOOST_LIBRARYDIR}) - elseif(_ENV_BOOST_LIBRARYDIR) - list(APPEND _boost_LIBRARY_SEARCH_DIRS_${c} ${_ENV_BOOST_LIBRARYDIR}) - endif() - - if(BOOST_ROOT) - list(APPEND _boost_LIBRARY_SEARCH_DIRS_${c} ${BOOST_ROOT}/lib ${BOOST_ROOT}/stage/lib) - _Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS(_boost_LIBRARY_SEARCH_DIRS_${c} "${BOOST_ROOT}") - elseif(_ENV_BOOST_ROOT) - list(APPEND _boost_LIBRARY_SEARCH_DIRS_${c} ${_ENV_BOOST_ROOT}/lib ${_ENV_BOOST_ROOT}/stage/lib) - _Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS(_boost_LIBRARY_SEARCH_DIRS_${c} "${_ENV_BOOST_ROOT}") - endif() - - list(APPEND _boost_LIBRARY_SEARCH_DIRS_${c} - ${Boost_INCLUDE_DIR}/lib - ${Boost_INCLUDE_DIR}/../lib - ${Boost_INCLUDE_DIR}/stage/lib - ) - _Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS(_boost_LIBRARY_SEARCH_DIRS_${c} "${Boost_INCLUDE_DIR}/..") - if( Boost_NO_SYSTEM_PATHS ) - list(APPEND _boost_LIBRARY_SEARCH_DIRS_${c} NO_CMAKE_SYSTEM_PATH NO_SYSTEM_ENVIRONMENT_PATH) - else() - foreach(ver ${_Boost_KNOWN_VERSIONS}) - string(REPLACE "." "_" ver "${ver}") - _Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS(_boost_LIBRARY_SEARCH_DIRS_${c} "C:/local/boost_${ver}") - endforeach() - _Boost_UPDATE_WINDOWS_LIBRARY_SEARCH_DIRS_WITH_PREBUILT_PATHS(_boost_LIBRARY_SEARCH_DIRS_${c} "C:/boost") - list(APPEND _boost_LIBRARY_SEARCH_DIRS_${c} PATHS - C:/boost/lib - C:/boost - /sw/local/lib - ) - endif() - endif() -endforeach() - -if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "_boost_LIBRARY_SEARCH_DIRS_RELEASE = ${_boost_LIBRARY_SEARCH_DIRS_RELEASE}" - "_boost_LIBRARY_SEARCH_DIRS_DEBUG = ${_boost_LIBRARY_SEARCH_DIRS_DEBUG}") -endif() - -# Support preference of static libs by adjusting CMAKE_FIND_LIBRARY_SUFFIXES -if( Boost_USE_STATIC_LIBS ) - set( _boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - if(WIN32) - list(INSERT CMAKE_FIND_LIBRARY_SUFFIXES 0 .lib .a) - else() - set(CMAKE_FIND_LIBRARY_SUFFIXES .a) - endif() -endif() - -# We want to use the tag inline below without risking double dashes -if(_boost_RELEASE_ABI_TAG) - if(${_boost_RELEASE_ABI_TAG} STREQUAL "-") - set(_boost_RELEASE_ABI_TAG "") - endif() -endif() -if(_boost_DEBUG_ABI_TAG) - if(${_boost_DEBUG_ABI_TAG} STREQUAL "-") - set(_boost_DEBUG_ABI_TAG "") - endif() -endif() - -# The previous behavior of FindBoost when Boost_USE_STATIC_LIBS was enabled -# on WIN32 was to: -# 1. Search for static libs compiled against a SHARED C++ standard runtime library (use if found) -# 2. Search for static libs compiled against a STATIC C++ standard runtime library (use if found) -# We maintain this behavior since changing it could break people's builds. -# To disable the ambiguous behavior, the user need only -# set Boost_USE_STATIC_RUNTIME either ON or OFF. -set(_boost_STATIC_RUNTIME_WORKAROUND false) -if(WIN32 AND Boost_USE_STATIC_LIBS) - if(NOT DEFINED Boost_USE_STATIC_RUNTIME) - set(_boost_STATIC_RUNTIME_WORKAROUND TRUE) - endif() -endif() - -# On versions < 1.35, remove the System library from the considered list -# since it wasn't added until 1.35. -if(Boost_VERSION AND Boost_FIND_COMPONENTS) - if(Boost_VERSION LESS 103500) - list(REMOVE_ITEM Boost_FIND_COMPONENTS system) - endif() -endif() - -# Additional components may be required via component dependencies. -# Add any missing components to the list. -_Boost_MISSING_DEPENDENCIES(Boost_FIND_COMPONENTS _Boost_EXTRA_FIND_COMPONENTS) - -# If thread is required, get the thread libs as a dependency -list(FIND Boost_FIND_COMPONENTS thread _Boost_THREAD_DEPENDENCY_LIBS) -if(NOT _Boost_THREAD_DEPENDENCY_LIBS EQUAL -1) - include(CMakeFindDependencyMacro) - find_dependency(Threads) -endif() - -# If the user changed any of our control inputs flush previous results. -if(_Boost_CHANGE_LIBDIR_DEBUG OR _Boost_CHANGE_LIBDIR_RELEASE OR _Boost_CHANGE_LIBNAME) - foreach(COMPONENT ${_Boost_COMPONENTS_SEARCHED}) - string(TOUPPER ${COMPONENT} UPPERCOMPONENT) - foreach(c DEBUG RELEASE) - set(_var Boost_${UPPERCOMPONENT}_LIBRARY_${c}) - unset(${_var} CACHE) - set(${_var} "${_var}-NOTFOUND") - endforeach() - endforeach() - set(_Boost_COMPONENTS_SEARCHED "") -endif() - -foreach(COMPONENT ${Boost_FIND_COMPONENTS}) - string(TOUPPER ${COMPONENT} UPPERCOMPONENT) - - set( _boost_docstring_release "Boost ${COMPONENT} library (release)") - set( _boost_docstring_debug "Boost ${COMPONENT} library (debug)") - - # Compute component-specific hints. - set(_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT "") - if(${COMPONENT} STREQUAL "mpi" OR ${COMPONENT} STREQUAL "mpi_python" OR - ${COMPONENT} STREQUAL "graph_parallel") - foreach(lib ${MPI_CXX_LIBRARIES} ${MPI_C_LIBRARIES}) - if(IS_ABSOLUTE "${lib}") - get_filename_component(libdir "${lib}" PATH) - string(REPLACE "\\" "/" libdir "${libdir}") - list(APPEND _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT ${libdir}) - endif() - endforeach() - endif() - - # Consolidate and report component-specific hints. - if(_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT) - list(REMOVE_DUPLICATES _Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT) - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Component-specific library search paths for ${COMPONENT}: " - "${_Boost_FIND_LIBRARY_HINTS_FOR_COMPONENT}") - endif() - endif() - - # - # Find headers - # - _Boost_COMPONENT_HEADERS("${COMPONENT}" Boost_${UPPERCOMPONENT}_HEADER_NAME) - # Look for a standard boost header file. - if(Boost_${UPPERCOMPONENT}_HEADER_NAME) - if(EXISTS "${Boost_INCLUDE_DIR}/${Boost_${UPPERCOMPONENT}_HEADER_NAME}") - set(Boost_${UPPERCOMPONENT}_HEADER ON) - else() - set(Boost_${UPPERCOMPONENT}_HEADER OFF) - endif() - else() - set(Boost_${UPPERCOMPONENT}_HEADER ON) - message(WARNING "No header defined for ${COMPONENT}; skipping header check") - endif() - - # - # Find RELEASE libraries - # - unset(_boost_RELEASE_NAMES) - foreach(compiler IN LISTS _boost_COMPILER) - list(APPEND _boost_RELEASE_NAMES - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} ) - endforeach() - list(APPEND _boost_RELEASE_NAMES - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_ABI_TAG} - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT} ) - if(_boost_STATIC_RUNTIME_WORKAROUND) - set(_boost_RELEASE_STATIC_ABI_TAG "-s${_boost_RELEASE_ABI_TAG}") - foreach(compiler IN LISTS _boost_COMPILER) - list(APPEND _boost_RELEASE_NAMES - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} ) - endforeach() - list(APPEND _boost_RELEASE_NAMES - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_RELEASE_STATIC_ABI_TAG} ) - endif() - if(Boost_THREADAPI AND ${COMPONENT} STREQUAL "thread") - _Boost_PREPEND_LIST_WITH_THREADAPI(_boost_RELEASE_NAMES ${_boost_RELEASE_NAMES}) - endif() - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Searching for ${UPPERCOMPONENT}_LIBRARY_RELEASE: ${_boost_RELEASE_NAMES}") - endif() - - # if Boost_LIBRARY_DIR_RELEASE is not defined, - # but Boost_LIBRARY_DIR_DEBUG is, look there first for RELEASE libs - if(NOT Boost_LIBRARY_DIR_RELEASE AND Boost_LIBRARY_DIR_DEBUG) - list(INSERT _boost_LIBRARY_SEARCH_DIRS_RELEASE 0 ${Boost_LIBRARY_DIR_DEBUG}) - endif() - - # Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing. - string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS_RELEASE}") - - _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE RELEASE - NAMES ${_boost_RELEASE_NAMES} - HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp} - NAMES_PER_DIR - DOC "${_boost_docstring_release}" - ) - - # - # Find DEBUG libraries - # - unset(_boost_DEBUG_NAMES) - foreach(compiler IN LISTS _boost_COMPILER) - list(APPEND _boost_DEBUG_NAMES - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} ) - endforeach() - list(APPEND _boost_DEBUG_NAMES - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_ABI_TAG} - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED} - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT} ) - if(_boost_STATIC_RUNTIME_WORKAROUND) - set(_boost_DEBUG_STATIC_ABI_TAG "-s${_boost_DEBUG_ABI_TAG}") - foreach(compiler IN LISTS _boost_COMPILER) - list(APPEND _boost_DEBUG_NAMES - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${compiler}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} ) - endforeach() - list(APPEND _boost_DEBUG_NAMES - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG}-${Boost_LIB_VERSION} - ${Boost_LIB_PREFIX}${Boost_NAMESPACE}_${COMPONENT}${_boost_MULTITHREADED}${_boost_DEBUG_STATIC_ABI_TAG} ) - endif() - if(Boost_THREADAPI AND ${COMPONENT} STREQUAL "thread") - _Boost_PREPEND_LIST_WITH_THREADAPI(_boost_DEBUG_NAMES ${_boost_DEBUG_NAMES}) - endif() - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] " - "Searching for ${UPPERCOMPONENT}_LIBRARY_DEBUG: ${_boost_DEBUG_NAMES}") - endif() - - # if Boost_LIBRARY_DIR_DEBUG is not defined, - # but Boost_LIBRARY_DIR_RELEASE is, look there first for DEBUG libs - if(NOT Boost_LIBRARY_DIR_DEBUG AND Boost_LIBRARY_DIR_RELEASE) - list(INSERT _boost_LIBRARY_SEARCH_DIRS_DEBUG 0 ${Boost_LIBRARY_DIR_RELEASE}) - endif() - - # Avoid passing backslashes to _Boost_FIND_LIBRARY due to macro re-parsing. - string(REPLACE "\\" "/" _boost_LIBRARY_SEARCH_DIRS_tmp "${_boost_LIBRARY_SEARCH_DIRS_DEBUG}") - - _Boost_FIND_LIBRARY(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG DEBUG - NAMES ${_boost_DEBUG_NAMES} - HINTS ${_boost_LIBRARY_SEARCH_DIRS_tmp} - NAMES_PER_DIR - DOC "${_boost_docstring_debug}" - ) - - if(Boost_REALPATH) - _Boost_SWAP_WITH_REALPATH(Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE "${_boost_docstring_release}") - _Boost_SWAP_WITH_REALPATH(Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG "${_boost_docstring_debug}" ) - endif() - - _Boost_ADJUST_LIB_VARS(${UPPERCOMPONENT}) - -endforeach() - -# Restore the original find library ordering -if( Boost_USE_STATIC_LIBS ) - set(CMAKE_FIND_LIBRARY_SUFFIXES ${_boost_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) -endif() - -# ------------------------------------------------------------------------ -# End finding boost libraries -# ------------------------------------------------------------------------ - -set(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR}) -set(Boost_LIBRARY_DIRS) -if(Boost_LIBRARY_DIR_RELEASE) - list(APPEND Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR_RELEASE}) -endif() -if(Boost_LIBRARY_DIR_DEBUG) - list(APPEND Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR_DEBUG}) -endif() -if(Boost_LIBRARY_DIRS) - list(REMOVE_DUPLICATES Boost_LIBRARY_DIRS) -endif() - -# The above setting of Boost_FOUND was based only on the header files. -# Update it for the requested component libraries. -if(Boost_FOUND) - # The headers were found. Check for requested component libs. - set(_boost_CHECKED_COMPONENT FALSE) - set(_Boost_MISSING_COMPONENTS "") - foreach(COMPONENT ${Boost_FIND_COMPONENTS}) - string(TOUPPER ${COMPONENT} COMPONENT) - set(_boost_CHECKED_COMPONENT TRUE) - if(NOT Boost_${COMPONENT}_FOUND) - string(TOLOWER ${COMPONENT} COMPONENT) - list(APPEND _Boost_MISSING_COMPONENTS ${COMPONENT}) - endif() - endforeach() - if(_Boost_MISSING_COMPONENTS AND _Boost_EXTRA_FIND_COMPONENTS) - # Optional indirect dependencies are not counted as missing. - list(REMOVE_ITEM _Boost_MISSING_COMPONENTS ${_Boost_EXTRA_FIND_COMPONENTS}) - endif() - - if(Boost_DEBUG) - message(STATUS "[ ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE} ] Boost_FOUND = ${Boost_FOUND}") - endif() - - if (_Boost_MISSING_COMPONENTS) - set(Boost_FOUND 0) - # We were unable to find some libraries, so generate a sensible - # error message that lists the libraries we were unable to find. - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} - "\nCould not find the following") - if(Boost_USE_STATIC_LIBS) - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} " static") - endif() - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} - " Boost libraries:\n") - foreach(COMPONENT ${_Boost_MISSING_COMPONENTS}) - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} - " ${Boost_NAMESPACE}_${COMPONENT}\n") - endforeach() - - list(LENGTH Boost_FIND_COMPONENTS Boost_NUM_COMPONENTS_WANTED) - list(LENGTH _Boost_MISSING_COMPONENTS Boost_NUM_MISSING_COMPONENTS) - if (${Boost_NUM_COMPONENTS_WANTED} EQUAL ${Boost_NUM_MISSING_COMPONENTS}) - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} - "No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.") - else () - string(CONCAT Boost_ERROR_REASON ${Boost_ERROR_REASON} - "Some (but not all) of the required Boost libraries were found. You may need to install these additional Boost libraries. Alternatively, set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.") - endif () - endif () - - if( NOT Boost_LIBRARY_DIRS AND NOT _boost_CHECKED_COMPONENT ) - # Compatibility Code for backwards compatibility with CMake - # 2.4's FindBoost module. - - # Look for the boost library path. - # Note that the user may not have installed any libraries - # so it is quite possible the Boost_LIBRARY_DIRS may not exist. - set(_boost_LIB_DIR ${Boost_INCLUDE_DIR}) - - if("${_boost_LIB_DIR}" MATCHES "boost-[0-9]+") - get_filename_component(_boost_LIB_DIR ${_boost_LIB_DIR} PATH) - endif() - - if("${_boost_LIB_DIR}" MATCHES "/include$") - # Strip off the trailing "/include" in the path. - get_filename_component(_boost_LIB_DIR ${_boost_LIB_DIR} PATH) - endif() - - if(EXISTS "${_boost_LIB_DIR}/lib") - string(CONCAT _boost_LIB_DIR ${_boost_LIB_DIR} /lib) - elseif(EXISTS "${_boost_LIB_DIR}/stage/lib") - string(CONCAT _boost_LIB_DIR ${_boost_LIB_DIR} "/stage/lib") - else() - set(_boost_LIB_DIR "") - endif() - - if(_boost_LIB_DIR AND EXISTS "${_boost_LIB_DIR}") - set(Boost_LIBRARY_DIRS ${_boost_LIB_DIR}) - endif() - - endif() -else() - # Boost headers were not found so no components were found. - foreach(COMPONENT ${Boost_FIND_COMPONENTS}) - string(TOUPPER ${COMPONENT} UPPERCOMPONENT) - set(Boost_${UPPERCOMPONENT}_FOUND 0) - endforeach() -endif() - -# ------------------------------------------------------------------------ -# Add imported targets -# ------------------------------------------------------------------------ - -if(Boost_FOUND) - # For header-only libraries - if(NOT TARGET Boost::boost) - add_library(Boost::boost INTERFACE IMPORTED) - if(Boost_INCLUDE_DIRS) - set_target_properties(Boost::boost PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}") - endif() - endif() - - foreach(COMPONENT ${Boost_FIND_COMPONENTS}) - if(_Boost_IMPORTED_TARGETS AND NOT TARGET Boost::${COMPONENT}) - string(TOUPPER ${COMPONENT} UPPERCOMPONENT) - if(Boost_${UPPERCOMPONENT}_FOUND) - if(Boost_USE_STATIC_LIBS) - add_library(Boost::${COMPONENT} STATIC IMPORTED) - else() - # Even if Boost_USE_STATIC_LIBS is OFF, we might have static - # libraries as a result. - add_library(Boost::${COMPONENT} UNKNOWN IMPORTED) - endif() - if(Boost_INCLUDE_DIRS) - set_target_properties(Boost::${COMPONENT} PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${Boost_INCLUDE_DIRS}") - endif() - if(EXISTS "${Boost_${UPPERCOMPONENT}_LIBRARY}") - set_target_properties(Boost::${COMPONENT} PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" - IMPORTED_LOCATION "${Boost_${UPPERCOMPONENT}_LIBRARY}") - endif() - if(EXISTS "${Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE}") - set_property(TARGET Boost::${COMPONENT} APPEND PROPERTY - IMPORTED_CONFIGURATIONS RELEASE) - set_target_properties(Boost::${COMPONENT} PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX" - IMPORTED_LOCATION_RELEASE "${Boost_${UPPERCOMPONENT}_LIBRARY_RELEASE}") - endif() - if(EXISTS "${Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG}") - set_property(TARGET Boost::${COMPONENT} APPEND PROPERTY - IMPORTED_CONFIGURATIONS DEBUG) - set_target_properties(Boost::${COMPONENT} PROPERTIES - IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX" - IMPORTED_LOCATION_DEBUG "${Boost_${UPPERCOMPONENT}_LIBRARY_DEBUG}") - endif() - if(_Boost_${UPPERCOMPONENT}_DEPENDENCIES) - unset(_Boost_${UPPERCOMPONENT}_TARGET_DEPENDENCIES) - foreach(dep ${_Boost_${UPPERCOMPONENT}_DEPENDENCIES}) - list(APPEND _Boost_${UPPERCOMPONENT}_TARGET_DEPENDENCIES Boost::${dep}) - endforeach() - if(COMPONENT STREQUAL "thread") - list(APPEND _Boost_${UPPERCOMPONENT}_TARGET_DEPENDENCIES Threads::Threads) - endif() - set_target_properties(Boost::${COMPONENT} PROPERTIES - INTERFACE_LINK_LIBRARIES "${_Boost_${UPPERCOMPONENT}_TARGET_DEPENDENCIES}") - endif() - endif() - endif() - endforeach() -endif() - -# ------------------------------------------------------------------------ -# Notification to end user about what was found -# ------------------------------------------------------------------------ - -set(Boost_LIBRARIES "") -if(Boost_FOUND) - if(NOT Boost_FIND_QUIETLY) - message(STATUS "Boost version: ${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION}.${Boost_SUBMINOR_VERSION}") - if(Boost_FIND_COMPONENTS) - message(STATUS "Found the following Boost libraries:") - endif() - endif() - foreach( COMPONENT ${Boost_FIND_COMPONENTS} ) - string( TOUPPER ${COMPONENT} UPPERCOMPONENT ) - if( Boost_${UPPERCOMPONENT}_FOUND ) - if(NOT Boost_FIND_QUIETLY) - message (STATUS " ${COMPONENT}") - endif() - list(APPEND Boost_LIBRARIES ${Boost_${UPPERCOMPONENT}_LIBRARY}) - endif() - endforeach() -else() - if(Boost_FIND_REQUIRED) - message(SEND_ERROR "Unable to find the requested Boost libraries.\n${Boost_ERROR_REASON}") - else() - if(NOT Boost_FIND_QUIETLY) - # we opt not to automatically output Boost_ERROR_REASON here as - # it could be quite lengthy and somewhat imposing in its requests - # Since Boost is not always a required dependency we'll leave this - # up to the end-user. - if(Boost_DEBUG OR Boost_DETAILED_FAILURE_MSG) - message(STATUS "Could NOT find Boost\n${Boost_ERROR_REASON}") - else() - message(STATUS "Could NOT find Boost") - endif() - endif() - endif() -endif() - -# Configure display of cache entries in GUI. -foreach(v BOOSTROOT BOOST_ROOT ${_Boost_VARS_INC} ${_Boost_VARS_LIB}) - get_property(_type CACHE ${v} PROPERTY TYPE) - if(_type) - set_property(CACHE ${v} PROPERTY ADVANCED 1) - if("x${_type}" STREQUAL "xUNINITIALIZED") - if("x${v}" STREQUAL "xBoost_ADDITIONAL_VERSIONS") - set_property(CACHE ${v} PROPERTY TYPE STRING) - else() - set_property(CACHE ${v} PROPERTY TYPE PATH) - endif() - endif() - endif() -endforeach() - -# Record last used values of input variables so we can -# detect on the next run if the user changed them. -foreach(v - ${_Boost_VARS_INC} ${_Boost_VARS_LIB} - ${_Boost_VARS_DIR} ${_Boost_VARS_NAME} - ) - if(DEFINED ${v}) - set(_${v}_LAST "${${v}}" CACHE INTERNAL "Last used ${v} value.") - else() - unset(_${v}_LAST CACHE) - endif() -endforeach() - -# Maintain a persistent list of components requested anywhere since -# the last flush. -set(_Boost_COMPONENTS_SEARCHED "${_Boost_COMPONENTS_SEARCHED}") -list(APPEND _Boost_COMPONENTS_SEARCHED ${Boost_FIND_COMPONENTS}) -list(REMOVE_DUPLICATES _Boost_COMPONENTS_SEARCHED) -list(SORT _Boost_COMPONENTS_SEARCHED) -set(_Boost_COMPONENTS_SEARCHED "${_Boost_COMPONENTS_SEARCHED}" - CACHE INTERNAL "Components requested for this build tree.") From f4e197d7b33fe7470aeba88dcd8bc03e6a421451 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 17:38:34 -0500 Subject: [PATCH 03/38] Add .clang-format --- .clang-format | 142 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..642eb4a --- /dev/null +++ b/.clang-format @@ -0,0 +1,142 @@ +--- +Language: Cpp +AccessModifierOffset: 0 +AlignAfterOpenBracket: DontAlign +AlignArrayOfStructures: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: AcrossEmptyLinesAndComments +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: None +AlignEscapedNewlines: Right +AlignOperands: DontAlign +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: TopLevelDefinitions +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: MultiLine + AfterEnum: true + AfterFunction: true + AfterNamespace: false + AfterStruct: true + AfterUnion: true + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakAfterAttributes: Leave +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakBeforeConceptDeclarations: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma +BreakStringLiterals: false +ColumnLimit: 80 +CompactNamespaces: false +ConstructorInitializerIndentWidth: 0 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: true +DeriveLineEnding: false +DerivePointerAlignment: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: Always +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: ['foreach', 'Q_FOREACH', 'BOOST_FOREACH'] +IncludeBlocks: Preserve +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: true +IndentExternBlock: NoIndent +IndentGotoLabels: false +IndentPPDirectives: AfterHash +IndentRequires: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: true +IntegerLiteralSeparator: + Binary: 4 + Decimal: 0 + Hex: 2 +KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature +LineEnding: LF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +NamespaceMacros: [] +PPIndentWidth: -1 +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 2 +PenaltyBreakComment: 2 +PenaltyBreakFirstLessLess: 10 +PenaltyBreakOpenParenthesis: 100 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 2 +PenaltyExcessCharacter: 100000 +PenaltyIndentedWhitespace: 100 +PenaltyReturnTypeOnItsOwnLine: 1000 +PointerAlignment: Left +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: false +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Always +ShortNamespaceLines: 1 +SortIncludes: Never +SortUsingDeclarations: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: Never +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: Never +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: [] +StatementMacros: [] +TypenameMacros: [] +TabWidth: 4 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: [] \ No newline at end of file From 67728231ae905e63f777686592405610c8897013 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 17:39:45 -0500 Subject: [PATCH 04/38] Add an initial CMakePresets.json (VS 2022 and ClangCL configurations for now) --- CMakePresets.json | 191 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 CMakePresets.json diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..80ed5d8 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,191 @@ +{ + // Core configuration presets: + "version": 7, + "configurePresets": [ + { + // Standard build directory, and always target x64: + "name": ".cml-configure-defaults", + "hidden": true, + "binaryDir": "${sourceDir}/.build/${presetName}", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "BUILD_SHARED_LIBS": { + "type": "BOOL", + "value": false + }, + "BUILD_STATIC_RUNTIME": { + "type": "BOOL", + "value": true + } + } + }, + { + // Inheritable preset to enable testing: + "name": ".cml-configure-testing", + "hidden": true, + "cacheVariables": { + "BUILD_TESTING": { + "type": "BOOL", + "value": true + } + } + }, + + { + // Inheritable conditional to enable a configuration preset on Windows only: + "name": ".cml-windows-only", + "hidden": true, + "condition": { + "type": "allOf", + "conditions": [ + { + "lhs": "${hostSystemName}", + "type": "equals", + "rhs": "Windows" + } + ] + } + }, + { + // Inheritable conditional to enable a configuration preset on Linux only: + "name": ".cml-linux-only", + "hidden": true, + "condition": { + "type": "allOf", + "conditions": [ + { + "lhs": "${hostSystemName}", + "type": "equals", + "rhs": "Linux" + } + ] + } + }, + { + // Inheritable conditional to enable a configuration preset on Darwin (Mac OS/X) only: + "name": ".cml-macosx-only", + "hidden": true, + "condition": { + "type": "allOf", + "conditions": [ + { + "lhs": "${hostSystemName}", + "type": "equals", + "rhs": "Darwin" + } + ] + } + }, + + { + // Inheritable configuration to use ClangCL and the Ninja generator: + "name": ".cml-ninja-clangcl", + "hidden": true, + "generator": "Ninja", + "cacheVariables": { + "CMAKE_C_COMPILER": "clang-cl.exe", + "CMAKE_CXX_COMPILER": "clang-cl.exe" + } + }, + { + // Inheritable configuration to use MSVC and the Ninja generator: + "name": ".cml-ninja-msvc", + "hidden": true, + "generator": "Ninja", + "cacheVariables": { + "CMAKE_C_COMPILER": "cl.exe", + "CMAKE_CXX_COMPILER": "cl.exe" + } + }, + { + // Inheritable configuration to use MSVC17 and MSBuild: + "name": ".cml-msvc17", + "hidden": true, + "inherits": [ ".cml-windows-only" ], + "generator": "Visual Studio 17 2022" + }, + { + // Inheritable configuration to use MSVC17+ClangCL and MSBuild: + "name": ".cml-msvc17-clangcl", + "hidden": true, + "inherits": [ ".cml-windows-only" ], + "generator": "Visual Studio 17 2022", + "toolset": "ClangCL" + }, + + { + // Preset to configure a static dev-test (IDE) build with MSVC17: + "name": "cml-dev-msvc17-mt-s", + "inherits": [ ".cml-configure-defaults", ".cml-msvc17", ".cml-configure-testing" ] + }, + + { + // Preset to configure a static dev-test build (IDE) with MSVC17+ClangCL: + "name": "cml-dev-msvc17-clangcl-mt-s", + "inherits": [ ".cml-configure-defaults", ".cml-msvc17-clangcl", ".cml-configure-testing" ] + }, + + { + // Preset to configure a CI test build with Ninja+ClangCL: + "name": "cml-ci-ninja-clangcl-mt-s", + "inherits": [ ".cml-configure-defaults", ".cml-ninja-clangcl", ".cml-configure-testing" ] + }, + + { + // Preset to configure a CI test build with Ninja+MSVC: + "name": "cml-ci-ninja-msvc-mt-s", + "inherits": [ ".cml-configure-defaults", ".cml-ninja-msvc", ".cml-configure-testing" ] + } + ], + + "buildPresets": [ + { + // Inheritable conditional to enable a build preset on Windows only: + "name": ".cml-windows-build-only", + "hidden": true, + "condition": { + "type": "allOf", + "conditions": [ + { + "lhs": "${hostSystemName}", + "type": "equals", + "rhs": "Windows" + } + ] + } + }, + { + // Inheritable conditional to enable a build preset on Linux only: + "name": ".cml-linux-build-only", + "hidden": true, + "condition": { + "type": "allOf", + "conditions": [ + { + "lhs": "${hostSystemName}", + "type": "equals", + "rhs": "Windows" + } + ] + } + }, + { + // Inheritable conditional to enable a build preset on OS/X only: + "name": ".cml-macosx-build-only", + "hidden": true, + "condition": { + "type": "allOf", + "conditions": [ + { + "lhs": "${hostSystemName}", + "type": "equals", + "rhs": "Darwin" + } + ] + } + } + ] +} \ No newline at end of file From fc381e71ad4fc8ed95dd6164833727fff85450e1 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 17:40:48 -0500 Subject: [PATCH 05/38] Clean up CML.cmake --- CML.cmake | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/CML.cmake b/CML.cmake index f134a5d..612e985 100644 --- a/CML.cmake +++ b/CML.cmake @@ -17,6 +17,7 @@ set(common_HEADERS cml/common/basis_tags.h cml/common/compiler.h cml/common/exception.h + cml/common/hash.h cml/common/layout_tags.h cml/common/memory_tags.h cml/common/promotion.h @@ -366,7 +367,6 @@ set(all_headers ) add_library(cml INTERFACE) -target_compile_options(cml INTERFACE $<$:/permissive->) target_compile_features(cml INTERFACE cxx_reference_qualified_functions cxx_constexpr @@ -376,23 +376,5 @@ target_include_directories(cml INTERFACE $) target_include_directories(cml INTERFACE $/include>) # Setup a custom target, and use IDE groups for the headers when possible: -if(${CMAKE_GENERATOR} MATCHES "Visual Studio") - set(_header_group "Header Files\\") - source_group("${_header_group}" FILES ${main_HEADERS}) - source_group("${_header_group}common" FILES ${common_HEADERS}) - source_group("${_header_group}common\\mpl" FILES ${common_mpl_HEADERS}) - source_group("${_header_group}scalar" FILES ${scalar_HEADERS}) - source_group("${_header_group}storage" FILES ${storage_HEADERS}) - source_group("${_header_group}vector" FILES ${vector_HEADERS}) - source_group("${_header_group}vector\\detail" FILES ${vector_detail_HEADERS}) - source_group("${_header_group}matrix" FILES ${matrix_HEADERS}) - source_group("${_header_group}matrix\\detail" FILES ${matrix_detail_HEADERS}) - source_group("${_header_group}quaternion" FILES ${quaternion_HEADERS}) - source_group("${_header_group}mathlib" FILES ${mathlib_HEADERS}) - source_group("${_header_group}mathlib\\vector" FILES ${mathlib_vector_HEADERS}) - source_group("${_header_group}mathlib\\matrix" FILES ${mathlib_matrix_HEADERS}) - source_group("${_header_group}mathlib\\quaternion" FILES ${mathlib_quaternion_HEADERS}) - source_group("${_header_group}\\util" FILES ${util_HEADERS}) -endif() - +source_group(TREE "${CML_ROOT}/cml" FILES ${all_headers}) add_custom_target(cml-dev SOURCES ${all_headers}) \ No newline at end of file From f39b2a59650c782ce5f2db2220a9da98fb6ce146 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 17:43:40 -0500 Subject: [PATCH 06/38] Cleanup headers and fix quaternion/quaternion.h - Applied clang-format (replacing tabs with spaces), removed extraneous header and footer comments, and made all files have Unix line endings. --- cml/cml.h | 9 +- cml/common/array_size_of.h | 65 ++- cml/common/basis_tags.h | 89 ++-- cml/common/compiler.h | 17 +- cml/common/exception.h | 17 +- cml/common/hash.h | 42 +- cml/common/layout_tags.h | 54 +-- cml/common/memory_tags.h | 49 +- cml/common/mpl/are_convertible.h | 25 +- cml/common/mpl/are_same.h | 25 +- cml/common/mpl/enable_if_arithmetic.h | 23 +- cml/common/mpl/enable_if_array.h | 24 +- cml/common/mpl/enable_if_convertible.h | 24 +- cml/common/mpl/enable_if_pointer.h | 22 +- cml/common/mpl/enable_if_reshapeable.h | 23 +- cml/common/mpl/enable_if_same.h | 23 +- cml/common/mpl/enable_if_t.h | 16 +- cml/common/mpl/if_t.h | 16 +- cml/common/mpl/int_c.h | 18 +- cml/common/mpl/is_reshapeable.h | 27 +- cml/common/mpl/is_same_pair.h | 28 +- cml/common/mpl/is_statically_polymorphic.h | 30 +- cml/common/mpl/item_at.h | 20 +- cml/common/mpl/plus_c.h | 17 +- cml/common/mpl/rebind.h | 29 +- cml/common/mpl/type_map.h | 135 +++--- cml/common/mpl/type_table.h | 118 ++--- cml/common/promotion.h | 122 ++--- cml/common/size_tags.h | 82 ++-- cml/common/storage_tags.h | 46 +- cml/common/temporary.h | 14 +- cml/common/traits.h | 26 +- cml/common/type_util.h | 61 +-- cml/mathlib/axis_order.h | 69 +-- cml/mathlib/constants.h | 28 +- cml/mathlib/coordinate_conversion.h | 103 ++--- cml/mathlib/coordinate_conversion.tpp | 179 ++++---- cml/mathlib/euler_order.h | 53 +-- cml/mathlib/frustum.h | 36 +- cml/mathlib/frustum.tpp | 112 ++--- cml/mathlib/mathlib.h | 12 +- cml/mathlib/matrix/basis.h | 246 +++++----- cml/mathlib/matrix/basis.tpp | 347 +++++++------- cml/mathlib/matrix/concat.h | 21 +- cml/mathlib/matrix/concat.tpp | 44 +- cml/mathlib/matrix/generators.h | 66 +-- cml/mathlib/matrix/invert.h | 14 +- cml/mathlib/matrix/invert.tpp | 51 +- cml/mathlib/matrix/misc.h | 31 +- cml/mathlib/matrix/misc.tpp | 52 +-- cml/mathlib/matrix/projection.h | 124 +++-- cml/mathlib/matrix/projection.tpp | 265 +++++------ cml/mathlib/matrix/rotation.h | 118 +++-- cml/mathlib/matrix/rotation.tpp | 511 ++++++++++----------- cml/mathlib/matrix/scale.h | 59 ++- cml/mathlib/matrix/scale.tpp | 103 ++--- cml/mathlib/matrix/size_checking.h | 20 +- cml/mathlib/matrix/size_checking.tpp | 83 ++-- cml/mathlib/matrix/temporary.h | 57 +-- cml/mathlib/matrix/transform.h | 65 ++- cml/mathlib/matrix/transform.tpp | 78 ++-- cml/mathlib/matrix/translation.h | 81 ++-- cml/mathlib/matrix/translation.tpp | 168 +++---- cml/mathlib/quaternion/basis.h | 45 +- cml/mathlib/quaternion/basis.tpp | 53 +-- cml/mathlib/quaternion/rotation.h | 101 ++-- cml/mathlib/quaternion/rotation.tpp | 237 +++++----- cml/mathlib/random_unit.h | 23 +- cml/mathlib/random_unit.tpp | 67 ++- cml/mathlib/vector/angle.h | 40 +- cml/mathlib/vector/angle.tpp | 73 ++- cml/mathlib/vector/generators.h | 70 +-- cml/mathlib/vector/misc.h | 36 +- cml/mathlib/vector/misc.tpp | 64 ++- cml/mathlib/vector/orthonormal.h | 27 +- cml/mathlib/vector/orthonormal.tpp | 65 ++- cml/mathlib/vector/rotation.h | 21 +- cml/mathlib/vector/rotation.tpp | 31 +- cml/mathlib/vector/transform.h | 51 +- cml/mathlib/vector/transform.tpp | 205 ++++----- cml/matrix.h | 12 +- cml/matrix/array_size_of.h | 22 +- cml/matrix/basis.h | 12 +- cml/matrix/basis_node.h | 127 +++-- cml/matrix/basis_node.tpp | 47 +- cml/matrix/basis_ops.h | 25 +- cml/matrix/binary_node.h | 166 +++---- cml/matrix/binary_node.tpp | 50 +- cml/matrix/binary_ops.h | 69 ++- cml/matrix/col_node.h | 127 +++-- cml/matrix/col_node.tpp | 47 +- cml/matrix/col_ops.h | 25 +- cml/matrix/comparison.h | 24 +- cml/matrix/comparison.tpp | 36 +- cml/matrix/detail/apply.h | 42 +- cml/matrix/detail/check_or_resize.h | 62 ++- cml/matrix/detail/copy.h | 40 +- cml/matrix/detail/determinant.h | 48 +- cml/matrix/detail/determinant.tpp | 116 +++-- cml/matrix/detail/generate.h | 42 +- cml/matrix/detail/get.h | 33 +- cml/matrix/detail/inverse.h | 249 +++++----- cml/matrix/detail/lu.h | 25 +- cml/matrix/detail/lu.tpp | 68 ++- cml/matrix/detail/resize.h | 30 +- cml/matrix/detail/transpose.h | 29 +- cml/matrix/determinant.h | 18 +- cml/matrix/determinant.tpp | 17 +- cml/matrix/dynamic.h | 12 +- cml/matrix/dynamic_allocated.h | 377 ++++++++------- cml/matrix/dynamic_allocated.tpp | 187 ++++---- cml/matrix/dynamic_external.h | 302 ++++++------ cml/matrix/dynamic_external.tpp | 92 ++-- cml/matrix/external.h | 12 +- cml/matrix/fixed.h | 12 +- cml/matrix/fixed_compiled.h | 334 +++++++------- cml/matrix/fixed_compiled.tpp | 106 ++--- cml/matrix/fixed_external.h | 288 ++++++------ cml/matrix/fixed_external.tpp | 100 ++-- cml/matrix/functions.h | 12 +- cml/matrix/fwd.h | 14 +- cml/matrix/hadamard_product.h | 27 +- cml/matrix/inverse.h | 17 +- cml/matrix/lu.h | 75 ++- cml/matrix/lu.tpp | 88 ++-- cml/matrix/matrix.h | 19 +- cml/matrix/matrix_product.h | 22 +- cml/matrix/matrix_product.tpp | 37 +- cml/matrix/ops.h | 12 +- cml/matrix/promotion.h | 219 ++++----- cml/matrix/readable_matrix.h | 117 ++--- cml/matrix/readable_matrix.tpp | 81 ++-- cml/matrix/row_col.h | 12 +- cml/matrix/row_node.h | 127 +++-- cml/matrix/row_node.tpp | 47 +- cml/matrix/row_ops.h | 25 +- cml/matrix/scalar_node.h | 149 +++--- cml/matrix/scalar_node.tpp | 56 ++- cml/matrix/scalar_ops.h | 82 ++-- cml/matrix/size_checking.h | 134 +++--- cml/matrix/size_checking.tpp | 493 ++++++++++---------- cml/matrix/temporary.h | 33 +- cml/matrix/trace.h | 18 +- cml/matrix/trace.tpp | 17 +- cml/matrix/traits.h | 20 +- cml/matrix/transpose.h | 12 +- cml/matrix/transpose_node.h | 139 +++--- cml/matrix/transpose_node.tpp | 32 +- cml/matrix/transpose_ops.h | 30 +- cml/matrix/type_util.h | 35 +- cml/matrix/types.h | 244 +++++----- cml/matrix/unary_node.h | 139 +++--- cml/matrix/unary_node.tpp | 44 +- cml/matrix/unary_ops.h | 35 +- cml/matrix/vector_product.h | 30 +- cml/matrix/vector_product.tpp | 55 +-- cml/matrix/writable_matrix.h | 322 ++++++------- cml/matrix/writable_matrix.tpp | 272 ++++++----- cml/quaternion.h | 12 +- cml/quaternion/binary_node.h | 146 +++--- cml/quaternion/binary_node.tpp | 44 +- cml/quaternion/binary_ops.h | 65 ++- cml/quaternion/comparison.h | 44 +- cml/quaternion/comparison.tpp | 90 ++-- cml/quaternion/conjugate.h | 12 +- cml/quaternion/conjugate_node.h | 116 ++--- cml/quaternion/conjugate_node.tpp | 27 +- cml/quaternion/conjugate_ops.h | 22 +- cml/quaternion/conjugate_ops.tpp | 23 +- cml/quaternion/cross_tags.h | 54 +-- cml/quaternion/dot.h | 22 +- cml/quaternion/dot.tpp | 36 +- cml/quaternion/fixed.h | 12 +- cml/quaternion/fixed_compiled.h | 313 ++++++------- cml/quaternion/fixed_compiled.tpp | 75 +-- cml/quaternion/functions.h | 60 +-- cml/quaternion/functions.tpp | 59 ++- cml/quaternion/fwd.h | 14 +- cml/quaternion/imaginary.h | 12 +- cml/quaternion/imaginary_node.h | 120 ++--- cml/quaternion/imaginary_node.tpp | 29 +- cml/quaternion/imaginary_ops.h | 22 +- cml/quaternion/imaginary_ops.tpp | 23 +- cml/quaternion/inverse.h | 12 +- cml/quaternion/inverse_node.h | 120 ++--- cml/quaternion/inverse_node.tpp | 39 +- cml/quaternion/inverse_ops.h | 22 +- cml/quaternion/inverse_ops.tpp | 23 +- cml/quaternion/ops.h | 12 +- cml/quaternion/order_tags.h | 70 +-- cml/quaternion/product.h | 22 +- cml/quaternion/product.tpp | 43 +- cml/quaternion/promotion.h | 71 ++- cml/quaternion/quaternion.h | 19 +- cml/quaternion/readable_quaternion.h | 168 ++++--- cml/quaternion/readable_quaternion.tpp | 127 ++--- cml/quaternion/scalar_node.h | 131 +++--- cml/quaternion/scalar_node.tpp | 48 +- cml/quaternion/scalar_ops.h | 79 ++-- cml/quaternion/size_checking.h | 20 +- cml/quaternion/temporary.h | 33 +- cml/quaternion/traits.h | 19 +- cml/quaternion/type_util.h | 35 +- cml/quaternion/types.h | 54 +-- cml/quaternion/unary_node.h | 119 ++--- cml/quaternion/unary_node.tpp | 32 +- cml/quaternion/unary_ops.h | 35 +- cml/quaternion/writable_quaternion.h | 370 +++++++-------- cml/quaternion/writable_quaternion.tpp | 313 +++++++------ cml/scalar/binary_ops.h | 38 +- cml/scalar/constants.h | 62 +-- cml/scalar/functions.h | 229 ++++++--- cml/scalar/promotion.h | 40 +- cml/scalar/traits.h | 190 ++++---- cml/scalar/unary_ops.h | 46 +- cml/storage/allocated_selector.h | 172 ++++--- cml/storage/any_selector.h | 107 +++-- cml/storage/compiled_selector.h | 98 ++-- cml/storage/external_selector.h | 131 +++--- cml/storage/promotion.h | 89 ++-- cml/storage/resize.h | 33 +- cml/storage/selectors.h | 12 +- cml/storage/type_util.h | 85 ++-- cml/types.h | 12 +- cml/util.h | 54 ++- cml/util/matrix_print.h | 19 +- cml/util/matrix_print.tpp | 19 +- cml/util/quaternion_print.h | 20 +- cml/util/quaternion_print.tpp | 24 +- cml/util/vector_hash.h | 24 +- cml/util/vector_print.h | 19 +- cml/util/vector_print.tpp | 17 +- cml/vector.h | 12 +- cml/vector/binary_node.h | 136 +++--- cml/vector/binary_node.tpp | 43 +- cml/vector/binary_ops.h | 69 ++- cml/vector/comparison.h | 44 +- cml/vector/comparison.tpp | 78 ++-- cml/vector/cross.h | 12 +- cml/vector/cross_node.h | 141 +++--- cml/vector/cross_node.tpp | 50 +- cml/vector/cross_ops.h | 31 +- cml/vector/detail/check_or_resize.h | 77 ++-- cml/vector/detail/combined_size_of.h | 40 +- cml/vector/detail/resize.h | 30 +- cml/vector/dot.h | 20 +- cml/vector/dot.tpp | 24 +- cml/vector/dynamic.h | 12 +- cml/vector/dynamic_allocated.h | 324 ++++++------- cml/vector/dynamic_allocated.tpp | 124 ++--- cml/vector/dynamic_const_external.h | 119 ++--- cml/vector/dynamic_const_external.tpp | 48 +- cml/vector/dynamic_external.h | 209 ++++----- cml/vector/dynamic_external.tpp | 72 +-- cml/vector/external.h | 12 +- cml/vector/fixed.h | 12 +- cml/vector/fixed_compiled.h | 268 +++++------ cml/vector/fixed_compiled.tpp | 67 +-- cml/vector/fixed_const_external.h | 110 ++--- cml/vector/fixed_const_external.tpp | 36 +- cml/vector/fixed_external.h | 200 ++++---- cml/vector/fixed_external.tpp | 63 ++- cml/vector/functions.h | 31 +- cml/vector/functions.tpp | 20 +- cml/vector/fwd.h | 14 +- cml/vector/hadamard_product.h | 27 +- cml/vector/ops.h | 12 +- cml/vector/outer_product.h | 12 +- cml/vector/outer_product_node.h | 164 +++---- cml/vector/outer_product_node.tpp | 53 +-- cml/vector/outer_product_ops.h | 42 +- cml/vector/perp_dot.h | 22 +- cml/vector/perp_dot.tpp | 22 +- cml/vector/products.h | 12 +- cml/vector/promotion.h | 64 ++- cml/vector/readable_vector.h | 120 +++-- cml/vector/readable_vector.tpp | 89 ++-- cml/vector/scalar_node.h | 125 +++-- cml/vector/scalar_node.tpp | 48 +- cml/vector/scalar_ops.h | 82 ++-- cml/vector/size_checking.h | 56 ++- cml/vector/size_checking.tpp | 189 ++++---- cml/vector/subvector.h | 12 +- cml/vector/subvector_node.h | 124 +++-- cml/vector/subvector_node.tpp | 38 +- cml/vector/subvector_ops.h | 23 +- cml/vector/subvector_ops.tpp | 23 +- cml/vector/temporary.h | 84 ++-- cml/vector/traits.h | 20 +- cml/vector/triple_product.h | 23 +- cml/vector/triple_product.tpp | 21 +- cml/vector/type_util.h | 35 +- cml/vector/types.h | 90 ++-- cml/vector/unary_node.h | 114 ++--- cml/vector/unary_node.tpp | 37 +- cml/vector/unary_ops.h | 35 +- cml/vector/vector.h | 14 +- cml/vector/writable_vector.h | 296 ++++++------ cml/vector/writable_vector.tpp | 275 ++++++----- cml/version.h | 13 +- 300 files changed, 10083 insertions(+), 12422 deletions(-) diff --git a/cml/cml.h b/cml/cml.h index b60c499..855223f 100644 --- a/cml/cml.h +++ b/cml/cml.h @@ -1,7 +1,8 @@ -#pragma once +/*------------------------------------------------------------------------- + @@COPYRIGHT@@ + *-----------------------------------------------------------------------*/ -#ifndef cml_cml_h -#define cml_cml_h +#pragma once #include #include @@ -9,5 +10,3 @@ #include #include #include - -#endif diff --git a/cml/common/array_size_of.h b/cml/common/array_size_of.h index ba4ced2..7a4d2d3 100644 --- a/cml/common/array_size_of.h +++ b/cml/common/array_size_of.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_array_size_of_h -#define cml_common_array_size_of_h - #include namespace cml { @@ -17,12 +12,12 @@ namespace detail { /** Helper defining a typedef @c type that is int if @c T is an integral * type, or @c T otherwise. */ -template struct int_if_integral { - typedef typename std::conditional< - std::is_integral::value, int, T>::type type; +template struct int_if_integral +{ + using type = typename std::conditional::value, int, T>::type; }; -} // namespace detail +} // namespace detail /** Specializable compile-time array size. */ @@ -35,8 +30,9 @@ template struct array_rows_of_c; template struct array_cols_of_c; /** Compile-time size of an array. */ -template struct array_size_of_c< - Array, typename std::enable_if::value>::type> +template +struct array_size_of_c::value>::type> { static const int value = int(std::extent::value); }; @@ -44,34 +40,37 @@ template struct array_size_of_c< /** Compile-time size of an object implementing an array_size integral or * enum member. */ -template struct array_size_of_c::type> +template +struct array_size_of_c::type> { static const int value = Array::array_size; }; /** Return the size of @c array if it implements the size() method. */ -template inline auto -array_size_of(const Array& array) --> typename detail::int_if_integral::type +template +inline auto +array_size_of(const Array& array) -> + typename detail::int_if_integral::type { - typedef typename detail::int_if_integral< - decltype(array.size())>::type result_type; + using result_type = typename detail::int_if_integral::type; return result_type(array.size()); } /** Return the size of a fixed-length array. */ -template inline int array_size_of(const Array&, +template +inline int +array_size_of(const Array&, typename std::enable_if::value>::type* = 0) { return int(array_size_of_c::value); } - /** Compile-time size of an object implementing an array_rows integral or * enum member. */ -template struct array_rows_of_c +struct array_rows_of_c::type> { static const int value = int(Array::array_rows); @@ -80,7 +79,8 @@ template struct array_rows_of_c struct array_cols_of_c +struct array_cols_of_c::type> { static const int value = int(Array::array_cols); @@ -89,22 +89,21 @@ template struct array_cols_of_c inline auto -array_rows_of(const Array& array) -> decltype(array.rows()) { +template +inline auto +array_rows_of(const Array& array) -> decltype(array.rows()) +{ return array.rows(); } /** Return the number of columns @c array if it implements the cols() * method. */ -template inline auto -array_cols_of(const Array& array) -> decltype(array.cols()) { +template +inline auto +array_cols_of(const Array& array) -> decltype(array.cols()) +{ return array.cols(); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/basis_tags.h b/cml/common/basis_tags.h index b9e7c20..f14868e 100644 --- a/cml/common/basis_tags.h +++ b/cml/common/basis_tags.h @@ -1,20 +1,16 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_basis_tags_h -#define cml_common_basis_tags_h - #include #include namespace cml { -enum basis_kind { +enum basis_kind +{ row_basis_c = 1, col_basis_c = 2, any_basis_c = 3, @@ -22,18 +18,27 @@ enum basis_kind { }; /** Row basis tag. */ -struct row_basis { static const basis_kind value = row_basis_c; }; +struct row_basis +{ + static const basis_kind value = row_basis_c; +}; /** Column basis tag. */ -struct col_basis { static const basis_kind value = col_basis_c; }; +struct col_basis +{ + static const basis_kind value = col_basis_c; +}; /** Any basis tag. */ -struct any_basis { static const basis_kind value = any_basis_c; }; +struct any_basis +{ + static const basis_kind value = any_basis_c; +}; /** Detect valid basis tags. */ -template struct is_basis_tag { - static const bool value - = std::is_same::value +template struct is_basis_tag +{ + static const bool value = std::is_same::value || std::is_same::value || std::is_same::value; }; @@ -41,8 +46,9 @@ template struct is_basis_tag { /** Templated helper to determine the basis tag of an expression that * defines the basis_tag type. */ -template struct basis_tag_of { - typedef typename T::basis_tag type; +template struct basis_tag_of +{ + using type = typename T::basis_tag; static_assert(is_basis_tag::value, "invalid basis tag"); }; @@ -50,60 +56,59 @@ template struct basis_tag_of { template using basis_tag_of_t = typename basis_tag_of::type; /** Retrieve the basis_tag of @c T via traits. */ -template struct basis_tag_trait_of { - typedef typename traits_of::type::basis_tag type; +template struct basis_tag_trait_of +{ + using type = typename traits_of::type::basis_tag; static_assert(is_basis_tag::value, "invalid basis tag"); }; /** Convenience alias for basis_tag_trait_of. */ template - using basis_tag_trait_of_t = typename basis_tag_trait_of::type; - +using basis_tag_trait_of_t = typename basis_tag_trait_of::type; /** Helper to detect row basis types. */ -template struct is_row_basis { +template struct is_row_basis +{ static const bool value = std::is_same, row_basis>::value; }; /** Wrapper for enable_if to detect types tagged with row_basis. */ -template struct enable_if_row_basis -: std::enable_if::value, T> {}; +template +struct enable_if_row_basis : std::enable_if::value, T> +{}; /** Convenience alias for enable_if_row_basis. */ -template using enable_if_row_basis_t - = typename enable_if_row_basis::type; - +template +using enable_if_row_basis_t = typename enable_if_row_basis::type; /** Helper to detect column basis types. */ -template struct is_col_basis { +template struct is_col_basis +{ static const bool value = std::is_same, col_basis>::value; }; /** Wrapper for enable_if to detect types tagged with col_basis. */ -template struct enable_if_col_basis -: std::enable_if::value, T> {}; +template +struct enable_if_col_basis : std::enable_if::value, T> +{}; /** Convenience alias for enable_if_col_basis. */ -template using enable_if_col_basis_t - = typename enable_if_col_basis::type; - +template +using enable_if_col_basis_t = typename enable_if_col_basis::type; /** Helper to detect arbitrary basis types. */ -template struct is_any_basis { +template struct is_any_basis +{ static const bool value = std::is_same, any_basis>::value; }; /** Wrapper for enable_if to detect types tagged with any_basis. */ -template struct enable_if_any_basis -: std::enable_if::value, T> {}; +template +struct enable_if_any_basis : std::enable_if::value, T> +{}; /** Convenience alias for enable_if_any_basis. */ -template using enable_if_any_basis_t - = typename enable_if_any_basis::type; - -} // namespace cml - -#endif +template +using enable_if_any_basis_t = typename enable_if_any_basis::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/compiler.h b/cml/common/compiler.h index 0759f8a..d1aa82a 100644 --- a/cml/common/compiler.h +++ b/cml/common/compiler.h @@ -1,28 +1,21 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_compiler_h -#define cml_common_compiler_h - /* N2439 move semantics for *this, used, for example, to efficiently return * an expression node from a class method. Without this, a temporary is * returned instead: */ #ifdef __cpp_ref_qualifiers -# define CML_HAS_RVALUE_REFERENCE_FROM_THIS -# define __CML_REF & +# define CML_HAS_RVALUE_REFERENCE_FROM_THIS +# define __CML_REF & #else -# error "Compiler does not support __cpp_ref_qualifiers." +# error "Compiler does not support __cpp_ref_qualifiers." #endif /* Compiler (optionally) supports C++17 structured bindings: */ #ifdef __cpp_structured_bindings -# define CML_HAS_STRUCTURED_BINDINGS +# define CML_HAS_STRUCTURED_BINDINGS #endif - -#endif \ No newline at end of file diff --git a/cml/common/exception.h b/cml/common/exception.h index 04271d2..e6973fb 100644 --- a/cml/common/exception.h +++ b/cml/common/exception.h @@ -1,21 +1,12 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_exception_h -#define cml_common_exception_h - #include /** Throw exception _e_ with message _msg_ if _cond_ is false. */ -#define cml_require(_cond_, _e_, _msg_) \ - if((_cond_)) {} else throw _e_ (_msg_) - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +#define cml_require(_cond_, _e_, _msg_) \ + if((_cond_)) { \ + } else throw _e_(_msg_) diff --git a/cml/common/hash.h b/cml/common/hash.h index f04aeca..27dd624 100644 --- a/cml/common/hash.h +++ b/cml/common/hash.h @@ -1,33 +1,28 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_hash_h -#define cml_common_hash_h - #include #include #include -namespace cml { -namespace detail { +namespace cml::detail { -/* Adapted mrom boost/functional/hash/hash.hpp> */ +/* Adapted from boost/functional/hash/hash.hpp> */ #if defined(_MSC_VER) -#define _HASH_ROTL32(x, r) _rotl(x,r) +# define _HASH_ROTL32(x, r) _rotl(x, r) #else -#define _HASH_ROTL32(x, r) ((x << r) | (x >> (32 - r))) +# define _HASH_ROTL32(x, r) ((x << r) | (x >> (32 - r))) #endif -template inline void +template +inline void hash_combine_impl(U32& h1, U32 k1, cml::int_c<4>) { - const auto c1 = UINT32_C(0xcc9e2d51); - const auto c2 = UINT32_C(0x1b873593); + const auto c1 = UINT32_C(0xcc'9e'2d'51); + const auto c2 = UINT32_C(0x1b'87'35'93); k1 *= c1; k1 = _HASH_ROTL32(k1, 15); @@ -35,15 +30,16 @@ hash_combine_impl(U32& h1, U32 k1, cml::int_c<4>) h1 ^= k1; h1 = _HASH_ROTL32(h1, 13); - h1 = h1 * 5 + 0xe6546b64; + h1 = h1 * 5 + 0xe6'54'6b'64; } #undef _CML_HASH_ROTL32 -template inline void +template +inline void hash_combine_impl(U64& h, U64 k, cml::int_c<8>) { - const auto m = UINT64_C(0xc6a4a7935bd1e995); + const auto m = UINT64_C(0xc6'a4'a7'93'5b'd1'e9'95); const auto r = 47; k *= m; @@ -55,20 +51,14 @@ hash_combine_impl(U64& h, U64 k, cml::int_c<8>) // Completely arbitrary number, to prevent 0's // from hashing to 0. - h += UINT64_C(0xe6546b64); + h += UINT64_C(0xe6'54'6b'64); } - -template inline void +template +inline void hash_combine(UInt& h, UInt k) { hash_combine_impl(h, k, cml::int_c()); } } -} - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/common/layout_tags.h b/cml/common/layout_tags.h index 6b4eb0e..2f8ac7b 100644 --- a/cml/common/layout_tags.h +++ b/cml/common/layout_tags.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_layout_tags_h -#define cml_common_layout_tags_h - #include namespace cml { @@ -18,7 +13,8 @@ struct row_major; struct col_major; struct any_major; -enum layout_kind { +enum layout_kind +{ row_major_c = 1, col_major_c = 2, any_major_c = 3, @@ -26,43 +22,42 @@ enum layout_kind { }; /** Row major tag. */ -struct row_major { - +struct row_major +{ /** row_major transposes to col_major. */ - typedef col_major transposed_tag; + using transposed_tag = col_major; /** Integral identifier. */ static const layout_kind value = row_major_c; }; /** Column major tag. */ -struct col_major { - +struct col_major +{ /** col_major transposes to row_major. */ - typedef row_major transposed_tag; + using transposed_tag = row_major; /** Integral identifier. */ static const layout_kind value = col_major_c; }; /** Arbitrary or unspecified major tag. */ -struct any_major { - +struct any_major +{ /** any_major transposes to itself. */ - typedef any_major transposed_tag; + using transposed_tag = any_major; /** Integral identifier. */ static const layout_kind value = any_major_c; }; - /** Detect valid layout tags. * * @note This can be specialized for user-defined layout tags. */ -template struct is_layout_tag { - static const bool value - = std::is_same::value +template struct is_layout_tag +{ + static const bool value = std::is_same::value || std::is_same::value || std::is_same::value; }; @@ -70,8 +65,9 @@ template struct is_layout_tag { /** Templated helper to determine the layout tag of an expression that * defines the layout_tag type. */ -template struct layout_tag_of { - typedef typename T::layout_tag type; +template struct layout_tag_of +{ + using type = typename T::layout_tag; static_assert(is_layout_tag::value, "invalid layout tag"); }; @@ -79,18 +75,14 @@ template struct layout_tag_of { template using layout_tag_of_t = typename layout_tag_of::type; /** Retrieve the layout_tag of @c T via traits. */ -template struct layout_tag_trait_of { - typedef typename traits_of::type::layout_tag type; +template struct layout_tag_trait_of +{ + using type = typename traits_of::type::layout_tag; static_assert(is_layout_tag::value, "invalid layout tag"); }; /** Convenience alias for layout_tag_trait_of. */ template - using layout_tag_trait_of_t = typename layout_tag_trait_of::type; - -} // namespace cml - -#endif +using layout_tag_trait_of_t = typename layout_tag_trait_of::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/memory_tags.h b/cml/common/memory_tags.h index 9328396..bb04132 100644 --- a/cml/common/memory_tags.h +++ b/cml/common/memory_tags.h @@ -1,45 +1,44 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_memory_tags_h -#define cml_common_memory_tags_h - namespace cml { /** Specify a type containing compile-time memory. */ -struct compiled_memory_tag {}; +struct compiled_memory_tag +{}; /** Specify a type containing allocated memory. */ -struct allocated_memory_tag {}; +struct allocated_memory_tag +{}; /** Specify a type containing externally referenced memory (pointer, * reference, etc.). */ -struct external_memory_tag {}; +struct external_memory_tag +{}; /** Specify a type having arbitrary or unspecified memory. */ -struct any_memory_tag {}; +struct any_memory_tag +{}; /** Detect valid memory tags. */ -template struct is_memory_tag { - static const bool value - = std::is_same::value +template struct is_memory_tag +{ + static const bool value = std::is_same::value || std::is_same::value || std::is_same::value - || std::is_same::value - ; + || std::is_same::value; }; /** Templated helper to determine the memory tag of an expression that * defines the memory_tag type. */ -template struct memory_tag_of { - typedef typename T::memory_tag type; +template struct memory_tag_of +{ + using type = typename T::memory_tag; static_assert(is_memory_tag::value, "invalid memory tag"); }; @@ -47,26 +46,24 @@ template struct memory_tag_of { template using memory_tag_of_t = typename memory_tag_of::type; /** Helper to detect compiled-memory types. */ -template struct is_compiled_memory { +template struct is_compiled_memory +{ static const bool value = std::is_same, compiled_memory_tag>::value; }; /** Helper to detect allocated-memory types. */ -template struct is_allocated_memory { +template struct is_allocated_memory +{ static const bool value = std::is_same, allocated_memory_tag>::value; }; /** Helper to detect external-memory types. */ -template struct is_external_memory { +template struct is_external_memory +{ static const bool value = std::is_same, external_memory_tag>::value; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/are_convertible.h b/cml/common/mpl/are_convertible.h index ff90704..569071d 100644 --- a/cml/common/mpl/are_convertible.h +++ b/cml/common/mpl/are_convertible.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_are_convertible_h -#define cml_common_mpl_are_convertible_h - #include namespace cml { @@ -20,19 +15,15 @@ template struct are_convertible; /** Determine if @c From is convertible to @c To. */ template - struct are_convertible : std::is_convertible {}; +struct are_convertible : std::is_convertible +{}; /** Recursively determine if @c From and @c Froms are convertible to @c To. */ template -struct are_convertible { - static const bool value - = std::is_convertible::value - && are_convertible::value; +struct are_convertible +{ + static const bool value = std::is_convertible::value + && are_convertible::value; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/are_same.h b/cml/common/mpl/are_same.h index ea9def4..cda5566 100644 --- a/cml/common/mpl/are_same.h +++ b/cml/common/mpl/are_same.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_are_same_h -#define cml_common_mpl_are_same_h - #include namespace cml { @@ -20,19 +15,15 @@ template struct are_same; /** Determine if @c From is the same as @c To. */ template - struct are_same : std::is_same {}; +struct are_same : std::is_same +{}; /** Recursively determine if @c From and @c Froms are the same as @c To. */ template -struct are_same { - static const bool value - = std::is_same::value - && are_same::value; +struct are_same +{ + static const bool value = + std::is_same::value && are_same::value; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/enable_if_arithmetic.h b/cml/common/mpl/enable_if_arithmetic.h index 2e93e68..dd62d43 100644 --- a/cml/common/mpl/enable_if_arithmetic.h +++ b/cml/common/mpl/enable_if_arithmetic.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_enable_if_arithmetic_h -#define cml_common_mpl_enable_if_arithmetic_h - #include namespace cml { @@ -16,16 +11,12 @@ namespace cml { /** Wrapper for enable_if to detect arithmetic types. @c T is tested after * removing const, volatile, and reference qualifiers. */ -template struct enable_if_arithmetic - : std::enable_if::value> {}; +template +struct enable_if_arithmetic : std::enable_if::value> +{}; /** Convenience alias for enable_if_arithmetic. */ -template using enable_if_arithmetic_t - = typename enable_if_arithmetic::type; - -} // namespace cml - -#endif +template +using enable_if_arithmetic_t = typename enable_if_arithmetic::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/enable_if_array.h b/cml/common/mpl/enable_if_array.h index ee13fc1..18dd81d 100644 --- a/cml/common/mpl/enable_if_array.h +++ b/cml/common/mpl/enable_if_array.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_enable_if_array_h -#define cml_common_mpl_enable_if_array_h - #include namespace cml { @@ -16,19 +11,14 @@ namespace cml { /** Alias for std::enable_if using std::is_array to determine the * boolean value. */ -template using enable_if_array - = typename std::enable_if< - std::is_array::value && !std::is_pointer::value>; +template +using enable_if_array = typename std::enable_if::value + && !std::is_pointer::value>; /** Alias for std::enable_if::type using std::is_array to determine * the boolean value. */ -template using enable_if_array_t - = typename enable_if_array::type; - -} // namespace cml - -#endif +template +using enable_if_array_t = typename enable_if_array::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/enable_if_convertible.h b/cml/common/mpl/enable_if_convertible.h index 44a68e2..98ff6b7 100644 --- a/cml/common/mpl/enable_if_convertible.h +++ b/cml/common/mpl/enable_if_convertible.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_enable_if_convertible_h -#define cml_common_mpl_enable_if_convertible_h - #include namespace cml { @@ -16,16 +11,13 @@ namespace cml { /** Convenience alias for enable_if to detect if a set of types, @c Froms, * are convertible to @c To. */ -template using enable_if_convertible - = std::enable_if::value>; +template +using enable_if_convertible = + std::enable_if::value>; /** Convenience alias for enable_if_convertible. */ -template using enable_if_convertible_t - = typename std::enable_if::value>::type; - -} // namespace cml - -#endif +template +using enable_if_convertible_t = + typename std::enable_if::value>::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/enable_if_pointer.h b/cml/common/mpl/enable_if_pointer.h index 207983b..c280849 100644 --- a/cml/common/mpl/enable_if_pointer.h +++ b/cml/common/mpl/enable_if_pointer.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_enable_if_pointer_h -#define cml_common_mpl_enable_if_pointer_h - #include namespace cml { @@ -16,19 +11,14 @@ namespace cml { /** Alias for std::enable_if using std::is_pointer to determine the * boolean value. */ -template using enable_if_pointer - = typename std::enable_if< +template +using enable_if_pointer = typename std::enable_if< std::is_pointer::value && !std::is_array::value>; /** Alias for std::enable_if::type using std::is_pointer to determine * the boolean value. */ -template using enable_if_pointer_t - = typename enable_if_pointer::type; - -} // namespace cml - -#endif +template +using enable_if_pointer_t = typename enable_if_pointer::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/enable_if_reshapeable.h b/cml/common/mpl/enable_if_reshapeable.h index 9cdc852..6ae48a3 100644 --- a/cml/common/mpl/enable_if_reshapeable.h +++ b/cml/common/mpl/enable_if_reshapeable.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_enable_if_reshapeable_h -#define cml_common_mpl_enable_if_reshapeable_h - #include namespace cml { @@ -16,16 +11,12 @@ namespace cml { /** Wrapper for enable_if to detect if @c T implements resize(m,n), where m * and n are convertible from int. */ -template struct enable_if_reshapeable - : std::enable_if::value> {}; +template +struct enable_if_reshapeable : std::enable_if::value> +{}; /** Convenience alias for enable_if_reshapeable. */ -template using enable_if_reshapeable_t - = typename enable_if_reshapeable::type; - -} // namespace cml - -#endif +template +using enable_if_reshapeable_t = typename enable_if_reshapeable::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/enable_if_same.h b/cml/common/mpl/enable_if_same.h index 55c131b..ec24f1d 100644 --- a/cml/common/mpl/enable_if_same.h +++ b/cml/common/mpl/enable_if_same.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_enable_if_same_h -#define cml_common_mpl_enable_if_same_h - #include namespace cml { @@ -16,16 +11,12 @@ namespace cml { /** Wrapper for enable_if to detect if a set of types, @c Froms, are the * same type as @c To. */ -template struct enable_if_same - : std::enable_if::value> {}; +template +struct enable_if_same : std::enable_if::value> +{}; /** Convenience alias for enable_if_same. */ -template using enable_if_same_t - = typename enable_if_same::type; - -} // namespace cml - -#endif +template +using enable_if_same_t = typename enable_if_same::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/enable_if_t.h b/cml/common/mpl/enable_if_t.h index 1a41de2..1c021ca 100644 --- a/cml/common/mpl/enable_if_t.h +++ b/cml/common/mpl/enable_if_t.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_enable_if_t_h -#define cml_common_mpl_enable_if_t_h - #include namespace cml { @@ -18,11 +13,6 @@ namespace cml { * @todo use C++14 enable_if_t if available. */ template - using enable_if_t = typename std::enable_if::type; - -} // namespace cml - -#endif +using enable_if_t = typename std::enable_if::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/if_t.h b/cml/common/mpl/if_t.h index b4ca760..4d8ca38 100644 --- a/cml/common/mpl/if_t.h +++ b/cml/common/mpl/if_t.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_if_t_h -#define cml_common_mpl_if_t_h - #include namespace cml { @@ -17,11 +12,6 @@ namespace cml { * takes the type of T. Otherwise, if_t takes the type of F. */ template - using if_t = typename std::conditional::type; - -} // namespace cml - -#endif +using if_t = typename std::conditional::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/int_c.h b/cml/common/mpl/int_c.h index 00a9c20..77c517a 100644 --- a/cml/common/mpl/int_c.h +++ b/cml/common/mpl/int_c.h @@ -1,27 +1,19 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_int_c_h -#define cml_common_mpl_int_c_h - #include namespace cml { /** Convenience "alias" for std::integral_constant. */ -template struct int_c : std::integral_constant {}; +template struct int_c : std::integral_constant +{}; + // Note: As of now, Visual C++ (18.00) apparently can't handle the obvious // alias when deducing function template arguments: // template using int_c = std::integral_constant; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/is_reshapeable.h b/cml/common/mpl/is_reshapeable.h index f71fd19..cdb471f 100644 --- a/cml/common/mpl/is_reshapeable.h +++ b/cml/common/mpl/is_reshapeable.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_is_reshapeable_h -#define cml_common_mpl_is_reshapeable_h - namespace cml { /** Helper that defines @c type as std::true_type and @c value as true if @@ -17,26 +12,22 @@ namespace cml { template struct is_reshapeable { /* Overload resolution trickery to determine if T implements resize(): */ + private: - template static inline auto has_resize(X&&) - -> decltype(std::declval().actual().resize(0,0), std::true_type()); + template + static inline auto has_resize(X&&) + -> decltype(std::declval().actual().resize(0, 0), std::true_type()); - template static inline auto has_resize(X...) - -> std::false_type; - public: + template static inline auto has_resize(X...) -> std::false_type; + public: /** std::true_type if @c T has a compatible resize() method, * std::false_type otherwise. */ - typedef decltype(has_resize(std::declval())) type; + using type = decltype(has_resize(std::declval())); /** true if @c T has a compatible resize() method, false otherwise. */ static const int value = type::value; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/is_same_pair.h b/cml/common/mpl/is_same_pair.h index 59ea89a..b68350e 100644 --- a/cml/common/mpl/is_same_pair.h +++ b/cml/common/mpl/is_same_pair.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_is_same_pair_h -#define cml_common_mpl_is_same_pair_h - #include namespace cml { @@ -16,25 +11,18 @@ namespace cml { /** Defines @c value to true if @c is symmetrically identical to @c * . */ -template -struct is_same_pair +template struct is_same_pair { - static const bool value - = (std::is_same::value && std::is_same::value) + static const bool value = + (std::is_same::value && std::is_same::value) || (std::is_same::value && std::is_same::value); }; /** Specialization of is_same_pair for matching @c U1 and @c U2. */ -template -struct is_same_pair +template struct is_same_pair { - static const bool value - = std::is_same::value && std::is_same::value; + static const bool value = + std::is_same::value && std::is_same::value; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/is_statically_polymorphic.h b/cml/common/mpl/is_statically_polymorphic.h index 9583f7d..ccb8628 100644 --- a/cml/common/mpl/is_statically_polymorphic.h +++ b/cml/common/mpl/is_statically_polymorphic.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_is_statically_polymorphic_h -#define cml_common_mpl_is_statically_polymorphic_h - #include namespace cml { @@ -17,34 +12,27 @@ namespace cml { * actual() that returns a reference type, or std::false_type otherwise. * The static bool @c value is set to true or false to match @c type. */ -template struct is_statically_polymorphic { +template struct is_statically_polymorphic +{ private: - /* SFINAE overload to deduce the return type of T::actual, if it exists. */ - template static auto get_type_of_actual(int) - -> decltype(std::declval().actual()); + template + static auto get_type_of_actual(int) -> decltype(std::declval().actual()); /* The default overload deduces a void return type. */ - template static auto get_type_of_actual(...) - -> void; + template static auto get_type_of_actual(...) -> void; public: - /* std::true_type if T::actual is a member function returning a * reference type, std::false_type otherwise. */ - typedef cml::if_t< + using type = cml::if_t< std::is_reference(0))>::value, - std::true_type, std::false_type> type; + std::true_type, std::false_type>; /* True or false, depending upon 'type': */ static const bool value = type::value; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/item_at.h b/cml/common/mpl/item_at.h index 806f9fa..00b6696 100644 --- a/cml/common/mpl/item_at.h +++ b/cml/common/mpl/item_at.h @@ -1,28 +1,20 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_item_at_h -#define cml_common_mpl_item_at_h - #include namespace cml { /** Return item @c N of argument pack @c Args. */ -template inline auto item_at(Args&&... args) --> decltype(std::get(std::forward_as_tuple(std::forward(args)...))) +template +inline auto +item_at(Args&&... args) + -> decltype(std::get(std::forward_as_tuple(std::forward(args)...))) { return std::get(std::forward_as_tuple(std::forward(args)...)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/plus_c.h b/cml/common/mpl/plus_c.h index 01f0017..a315e5e 100644 --- a/cml/common/mpl/plus_c.h +++ b/cml/common/mpl/plus_c.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_plus_c_h -#define cml_common_mpl_plus_c_h - namespace cml { /** Helper to add two integral constants. @@ -16,13 +11,9 @@ namespace cml { * @note This also avoids spurious VC14 "integral constant overflow" * warnings. */ -template struct plus_c { +template struct plus_c +{ static const int value = a + b; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/rebind.h b/cml/common/mpl/rebind.h index 0b22f89..b12a61f 100644 --- a/cml/common/mpl/rebind.h +++ b/cml/common/mpl/rebind.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_rebind_h -#define cml_common_mpl_rebind_h - #include #include @@ -18,13 +13,14 @@ namespace cml { * * @note Only typed parameters are supported. */ -template struct rebind { +template struct rebind +{ using other = typename T::template rebind::other; }; /** Convenience alias for rebind. */ template - using rebind_t = typename rebind::other; +using rebind_t = typename rebind::other; #ifdef CML_HAS_MSVC_WONKY_PARAMETER_PACK @@ -32,32 +28,29 @@ template * * @note Only typed parameters are supported. */ -template struct rebind_alloc { +template struct rebind_alloc +{ using traits = std::allocator_traits; using other = typename traits::template rebind_alloc; }; /** Convenience alias for rebind_alloc. */ template - using rebind_alloc_t = typename rebind_alloc::other; +using rebind_alloc_t = typename rebind_alloc::other; #else /** Helper to rebind allocator @c T. * * @note Only typed parameters are supported. */ -template struct rebind_alloc { +template struct rebind_alloc +{ using traits = std::allocator_traits; using other = typename traits::template rebind_alloc; }; /** Convenience alias for rebind_alloc. */ template - using rebind_alloc_t = typename rebind_alloc::other; -#endif - -} // namespace cml - +using rebind_alloc_t = typename rebind_alloc::other; #endif -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/mpl/type_map.h b/cml/common/mpl/type_map.h index 0bf2136..5f265cf 100644 --- a/cml/common/mpl/type_map.h +++ b/cml/common/mpl/type_map.h @@ -1,20 +1,15 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_type_map_h -#define cml_common_mpl_type_map_h - #include #ifdef _MSC_VER /* Disable "identifier too long" warning: */ -#pragma warning(push) -#pragma warning(disable : 4503) +# pragma warning(push) +# pragma warning(disable : 4503) #endif namespace cml { @@ -31,101 +26,95 @@ namespace cml { * }; * @endcode */ -template -class type_map +template class type_map { public: - - /** The type of @c type_map::find::type. */ - template struct result_type { - - /** The found type. Only valid if @c value is true. */ - typedef T type; - - /** @c value is true if @c type is in the table, false otherwise. */ - enum { value = Found }; + /** The type of @c type_map::find::type. */ + template struct result_type + { + /** The found type. Only valid if @c value is true. */ + using type = T; + + /** @c value is true if @c type is in the table, false otherwise. */ + enum + { + value = Found }; + }; public: - - /** Type-compare @c T to @c Entry::first. @c value is set to the + /** Type-compare @c T to @c Entry::first. @c value is set to the * comparison result. */ - template struct match { - typedef typename Entry::first first; - static const bool value = std::is_same::value; - }; + template struct match + { + using first = typename Entry::first; + static const bool value = std::is_same::value; + }; private: + /** The internal find<> helper. */ + template class Map, typename T, class... Rest> struct _find; - /** The internal find<> helper. */ - template class Map, - typename T, class... Rest> struct _find; - - template struct map_first { - typedef typename E::first first; - typedef typename E::second second; - }; + template struct map_first + { + using first = typename E::first; + using second = typename E::second; + }; - template struct map_second { - typedef typename E::second first; - typedef typename E::first second; - }; + template struct map_second + { + using first = typename E::second; + using second = typename E::first; + }; public: - - /** Search the @c first type of the map entries for T. If the match is + /** Search the @c first type of the map entries for T. If the match is * found, @c type is set to <@c T2, true>, where @c T2 is the @c first * type of the matching Entry. Otherwise, @c type is set to * . */ - template struct find_first { - typedef typename _find::type type; - }; + template struct find_first + { + using type = typename _find::type; + }; - template struct find_second { - typedef typename _find::type type; - }; + template struct find_second + { + using type = typename _find::type; + }; private: - - /** Match @c T to @c Entry, and recursively to @c Rest. */ - template class Map, - typename T, class Entry, class... Rest> - struct _find - { - typedef Map map_type; - static const bool found = match::value; - typedef cml::if_t - , typename _find::type> type; - }; - - /** The not-found case. */ - template class Map, typename T> struct _find { - typedef result_type type; - }; + /** Match @c T to @c Entry, and recursively to @c Rest. */ + template class Map, typename T, class Entry, class... Rest> + struct _find + { + using map_type = Map; + static const bool found = match::value; + using type = cml::if_t, + typename _find::type>; + }; + + /** The not-found case. */ + template class Map, typename T> struct _find + { + using type = result_type; + }; }; /** Basic implementation of a type_map entry. */ -template -struct type_map_item +template struct type_map_item { - typedef T1 first; - typedef T2 second; + using first = T1; + using second = T2; }; -} // namespace cml +} // namespace cml #ifdef _MSC_VER -#pragma warning(pop) -#endif - +# pragma warning(pop) #endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/common/mpl/type_table.h b/cml/common/mpl/type_table.h index 24e81fa..37b5f64 100644 --- a/cml/common/mpl/type_table.h +++ b/cml/common/mpl/type_table.h @@ -1,20 +1,15 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_mpl_type_table_h -#define cml_common_mpl_type_table_h - #include #ifdef _MSC_VER /* Disable "identifier too long" warning: */ -#pragma warning(push) -#pragma warning(disable : 4503) +# pragma warning(push) +# pragma warning(disable : 4503) #endif namespace cml { @@ -32,92 +27,81 @@ namespace cml { * }; * @endcode */ -template -class type_table +template class type_table { public: - - /** The type of @c type_table::find::type. */ - template struct result_type { - - /** The found type. Only valid if @c value is true. */ - typedef T type; - - /** @c value is true if @c type is in the table, false otherwise. */ - enum { value = Found }; + /** The type of @c type_table::find::type. */ + template struct result_type + { + /** The found type. Only valid if @c value is true. */ + using type = T; + + /** @c value is true if @c type is in the table, false otherwise. */ + enum + { + value = Found }; + }; public: - - /** Type-compare <@c Ta,@c Tb> to <@c Entry::first,@c Entry::second> + /** Type-compare <@c Ta,@c Tb> to <@c Entry::first,@c Entry::second> * using std::is_same, ignoring order. @c value is set to the * comparison result. */ - template - struct match - { - typedef typename Entry::first first; - typedef typename Entry::second second; - static const bool value - = (std::is_same::value && std::is_same::value) - || (std::is_same::value && std::is_same::value); - }; + template struct match + { + using first = typename Entry::first; + using second = typename Entry::second; + static const bool value = + (std::is_same::value && std::is_same::value) + || (std::is_same::value && std::is_same::value); + }; private: - - /** The internal find<> helper. */ - template struct _find; + /** The internal find<> helper. */ + template struct _find; public: - - /** Search the table for type pair <@c T1, @c T2>. If the pair is + /** Search the table for type pair <@c T1, @c T2>. If the pair is * found, @c type is set to <@c T, true>, where @c T is the mapped-to * type. Otherwise, @c type is set to . */ - template struct find { - typedef typename _find::type type; - }; + template struct find + { + using type = typename _find::type; + }; private: - - /** Match <@c T1, @c T2> to @c Entry, and recursively to @c Rest. */ - template - struct _find - { - static const bool found = match::value; - typedef cml::if_t - , typename _find::type> type; - }; - - /** The not-found case. */ - template - struct _find - { - typedef result_type type; - }; + /** Match <@c T1, @c T2> to @c Entry, and recursively to @c Rest. */ + template + struct _find + { + static const bool found = match::value; + using type = cml::if_t, + typename _find::type>; + }; + + /** The not-found case. */ + template struct _find + { + using type = result_type; + }; }; /** Basic implementation of a type_table entry. */ -template -struct type_table_item +template struct type_table_item { - typedef T1 first; - typedef T2 second; - typedef T type; + using first = T1; + using second = T2; + using type = T; }; -} // namespace cml +} // namespace cml #ifdef _MSC_VER -#pragma warning(pop) +# pragma warning(pop) #endif - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/common/promotion.h b/cml/common/promotion.h index 0a73735..56b807e 100644 --- a/cml/common/promotion.h +++ b/cml/common/promotion.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_promotion_h -#define cml_common_promotion_h - #include #include #include @@ -30,28 +25,24 @@ template struct size_check_promote static_assert(is_size_tag::value, "invalid size tag"); /* Promote to any_size_tag when combined with any other tag: */ - static const bool is_any - = std::is_same::value + static const bool is_any = std::is_same::value || std::is_same::value; /* Promote to fixed_size_tag when combining two fixed-size expressions: */ - static const bool is_fixed - = std::is_same::value - && std::is_same::value; + static const bool is_fixed = std::is_same::value + && std::is_same::value; /* Promote to dynamic_size_tag by default if not promoting to * any_size_tag or fixed_size_tag: */ - typedef - cml::if_t< is_any, any_size_tag, - cml::if_t< is_fixed, fixed_size_tag, - /* else */ dynamic_size_tag>> type; + using type = cml::if_t>; }; /** Convenience alias for size_check_promote. */ -template using size_check_promote_t -= typename size_check_promote::type; - +template +using size_check_promote_t = typename size_check_promote::type; /** Deduce the default size tag needed to promote the result of combining * two expressions having size tags @c Tag1 and @c Tag2. By default: @@ -66,48 +57,45 @@ template struct size_tag_promote static_assert(is_size_tag::value, "invalid size tag"); /* Fixed-size with any other tag promotes to fixed-size: */ - static const bool is_fixed - = std::is_same::value - || std::is_same::value; + static const bool is_fixed = std::is_same::value + || std::is_same::value; /* Promote to dynamic if not promoting to fixed, and if at least one of * the size tags is dynamic_size_tag: */ - static const bool is_dynamic = !is_fixed && - (std::is_same::value - || std::is_same::value); + static const bool is_dynamic = !is_fixed + && (std::is_same::value + || std::is_same::value); /* Promote to any_size_tag when both are any_size_tag: */ - static const bool is_any - = std::is_same::value + static const bool is_any = std::is_same::value && std::is_same::value; /* Has to be one of the deduced categories: */ static_assert(is_fixed || is_dynamic || is_any, "unexpected size tag type"); /* Promote to the selected tag: */ - typedef cml::if_t< is_fixed, fixed_size_tag, - cml::if_t< is_dynamic, dynamic_size_tag, - /* else */ any_size_tag>> type; + using type = cml::if_t>; }; /** Convenience alias for size_tag_promote. */ template - using size_tag_promote_t = typename size_tag_promote::type; +using size_tag_promote_t = typename size_tag_promote::type; /** Deduce the default size tag needed to promote the result of combining * two expressions @c T1 and @c T2 with traits that define the size_tag * type. */ -template struct size_tag_trait_promote { - typedef size_tag_promote_t< - size_tag_trait_of_t, size_tag_trait_of_t> type; +template struct size_tag_trait_promote +{ + using type = size_tag_promote_t, size_tag_trait_of_t>; }; /** Convenience alias for size_tag_trait_promote. */ -template using size_tag_trait_promote_t - = typename size_tag_trait_promote::type; - +template +using size_tag_trait_promote_t = typename size_tag_trait_promote::type; /** Deduce the default basis tag needed to promote the result of combining * two expressions having basis tags @c Tag1 and @c Tag2. By default: @@ -122,42 +110,40 @@ template struct basis_tag_promote static_assert(is_basis_tag::value, "invalid basis tag"); /* True if possible to promote to row_basis: */ - static const bool is_row_basis - = is_same_pair::value + static const bool is_row_basis = is_same_pair::value || is_same_pair::value; /* True if possible to promote to col_basis: */ - static const bool is_col_basis - = is_same_pair::value + static const bool is_col_basis = is_same_pair::value || is_same_pair::value; /* At least one has to be false: */ static_assert(!is_row_basis || !is_col_basis, "invalid basis promotion"); /* Promote to the selected basis, or any_basis otherwise: */ - typedef - cml::if_t< is_row_basis, row_basis, - cml::if_t< is_col_basis, col_basis, - /* else */ any_basis>> type; + using type = cml::if_t>; }; /** Convenience alias for basis_tag_promote. */ template - using basis_tag_promote_t = typename basis_tag_promote::type; +using basis_tag_promote_t = typename basis_tag_promote::type; /** Deduce the default basis tag needed to promote the result of combining * two expressions @c T1 and @c T2 with traits that define the basis_tag * type. */ -template struct basis_tag_trait_promote { - typedef basis_tag_promote_t< - basis_tag_trait_of_t, basis_tag_trait_of_t> type; +template struct basis_tag_trait_promote +{ + using type = basis_tag_promote_t, + basis_tag_trait_of_t>; }; /** Convenience alias for basis_tag_trait_promote. */ -template using basis_tag_trait_promote_t - = typename basis_tag_trait_promote::type; - +template +using basis_tag_trait_promote_t = + typename basis_tag_trait_promote::type; /** Deduce the default layout tag needed to promote the result of combining * two expressions having layout tags @c Tag1 and @c Tag2. By default: @@ -172,45 +158,39 @@ template struct layout_tag_promote static_assert(is_layout_tag::value, "invalid layout tag"); /* True if possible to promote to row_major: */ - static const bool is_row_major - = is_same_pair::value + static const bool is_row_major = is_same_pair::value || is_same_pair::value; /* True if possible to promote to col_major: */ - static const bool is_col_major - = is_same_pair::value + static const bool is_col_major = is_same_pair::value || is_same_pair::value; /* At least one has to be false: */ static_assert(!is_row_major || !is_col_major, "invalid layout promotion"); /* Promote to the selected layout, or any_major otherwise: */ - typedef - cml::if_t< is_row_major, row_major, - cml::if_t< is_col_major, col_major, - /* else */ any_major>> type; + using type = cml::if_t>; }; /** Convenience alias for layout_tag_promote. */ template - using layout_tag_promote_t = typename layout_tag_promote::type; +using layout_tag_promote_t = typename layout_tag_promote::type; /** Deduce the default layout tag needed to promote the result of combining * two expressions @c T1 and @c T2 with traits that define the layout_tag * type. */ -template struct layout_tag_trait_promote { - typedef layout_tag_promote_t< - layout_tag_trait_of_t, layout_tag_trait_of_t> type; +template struct layout_tag_trait_promote +{ + using type = layout_tag_promote_t, + layout_tag_trait_of_t>; }; /** Convenience alias for layout_tag_trait_promote. */ -template using layout_tag_trait_promote_t - = typename layout_tag_trait_promote::type; - -} // namespace cml - -#endif +template +using layout_tag_trait_promote_t = + typename layout_tag_trait_promote::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/size_tags.h b/cml/common/size_tags.h index 8c75230..5e81018 100644 --- a/cml/common/size_tags.h +++ b/cml/common/size_tags.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_size_tags_h -#define cml_common_size_tags_h - #include #include @@ -22,7 +17,8 @@ namespace cml { * @note Fixed-size matrix types define two constants, @c array_rows and @c * array_cols, containing the number of rows and columns. */ -struct fixed_size_tag {}; +struct fixed_size_tag +{}; /** Indicates a runtime-sized operand. * @@ -32,20 +28,22 @@ struct fixed_size_tag {}; * @note Dynamic-size matrices define two constants, @c array_rows and @c * array_cols, both set to -1. */ -struct dynamic_size_tag {}; +struct dynamic_size_tag +{}; /** Indicates that the vector or matrix type has an unspecified or * arbitrary size tag. */ -struct any_size_tag {}; +struct any_size_tag +{}; /** Detect valid size tags. * * @note This can be specialized for user-defined size tags. */ -template struct is_size_tag { - static const bool value - = std::is_same::value +template struct is_size_tag +{ + static const bool value = std::is_same::value || std::is_same::value || std::is_same::value; }; @@ -53,8 +51,9 @@ template struct is_size_tag { /** Templated helper to determine the size tag of an expression that * defines the size_tag type. */ -template struct size_tag_of { - typedef typename T::size_tag type; +template struct size_tag_of +{ + using type = typename T::size_tag; static_assert(is_size_tag::value, "invalid size tag"); }; @@ -62,62 +61,61 @@ template struct size_tag_of { template using size_tag_of_t = typename size_tag_of::type; /** Retrieve the size_tag of @c T via traits. */ -template struct size_tag_trait_of { - typedef typename traits_of::type::size_tag type; +template struct size_tag_trait_of +{ + using type = typename traits_of::type::size_tag; static_assert(is_size_tag::value, "invalid size tag"); }; /** Convenience alias for size_tag_trait_of. */ template - using size_tag_trait_of_t = typename size_tag_trait_of::type; +using size_tag_trait_of_t = typename size_tag_trait_of::type; /** Helper to detect fixed-size types. */ -template struct is_fixed_size { +template struct is_fixed_size +{ static const bool value = std::is_same, fixed_size_tag>::value; }; /** Wrapper for enable_if to detect types tagged with fixed_size_tag. */ -template struct enable_if_fixed_size -: std::enable_if::value, T> {}; +template +struct enable_if_fixed_size : std::enable_if::value, T> +{}; /** Convenience alias for enable_if_fixed_size. */ -template using enable_if_fixed_size_t - = typename enable_if_fixed_size::type; - +template +using enable_if_fixed_size_t = typename enable_if_fixed_size::type; /** Helper to detect dynamic-size types. */ -template struct is_dynamic_size { +template struct is_dynamic_size +{ static const bool value = std::is_same, dynamic_size_tag>::value; }; /** Wrapper for enable_if to detect types tagged with dynamic_size_tag. */ -template struct enable_if_dynamic_size -: std::enable_if::value, T> {}; +template +struct enable_if_dynamic_size : std::enable_if::value, T> +{}; /** Convenience alias for enable_if_dynamic_size. */ -template using enable_if_dynamic_size_t - = typename enable_if_dynamic_size::type; - +template +using enable_if_dynamic_size_t = typename enable_if_dynamic_size::type; /** Helper to detect any-size types. */ -template struct is_any_size { - static const bool value = - std::is_same, any_size_tag>::value; +template struct is_any_size +{ + static const bool value = std::is_same, any_size_tag>::value; }; /** Wrapper for enable_if to detect types tagged with any_size_tag. */ -template struct enable_if_any_size -: std::enable_if::value, T> {}; +template +struct enable_if_any_size : std::enable_if::value, T> +{}; /** Convenience alias for enable_if_any_size. */ -template using enable_if_any_size_t - = typename enable_if_any_size::type; - -} // namespace cml - -#endif +template +using enable_if_any_size_t = typename enable_if_any_size::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/storage_tags.h b/cml/common/storage_tags.h index d40e5fe..e5af02f 100644 --- a/cml/common/storage_tags.h +++ b/cml/common/storage_tags.h @@ -1,41 +1,39 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_storage_tags_h -#define cml_common_storage_tags_h - #include namespace cml { /** Specify vector storage types. */ -struct vector_storage_tag {}; +struct vector_storage_tag +{}; /** Specify matrix storage types. */ -struct matrix_storage_tag {}; +struct matrix_storage_tag +{}; /** Specify quaternion storage types. */ -struct quaternion_storage_tag {}; +struct quaternion_storage_tag +{}; /** Detect valid storage tags. */ -template struct is_storage_tag { - static const bool value - = std::is_same::value +template struct is_storage_tag +{ + static const bool value = std::is_same::value || std::is_same::value - || std::is_same::value - ; + || std::is_same::value; }; /** Templated helper to determine the storage tag of an expression that * defines the storage_tag type. */ -template struct storage_tag_of { - typedef typename T::storage_tag type; +template struct storage_tag_of +{ + using type = typename T::storage_tag; static_assert(is_storage_tag::value, "invalid storage tag"); }; @@ -43,26 +41,24 @@ template struct storage_tag_of { template using storage_tag_of_t = typename storage_tag_of::type; /** Helper to detect vector storage types. */ -template struct is_vector_storage { +template struct is_vector_storage +{ static const bool value = std::is_same, vector_storage_tag>::value; }; /** Helper to detect matrix storage types. */ -template struct is_matrix_storage { +template struct is_matrix_storage +{ static const bool value = std::is_same, matrix_storage_tag>::value; }; /** Helper to detect quaternion storage types. */ -template struct is_quaternion_storage { +template struct is_quaternion_storage +{ static const bool value = std::is_same, quaternion_storage_tag>::value; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/temporary.h b/cml/common/temporary.h index 3ccc9a0..de33e8b 100644 --- a/cml/common/temporary.h +++ b/cml/common/temporary.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_temporary_h -#define cml_common_temporary_h - namespace cml { /** Specializable struct to obtain a temporary for a specified expression @@ -20,9 +15,4 @@ template struct temporary_of; /** Convenience alias for temporary_of. */ template using temporary_of_t = typename temporary_of::type; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/traits.h b/cml/common/traits.h index 2bae744..b710204 100644 --- a/cml/common/traits.h +++ b/cml/common/traits.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_traits_h -#define cml_common_traits_h - namespace cml { /** Specializable struct to obtain the traits of a specified class, @@ -24,8 +19,9 @@ template using traits_of_t = typename traits_of::type; /*@{*/ /** Retrieve the value_type of @c T via an embedded typedef. */ -template struct value_type_of { - typedef typename T::value_type type; +template struct value_type_of +{ + using type = typename T::value_type; }; /** Convenience alias for value_typet_of. */ @@ -35,19 +31,15 @@ template using value_type_of_t = typename value_type_of::type; * * @note This applies to CML expression types, including scalars. */ -template struct value_type_trait_of { - typedef typename traits_of::type::value_type type; +template struct value_type_trait_of +{ + using type = typename traits_of::type::value_type; }; /** Convenience alias for value_type_trait_of. */ template - using value_type_trait_of_t = typename value_type_trait_of::type; +using value_type_trait_of_t = typename value_type_trait_of::type; /*@}*/ -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/common/type_util.h b/cml/common/type_util.h index c9b1126..72b5084 100644 --- a/cml/common/type_util.h +++ b/cml/common/type_util.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_common_type_util_h -#define cml_common_type_util_h - #include #include #include @@ -18,43 +13,41 @@ namespace cml { /** Remove const-volatile and reference types from @c T, but leave array and * function pointer types alone. */ -template struct unqualified_type { - typedef typename std::remove_cv< - typename std::remove_reference::type>::type type; +template struct unqualified_type +{ + using type = typename std::remove_cv::type>::type; }; /** Convenience alias for unqualified_type. */ -template using unqualified_type_t - = typename cml::unqualified_type::type; +template +using unqualified_type_t = typename cml::unqualified_type::type; /** Deduce the derived type of a statically polymorphic type @c T from the * reference return type of @c T::actual, if defined. If @c T does not * implement @c T::actual having a reference return type, then @c type is * defined as the unqualified base type of @c T. */ -template struct actual_type_of { +template struct actual_type_of +{ private: - /* Strip const, volatile, and reference from T to get the return type * of T::actual: */ - typedef cml::unqualified_type_t naked_type; + using naked_type = cml::unqualified_type_t; /* SFINAE overload to deduce the return type of T::actual, if it exists. */ - template static auto get_naked_type_of_actual(int) + template + static auto get_naked_type_of_actual(int) -> cml::unqualified_type_t().actual())>; /* The default overload deduces a void return type. */ - template static auto get_naked_type_of_actual(...) - -> void; + template static auto get_naked_type_of_actual(...) -> void; public: - /* Deduce the return type of T::actual: */ - typedef cml::if_t::value, - decltype(get_naked_type_of_actual(0)), - naked_type> type; + using type = cml::if_t::value, + decltype(get_naked_type_of_actual(0)), naked_type>; }; /** Convenience alias for actual_type_of<>. */ @@ -65,33 +58,27 @@ template using actual_type_of_t = typename actual_type_of::type; * types. For example, if @c T is readable_matrix&, then @c type is S&. * The const-ness of @c T is maintained for lvalue references. */ -template struct actual_operand_type_of { +template struct actual_operand_type_of +{ private: static_assert(std::is_reference::value, "T is not a reference type"); /* Possibly const, non-reference type: */ - typedef typename std::remove_reference::type base_type; + using base_type = typename std::remove_reference::type; /* Derived type of T: */ - typedef actual_type_of_t actual_type; + using actual_type = actual_type_of_t; public: - /* Build the reference type: */ - typedef cml::if_t< - std::is_rvalue_reference::value, actual_type&&, - cml::if_t::value, - const actual_type&, actual_type&>> type; + using type = cml::if_t::value, actual_type&&, + cml::if_t::value, const actual_type&, + actual_type&>>; }; /** Convenience alias for actual_operand_type_of<>. */ -template using actual_operand_type_of_t - = typename actual_operand_type_of::type; - -} // namespace cml - -#endif +template +using actual_operand_type_of_t = typename actual_operand_type_of::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/mathlib/axis_order.h b/cml/mathlib/axis_order.h index ec25a6d..a0f6296 100644 --- a/cml/mathlib/axis_order.h +++ b/cml/mathlib/axis_order.h @@ -1,43 +1,43 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_axis_order_h -#define cml_mathlib_axis_order_h - #include namespace cml { /** Specify 3D axis ordering. */ -enum axis_order { - axis_order_xyz = euler_order_xyz, // 0x00 [0000] - axis_order_xzy = euler_order_xzy, // 0x02 [0010] - axis_order_yzx = euler_order_yzx, // 0x04 [0100] - axis_order_yxz = euler_order_yxz, // 0x06 [0110] - axis_order_zxy = euler_order_zxy, // 0x08 [1000] - axis_order_zyx = euler_order_zyx // 0x0A [1010] +enum axis_order +{ + axis_order_xyz = euler_order_xyz, // 0x00 [0000] + axis_order_xzy = euler_order_xzy, // 0x02 [0010] + axis_order_yzx = euler_order_yzx, // 0x04 [0100] + axis_order_yxz = euler_order_yxz, // 0x06 [0110] + axis_order_zxy = euler_order_zxy, // 0x08 [1000] + axis_order_zyx = euler_order_zyx // 0x0A [1010] }; /** Specify 2D axis ordering. */ -enum axis_order2D { - axis_order_xy = axis_order_xyz, // 0x00 [0000] - axis_order_yx = axis_order_yxz, // 0x06 [0110] +enum axis_order2D +{ + axis_order_xy = axis_order_xyz, // 0x00 [0000] + axis_order_yx = axis_order_yxz, // 0x06 [0110] }; /** For CML1 compatibility. */ -typedef axis_order AxisOrder; -typedef axis_order2D AxisOrder2D; +using AxisOrder = axis_order; +using AxisOrder2D = axis_order2D; -inline void unpack_axis_order( - axis_order order, int& i, int& j, int& k, bool& odd - ) +inline void +unpack_axis_order(axis_order order, int& i, int& j, int& k, bool& odd) { - enum { ODD = 0x02, AXIS = 0x0C }; + enum + { + ODD = 0x02, + AXIS = 0x0C + }; odd = ((order & ODD) == ODD); int offset = int(odd); @@ -46,11 +46,14 @@ inline void unpack_axis_order( k = (i + 2 - offset) % 3; } -inline void unpack_axis_order2D( - axis_order2D order, int& i, int& j, bool& odd - ) +inline void +unpack_axis_order2D(axis_order2D order, int& i, int& j, bool& odd) { - enum { ODD = 0x02, AXIS = 0x0C }; + enum + { + ODD = 0x02, + AXIS = 0x0C + }; odd = ((order & ODD) == ODD); int offset = int(odd); @@ -58,11 +61,14 @@ inline void unpack_axis_order2D( j = (i + 1 + offset) % 3; } -inline axis_order pack_axis_order(int i, bool odd) { +inline axis_order +pack_axis_order(int i, bool odd) +{ return axis_order((i << 2) | (int(odd) << 1)); } -inline axis_order swap_axis_order(axis_order order) +inline axis_order +swap_axis_order(axis_order order) { int i, j, k; bool odd; @@ -70,9 +76,4 @@ inline axis_order swap_axis_order(axis_order order) return pack_axis_order(j, !odd); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/mathlib/constants.h b/cml/mathlib/constants.h index 28f4ba2..7577eae 100644 --- a/cml/mathlib/constants.h +++ b/cml/mathlib/constants.h @@ -1,28 +1,26 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_constants_h -#define cml_mathlib_constants_h - namespace cml { /** Coordinate system handedness. */ -enum AxisOrientation { left_handed, right_handed }; +enum AxisOrientation +{ + left_handed, + right_handed +}; /** For CML1 compatibility. */ -typedef AxisOrientation Handedness; +using Handedness = AxisOrientation; /** Perspective clipping type. */ -enum ZClip { z_clip_neg_one, z_clip_zero }; - -} // namespace cml - -#endif +enum ZClip +{ + z_clip_neg_one, + z_clip_zero +}; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/mathlib/coordinate_conversion.h b/cml/mathlib/coordinate_conversion.h index 69c09f9..b1be247 100644 --- a/cml/mathlib/coordinate_conversion.h +++ b/cml/mathlib/coordinate_conversion.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_coordinate_conversion_h -#define cml_mathlib_coordinate_conversion_h - #include #include @@ -20,10 +15,14 @@ namespace cml { /*@{*/ /** Spherical conversion types. */ -enum LatitudeType { latitude, colatitude }; +enum LatitudeType +{ + latitude, + colatitude +}; /** For CML1 compatibility. */ -typedef LatitudeType SphericalType; +using SphericalType = LatitudeType; /** @addtogroup mathlib_coord_conversion_to_cartesion Conversions to Cartesian Coordinates */ @@ -34,12 +33,12 @@ typedef LatitudeType SphericalType; * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 2D. If @c m is fixed-size, the size is checked at compile-time. */ -template void -polar_to_cartesian(writable_vector& v, E0 radius, E1 theta); +template +void polar_to_cartesian(writable_vector& v, E0 radius, E1 theta); /** For CML1 compatibility. */ -template void -polar_to_cartesian(E radius, E theta, writable_vector& v); +template +void polar_to_cartesian(E radius, E theta, writable_vector& v); /** Convert 3D cylindrical coordinates to Cartesian coordinates. @c v[axis] @@ -57,14 +56,14 @@ polar_to_cartesian(E radius, E theta, writable_vector& v); * * @throws std::invalid_argument if @c axis is not 0, 1, or 2. */ -template void -cylindrical_to_cartesian( - writable_vector& v, int axis, E0 radius, E1 theta, E2 height); +template +void cylindrical_to_cartesian(writable_vector& v, int axis, E0 radius, + E1 theta, E2 height); /** For CML1 compatibility. */ -template void -cylindrical_to_cartesian( - E radius, E theta, E height, int axis, writable_vector& v); +template +void cylindrical_to_cartesian(E radius, E theta, E height, int axis, + writable_vector& v); /** Convert 3D spherical coordinates to Cartesian coordinates. @@ -80,14 +79,14 @@ cylindrical_to_cartesian( * * @throws std::invalid_argument if @c axis is not 0, 1, or 2. */ -template void -spherical_to_cartesian(writable_vector& v, - int axis, LatitudeType type, E0 radius, E1 theta, E2 phi); +template +void spherical_to_cartesian(writable_vector& v, int axis, + LatitudeType type, E0 radius, E1 theta, E2 phi); /** For CML1 compatibility. */ -template void -spherical_to_cartesian(E radius, E theta, E phi, - int axis, LatitudeType type, writable_vector& v); +template +void spherical_to_cartesian(E radius, E theta, E phi, int axis, + LatitudeType type, writable_vector& v); /*@}*/ @@ -104,14 +103,14 @@ spherical_to_cartesian(E radius, E theta, E phi, * @note @c theta will be 0 if @c radius < sqrt(eps), where eps is machine * epsilon for the value_type of @c Sub. */ -template void -cartesian_to_polar(const readable_vector& v, E0& radius, E1& theta); +template +void cartesian_to_polar(const readable_vector& v, E0& radius, E1& theta); /** Convert 2D Cartesian coordinates to polar coordinates, specifying a * zero tolerance on @c radius. */ -template void -cartesian_to_polar(const readable_vector& v, E0& radius, E1& theta, +template +void cartesian_to_polar(const readable_vector& v, E0& radius, E1& theta, Tol tolerance); @@ -134,22 +133,22 @@ cartesian_to_polar(const readable_vector& v, E0& radius, E1& theta, * @note @c theta will be 0 if @c radius < sqrt(eps), where eps is machine * epsilon for the value_type of @c Sub. */ -template void -cartesian_to_cylindrical(const readable_vector& v, - int axis, E0& radius, E1& theta, E2& height); +template +void cartesian_to_cylindrical(const readable_vector& v, int axis, + E0& radius, E1& theta, E2& height); /** Convert 3D Cartesian coordinates to cylindrical coordinates, specifying * a zero tolerance on @c radius. */ -template void -cartesian_to_cylindrical(const readable_vector& v, - int axis, E0& radius, E1& theta, E2& height, Tol tolerance); +template +void cartesian_to_cylindrical(const readable_vector& v, int axis, + E0& radius, E1& theta, E2& height, Tol tolerance); /** For compatibility with CML1. */ -template void -cartesian_to_cylindrical(const readable_vector& v, - E& radius, E& theta, E& height, int axis, - E tolerance = scalar_traits::sqrt_epsilon()); +template +void cartesian_to_cylindrical(const readable_vector& v, E& radius, + E& theta, E& height, int axis, + E tolerance = scalar_traits::sqrt_epsilon()); /** Convert 3D Cartesian coordinates to spherical coordinates. @@ -169,35 +168,29 @@ cartesian_to_cylindrical(const readable_vector& v, * * @note @c phi will be 0 if @c v lies on the base plane. */ -template void -cartesian_to_spherical(const readable_vector& v, - int axis, LatitudeType type, E0& radius, E1& theta, E2& phi); +template +void cartesian_to_spherical(const readable_vector& v, int axis, + LatitudeType type, E0& radius, E1& theta, E2& phi); /** Convert 3D Cartesian coordinates to spherical coordinates, specifying * the zero tolerance on @c theta. */ -template void -cartesian_to_spherical(const readable_vector& v, - int axis, LatitudeType type, E0& radius, E1& theta, E2& phi, - Tol tolerance); +template +void cartesian_to_spherical(const readable_vector& v, int axis, + LatitudeType type, E0& radius, E1& theta, E2& phi, Tol tolerance); /** For compatibility with CML1. */ -template void -cartesian_to_spherical(const readable_vector& v, - E& radius, E& theta, E& phi, int axis, LatitudeType type, - E tolerance = scalar_traits::sqrt_epsilon()); +template +void cartesian_to_spherical(const readable_vector& v, E& radius, E& theta, + E& phi, int axis, LatitudeType type, + E tolerance = scalar_traits::sqrt_epsilon()); /*@}*/ /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_COORDINATE_CONVERSION_TPP #include #undef __CML_MATHLIB_COORDINATE_CONVERSION_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/coordinate_conversion.tpp b/cml/mathlib/coordinate_conversion.tpp index 4294372..e5e2924 100644 --- a/cml/mathlib/coordinate_conversion.tpp +++ b/cml/mathlib/coordinate_conversion.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_COORDINATE_CONVERSION_TPP -#error "mathlib/matrix/coordinate_conversion.tpp not included correctly" +# error "mathlib/matrix/coordinate_conversion.tpp not included correctly" #endif #include @@ -16,15 +14,13 @@ namespace cml { /* To Cartesian: */ -template inline void -polar_to_cartesian( - writable_vector& v, E0 radius, E1 theta - ) +template +inline void +polar_to_cartesian(writable_vector& v, E0 radius, E1 theta) { - typedef scalar_traits theta_traits; + using theta_traits = scalar_traits; - static_assert( - cml::are_convertible, E0, E1>::value, + static_assert(cml::are_convertible, E0, E1>::value, "incompatible scalar types"); cml::check_size(v, int_c<2>()); @@ -32,27 +28,25 @@ polar_to_cartesian( v[1] = theta_traits::sin(theta) * radius; } -template inline void -polar_to_cartesian( - E radius, E theta, writable_vector& v - ) +template +inline void +polar_to_cartesian(E radius, E theta, writable_vector& v) { polar_to_cartesian(v, radius, theta); } - -template inline void -cylindrical_to_cartesian( - writable_vector& v, int axis, E0 radius, E1 theta, E2 height - ) +template +inline void +cylindrical_to_cartesian(writable_vector& v, int axis, E0 radius, E1 theta, + E2 height) { - typedef scalar_traits theta_traits; + using theta_traits = scalar_traits; static_assert( cml::are_convertible, E0, E1, E2>::value, "incompatible scalar types"); - cml_require(0 <= axis && axis <= 2, - std::invalid_argument, "axis must be 0, 1, or 2"); + cml_require(0 <= axis && axis <= 2, std::invalid_argument, + "axis must be 0, 1, or 2"); cml::check_size(v, int_c<3>()); /* Make i = axis, and (j,k) equal to the other axis in cyclic order from @@ -67,27 +61,27 @@ cylindrical_to_cartesian( v[k] = theta_traits::sin(theta) * radius; } -template inline void -cylindrical_to_cartesian( - E radius, E theta, E height, int axis, writable_vector& v - ) +template +inline void +cylindrical_to_cartesian(E radius, E theta, E height, int axis, + writable_vector& v) { cylindrical_to_cartesian(v, axis, radius, theta, height); } - -template inline void -spherical_to_cartesian(writable_vector& v, - int axis, LatitudeType type, E0 radius, E1 theta, E2 phi) +template +inline void +spherical_to_cartesian(writable_vector& v, int axis, LatitudeType type, + E0 radius, E1 theta, E2 phi) { - typedef scalar_traits theta_traits; - typedef scalar_traits phi_traits; + using theta_traits = scalar_traits; + using phi_traits = scalar_traits; static_assert( cml::are_convertible, E0, E1, E2>::value, "incompatible scalar types"); - cml_require(0 <= axis && axis <= 2, - std::invalid_argument, "axis must be 0, 1, or 2"); + cml_require(0 <= axis && axis <= 2, std::invalid_argument, + "axis must be 0, 1, or 2"); cml::check_size(v, int_c<3>()); if(type == latitude) phi = constants::pi_over_2() - phi; @@ -108,25 +102,23 @@ spherical_to_cartesian(writable_vector& v, v[k] = sin_phi_r * theta_traits::sin(theta); } -template inline void -spherical_to_cartesian( - E radius, E theta, E phi, - int axis, LatitudeType type, writable_vector& v) +template +inline void +spherical_to_cartesian(E radius, E theta, E phi, int axis, LatitudeType type, + writable_vector& v) { spherical_to_cartesian(v, axis, type, radius, theta, phi); } - - /* From Cartesian: */ -template inline void -cartesian_to_polar( - const readable_vector& v, E0& radius, E1& theta, Tol tolerance - ) +template +inline void +cartesian_to_polar(const readable_vector& v, E0& radius, E1& theta, + Tol tolerance) { - typedef value_type_trait_of_t value_type; - typedef scalar_traits value_traits; + using value_type = value_type_trait_of_t; + using value_traits = scalar_traits; static_assert( cml::are_convertible, E0, E1, Tol>::value, @@ -134,34 +126,31 @@ cartesian_to_polar( cml::check_size(v, int_c<2>()); radius = v.length(); - theta = radius < tolerance - ? E1(0) : E1(value_traits::atan2(v[1], v[0])); + theta = radius < tolerance ? E1(0) : E1(value_traits::atan2(v[1], v[0])); } -template inline void -cartesian_to_polar( - const readable_vector& v, E0& radius, E1& theta - ) +template +inline void +cartesian_to_polar(const readable_vector& v, E0& radius, E1& theta) { - typedef value_type_trait_promote_t tolerance_type; + using tolerance_type = value_type_trait_promote_t; cartesian_to_polar(v, radius, theta, scalar_traits::sqrt_epsilon()); } - -template inline void -cartesian_to_cylindrical(const readable_vector& v, - int axis, E0& radius, E1& theta, E2& height, Tol tolerance - ) +template +inline void +cartesian_to_cylindrical(const readable_vector& v, int axis, E0& radius, + E1& theta, E2& height, Tol tolerance) { - typedef value_type_trait_of_t value_type; - typedef scalar_traits value_traits; + using value_type = value_type_trait_of_t; + using value_traits = scalar_traits; static_assert( cml::are_convertible, E0, E1, E2, Tol>::value, "incompatible scalar types"); - cml_require(0 <= axis && axis <= 2, - std::invalid_argument, "axis must be 0, 1, or 2"); + cml_require(0 <= axis && axis <= 2, std::invalid_argument, + "axis must be 0, 1, or 2"); cml::check_size(v, int_c<3>()); /* Make i = axis, and (j,k) equal to the other axis in cyclic order from @@ -173,43 +162,40 @@ cartesian_to_cylindrical(const readable_vector& v, /* Initialize return values; */ height = E2(v[i]); radius = E0(cml::length(v[j], v[k])); - theta = radius < tolerance - ? E1(0) : E1(value_traits::atan2(v[k], v[j])); + theta = radius < tolerance ? E1(0) : E1(value_traits::atan2(v[k], v[j])); } -template inline void -cartesian_to_cylindrical( - const readable_vector& v, int axis, E0& radius, E1& theta, E2& height - ) +template +inline void +cartesian_to_cylindrical(const readable_vector& v, int axis, E0& radius, + E1& theta, E2& height) { - typedef value_type_trait_promote_t tolerance_type; + using tolerance_type = value_type_trait_promote_t; cartesian_to_cylindrical(v, axis, radius, theta, height, scalar_traits::sqrt_epsilon()); } -template inline void -cartesian_to_cylindrical(const readable_vector& v, - E& radius, E& theta, E& height, int axis, E tolerance - ) +template +inline void +cartesian_to_cylindrical(const readable_vector& v, E& radius, E& theta, + E& height, int axis, E tolerance) { cartesian_to_cylindrical(v, axis, radius, theta, height, tolerance); } - -template inline void -cartesian_to_spherical(const readable_vector& v, - int axis, LatitudeType type, E0& radius, E1& theta, E2& phi, - Tol tolerance - ) +template +inline void +cartesian_to_spherical(const readable_vector& v, int axis, + LatitudeType type, E0& radius, E1& theta, E2& phi, Tol tolerance) { - typedef value_type_trait_of_t value_type; - typedef scalar_traits value_traits; + using value_type = value_type_trait_of_t; + using value_traits = scalar_traits; static_assert( cml::are_convertible, E0, E1, E2, Tol>::value, "incompatible scalar types"); - cml_require(0 <= axis && axis <= 2, - std::invalid_argument, "axis must be 0, 1, or 2"); + cml_require(0 <= axis && axis <= 2, std::invalid_argument, + "axis must be 0, 1, or 2"); cml::check_size(v, int_c<3>()); /* Make i = axis, and (j,k) equal to the other axis in cyclic order from @@ -224,30 +210,27 @@ cartesian_to_spherical(const readable_vector& v, if(radius < tolerance) { phi = E2(0); } else { - phi = E2(value_traits::atan2(len,v[i])); + phi = E2(value_traits::atan2(len, v[i])); if(type == latitude) phi = constants::pi_over_2() - phi; } } -template inline void -cartesian_to_spherical(const readable_vector& v, - int axis, LatitudeType type, E0& radius, E1& theta, E2& phi - ) +template +inline void +cartesian_to_spherical(const readable_vector& v, int axis, + LatitudeType type, E0& radius, E1& theta, E2& phi) { - typedef value_type_trait_promote_t tolerance_type; + using tolerance_type = value_type_trait_promote_t; cartesian_to_spherical(v, axis, type, radius, theta, phi, scalar_traits::sqrt_epsilon()); } -template inline void -cartesian_to_spherical(const readable_vector& v, - E& radius, E& theta, E& phi, int axis, LatitudeType type, E tolerance - ) +template +inline void +cartesian_to_spherical(const readable_vector& v, E& radius, E& theta, + E& phi, int axis, LatitudeType type, E tolerance) { cartesian_to_spherical(v, axis, type, radius, theta, phi, tolerance); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/mathlib/euler_order.h b/cml/mathlib/euler_order.h index ec6c37e..319c495 100644 --- a/cml/mathlib/euler_order.h +++ b/cml/mathlib/euler_order.h @@ -1,45 +1,45 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_euler_order_h -#define cml_mathlib_euler_order_h - namespace cml { /** Constants for specifying the order of Euler angle computations. */ enum euler_order { - euler_order_xyz, // 0x00 [0000] - euler_order_xyx, // 0x01 [0001] - euler_order_xzy, // 0x02 [0010] - euler_order_xzx, // 0x03 [0011] - euler_order_yzx, // 0x04 [0100] - euler_order_yzy, // 0x05 [0101] - euler_order_yxz, // 0x06 [0110] - euler_order_yxy, // 0x07 [0111] - euler_order_zxy, // 0x08 [1000] - euler_order_zxz, // 0x09 [1001] - euler_order_zyx, // 0x0A [1010] - euler_order_zyz // 0x0B [1011] + euler_order_xyz, // 0x00 [0000] + euler_order_xyx, // 0x01 [0001] + euler_order_xzy, // 0x02 [0010] + euler_order_xzx, // 0x03 [0011] + euler_order_yzx, // 0x04 [0100] + euler_order_yzy, // 0x05 [0101] + euler_order_yxz, // 0x06 [0110] + euler_order_yxy, // 0x07 [0111] + euler_order_zxy, // 0x08 [1000] + euler_order_zxz, // 0x09 [1001] + euler_order_zyx, // 0x0A [1010] + euler_order_zyz // 0x0B [1011] }; /** For CML1 compatibility. */ -typedef euler_order EulerOrder; +using EulerOrder = euler_order; /** Unpack Euler ordering @c order as three integers in {0, 1, 2}. If @c * odd is true, the ordering is swapped. If @c repeat is true, one axis * appears twice in the order. */ -inline void unpack_euler_order( - euler_order order, int& i, int& j, int& k, bool& odd, bool& repeat - ) +inline void +unpack_euler_order(euler_order order, int& i, int& j, int& k, bool& odd, + bool& repeat) { - enum { REPEAT = 0x01, ODD = 0x02, AXIS = 0x0C }; + enum + { + REPEAT = 0x01, + ODD = 0x02, + AXIS = 0x0C + }; repeat = order & REPEAT; odd = ((order & ODD) == ODD); @@ -49,9 +49,4 @@ inline void unpack_euler_order( k = (i + 2 - offset) % 3; } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/mathlib/frustum.h b/cml/mathlib/frustum.h index 678bc06..d97c054 100644 --- a/cml/mathlib/frustum.h +++ b/cml/mathlib/frustum.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_frustum_h -#define cml_mathlib_frustum_h - #include #include @@ -39,11 +34,10 @@ namespace cml { * is dynamically-sized and non-square. The size is checked at * compile-time for fixed-size matrices. */ -template void -extract_frustum_planes( - const readable_matrix& modelview, - const readable_matrix& projection, - E planes[6][4], ZClip z_clip, bool normalize = true); +template +void extract_frustum_planes(const readable_matrix& modelview, + const readable_matrix& projection, E planes[6][4], ZClip z_clip, + bool normalize = true); /** Extract the planes of a frustum from a matrix assumed to contain any * model and view transforms, followed by a projection transform with the @@ -62,10 +56,9 @@ extract_frustum_planes( * and is not at least 4x4. The size is checked at compile-time for * fixed-size matrices. */ -template void -extract_frustum_planes( - const readable_matrix& m, - E planes[6][4], ZClip z_clip, bool normalize = true); +template +void extract_frustum_planes(const readable_matrix& m, E planes[6][4], + ZClip z_clip, bool normalize = true); /** Extract the near plane of a frustum given a concatenated modelview and * projection matrix @c m and the near z-clipping range. The plane is not @@ -78,19 +71,14 @@ extract_frustum_planes( * and is not at least 4x4. The size is checked at compile-time for * fixed-size matrices. */ -template void -extract_near_frustum_plane( - const readable_matrix& m, Plane& plane, ZClip z_clip); +template +void extract_near_frustum_plane(const readable_matrix& m, Plane& plane, + ZClip z_clip); /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_FRUSTUM_TPP #include #undef __CML_MATHLIB_FRUSTUM_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/frustum.tpp b/cml/mathlib/frustum.tpp index 870af99..a407b5f 100644 --- a/cml/mathlib/frustum.tpp +++ b/cml/mathlib/frustum.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_FRUSTUM_TPP -#error "mathlib/frustum.tpp not included correctly" +# error "mathlib/frustum.tpp not included correctly" #endif #include @@ -14,29 +12,22 @@ namespace cml { -template void -extract_frustum_planes( - const readable_matrix& modelview, - const readable_matrix& projection, - E planes[6][4], - ZClip z_clip, - bool normalize - ) +template +void +extract_frustum_planes(const readable_matrix& modelview, + const readable_matrix& projection, E planes[6][4], ZClip z_clip, + bool normalize) { - extract_frustum_planes( - matrix_concat(modelview, projection), planes, z_clip, normalize); + extract_frustum_planes(matrix_concat(modelview, projection), planes, z_clip, + normalize); } -template void -extract_frustum_planes( - const readable_matrix& m, - E planes[6][4], - ZClip z_clip, - bool normalize - ) +template +void +extract_frustum_planes(const readable_matrix& m, E planes[6][4], + ZClip z_clip, bool normalize) { - static_assert( - cml::are_convertible, E>::value, + static_assert(cml::are_convertible, E>::value, "incompatible scalar types"); /* Near: [03+02, 13+12, 23+22, 33+32] : [02, 12, 22, 32] */ @@ -45,38 +36,38 @@ extract_frustum_planes( /* Left: [03+00, 13+10, 23+20, 33+30] */ - planes[0][0] = E(m.basis_element(0,3) + m.basis_element(0,0)); - planes[0][1] = E(m.basis_element(1,3) + m.basis_element(1,0)); - planes[0][2] = E(m.basis_element(2,3) + m.basis_element(2,0)); - planes[0][3] = E(m.basis_element(3,3) + m.basis_element(3,0)); + planes[0][0] = E(m.basis_element(0, 3) + m.basis_element(0, 0)); + planes[0][1] = E(m.basis_element(1, 3) + m.basis_element(1, 0)); + planes[0][2] = E(m.basis_element(2, 3) + m.basis_element(2, 0)); + planes[0][3] = E(m.basis_element(3, 3) + m.basis_element(3, 0)); /* Right: [03-00, 13-10, 23-20, 33-30] */ - planes[1][0] = E(m.basis_element(0,3) - m.basis_element(0,0)); - planes[1][1] = E(m.basis_element(1,3) - m.basis_element(1,0)); - planes[1][2] = E(m.basis_element(2,3) - m.basis_element(2,0)); - planes[1][3] = E(m.basis_element(3,3) - m.basis_element(3,0)); + planes[1][0] = E(m.basis_element(0, 3) - m.basis_element(0, 0)); + planes[1][1] = E(m.basis_element(1, 3) - m.basis_element(1, 0)); + planes[1][2] = E(m.basis_element(2, 3) - m.basis_element(2, 0)); + planes[1][3] = E(m.basis_element(3, 3) - m.basis_element(3, 0)); /* Bottom: [03+01, 13+11, 23+21, 33+31] */ - planes[2][0] = E(m.basis_element(0,3) + m.basis_element(0,1)); - planes[2][1] = E(m.basis_element(1,3) + m.basis_element(1,1)); - planes[2][2] = E(m.basis_element(2,3) + m.basis_element(2,1)); - planes[2][3] = E(m.basis_element(3,3) + m.basis_element(3,1)); + planes[2][0] = E(m.basis_element(0, 3) + m.basis_element(0, 1)); + planes[2][1] = E(m.basis_element(1, 3) + m.basis_element(1, 1)); + planes[2][2] = E(m.basis_element(2, 3) + m.basis_element(2, 1)); + planes[2][3] = E(m.basis_element(3, 3) + m.basis_element(3, 1)); /* Top: [03-01, 13-11, 23-21, 33-31] */ - planes[3][0] = E(m.basis_element(0,3) - m.basis_element(0,1)); - planes[3][1] = E(m.basis_element(1,3) - m.basis_element(1,1)); - planes[3][2] = E(m.basis_element(2,3) - m.basis_element(2,1)); - planes[3][3] = E(m.basis_element(3,3) - m.basis_element(3,1)); + planes[3][0] = E(m.basis_element(0, 3) - m.basis_element(0, 1)); + planes[3][1] = E(m.basis_element(1, 3) - m.basis_element(1, 1)); + planes[3][2] = E(m.basis_element(2, 3) - m.basis_element(2, 1)); + planes[3][3] = E(m.basis_element(3, 3) - m.basis_element(3, 1)); /* Far: [03-02, 13-12, 23-22, 33-32] */ - planes[5][0] = E(m.basis_element(0,3) - m.basis_element(0,2)); - planes[5][1] = E(m.basis_element(1,3) - m.basis_element(1,2)); - planes[5][2] = E(m.basis_element(2,3) - m.basis_element(2,2)); - planes[5][3] = E(m.basis_element(3,3) - m.basis_element(3,2)); + planes[5][0] = E(m.basis_element(0, 3) - m.basis_element(0, 2)); + planes[5][1] = E(m.basis_element(1, 3) - m.basis_element(1, 2)); + planes[5][2] = E(m.basis_element(2, 3) - m.basis_element(2, 2)); + planes[5][3] = E(m.basis_element(3, 3) - m.basis_element(3, 2)); /* Compute normalized planes: */ if(normalize) { @@ -90,29 +81,29 @@ extract_frustum_planes( } } -template void -extract_near_frustum_plane( - const readable_matrix& m, Plane& plane, ZClip z_clip - ) +template +void +extract_near_frustum_plane(const readable_matrix& m, Plane& plane, + ZClip z_clip) { cml::check_minimum_size(m, cml::int_c<4>(), cml::int_c<4>()); //XXX cml::check_minimum_size(plane, cml::int_c<4>()); /* Near: [03+02, 13+12, 23+22, 33+32] : [02, 12, 22, 32] */ - if (z_clip == z_clip_neg_one) { - plane[0] = m.basis_element(0,3) + m.basis_element(0,2); - plane[1] = m.basis_element(1,3) + m.basis_element(1,2); - plane[2] = m.basis_element(2,3) + m.basis_element(2,2); - plane[3] = m.basis_element(3,3) + m.basis_element(3,2); - } else { // z_clip == z_clip_zero - plane[0] = m.basis_element(0,2); - plane[1] = m.basis_element(1,2); - plane[2] = m.basis_element(2,2); - plane[3] = m.basis_element(3,2); + if(z_clip == z_clip_neg_one) { + plane[0] = m.basis_element(0, 3) + m.basis_element(0, 2); + plane[1] = m.basis_element(1, 3) + m.basis_element(1, 2); + plane[2] = m.basis_element(2, 3) + m.basis_element(2, 2); + plane[3] = m.basis_element(3, 3) + m.basis_element(3, 2); + } else { // z_clip == z_clip_zero + plane[0] = m.basis_element(0, 2); + plane[1] = m.basis_element(1, 2); + plane[2] = m.basis_element(2, 2); + plane[3] = m.basis_element(3, 2); } } -} // namespace cml +} // namespace cml #if 0 // XXX INCOMPLETE XXX @@ -217,7 +208,4 @@ get_frustum_corners(Real planes[6][4], vector corners[8]) ); } -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +#endif \ No newline at end of file diff --git a/cml/mathlib/mathlib.h b/cml/mathlib/mathlib.h index 996073e..37b8e4f 100644 --- a/cml/mathlib/mathlib.h +++ b/cml/mathlib/mathlib.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_mathlib_h -#define cml_mathlib_mathlib_h - #include #include #include @@ -33,8 +28,3 @@ #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/matrix/basis.h b/cml/mathlib/matrix/basis.h index 0a1242d..f545694 100644 --- a/cml/mathlib/matrix/basis.h +++ b/cml/mathlib/matrix/basis.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_matrix_basis_h -#define cml_mathlib_matrix_basis_h - #include #include #include @@ -24,236 +19,231 @@ namespace cml { /*@{*/ /** Set the i'th basis vector of a 2D transform */ -template inline void -matrix_set_basis_vector_2D( - writable_matrix& m, int i, const readable_vector& v); +template +inline void matrix_set_basis_vector_2D(writable_matrix& m, int i, + const readable_vector& v); /** Set the x basis vector of a 2D transform */ -template inline void -matrix_set_x_basis_vector_2D( - writable_matrix& m, const readable_vector& x); +template +inline void matrix_set_x_basis_vector_2D(writable_matrix& m, + const readable_vector& x); /** Set the y basis vector of a 2D transform */ -template inline void -matrix_set_y_basis_vector_2D( - writable_matrix& m, const readable_vector& y); +template +inline void matrix_set_y_basis_vector_2D(writable_matrix& m, + const readable_vector& y); /** Set the basis vectors of 2D transform @c m. */ -template inline void -matrix_set_basis_vectors_2D(writable_matrix& m, +template +inline void matrix_set_basis_vectors_2D(writable_matrix& m, const readable_vector& x, const readable_vector& y); /** Set the i'th transposed basis vector of a 2D transform */ -template inline void -matrix_set_transposed_basis_vector_2D( - writable_matrix& m, int i, const readable_vector& v); +template +inline void matrix_set_transposed_basis_vector_2D(writable_matrix& m, + int i, const readable_vector& v); /** Set the transposed x basis vector of a 2D transform */ -template inline void -matrix_set_transposed_x_basis_vector_2D( - writable_matrix& m, const readable_vector& x); +template +inline void matrix_set_transposed_x_basis_vector_2D(writable_matrix& m, + const readable_vector& x); /** Set the transposed y basis vector of a 2D transform */ -template inline void -matrix_set_transposed_y_basis_vector_2D( - writable_matrix& m, const readable_vector& y); +template +inline void matrix_set_transposed_y_basis_vector_2D(writable_matrix& m, + const readable_vector& y); /** Set the transposed basis vectors of 2D transform @c m. */ -template inline void -matrix_set_transposed_basis_vectors_2D(writable_matrix& m, +template +inline void matrix_set_transposed_basis_vectors_2D(writable_matrix& m, const readable_vector& x, const readable_vector& y); /** Get the i'th basis vector of a 2D transform as a temporary vector. */ -template inline auto -matrix_get_basis_vector_2D(const readable_matrix& m, int i) --> n_basis_vector_of_t; +template +inline auto matrix_get_basis_vector_2D(const readable_matrix& m, int i) + -> n_basis_vector_of_t; /** Get the x basis vector of a 2D transform as a temporary vector. */ -template inline auto -matrix_get_x_basis_vector_2D(const readable_matrix& m) --> n_basis_vector_of_t; +template +inline auto matrix_get_x_basis_vector_2D(const readable_matrix& m) + -> n_basis_vector_of_t; /** Get the y basis vector of a 2D transform as a temporary vector. */ -template inline auto -matrix_get_y_basis_vector_2D(const readable_matrix& m) --> n_basis_vector_of_t; +template +inline auto matrix_get_y_basis_vector_2D(const readable_matrix& m) + -> n_basis_vector_of_t; /** Get the basis vectors of 2D transform @c m. */ -template inline void -matrix_get_basis_vectors_2D(const readable_matrix& m, +template +inline void matrix_get_basis_vectors_2D(const readable_matrix& m, writable_vector& x, writable_vector& y); /** Get the i'th transposed basis vector of a 2D transform as a temporary * vector. */ -template inline auto -matrix_get_transposed_basis_vector_2D(const readable_matrix& m, int i) --> n_basis_vector_of_t; +template +inline auto matrix_get_transposed_basis_vector_2D(const readable_matrix& m, + int i) -> n_basis_vector_of_t; /** Get the transposed x basis vector of a 2D transform as a temporary * vector. */ -template inline auto -matrix_get_transposed_x_basis_vector_2D(const readable_matrix& m) --> n_basis_vector_of_t; +template +inline auto matrix_get_transposed_x_basis_vector_2D( + const readable_matrix& m) -> n_basis_vector_of_t; /** Get the transposed y basis vector of a 2D transform as a temporary * vector. */ -template inline auto -matrix_get_transposed_y_basis_vector_2D(const readable_matrix& m) --> n_basis_vector_of_t; +template +inline auto matrix_get_transposed_y_basis_vector_2D( + const readable_matrix& m) -> n_basis_vector_of_t; /** Get the transposed basis vectors of 2D transform @c m. */ -template inline void -matrix_get_transposed_basis_vectors_2D(const readable_matrix& m, - writable_vector& v1, writable_vector& v2); +template +inline void matrix_get_transposed_basis_vectors_2D( + const readable_matrix& m, writable_vector& v1, + writable_vector& v2); -/*@}*/ // mathlib_matrix_basis_2D +/*@}*/ // mathlib_matrix_basis_2D /** @defgroup mathlib_matrix_basis_3D 3D Matrix Basis Functions */ /*@{*/ /** Set the i'th basis vector of a 3D transform */ -template inline void -matrix_set_basis_vector( - writable_matrix& m, int i, const readable_vector& v); +template +inline void matrix_set_basis_vector(writable_matrix& m, int i, + const readable_vector& v); /** Set the x basis vector of a 3D transform */ -template inline void -matrix_set_x_basis_vector( - writable_matrix& m, const readable_vector& x); +template +inline void matrix_set_x_basis_vector(writable_matrix& m, + const readable_vector& x); /** Set the y basis vector of a 3D transform */ -template inline void -matrix_set_y_basis_vector( - writable_matrix& m, const readable_vector& y); +template +inline void matrix_set_y_basis_vector(writable_matrix& m, + const readable_vector& y); /** Set the z basis vector of a 3D transform */ -template inline void -matrix_set_z_basis_vector( - writable_matrix& m, const readable_vector& z); +template +inline void matrix_set_z_basis_vector(writable_matrix& m, + const readable_vector& z); /** Set the basis vectors of 3D transform @c m. */ -template inline void -matrix_set_basis_vectors( - writable_matrix& m, const readable_vector& x, - const readable_vector& y, const readable_vector& z); +template +inline void matrix_set_basis_vectors(writable_matrix& m, + const readable_vector& x, const readable_vector& y, + const readable_vector& z); /** Set the i'th transposed basis vector of a 3D transform */ -template inline void -matrix_set_transposed_basis_vector( - writable_matrix& m, int i, const readable_vector& v); +template +inline void matrix_set_transposed_basis_vector(writable_matrix& m, int i, + const readable_vector& v); /** Set the transposed x basis vector of a 3D transform */ -template inline void -matrix_set_transposed_x_basis_vector( - writable_matrix& m, const readable_vector& x); +template +inline void matrix_set_transposed_x_basis_vector(writable_matrix& m, + const readable_vector& x); /** Set the transposed y basis vector of a 3D transform */ -template inline void -matrix_set_transposed_y_basis_vector( - writable_matrix& m, const readable_vector& y); +template +inline void matrix_set_transposed_y_basis_vector(writable_matrix& m, + const readable_vector& y); /** Set the transposed z basis vector of a 3D transform */ -template inline void -matrix_set_transposed_z_basis_vector( - writable_matrix& m, const readable_vector& z); +template +inline void matrix_set_transposed_z_basis_vector(writable_matrix& m, + const readable_vector& z); /** Set the transposed basis vectors of 3D transform @c m. */ -template inline void -matrix_set_transposed_basis_vectors( - writable_matrix& m, const readable_vector& x, - const readable_vector& y, const readable_vector& z); +template +inline void matrix_set_transposed_basis_vectors(writable_matrix& m, + const readable_vector& x, const readable_vector& y, + const readable_vector& z); /** Get the i'th basis vector of a 3D transform as a temporary vector. */ -template inline auto -matrix_get_basis_vector(const readable_matrix& m, int i) --> n_basis_vector_of_t; +template +inline auto matrix_get_basis_vector(const readable_matrix& m, int i) + -> n_basis_vector_of_t; /** Get the x basis vector of a 3D transform as a temporary vector. */ -template inline auto -matrix_get_x_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t; +template +inline auto matrix_get_x_basis_vector(const readable_matrix& m) + -> n_basis_vector_of_t; /** Get the y basis vector of a 3D transform as a temporary vector. */ -template inline auto -matrix_get_y_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t; +template +inline auto matrix_get_y_basis_vector(const readable_matrix& m) + -> n_basis_vector_of_t; /** Get the z basis vector of a 3D transform as a temporary vector. */ -template inline auto -matrix_get_z_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t; +template +inline auto matrix_get_z_basis_vector(const readable_matrix& m) + -> n_basis_vector_of_t; /** Get the basis vectors of a 3D transform */ -template inline void -matrix_get_basis_vectors( - const readable_matrix& m, writable_vector& v1, - writable_vector& v2, writable_vector& v3); +template +inline void matrix_get_basis_vectors(const readable_matrix& m, + writable_vector& v1, writable_vector& v2, + writable_vector& v3); /** Get the i'th transposed basis vector of a 3D transform as a temporary * vector. */ -template inline auto -matrix_get_transposed_basis_vector(const readable_matrix& m, int i) --> n_basis_vector_of_t; +template +inline auto matrix_get_transposed_basis_vector(const readable_matrix& m, + int i) -> n_basis_vector_of_t; /** Get the transposed x basis vector of a 3D transform as a temporary * vector. */ -template inline auto -matrix_get_transposed_x_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t; +template +inline auto matrix_get_transposed_x_basis_vector(const readable_matrix& m) + -> n_basis_vector_of_t; /** Get the transposed y basis vector of a 3D transform as a temporary * vector. */ -template inline auto -matrix_get_transposed_y_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t; +template +inline auto matrix_get_transposed_y_basis_vector(const readable_matrix& m) + -> n_basis_vector_of_t; /** Get the transposed z basis vector of a 3D transform as a temporary * vector. */ -template inline auto -matrix_get_transposed_z_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t; +template +inline auto matrix_get_transposed_z_basis_vector(const readable_matrix& m) + -> n_basis_vector_of_t; /** Get the transposed basis vectors of 3D transform @c m. */ -template inline void -matrix_get_transposed_basis_vectors( - const readable_matrix& m, writable_vector& x, - writable_vector& y, writable_vector& z); +template +inline void matrix_get_transposed_basis_vectors(const readable_matrix& m, + writable_vector& x, writable_vector& y, writable_vector& z); -/*@}*/ // mathlib_matrix_basis_3D +/*@}*/ // mathlib_matrix_basis_3D /** @defgroup mathlib_matrix_basis_nD nD Matrix Basis Functions */ /*@{*/ -template auto -matrix_get_basis_vector_nD(const readable_matrix& m, int i) --> basis_vector_of_t; +template +auto matrix_get_basis_vector_nD(const readable_matrix& m, int i) + -> basis_vector_of_t; -/*@}*/ // mathlib_matrix_basis_nD +/*@}*/ // mathlib_matrix_basis_nD -/*@}*/ // mathlib_matrix_basis +/*@}*/ // mathlib_matrix_basis -} // namespace cml +} // namespace cml #define __CML_MATHLIB_MATRIX_BASIS_TPP #include #undef __CML_MATHLIB_MATRIX_BASIS_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/matrix/basis.tpp b/cml/mathlib/matrix/basis.tpp index 4bfa1ba..48b8aa1 100644 --- a/cml/mathlib/matrix/basis.tpp +++ b/cml/mathlib/matrix/basis.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_MATRIX_BASIS_TPP -#error "mathlib/matrix/basis.tpp not included correctly" +# error "mathlib/matrix/basis.tpp not included correctly" #endif #include @@ -16,10 +14,10 @@ namespace cml { /* 2D basis functions: */ -template inline void -matrix_set_basis_vector_2D( - writable_matrix& m, int i, const readable_vector& v - ) +template +inline void +matrix_set_basis_vector_2D(writable_matrix& m, int i, + const readable_vector& v) { cml::check_linear_2D(m); cml::check_size(v, int_c<2>()); @@ -29,38 +27,35 @@ matrix_set_basis_vector_2D( m.set_basis_element(i, 1, v[1]); } -template inline void -matrix_set_x_basis_vector_2D( - writable_matrix& m, const readable_vector& x - ) +template +inline void +matrix_set_x_basis_vector_2D(writable_matrix& m, + const readable_vector& x) { matrix_set_basis_vector_2D(m, 0, x); } -template inline void -matrix_set_y_basis_vector_2D( - writable_matrix& m, const readable_vector& y - ) +template +inline void +matrix_set_y_basis_vector_2D(writable_matrix& m, + const readable_vector& y) { matrix_set_basis_vector_2D(m, 1, y); } -template inline void -matrix_set_basis_vectors_2D( - writable_matrix& m, - const readable_vector& x, - const readable_vector& y - ) +template +inline void +matrix_set_basis_vectors_2D(writable_matrix& m, + const readable_vector& x, const readable_vector& y) { matrix_set_x_basis_vector_2D(m, x); matrix_set_y_basis_vector_2D(m, y); } - -template inline void -matrix_set_transposed_basis_vector_2D( - writable_matrix& m, int i, const readable_vector& v - ) +template +inline void +matrix_set_transposed_basis_vector_2D(writable_matrix& m, int i, + const readable_vector& v) { cml::check_linear_2D(m); cml::check_size(v, int_c<2>()); @@ -70,113 +65,109 @@ matrix_set_transposed_basis_vector_2D( m.set_basis_element(1, i, v[1]); } -template inline void -matrix_set_transposed_x_basis_vector_2D( - writable_matrix& m, const readable_vector& x - ) +template +inline void +matrix_set_transposed_x_basis_vector_2D(writable_matrix& m, + const readable_vector& x) { matrix_set_transposed_basis_vector_2D(m, 0, x); } -template inline void -matrix_set_transposed_y_basis_vector_2D( - writable_matrix& m, const readable_vector& y - ) +template +inline void +matrix_set_transposed_y_basis_vector_2D(writable_matrix& m, + const readable_vector& y) { matrix_set_transposed_basis_vector_2D(m, 1, y); } -template inline void -matrix_set_transposed_basis_vectors_2D( - writable_matrix& m, - const readable_vector& x, - const readable_vector& y - ) +template +inline void +matrix_set_transposed_basis_vectors_2D(writable_matrix& m, + const readable_vector& x, const readable_vector& y) { matrix_set_transposed_x_basis_vector_2D(m, x); matrix_set_transposed_y_basis_vector_2D(m, y); } - -template inline auto +template +inline auto matrix_get_basis_vector_2D(const readable_matrix& m, int i) --> n_basis_vector_of_t + -> n_basis_vector_of_t { cml::check_linear_2D(m); cml_require(0 <= i && i <= 1, std::invalid_argument, "invalid 2D index"); - return n_basis_vector_of_t( - m.basis_element(i,0), m.basis_element(i,1)); + return n_basis_vector_of_t(m.basis_element(i, 0), + m.basis_element(i, 1)); } -template inline auto +template +inline auto matrix_get_x_basis_vector_2D(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { - return matrix_get_basis_vector_2D(m,0); + return matrix_get_basis_vector_2D(m, 0); } -template inline auto +template +inline auto matrix_get_y_basis_vector_2D(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { - return matrix_get_basis_vector_2D(m,1); + return matrix_get_basis_vector_2D(m, 1); } -template inline void -matrix_get_basis_vectors_2D( - const readable_matrix& m, - writable_vector& x, - writable_vector& y - ) +template +inline void +matrix_get_basis_vectors_2D(const readable_matrix& m, + writable_vector& x, writable_vector& y) { x = matrix_get_x_basis_vector_2D(m); y = matrix_get_y_basis_vector_2D(m); } - -template inline auto +template +inline auto matrix_get_transposed_basis_vector_2D(const readable_matrix& m, int i) --> n_basis_vector_of_t + -> n_basis_vector_of_t { cml::check_linear_2D(m); cml_require(0 <= i && i <= 1, std::invalid_argument, "invalid 2D index"); - return n_basis_vector_of_t( - m.basis_element(0,i), m.basis_element(1,i)); + return n_basis_vector_of_t(m.basis_element(0, i), + m.basis_element(1, i)); } -template inline auto +template +inline auto matrix_get_transposed_x_basis_vector_2D(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { - return matrix_get_transposed_basis_vector_2D(m,0); + return matrix_get_transposed_basis_vector_2D(m, 0); } -template inline auto +template +inline auto matrix_get_transposed_y_basis_vector_2D(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { - return matrix_get_transposed_basis_vector_2D(m,1); + return matrix_get_transposed_basis_vector_2D(m, 1); } -template inline void -matrix_get_transposed_basis_vectors_2D( - const readable_matrix& m, - writable_vector& x, - writable_vector& y - ) +template +inline void +matrix_get_transposed_basis_vectors_2D(const readable_matrix& m, + writable_vector& x, writable_vector& y) { x = matrix_get_transposed_x_basis_vector_2D(m); y = matrix_get_transposed_y_basis_vector_2D(m); } - - /* 3D basis functions: */ -template inline void -matrix_set_basis_vector( - writable_matrix& m, int i, const readable_vector& v - ) +template +inline void +matrix_set_basis_vector(writable_matrix& m, int i, + const readable_vector& v) { cml::check_linear_3D(m); cml::check_size(v, int_c<3>()); @@ -187,48 +178,45 @@ matrix_set_basis_vector( m.set_basis_element(i, 2, v[2]); } -template inline void -matrix_set_x_basis_vector( - writable_matrix& m, const readable_vector& x - ) +template +inline void +matrix_set_x_basis_vector(writable_matrix& m, + const readable_vector& x) { matrix_set_basis_vector(m, 0, x); } -template inline void -matrix_set_y_basis_vector( - writable_matrix& m, const readable_vector& y - ) +template +inline void +matrix_set_y_basis_vector(writable_matrix& m, + const readable_vector& y) { matrix_set_basis_vector(m, 1, y); } -template inline void -matrix_set_z_basis_vector( - writable_matrix& m, const readable_vector& z - ) +template +inline void +matrix_set_z_basis_vector(writable_matrix& m, + const readable_vector& z) { matrix_set_basis_vector(m, 2, z); } -template inline void -matrix_set_basis_vectors( - writable_matrix& m, - const readable_vector& x, - const readable_vector& y, - const readable_vector& z - ) +template +inline void +matrix_set_basis_vectors(writable_matrix& m, + const readable_vector& x, const readable_vector& y, + const readable_vector& z) { matrix_set_x_basis_vector(m, x); matrix_set_y_basis_vector(m, y); matrix_set_z_basis_vector(m, z); } - -template inline void -matrix_set_transposed_basis_vector( - writable_matrix& m, int i, const readable_vector& v - ) +template +inline void +matrix_set_transposed_basis_vector(writable_matrix& m, int i, + const readable_vector& v) { cml::check_linear_3D(m); cml::check_size(v, int_c<3>()); @@ -239,163 +227,160 @@ matrix_set_transposed_basis_vector( m.set_basis_element(2, i, v[2]); } -template inline void -matrix_set_transposed_x_basis_vector( - writable_matrix& m, const readable_vector& x - ) +template +inline void +matrix_set_transposed_x_basis_vector(writable_matrix& m, + const readable_vector& x) { matrix_set_transposed_basis_vector(m, 0, x); } -template inline void -matrix_set_transposed_y_basis_vector( - writable_matrix& m, const readable_vector& y - ) +template +inline void +matrix_set_transposed_y_basis_vector(writable_matrix& m, + const readable_vector& y) { matrix_set_transposed_basis_vector(m, 1, y); } -template inline void -matrix_set_transposed_z_basis_vector( - writable_matrix& m, const readable_vector& z - ) +template +inline void +matrix_set_transposed_z_basis_vector(writable_matrix& m, + const readable_vector& z) { matrix_set_transposed_basis_vector(m, 2, z); } -template inline void -matrix_set_transposed_basis_vectors( - writable_matrix& m, - const readable_vector& x, - const readable_vector& y, - const readable_vector& z - ) +template +inline void +matrix_set_transposed_basis_vectors(writable_matrix& m, + const readable_vector& x, const readable_vector& y, + const readable_vector& z) { matrix_set_transposed_x_basis_vector(m, x); matrix_set_transposed_y_basis_vector(m, y); matrix_set_transposed_z_basis_vector(m, z); } - -template inline auto +template +inline auto matrix_get_basis_vector(const readable_matrix& m, int i) --> n_basis_vector_of_t + -> n_basis_vector_of_t { cml::check_linear_3D(m); cml_require(0 <= i && i <= 2, std::invalid_argument, "invalid 3D index"); - return n_basis_vector_of_t( - m.basis_element(i,0), m.basis_element(i,1), m.basis_element(i,2)); + return n_basis_vector_of_t(m.basis_element(i, 0), + m.basis_element(i, 1), m.basis_element(i, 2)); } -template inline auto +template +inline auto matrix_get_x_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { - return matrix_get_basis_vector(m,0); + return matrix_get_basis_vector(m, 0); } -template inline auto +template +inline auto matrix_get_y_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { - return matrix_get_basis_vector(m,1); + return matrix_get_basis_vector(m, 1); } -template inline auto +template +inline auto matrix_get_z_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { - return matrix_get_basis_vector(m,2); + return matrix_get_basis_vector(m, 2); } -template inline void -matrix_get_basis_vectors( - const readable_matrix& m, - writable_vector& x, - writable_vector& y, - writable_vector& z - ) +template +inline void +matrix_get_basis_vectors(const readable_matrix& m, + writable_vector& x, writable_vector& y, writable_vector& z) { x = matrix_get_x_basis_vector(m); y = matrix_get_y_basis_vector(m); z = matrix_get_z_basis_vector(m); } - -template inline auto +template +inline auto matrix_get_transposed_basis_vector(const readable_matrix& m, int i) --> n_basis_vector_of_t + -> n_basis_vector_of_t { cml::check_linear_3D(m); cml_require(0 <= i && i <= 2, std::invalid_argument, "invalid 3D index"); - return n_basis_vector_of_t( - m.basis_element(0,i), m.basis_element(1,i), m.basis_element(2,i)); + return n_basis_vector_of_t(m.basis_element(0, i), + m.basis_element(1, i), m.basis_element(2, i)); } -template inline auto +template +inline auto matrix_get_transposed_x_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { - return matrix_get_transposed_basis_vector(m,0); + return matrix_get_transposed_basis_vector(m, 0); } -template inline auto +template +inline auto matrix_get_transposed_y_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { - return matrix_get_transposed_basis_vector(m,1); + return matrix_get_transposed_basis_vector(m, 1); } -template inline auto +template +inline auto matrix_get_transposed_z_basis_vector(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { - return matrix_get_transposed_basis_vector(m,2); + return matrix_get_transposed_basis_vector(m, 2); } -template inline void -matrix_get_transposed_basis_vectors( - const readable_matrix& m, - writable_vector& x, - writable_vector& y, - writable_vector& z) +template +inline void +matrix_get_transposed_basis_vectors(const readable_matrix& m, + writable_vector& x, writable_vector& y, writable_vector& z) { x = matrix_get_transposed_x_basis_vector(m); y = matrix_get_transposed_y_basis_vector(m); z = matrix_get_transposed_z_basis_vector(m); } - - /* nD basis functions: */ namespace detail { -template inline auto +template +inline auto matrix_get_basis_vector(const readable_matrix& m, int i, row_basis) --> basis_vector_of_t + -> basis_vector_of_t { - return cml::row(m,i); + return cml::row(m, i); } -template inline auto +template +inline auto matrix_get_basis_vector(const readable_matrix& m, int i, col_basis) --> basis_vector_of_t + -> basis_vector_of_t { - return cml::col(m,i); + return cml::col(m, i); } -} // namespace detail +} // namespace detail -template auto +template +auto matrix_get_basis_vector_nD(const readable_matrix& m, int i) --> basis_vector_of_t + -> basis_vector_of_t { - typedef basis_tag_of_t tag; + using tag = basis_tag_of_t; return detail::matrix_get_basis_vector(m, i, tag()); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/mathlib/matrix/concat.h b/cml/mathlib/matrix/concat.h index cc24983..bdc14ec 100644 --- a/cml/mathlib/matrix/concat.h +++ b/cml/mathlib/matrix/concat.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_matrix_concat_h -#define cml_mathlib_matrix_concat_h - #include #include @@ -30,19 +25,15 @@ namespace cml { * dynamically-sized and non-square. The size is checked at compile-time * for fixed-size matrices. */ -template auto matrix_concat( - const readable_matrix& m1, const readable_matrix& m2) --> matrix_inner_product_promote_t; +template +auto matrix_concat(const readable_matrix& m1, + const readable_matrix& m2) + -> matrix_inner_product_promote_t; /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_MATRIX_CONCAT_TPP #include #undef __CML_MATHLIB_MATRIX_CONCAT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/matrix/concat.tpp b/cml/mathlib/matrix/concat.tpp index 19cdb95..78cefa8 100644 --- a/cml/mathlib/matrix/concat.tpp +++ b/cml/mathlib/matrix/concat.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_MATRIX_CONCAT_TPP -#error "mathlib/matrix/concat.tpp not included correctly" +# error "mathlib/matrix/concat.tpp not included correctly" #endif #include @@ -14,36 +12,33 @@ namespace cml { namespace detail { /** Row-basis concatenation. */ -template inline auto -matrix_concat( - const readable_matrix& m1, const readable_matrix& m2, row_basis - ) --> matrix_inner_product_promote_t +template +inline auto +matrix_concat(const readable_matrix& m1, const readable_matrix& m2, + row_basis) -> matrix_inner_product_promote_t { return m1 * m2; } /** Column-basis concatenation. */ -template inline auto -matrix_concat( - const readable_matrix& m1, const readable_matrix& m2, col_basis - ) --> matrix_inner_product_promote_t +template +inline auto +matrix_concat(const readable_matrix& m1, const readable_matrix& m2, + col_basis) -> matrix_inner_product_promote_t { return m2 * m1; } -} // namespace detail +} // namespace detail -template inline auto -matrix_concat( - const readable_matrix& m1, const readable_matrix& m2 - ) --> matrix_inner_product_promote_t +template +inline auto +matrix_concat(const readable_matrix& m1, const readable_matrix& m2) + -> matrix_inner_product_promote_t { /* Use the promoted type to determine how to multiply: */ - typedef matrix_inner_product_promote_t concat_type; - typedef basis_tag_of_t tag; + using concat_type = matrix_inner_product_promote_t; + using tag = basis_tag_of_t; static_assert(tag::value != any_basis_c, "invalid matrix basis orientations"); cml::check_square(m1); @@ -52,7 +47,4 @@ matrix_concat( return detail::matrix_concat(m1, m2, tag()); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/mathlib/matrix/generators.h b/cml/mathlib/matrix/generators.h index 3387cce..3e552f9 100644 --- a/cml/mathlib/matrix/generators.h +++ b/cml/mathlib/matrix/generators.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ - /** @file - */ #pragma once -#ifndef cml_mathlib_matrix_generators_h -#define cml_mathlib_matrix_generators_h - #include /** @defgroup mathlib_matrix_generators Matrix Generator Functions */ @@ -22,20 +17,33 @@ namespace cml { /*@{*/ /** Return a fixed-size double-precision zero matrix. */ -template inline auto zero() --> matrix> +template +inline auto +zero() -> matrix> { return matrix>().zero(); } /** Return the 2x2 zero matrix */ -inline auto zero_2x2() -> decltype(zero<2, 2>()) { return zero<2, 2>(); } +inline auto +zero_2x2() -> decltype(zero<2, 2>()) +{ + return zero<2, 2>(); +} /** Return the 3x3 zero matrix */ -inline auto zero_3x3() -> decltype(zero<3, 3>()) { return zero<3, 3>(); } +inline auto +zero_3x3() -> decltype(zero<3, 3>()) +{ + return zero<3, 3>(); +} /** Return the 4x4 zero matrix */ -inline auto zero_4x4() -> decltype(zero<4, 4>()) { return zero<4, 4>(); } +inline auto +zero_4x4() -> decltype(zero<4, 4>()) +{ + return zero<4, 4>(); +} /*@}*/ @@ -43,34 +51,36 @@ inline auto zero_4x4() -> decltype(zero<4, 4>()) { return zero<4, 4>(); } /*@{*/ /** Return a fixed-size double-precision identity matrix. */ -template inline auto identity() --> matrix> +template +inline auto +identity() -> matrix> { return matrix>().identity(); } - /** Return the 2x2 identity matrix */ -inline auto identity_2x2() --> decltype(identity<2,2>()) { return identity<2, 2>(); } +inline auto +identity_2x2() -> decltype(identity<2, 2>()) +{ + return identity<2, 2>(); +} /** Return the 3x3 identity matrix */ -inline auto identity_3x3() --> decltype(identity<3, 3>()) { return identity<3, 3>(); } +inline auto +identity_3x3() -> decltype(identity<3, 3>()) +{ + return identity<3, 3>(); +} /** Return the 4x4 identity matrix */ -inline auto identity_4x4() --> decltype(identity<4, 4>()) { return identity<4, 4>(); } +inline auto +identity_4x4() -> decltype(identity<4, 4>()) +{ + return identity<4, 4>(); +} /*@}*/ /*@}*/ -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 - - +} // namespace cml diff --git a/cml/mathlib/matrix/invert.h b/cml/mathlib/matrix/invert.h index d57d487..778774e 100644 --- a/cml/mathlib/matrix/invert.h +++ b/cml/mathlib/matrix/invert.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_matrix_invert_h -#define cml_mathlib_matrix_invert_h - #include namespace cml { @@ -40,13 +35,8 @@ template void matrix_invert_RT_only(writable_matrix& m); */ template void matrix_invert_RT(writable_matrix& m); -} // namespace cml +} // namespace cml #define __CML_MATHLIB_MATRIX_INVERT_TPP #include #undef __CML_MATHLIB_MATRIX_INVERT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/matrix/invert.tpp b/cml/mathlib/matrix/invert.tpp index 9e10f6d..36eb83b 100644 --- a/cml/mathlib/matrix/invert.tpp +++ b/cml/mathlib/matrix/invert.tpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -10,7 +8,8 @@ namespace cml { -template void +template +void matrix_invert_RT_only_2D(writable_matrix& m) { cml::check_affine_2D(m); @@ -18,14 +17,15 @@ matrix_invert_RT_only_2D(writable_matrix& m) /* Transpose the basis vectors: */ auto x = matrix_get_x_basis_vector_2D(m); auto y = matrix_get_y_basis_vector_2D(m); - matrix_set_transposed_basis_vectors_2D(m, x,y); + matrix_set_transposed_basis_vectors_2D(m, x, y); /* Transform the translation: */ auto p = matrix_get_translation_2D(m); - matrix_set_translation_2D(m, - dot(p,x), - dot(p,y)); + matrix_set_translation_2D(m, -dot(p, x), -dot(p, y)); } -template void +template +void matrix_invert_RT_only(writable_matrix& m) { cml::check_affine_3D(m); @@ -34,31 +34,33 @@ matrix_invert_RT_only(writable_matrix& m) auto x = matrix_get_x_basis_vector(m); auto y = matrix_get_y_basis_vector(m); auto z = matrix_get_z_basis_vector(m); - matrix_set_transposed_basis_vectors(m, x,y,z); + matrix_set_transposed_basis_vectors(m, x, y, z); /* Transform the translation: */ auto p = matrix_get_translation(m); - matrix_set_translation(m, - dot(p,x), - dot(p,y), - dot(p,z)); + matrix_set_translation(m, -dot(p, x), -dot(p, y), -dot(p, z)); } -template void +template +void matrix_invert_RT(writable_matrix& m) { cml::check_affine(m); int R = m.rows(), C = m.cols(); int M; - /**/ if(R > C) M = C; // Rectangular, row basis, e.g. 4x3 - else if(R < C) M = R; // Rectangular, col basis, e.g. 3x4 - else M = R-1; // Square, either, e.g. 4x4. + /**/ if(R > C) + M = C; // Rectangular, row basis, e.g. 4x3 + else if(R < C) M = R; // Rectangular, col basis, e.g. 3x4 + else M = R - 1; // Square, either, e.g. 4x4. /* Transpose the MxM rotation part of m in-place: */ - for(int i = 0; i < M; ++ i) { - for(int j = i+1; j < M; ++ j) { - auto e_ij = m.basis_element(i,j); - auto e_ji = m.basis_element(j,i); - m.set_basis_element(i,j, e_ji); - m.set_basis_element(j,i, e_ij); + for(int i = 0; i < M; ++i) { + for(int j = i + 1; j < M; ++j) { + auto e_ij = m.basis_element(i, j); + auto e_ji = m.basis_element(j, i); + m.set_basis_element(i, j, e_ji); + m.set_basis_element(j, i, e_ij); } } @@ -66,14 +68,11 @@ matrix_invert_RT(writable_matrix& m) * transposed rotation: */ auto T = matrix_get_basis_vector_nD(m, M); - for(int i = 0; i < M; ++ i) { + for(int i = 0; i < M; ++i) { auto e = m.basis_element(0, i) * T[0]; - for(int j = 1; j < M; ++ j) e += m.basis_element(j,i) * T[j]; - m.set_basis_element(M, i, - e); + for(int j = 1; j < M; ++j) e += m.basis_element(j, i) * T[j]; + m.set_basis_element(M, i, -e); } } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/mathlib/matrix/misc.h b/cml/mathlib/matrix/misc.h index ec76328..1350533 100644 --- a/cml/mathlib/matrix/misc.h +++ b/cml/mathlib/matrix/misc.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_matrix_misc_h -#define cml_mathlib_matrix_misc_h - #include #include #include @@ -26,8 +21,8 @@ namespace cml { * not at least 2x2. If @c m is fixed-size, the size is checked at * run-time. */ -template auto trace_2x2(const readable_matrix& m) - -> value_type_trait_of_t; +template +auto trace_2x2(const readable_matrix& m) -> value_type_trait_of_t; /** Compute the trace of the upper-left 3x3 submatrix of @c m. * @@ -35,8 +30,8 @@ template auto trace_2x2(const readable_matrix& m) * not at least 3x3. If @c m is fixed-size, the size is checked at * run-time. */ -template auto trace_3x3(const readable_matrix& m) - -> value_type_trait_of_t; +template +auto trace_3x3(const readable_matrix& m) -> value_type_trait_of_t; /** Generate an upper-left 3x3 skew-symmetric submatrix @c m from the @@ -49,8 +44,9 @@ template auto trace_3x3(const readable_matrix& m) * @throws vector_size_error if @c v is dynamically-sized, and is not 3D. * If @c v is fixed-size, the size is checked at run-time. */ -template void matrix_skew_symmetric( - writable_matrix& m, const readable_vector& v); +template +void matrix_skew_symmetric(writable_matrix& m, + const readable_vector& v); /** Generate an upper-left 2x2 skew-symmetric submatrix in @c m from the * value of @c s, accounting for the basis orientation. @@ -59,8 +55,8 @@ template void matrix_skew_symmetric( * not at least 2x2. If @c m is fixed-size, the size is checked at * run-time. */ -template void matrix_skew_symmetric( - writable_matrix& m, const Scalar& s); +template +void matrix_skew_symmetric(writable_matrix& m, const Scalar& s); /** Invert a 3D matrix composed of a rotation and translation. @@ -72,13 +68,8 @@ template void matrix_skew_symmetric( /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_MATRIX_MISC_TPP #include #undef __CML_MATHLIB_MATRIX_MISC_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/matrix/misc.tpp b/cml/mathlib/matrix/misc.tpp index 2f65447..3fd152b 100644 --- a/cml/mathlib/matrix/misc.tpp +++ b/cml/mathlib/matrix/misc.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_MATRIX_MISC_TPP -#error "mathlib/matrix/misc.tpp not included correctly" +# error "mathlib/matrix/misc.tpp not included correctly" #endif #include @@ -14,52 +12,48 @@ namespace cml { -template inline auto +template +inline auto trace_2x2(const readable_matrix& m) -> value_type_trait_of_t { cml::check_linear_2D(m); - return m(0,0) + m(1,1); + return m(0, 0) + m(1, 1); } -template inline auto +template +inline auto trace_3x3(const readable_matrix& m) -> value_type_trait_of_t { cml::check_linear_3D(m); - return m(0,0) + m(1,1) + m(2,2); + return m(0, 0) + m(1, 1) + m(2, 2); } - -template inline void -matrix_skew_symmetric( - writable_matrix& m, const readable_vector& v - ) +template +inline void +matrix_skew_symmetric(writable_matrix& m, const readable_vector& v) { cml::check_linear_3D(m); cml::check_size(v, int_c<3>()); m.zero(); - m.set_basis_element(1,2, v[0]); - m.set_basis_element(2,1, -v[0]); - m.set_basis_element(2,0, v[1]); - m.set_basis_element(0,2, -v[1]); - m.set_basis_element(0,1, v[2]); - m.set_basis_element(1,0, -v[2]); + m.set_basis_element(1, 2, v[0]); + m.set_basis_element(2, 1, -v[0]); + m.set_basis_element(2, 0, v[1]); + m.set_basis_element(0, 2, -v[1]); + m.set_basis_element(0, 1, v[2]); + m.set_basis_element(1, 0, -v[2]); } -template inline void -matrix_skew_symmetric_2D( - writable_matrix& m, const Scalar& s - ) +template +inline void +matrix_skew_symmetric_2D(writable_matrix& m, const Scalar& s) { cml::check_linear_2D(m); m.zero(); - m.set_basis_element(0,1, s); - m.set_basis_element(1,0, -s); + m.set_basis_element(0, 1, s); + m.set_basis_element(1, 0, -s); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/mathlib/matrix/projection.h b/cml/mathlib/matrix/projection.h index 9b514fa..3ea2438 100644 --- a/cml/mathlib/matrix/projection.h +++ b/cml/mathlib/matrix/projection.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_matrix_projection_h -#define cml_mathlib_matrix_projection_h - #include #include @@ -29,10 +24,9 @@ namespace cml { * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_orthographic(writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, - AxisOrientation handedness, ZClip z_clip); +template +void matrix_orthographic(writable_matrix& m, E left, E right, E bottom, + E top, E n, E f, AxisOrientation handedness, ZClip z_clip); /** Build a matrix representing a left-handed orthographic projection given * the z-clipping range and frustum bounds. @@ -41,9 +35,9 @@ matrix_orthographic(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_orthographic_LH(writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, ZClip z_clip); +template +void matrix_orthographic_LH(writable_matrix& m, E left, E right, E bottom, + E top, E n, E f, ZClip z_clip); /** Build a matrix representing a right-handed orthographic projection given * the z-clipping range and frustum bounds. @@ -52,9 +46,9 @@ matrix_orthographic_LH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_orthographic_RH(writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, ZClip z_clip); +template +void matrix_orthographic_RH(writable_matrix& m, E left, E right, E bottom, + E top, E n, E f, ZClip z_clip); /** Build a matrix representing a orthographic projection given the @@ -64,9 +58,9 @@ matrix_orthographic_RH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_orthographic(writable_matrix& m, - E width, E height, E n, E f, AxisOrientation handedness, ZClip z_clip); +template +void matrix_orthographic(writable_matrix& m, E width, E height, E n, E f, + AxisOrientation handedness, ZClip z_clip); /** Build a matrix representing a left-handed orthographic projection given * the z-clipping range and frustum size. @@ -75,9 +69,9 @@ matrix_orthographic(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_orthographic_LH(writable_matrix& m, - E width, E height, E n, E f, ZClip z_clip); +template +void matrix_orthographic_LH(writable_matrix& m, E width, E height, E n, + E f, ZClip z_clip); /** Build a matrix representing a right-handed orthographic projection given * the z-clipping range and frustum size. @@ -86,9 +80,9 @@ matrix_orthographic_LH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_orthographic_RH(writable_matrix& m, - E width, E height, E n, E f, ZClip z_clip); +template +void matrix_orthographic_RH(writable_matrix& m, E width, E height, E n, + E f, ZClip z_clip); /*@}*/ @@ -103,10 +97,9 @@ matrix_orthographic_RH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective(writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, - AxisOrientation handedness, ZClip z_clip); +template +void matrix_perspective(writable_matrix& m, E left, E right, E bottom, + E top, E n, E f, AxisOrientation handedness, ZClip z_clip); /** Build a matrix representing a left-handed perspective projection given * the z-clipping range and frustum bounds. @@ -115,9 +108,9 @@ matrix_perspective(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective_LH(writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, ZClip z_clip); +template +void matrix_perspective_LH(writable_matrix& m, E left, E right, E bottom, + E top, E n, E f, ZClip z_clip); /** Build a matrix representing a right-handed perspective projection given * the z-clipping range and frustum bounds. @@ -126,9 +119,9 @@ matrix_perspective_LH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective_RH(writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, ZClip z_clip); +template +void matrix_perspective_RH(writable_matrix& m, E left, E right, E bottom, + E top, E n, E f, ZClip z_clip); /** Build a matrix representing a perspective projection given the @@ -138,9 +131,9 @@ matrix_perspective_RH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective(writable_matrix& m, - E width, E height, E n, E f, AxisOrientation handedness, ZClip z_clip); +template +void matrix_perspective(writable_matrix& m, E width, E height, E n, E f, + AxisOrientation handedness, ZClip z_clip); /** Build a matrix representing a left-handed perspective projection given * the z-clipping range and frustum size. @@ -149,9 +142,9 @@ matrix_perspective(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective_LH(writable_matrix& m, - E width, E height, E n, E f, ZClip z_clip); +template +void matrix_perspective_LH(writable_matrix& m, E width, E height, E n, E f, + ZClip z_clip); /** Build a matrix representing a right-handed perspective projection given * the z-clipping range and frustum size. @@ -160,9 +153,9 @@ matrix_perspective_LH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective_RH(writable_matrix& m, - E width, E height, E n, E f, ZClip z_clip); +template +void matrix_perspective_RH(writable_matrix& m, E width, E height, E n, E f, + ZClip z_clip); /** Build a matrix representing a perspective projection given the @@ -173,9 +166,9 @@ matrix_perspective_RH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective_xfov(writable_matrix& m, - E xfov, E aspect, E n, E f, AxisOrientation handedness, ZClip z_clip); +template +void matrix_perspective_xfov(writable_matrix& m, E xfov, E aspect, E n, + E f, AxisOrientation handedness, ZClip z_clip); /** Build a matrix representing a left-hand perspective projection given * the z-clipping range, aspect ratio, horizontal field of view, and near @@ -185,9 +178,9 @@ matrix_perspective_xfov(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective_xfov_LH(writable_matrix& m, - E xfov, E aspect, E n, E f, ZClip z_clip); +template +void matrix_perspective_xfov_LH(writable_matrix& m, E xfov, E aspect, E n, + E f, ZClip z_clip); /** Build a matrix representing a right-hand perspective projection given * the z-clipping range, aspect ratio, horizontal field of view, and near @@ -197,9 +190,9 @@ matrix_perspective_xfov_LH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective_xfov_RH(writable_matrix& m, - E xfov, E aspect, E n, E f, ZClip z_clip); +template +void matrix_perspective_xfov_RH(writable_matrix& m, E xfov, E aspect, E n, + E f, ZClip z_clip); /** Build a matrix representing a perspective projection given the @@ -210,9 +203,9 @@ matrix_perspective_xfov_RH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective_yfov(writable_matrix& m, - E yfov, E aspect, E n, E f, AxisOrientation handedness, ZClip z_clip); +template +void matrix_perspective_yfov(writable_matrix& m, E yfov, E aspect, E n, + E f, AxisOrientation handedness, ZClip z_clip); /** Build a matrix representing a left-hand perspective projection given * the z-clipping range, aspect ratio, vertical field of view, and near @@ -222,9 +215,9 @@ matrix_perspective_yfov(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective_yfov_LH(writable_matrix& m, - E yfov, E aspect, E n, E f, ZClip z_clip); +template +void matrix_perspective_yfov_LH(writable_matrix& m, E yfov, E aspect, E n, + E f, ZClip z_clip); /** Build a matrix representing a right-hand perspective projection given * the z-clipping range, aspect ratio, vertical field of view, and near @@ -234,21 +227,16 @@ matrix_perspective_yfov_LH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_perspective_yfov_RH(writable_matrix& m, - E yfov, E aspect, E n, E f, ZClip z_clip); +template +void matrix_perspective_yfov_RH(writable_matrix& m, E yfov, E aspect, E n, + E f, ZClip z_clip); /*@}*/ /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_MATRIX_PROJECTION_TPP #include #undef __CML_MATHLIB_MATRIX_PROJECTION_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/matrix/projection.tpp b/cml/mathlib/matrix/projection.tpp index daaf843..c191d60 100644 --- a/cml/mathlib/matrix/projection.tpp +++ b/cml/mathlib/matrix/projection.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_MATRIX_PROJECTION_TPP -#error "mathlib/matrix/projection.tpp not included correctly" +# error "mathlib/matrix/projection.tpp not included correctly" #endif #include @@ -20,109 +18,89 @@ namespace cml { * clipping range */ -template inline void -matrix_orthographic( - writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, - AxisOrientation handedness, ZClip z_clip - ) +template +inline void +matrix_orthographic(writable_matrix& m, E left, E right, E bottom, E top, + E n, E f, AxisOrientation handedness, ZClip z_clip) { - static_assert( - cml::are_convertible, E>::value, + static_assert(cml::are_convertible, E>::value, "incompatible scalar types"); cml::check_minimum_size(m, int_c<4>(), int_c<4>()); /* Initialize: */ m.identity(); - + auto inv_width = E(1) / (right - left); auto inv_height = E(1) / (top - bottom); auto inv_depth = E(1) / (f - n); auto s = E(handedness == left_handed ? 1 : -1); - if (z_clip == z_clip_neg_one) { - m.set_basis_element(2,2, s * E(2) * inv_depth); - m.set_basis_element(3,2, -(f + n) * inv_depth); - } else { // z_clip.z_clip() == 0 - m.set_basis_element(2,2, s * inv_depth); - m.set_basis_element(3,2, -n * inv_depth); + if(z_clip == z_clip_neg_one) { + m.set_basis_element(2, 2, s * E(2) * inv_depth); + m.set_basis_element(3, 2, -(f + n) * inv_depth); + } else { // z_clip.z_clip() == 0 + m.set_basis_element(2, 2, s * inv_depth); + m.set_basis_element(3, 2, -n * inv_depth); } - m.set_basis_element(0,0, E(2) * inv_width ); - m.set_basis_element(1,1, E(2) * inv_height ); - m.set_basis_element(3,0, -(right + left) * inv_width ); - m.set_basis_element(3,1, -(top + bottom) * inv_height); + m.set_basis_element(0, 0, E(2) * inv_width); + m.set_basis_element(1, 1, E(2) * inv_height); + m.set_basis_element(3, 0, -(right + left) * inv_width); + m.set_basis_element(3, 1, -(top + bottom) * inv_height); } -template inline void -matrix_orthographic_LH( - writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_orthographic_LH(writable_matrix& m, E left, E right, E bottom, + E top, E n, E f, ZClip z_clip) { matrix_orthographic(m, left, right, bottom, top, n, f, left_handed, z_clip); } -template inline void -matrix_orthographic_RH( - writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_orthographic_RH(writable_matrix& m, E left, E right, E bottom, + E top, E n, E f, ZClip z_clip) { matrix_orthographic(m, left, right, bottom, top, n, f, right_handed, z_clip); } - -template inline void -matrix_orthographic( - writable_matrix& m, - E width, E height, E n, E f, - AxisOrientation handedness, ZClip z_clip - ) +template +inline void +matrix_orthographic(writable_matrix& m, E width, E height, E n, E f, + AxisOrientation handedness, ZClip z_clip) { auto half_width = width / E(2); auto half_height = height / E(2); - matrix_orthographic(m, - -half_width, half_width, -half_height, half_height, - n, f, handedness, z_clip); + matrix_orthographic(m, -half_width, half_width, -half_height, half_height, n, + f, handedness, z_clip); } -template inline void -matrix_orthographic_LH( - writable_matrix& m, - E width, E height, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_orthographic_LH(writable_matrix& m, E width, E height, E n, E f, + ZClip z_clip) { matrix_orthographic(m, width, height, n, f, left_handed, z_clip); } -template inline void -matrix_orthographic_RH( - writable_matrix& m, - E width, E height, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_orthographic_RH(writable_matrix& m, E width, E height, E n, E f, + ZClip z_clip) { matrix_orthographic(m, width, height, n, f, right_handed, z_clip); } - - /* Perspective projection functions: */ -template inline void -matrix_perspective( - writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, - AxisOrientation handedness, ZClip z_clip - ) +template +inline void +matrix_perspective(writable_matrix& m, E left, E right, E bottom, E top, + E n, E f, AxisOrientation handedness, ZClip z_clip) { - static_assert( - cml::are_convertible, E>::value, + static_assert(cml::are_convertible, E>::value, "incompatible scalar types"); cml::check_minimum_size(m, int_c<4>(), int_c<4>()); @@ -136,148 +114,122 @@ matrix_perspective( auto near2 = E(2) * n; auto s = E(handedness == left_handed ? 1 : -1); - if (z_clip == z_clip_neg_one) { - m.set_basis_element(2,2, s * (f + n) * inv_depth); - m.set_basis_element(3,2, - E(2) * f * n * inv_depth); - } else { // z_clip == z_clip_zero - m.set_basis_element(2,2, s * f * inv_depth); - m.set_basis_element(3,2, -s * n * m.basis_element(2,2)); + if(z_clip == z_clip_neg_one) { + m.set_basis_element(2, 2, s * (f + n) * inv_depth); + m.set_basis_element(3, 2, -E(2) * f * n * inv_depth); + } else { // z_clip == z_clip_zero + m.set_basis_element(2, 2, s * f * inv_depth); + m.set_basis_element(3, 2, -s * n * m.basis_element(2, 2)); } - m.set_basis_element(0,0, near2 * inv_width ); - m.set_basis_element(1,1, near2 * inv_height ); - m.set_basis_element(2,0, -s * (right + left) * inv_width ); - m.set_basis_element(2,1, -s * (top + bottom) * inv_height); - m.set_basis_element(2,3, s ); - m.set_basis_element(3,3, 0 ); + m.set_basis_element(0, 0, near2 * inv_width); + m.set_basis_element(1, 1, near2 * inv_height); + m.set_basis_element(2, 0, -s * (right + left) * inv_width); + m.set_basis_element(2, 1, -s * (top + bottom) * inv_height); + m.set_basis_element(2, 3, s); + m.set_basis_element(3, 3, 0); } -template inline void -matrix_perspective_LH( - writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_perspective_LH(writable_matrix& m, E left, E right, E bottom, E top, + E n, E f, ZClip z_clip) { matrix_perspective(m, left, right, bottom, top, n, f, left_handed, z_clip); } -template inline void -matrix_perspective_RH( - writable_matrix& m, - E left, E right, E bottom, E top, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_perspective_RH(writable_matrix& m, E left, E right, E bottom, E top, + E n, E f, ZClip z_clip) { matrix_perspective(m, left, right, bottom, top, n, f, right_handed, z_clip); } - -template inline void -matrix_perspective( - writable_matrix& m, - E width, E height, E n, E f, - AxisOrientation handedness, ZClip z_clip - ) +template +inline void +matrix_perspective(writable_matrix& m, E width, E height, E n, E f, + AxisOrientation handedness, ZClip z_clip) { auto half_width = width / E(2); auto half_height = height / E(2); - matrix_perspective(m, - -half_width, half_width, -half_height, half_height, - n, f, handedness, z_clip); + matrix_perspective(m, -half_width, half_width, -half_height, half_height, n, + f, handedness, z_clip); } -template inline void -matrix_perspective_LH( - writable_matrix& m, - E width, E height, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_perspective_LH(writable_matrix& m, E width, E height, E n, E f, + ZClip z_clip) { matrix_perspective(m, width, height, n, f, left_handed, z_clip); } -template inline void -matrix_perspective_RH( - writable_matrix& m, - E width, E height, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_perspective_RH(writable_matrix& m, E width, E height, E n, E f, + ZClip z_clip) { matrix_perspective(m, width, height, n, f, right_handed, z_clip); } - -template inline void -matrix_perspective_xfov( - writable_matrix& m, - E xfov, E aspect, E n, E f, - AxisOrientation handedness, ZClip z_clip - ) +template +inline void +matrix_perspective_xfov(writable_matrix& m, E xfov, E aspect, E n, E f, + AxisOrientation handedness, ZClip z_clip) { - typedef scalar_traits E_traits; + using E_traits = scalar_traits; /* Compute the view height from the field of view: */ auto width = E(2) * n * E_traits::tan(xfov / E(2)); matrix_perspective(m, width, width / aspect, n, f, handedness, z_clip); } -template inline void -matrix_perspective_xfov_LH( - writable_matrix& m, - E xfov, E aspect, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_perspective_xfov_LH(writable_matrix& m, E xfov, E aspect, E n, E f, + ZClip z_clip) { matrix_perspective_xfov(m, xfov, aspect, n, f, left_handed, z_clip); } -template inline void -matrix_perspective_xfov_RH( - writable_matrix& m, - E xfov, E aspect, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_perspective_xfov_RH(writable_matrix& m, E xfov, E aspect, E n, E f, + ZClip z_clip) { matrix_perspective_xfov(m, xfov, aspect, n, f, right_handed, z_clip); } - -template inline void -matrix_perspective_yfov( - writable_matrix& m, - E yfov, E aspect, E n, E f, - AxisOrientation handedness, ZClip z_clip - ) +template +inline void +matrix_perspective_yfov(writable_matrix& m, E yfov, E aspect, E n, E f, + AxisOrientation handedness, ZClip z_clip) { - typedef scalar_traits E_traits; + using E_traits = scalar_traits; /* Compute the view height from the field of view: */ auto height = E(2) * n * E_traits::tan(yfov / E(2)); matrix_perspective(m, height * aspect, height, n, f, handedness, z_clip); } -template inline void -matrix_perspective_yfov_LH( - writable_matrix& m, - E yfov, E aspect, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_perspective_yfov_LH(writable_matrix& m, E yfov, E aspect, E n, E f, + ZClip z_clip) { matrix_perspective_yfov(m, yfov, aspect, n, f, left_handed, z_clip); } -template inline void -matrix_perspective_yfov_RH( - writable_matrix& m, - E yfov, E aspect, E n, E f, - ZClip z_clip - ) +template +inline void +matrix_perspective_yfov_RH(writable_matrix& m, E yfov, E aspect, E n, E f, + ZClip z_clip) { matrix_perspective_yfov(m, yfov, aspect, n, f, right_handed, z_clip); } -} // namespace cml +} // namespace cml #if 0 // XXX INCOMPLETE XXX @@ -340,7 +292,4 @@ matrix_pick( m.set_basis_element(3,1, (viewport_height+value_type(2)*(viewport_y-pick_y))*inv_height); } -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +#endif \ No newline at end of file diff --git a/cml/mathlib/matrix/rotation.h b/cml/mathlib/matrix/rotation.h index 40fb003..950b739 100644 --- a/cml/mathlib/matrix/rotation.h +++ b/cml/mathlib/matrix/rotation.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_matrix_rotation_h -#define cml_mathlib_matrix_rotation_h - #include #include #include @@ -35,8 +30,8 @@ namespace cml { * dynamically-sized, and is not at least 2x2. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_rotation_2D(writable_matrix& m, E angle); +template +void matrix_rotation_2D(writable_matrix& m, E angle); /*@}*/ @@ -50,10 +45,10 @@ matrix_rotation_2D(writable_matrix& m, E angle); * dynamically-sized, and is not at least 2x2. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_rotation_align_2D( - writable_matrix& m, const readable_vector& align, - bool normalize = true, axis_order2D order = axis_order_xy); +template +void matrix_rotation_align_2D(writable_matrix& m, + const readable_vector& align, bool normalize = true, + axis_order2D order = axis_order_xy); /*@}*/ @@ -70,8 +65,9 @@ matrix_rotation_align_2D( * * @throws std::invalid_argument if @c axis < 0 or @c axis > 2. */ -template void -matrix_rotation_world_axis(writable_matrix& m, int axis, const E& angle); +template +void matrix_rotation_world_axis(writable_matrix& m, int axis, + const E& angle); /** Compute a matrix representing a 3D rotation @c angle about the world * x-axis. @@ -80,8 +76,8 @@ matrix_rotation_world_axis(writable_matrix& m, int axis, const E& angle); * dynamically-sized, and is not at least 3x3. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_rotation_world_x(writable_matrix& m, const E& angle); +template +void matrix_rotation_world_x(writable_matrix& m, const E& angle); /** Compute a matrix representing a 3D rotation @c angle about the world * y-axis. @@ -90,8 +86,8 @@ matrix_rotation_world_x(writable_matrix& m, const E& angle); * dynamically-sized, and is not at least 3x3. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_rotation_world_y(writable_matrix& m, const E& angle); +template +void matrix_rotation_world_y(writable_matrix& m, const E& angle); /** Compute a matrix representing a 3D rotation @c angle about the world * z-axis. @@ -100,8 +96,8 @@ matrix_rotation_world_y(writable_matrix& m, const E& angle); * dynamically-sized, and is not at least 3x3. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_rotation_world_z(writable_matrix& m, const E& angle); +template +void matrix_rotation_world_z(writable_matrix& m, const E& angle); /** Compute a rotation matrix from an axis and angle. * @@ -112,8 +108,9 @@ matrix_rotation_world_z(writable_matrix& m, const E& angle); * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 3D. If @c v is fixed-size, the size is checked at compile-time. */ -template void matrix_rotation_axis_angle( - writable_matrix& m, const readable_vector& axis, const E& angle); +template +void matrix_rotation_axis_angle(writable_matrix& m, + const readable_vector& axis, const E& angle); /** Compute a rotation matrix given three Euler angles and the required * order. @@ -143,17 +140,17 @@ template void matrix_rotation_axis_angle( * dynamically-sized, and is not at least 3x3. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_rotation_euler(writable_matrix& m, - E0 angle_0, E1 angle_1, E2 angle_2, euler_order order); +template +void matrix_rotation_euler(writable_matrix& m, E0 angle_0, E1 angle_1, + E2 angle_2, euler_order order); /** Compute a rotation matrix given a vector containing the Euler angles. * * @throws vector_size_error at run-time if @c euler is dynamically-sized, * and is not 3D. If fixed-size, the sizs is checked at compile-time. */ -template void -matrix_rotation_euler(writable_matrix& m, +template +void matrix_rotation_euler(writable_matrix& m, const readable_vector& euler, euler_order order); /** Build a matrix of derivatives of Euler angles about the specified axis. @@ -185,8 +182,8 @@ matrix_rotation_euler(writable_matrix& m, * @throws std::invalid_argument if @c axis is not 0, 1, or 2, or if @c * order has a repeated axis. */ -template void -matrix_rotation_euler_derivatives(writable_matrix& m, int axis, +template +void matrix_rotation_euler_derivatives(writable_matrix& m, int axis, E0 angle_0, E1 angle_1, E2 angle_2, euler_order order); /** Build a matrix of derivatives of Euler angles about the specified axis, @@ -195,8 +192,8 @@ matrix_rotation_euler_derivatives(writable_matrix& m, int axis, * @throws vector_size_error at run-time if @c euler is dynamically-sized, * and is not 3D. If fixed-size, the sizs is checked at compile-time. */ -template void -matrix_rotation_euler_derivatives(writable_matrix& m, int axis, +template +void matrix_rotation_euler_derivatives(writable_matrix& m, int axis, const readable_vector& euler, euler_order order); /** Compute a rotation matrix from a quaternion. @@ -205,9 +202,9 @@ matrix_rotation_euler_derivatives(writable_matrix& m, int axis, * dynamically-sized, and is not at least 3x3. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_rotation_quaternion( - writable_matrix& m, const readable_quaternion& q); +template +void matrix_rotation_quaternion(writable_matrix& m, + const readable_quaternion& q); /*@}*/ @@ -217,16 +214,16 @@ matrix_rotation_quaternion( /** Compute a rotation matrix that aligns vector @c align to @c reference, * using rotations in axis order @c order. */ -template void -matrix_rotation_align(writable_matrix& m, +template +void matrix_rotation_align(writable_matrix& m, const readable_vector& align, const readable_vector& reference, bool normalize = true, axis_order order = axis_order_zyx); /** Compute a rotation matrix to align the vector from @c pos to @c target * with @c reference. */ -template void -matrix_rotation_aim_at(writable_matrix& m, +template +void matrix_rotation_aim_at(writable_matrix& m, const readable_vector& pos, const readable_vector& target, const readable_vector& reference, axis_order order = axis_order_zyx); @@ -240,10 +237,10 @@ matrix_rotation_aim_at(writable_matrix& m, * @note @c tolerance is used to detect a near-zero axis length. */ template> void -matrix_to_axis_angle( - const readable_matrix& m, writable_vector& axis, - E& angle, Tol tolerance = scalar_traits::epsilon()); + class Tol = value_type_trait_of_t> +void matrix_to_axis_angle(const readable_matrix& m, + writable_vector& axis, E& angle, + Tol tolerance = scalar_traits::epsilon()); /** Convert a 3D rotation matrix @c m to an axis-angle pair returned as a * std::tuple. @@ -251,22 +248,19 @@ matrix_to_axis_angle( * @note @c tolerance is used to detect a near-zero axis length. */ template> -std::tuple< - vector, compiled<3>>, value_type_trait_of_t - > -matrix_to_axis_angle( - const readable_matrix& m, - Tol tolerance = scalar_traits::epsilon()); +std::tuple, compiled<3>>, + value_type_trait_of_t> +matrix_to_axis_angle(const readable_matrix& m, + Tol tolerance = scalar_traits::epsilon()); /** Convert a 3D rotation matrix @c m to an Euler-angle triple. * * @note @c tolerance is used to detect degeneracies. */ template> void -matrix_to_euler(const readable_matrix& m, - E0& angle_0, E1& angle_1, E2& angle_2, euler_order order, - Tol tolerance = scalar_traits::epsilon(), + class Tol = value_type_trait_of_t> +void matrix_to_euler(const readable_matrix& m, E0& angle_0, E1& angle_1, + E2& angle_2, euler_order order, Tol tolerance = scalar_traits::epsilon(), enable_if_matrix_t* = nullptr); /** Convert a 3D rotation matrix @c m to an Euler-angle triple, and return @@ -275,9 +269,9 @@ matrix_to_euler(const readable_matrix& m, * @note @c tolerance is used to detect degeneracies. */ template> -vector, compiled<3>> -matrix_to_euler(const readable_matrix& m, euler_order order, - Tol tolerance = scalar_traits::epsilon(), +vector, compiled<3>> matrix_to_euler( + const readable_matrix& m, euler_order order, + Tol tolerance = scalar_traits::epsilon(), enable_if_matrix_t* = nullptr); /** Convert a 3D rotation matrix @c m to an Euler-angle triple, and return @@ -289,23 +283,17 @@ matrix_to_euler(const readable_matrix& m, euler_order order, * storage (e.g. compiled<3> or allocated<>). The default is vector>, where T is the value_type of the matrix. */ -template> VectorT -matrix_to_euler(const readable_matrix& m, euler_order order, - Tol tolerance = scalar_traits::epsilon(), +template> +VectorT matrix_to_euler(const readable_matrix& m, euler_order order, + Tol tolerance = scalar_traits::epsilon(), enable_if_vector_t* = nullptr, enable_if_matrix_t* = nullptr); /*@}*/ /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_MATRIX_ROTATION_TPP #include #undef __CML_MATHLIB_MATRIX_ROTATION_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/matrix/rotation.tpp b/cml/mathlib/matrix/rotation.tpp index 1ae9b77..5e83395 100644 --- a/cml/mathlib/matrix/rotation.tpp +++ b/cml/mathlib/matrix/rotation.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_MATRIX_ROTATION_TPP -#error "mathlib/matrix/rotation.tpp not included correctly" +# error "mathlib/matrix/rotation.tpp not included correctly" #endif #include @@ -21,14 +19,14 @@ namespace cml { /* 2D rotations: */ -template inline void +template +inline void matrix_rotation_2D(writable_matrix& m, E angle) { - static_assert( - cml::are_convertible, E>::value, + static_assert(cml::are_convertible, E>::value, "incompatible scalar types"); - typedef scalar_traits angle_traits; + using angle_traits = scalar_traits; cml::check_linear_2D(m); @@ -38,24 +36,25 @@ matrix_rotation_2D(writable_matrix& m, E angle) /* Initialize m: */ auto s = angle_traits::sin(angle); auto c = angle_traits::cos(angle); - m.set_basis_element(0,0, c); - m.set_basis_element(0,1, s); - m.set_basis_element(1,0,-s); - m.set_basis_element(1,1, c); + m.set_basis_element(0, 0, c); + m.set_basis_element(0, 1, s); + m.set_basis_element(1, 0, -s); + m.set_basis_element(1, 1, c); } - /* 2D alignment: */ -template void -matrix_rotation_align_2D( - writable_matrix& m, const readable_vector& align, - bool normalize, axis_order2D order) +template +void +matrix_rotation_align_2D(writable_matrix& m, + const readable_vector& align, bool normalize, axis_order2D order) { - static_assert(cml::are_convertible, - value_type_trait_of_t>::value, "incompatible scalar types"); + static_assert( + cml::are_convertible, + value_type_trait_of_t>::value, + "incompatible scalar types"); - typedef value_type_trait_of_t value_type; + using value_type = value_type_trait_of_t; cml::check_linear_2D(m); @@ -66,22 +65,23 @@ matrix_rotation_align_2D( matrix_set_basis_vectors_2D(m, x, y); } - /* 3D rotations: */ -template inline void +template +inline void matrix_rotation_world_axis(writable_matrix& m, int axis, const E& angle) { - static_assert(cml::are_convertible< - value_type_trait_of_t, E>::value, "incompatible scalar types"); + static_assert(cml::are_convertible, E>::value, + "incompatible scalar types"); - typedef traits_of_t angle_traits; + using angle_traits = traits_of_t; cml::check_linear_3D(m); cml_require(0 <= axis && axis <= 2, std::invalid_argument, "invalid axis"); - + /* Setup sin() and cos() for the chosen axis: */ - int i, j, k; cml::cyclic_permutation(axis, i, j, k); + int i, j, k; + cml::cyclic_permutation(axis, i, j, k); auto s = angle_traits::sin(angle); auto c = angle_traits::cos(angle); @@ -89,40 +89,44 @@ matrix_rotation_world_axis(writable_matrix& m, int axis, const E& angle) m.identity(); /* Set elements: */ - m.set_basis_element(j,j, c); - m.set_basis_element(j,k, s); - m.set_basis_element(k,j,-s); - m.set_basis_element(k,k, c); + m.set_basis_element(j, j, c); + m.set_basis_element(j, k, s); + m.set_basis_element(k, j, -s); + m.set_basis_element(k, k, c); } -template inline void +template +inline void matrix_rotation_world_x(writable_matrix& m, const E& angle) { matrix_rotation_world_axis(m, 0, angle); } -template inline void +template +inline void matrix_rotation_world_y(writable_matrix& m, const E& angle) { matrix_rotation_world_axis(m, 1, angle); } -template inline void +template +inline void matrix_rotation_world_z(writable_matrix& m, const E& angle) { matrix_rotation_world_axis(m, 2, angle); } -template inline void -matrix_rotation_axis_angle( - writable_matrix& m, const readable_vector& axis, const E& angle - ) +template +inline void +matrix_rotation_axis_angle(writable_matrix& m, + const readable_vector& axis, const E& angle) { - static_assert(cml::are_convertible< - value_type_trait_of_t, value_type_trait_of_t, E>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t, E>::value, "incompatible scalar types"); - typedef scalar_traits angle_traits; + using angle_traits = scalar_traits; cml::check_linear_3D(m); cml::check_size(axis, int_c<3>()); @@ -150,29 +154,29 @@ matrix_rotation_axis_angle( auto ys = axis[1] * s; auto zs = axis[2] * s; - m.set_basis_element(0,0, xxomc + c ); - m.set_basis_element(0,1, xyomc + zs); - m.set_basis_element(0,2, zxomc - ys); - m.set_basis_element(1,0, xyomc - zs); - m.set_basis_element(1,1, yyomc + c ); - m.set_basis_element(1,2, yzomc + xs); - m.set_basis_element(2,0, zxomc + ys); - m.set_basis_element(2,1, yzomc - xs); - m.set_basis_element(2,2, zzomc + c ); + m.set_basis_element(0, 0, xxomc + c); + m.set_basis_element(0, 1, xyomc + zs); + m.set_basis_element(0, 2, zxomc - ys); + m.set_basis_element(1, 0, xyomc - zs); + m.set_basis_element(1, 1, yyomc + c); + m.set_basis_element(1, 2, yzomc + xs); + m.set_basis_element(2, 0, zxomc + ys); + m.set_basis_element(2, 1, yzomc - xs); + m.set_basis_element(2, 2, zzomc + c); } -template inline void -matrix_rotation_euler(writable_matrix& m, - E0 angle_0, E1 angle_1, E2 angle_2, euler_order order - ) +template +inline void +matrix_rotation_euler(writable_matrix& m, E0 angle_0, E1 angle_1, + E2 angle_2, euler_order order) { - static_assert(cml::are_convertible< - value_type_trait_of_t, E0, E1, E2>::value, + static_assert( + cml::are_convertible, E0, E1, E2>::value, "incompatible scalar types"); - typedef scalar_traits angle0_traits; - typedef scalar_traits angle1_traits; - typedef scalar_traits angle2_traits; + using angle0_traits = scalar_traits; + using angle1_traits = scalar_traits; + using angle2_traits = scalar_traits; cml::check_linear_3D(m); @@ -201,53 +205,53 @@ matrix_rotation_euler(writable_matrix& m, auto c0s2 = c0 * s2; auto c0c2 = c0 * c2; - if (repeat) { - m.set_basis_element(i,i, c1 ); - m.set_basis_element(i,j, s1 * s2 ); - m.set_basis_element(i,k,-s1 * c2 ); - m.set_basis_element(j,i, s0 * s1 ); - m.set_basis_element(j,j,-c1 * s0s2 + c0c2); - m.set_basis_element(j,k, c1 * s0c2 + c0s2); - m.set_basis_element(k,i, c0 * s1 ); - m.set_basis_element(k,j,-c1 * c0s2 - s0c2); - m.set_basis_element(k,k, c1 * c0c2 - s0s2); + if(repeat) { + m.set_basis_element(i, i, c1); + m.set_basis_element(i, j, s1 * s2); + m.set_basis_element(i, k, -s1 * c2); + m.set_basis_element(j, i, s0 * s1); + m.set_basis_element(j, j, -c1 * s0s2 + c0c2); + m.set_basis_element(j, k, c1 * s0c2 + c0s2); + m.set_basis_element(k, i, c0 * s1); + m.set_basis_element(k, j, -c1 * c0s2 - s0c2); + m.set_basis_element(k, k, c1 * c0c2 - s0s2); } else { - m.set_basis_element(i,i, c1 * c2 ); - m.set_basis_element(i,j, c1 * s2 ); - m.set_basis_element(i,k,-s1 ); - m.set_basis_element(j,i, s1 * s0c2 - c0s2); - m.set_basis_element(j,j, s1 * s0s2 + c0c2); - m.set_basis_element(j,k, s0 * c1 ); - m.set_basis_element(k,i, s1 * c0c2 + s0s2); - m.set_basis_element(k,j, s1 * c0s2 - s0c2); - m.set_basis_element(k,k, c0 * c1 ); + m.set_basis_element(i, i, c1 * c2); + m.set_basis_element(i, j, c1 * s2); + m.set_basis_element(i, k, -s1); + m.set_basis_element(j, i, s1 * s0c2 - c0s2); + m.set_basis_element(j, j, s1 * s0s2 + c0c2); + m.set_basis_element(j, k, s0 * c1); + m.set_basis_element(k, i, s1 * c0c2 + s0s2); + m.set_basis_element(k, j, s1 * c0s2 - s0c2); + m.set_basis_element(k, k, c0 * c1); } } -template inline void +template +inline void matrix_rotation_euler(writable_matrix& m, - const readable_vector& euler, euler_order order - ) + const readable_vector& euler, euler_order order) { cml::check_size(euler, cml::int_c<3>()); matrix_rotation_euler(m, euler[0], euler[1], euler[2], order); } -template inline void -matrix_rotation_euler_derivatives(writable_matrix& m, int axis, - E0 angle_0, E1 angle_1, E2 angle_2, euler_order order - ) +template +inline void +matrix_rotation_euler_derivatives(writable_matrix& m, int axis, E0 angle_0, + E1 angle_1, E2 angle_2, euler_order order) { - static_assert(cml::are_convertible< - value_type_trait_of_t, E0, E1, E2>::value, + static_assert( + cml::are_convertible, E0, E1, E2>::value, "incompatible scalar types"); - typedef scalar_traits angle0_traits; - typedef scalar_traits angle1_traits; - typedef scalar_traits angle2_traits; + using angle0_traits = scalar_traits; + using angle1_traits = scalar_traits; + using angle2_traits = scalar_traits; - cml_require(0 <= axis && axis <= 2, - std::invalid_argument, "axis must be 0, 1, or 2"); + cml_require(0 <= axis && axis <= 2, std::invalid_argument, + "axis must be 0, 1, or 2"); cml::check_linear_3D(m); /* Initialize: */ @@ -258,7 +262,7 @@ matrix_rotation_euler_derivatives(writable_matrix& m, int axis, cml::unpack_euler_order(order, i, j, k, odd, repeat); cml_require(!repeat, std::invalid_argument, "repeated axis not supported"); - if (odd) { + if(odd) { angle_0 = -angle_0; angle_1 = -angle_1; angle_2 = -angle_2; @@ -277,64 +281,66 @@ matrix_rotation_euler_derivatives(writable_matrix& m, int axis, auto c0c2 = c0 * c2; if(axis == 0) { - m.set_basis_element(i,i, 0. ); - m.set_basis_element(i,j, 0. ); - m.set_basis_element(i,k, 0. ); - m.set_basis_element(j,i, s1 * c0c2 + s0s2); - m.set_basis_element(j,j, s1 * c0s2 - s0c2); - m.set_basis_element(j,k, c0 * c1 ); - m.set_basis_element(k,i,-s1 * s0c2 + c0s2); - m.set_basis_element(k,j,-s1 * s0s2 - c0c2); - m.set_basis_element(k,k,-s0 * c1 ); + m.set_basis_element(i, i, 0.); + m.set_basis_element(i, j, 0.); + m.set_basis_element(i, k, 0.); + m.set_basis_element(j, i, s1 * c0c2 + s0s2); + m.set_basis_element(j, j, s1 * c0s2 - s0c2); + m.set_basis_element(j, k, c0 * c1); + m.set_basis_element(k, i, -s1 * s0c2 + c0s2); + m.set_basis_element(k, j, -s1 * s0s2 - c0c2); + m.set_basis_element(k, k, -s0 * c1); } else if(axis == 1) { - m.set_basis_element(i,i,-s1 * c2 ); - m.set_basis_element(i,j,-s1 * s2 ); - m.set_basis_element(i,k,-c1 ); - m.set_basis_element(j,i, c1 * s0c2 ); - m.set_basis_element(j,j, c1 * s0s2 ); - m.set_basis_element(j,k,-s0 * s1 ); - m.set_basis_element(k,i, c1 * c0c2 ); - m.set_basis_element(k,j, c1 * c0s2 ); - m.set_basis_element(k,k,-c0 * s1 ); + m.set_basis_element(i, i, -s1 * c2); + m.set_basis_element(i, j, -s1 * s2); + m.set_basis_element(i, k, -c1); + m.set_basis_element(j, i, c1 * s0c2); + m.set_basis_element(j, j, c1 * s0s2); + m.set_basis_element(j, k, -s0 * s1); + m.set_basis_element(k, i, c1 * c0c2); + m.set_basis_element(k, j, c1 * c0s2); + m.set_basis_element(k, k, -c0 * s1); } else if(axis == 2) { - m.set_basis_element(i,i,-c1 * s2 ); - m.set_basis_element(i,j, c1 * c2 ); - m.set_basis_element(i,k, 0. ); - m.set_basis_element(j,i,-s1 * s0s2 - c0c2); - m.set_basis_element(j,j, s1 * s0c2 - c0s2); - m.set_basis_element(j,k, 0. ); - m.set_basis_element(k,i,-s1 * c0s2 + s0c2); - m.set_basis_element(k,j, s1 * c0c2 + s0s2); - m.set_basis_element(k,k, 0. ); + m.set_basis_element(i, i, -c1 * s2); + m.set_basis_element(i, j, c1 * c2); + m.set_basis_element(i, k, 0.); + m.set_basis_element(j, i, -s1 * s0s2 - c0c2); + m.set_basis_element(j, j, s1 * s0c2 - c0s2); + m.set_basis_element(j, k, 0.); + m.set_basis_element(k, i, -s1 * c0s2 + s0c2); + m.set_basis_element(k, j, s1 * c0c2 + s0s2); + m.set_basis_element(k, k, 0.); } } -template inline void +template +inline void matrix_rotation_euler_derivatives(writable_matrix& m, int axis, - const readable_vector& euler, euler_order order - ) + const readable_vector& euler, euler_order order) { cml::check_size(euler, cml::int_c<3>()); - matrix_rotation_euler_derivatives( - m, axis, euler[0], euler[1], euler[2], order); + matrix_rotation_euler_derivatives(m, axis, euler[0], euler[1], euler[2], + order); } -template inline void -matrix_rotation_quaternion( - writable_matrix& m, const readable_quaternion& q - ) +template +inline void +matrix_rotation_quaternion(writable_matrix& m, + const readable_quaternion& q) { - static_assert(cml::are_convertible< - value_type_trait_of_t, value_type_trait_of_t>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t>::value, "incompatible scalar types"); - typedef order_type_trait_of_t order_type; - typedef value_type_trait_of_t q_type; + using order_type = order_type_trait_of_t; + using q_type = value_type_trait_of_t; cml::check_linear_3D(m); /* Local version of the quaternion ordering: */ - enum { + enum + { W = order_type::W, X = order_type::X, Y = order_type::Y, @@ -343,7 +349,7 @@ matrix_rotation_quaternion( auto x2 = q[X] + q[X]; auto y2 = q[Y] + q[Y]; - auto z2 = q[Z] + q[Z]; + auto z2 = q[Z] + q[Z]; auto xx2 = q[X] * x2; auto yy2 = q[Y] * y2; @@ -356,32 +362,31 @@ matrix_rotation_quaternion( auto zw2 = q[W] * z2; m.identity(); - m.set_basis_element(0,0, q_type(1) - yy2 - zz2); - m.set_basis_element(0,1, xy2 + zw2); - m.set_basis_element(0,2, zx2 - yw2); - m.set_basis_element(1,0, xy2 - zw2); - m.set_basis_element(1,1, q_type(1) - zz2 - xx2); - m.set_basis_element(1,2, yz2 + xw2); - m.set_basis_element(2,0, zx2 + yw2); - m.set_basis_element(2,1, yz2 - xw2); - m.set_basis_element(2,2, q_type(1) - xx2 - yy2); + m.set_basis_element(0, 0, q_type(1) - yy2 - zz2); + m.set_basis_element(0, 1, xy2 + zw2); + m.set_basis_element(0, 2, zx2 - yw2); + m.set_basis_element(1, 0, xy2 - zw2); + m.set_basis_element(1, 1, q_type(1) - zz2 - xx2); + m.set_basis_element(1, 2, yz2 + xw2); + m.set_basis_element(2, 0, zx2 + yw2); + m.set_basis_element(2, 1, yz2 - xw2); + m.set_basis_element(2, 2, q_type(1) - xx2 - yy2); } - /* Alignment: */ -template inline void -matrix_rotation_align( - writable_matrix& m, +template +inline void +matrix_rotation_align(writable_matrix& m, const readable_vector& align, const readable_vector& reference, - bool normalize, axis_order order - ) + bool normalize, axis_order order) { - static_assert(cml::are_convertible, - value_type_trait_of_t, value_type_trait_of_t>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t, value_type_trait_of_t>::value, "incompatible scalar types"); - typedef value_type_trait_of_t value_type; + using value_type = value_type_trait_of_t; m.identity(); @@ -390,43 +395,38 @@ matrix_rotation_align( matrix_set_basis_vectors(m, x, y, z); } -template void -matrix_rotation_aim_at( - writable_matrix& m, +template +void +matrix_rotation_aim_at(writable_matrix& m, const readable_vector& pos, const readable_vector& target, - const readable_vector& reference, - axis_order order - ) + const readable_vector& reference, axis_order order) { matrix_rotation_align(m, target - pos, reference, true, order); } - /* Conversion: */ -template inline void -matrix_to_axis_angle( - const readable_matrix& m, writable_vector& axis, - E& angle, Tol tolerance - ) +template +inline void +matrix_to_axis_angle(const readable_matrix& m, writable_vector& axis, + E& angle, Tol tolerance) { - static_assert(cml::are_convertible< - value_type_trait_of_t, value_type_trait_of_t, E, Tol>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t, E, Tol>::value, "incompatible scalar types"); - typedef value_type_trait_of_t value_type; - typedef scalar_traits value_traits; - typedef value_type_trait_of_t asub_type; + using value_type = value_type_trait_of_t; + using value_traits = scalar_traits; + using asub_type = value_type_trait_of_t; cml::check_linear_3D(m); cml::detail::check_or_resize(axis, int_c<3>()); /* Assign the axis first: */ - axis.set( - m.basis_element(1,2) - m.basis_element(2,1), - m.basis_element(2,0) - m.basis_element(0,2), - m.basis_element(0,1) - m.basis_element(1,0) - ); + axis.set(m.basis_element(1, 2) - m.basis_element(2, 1), + m.basis_element(2, 0) - m.basis_element(0, 2), + m.basis_element(0, 1) - m.basis_element(1, 0)); /* Compute the angle: */ auto l = axis.length(); @@ -440,26 +440,29 @@ matrix_to_axis_angle( } /* Near-zero axis: */ - else if(tmo > value_type(0)) { + else if(tmo > value_type(0)) + { axis.zero(); angle = E(0); } /* Reflection: */ - else { - auto largest_diagonal_element = cml::index_of_max( - m.basis_element(0,0), m.basis_element(1,1), m.basis_element(2,2)); + else + { + auto largest_diagonal_element = cml::index_of_max(m.basis_element(0, 0), + m.basis_element(1, 1), m.basis_element(2, 2)); int i, j, k; cyclic_permutation(largest_diagonal_element, i, j, k); - axis[i] = asub_type(value_traits::sqrt( - m.basis_element(i,i) - m.basis_element(j,j) - - m.basis_element(k,k) + value_type(1)) / value_type(2)); + axis[i] = asub_type( + value_traits::sqrt(m.basis_element(i, i) - m.basis_element(j, j) + - m.basis_element(k, k) + value_type(1)) + / value_type(2)); auto s = value_type(1) / (value_type(2) * axis[i]); - axis[j] = asub_type(m.basis_element(i,j) * s); - axis[k] = asub_type(m.basis_element(i,k) * s); + axis[j] = asub_type(m.basis_element(i, j) * s); + axis[k] = asub_type(m.basis_element(i, k) * s); angle = constants::pi(); } @@ -467,16 +470,16 @@ matrix_to_axis_angle( /* Done. */ } - namespace detail { /** Helper for the matrix_to_axis_angle() overloads. */ -template +template inline std::tuple> matrix_to_axis_angle(const readable_matrix& m, Tol tolerance) { - static_assert(cml::are_convertible< - value_type_trait_of_t, value_type_trait_of_t, Tol>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t, Tol>::value, "incompatible scalar types"); VectorT axis; @@ -485,33 +488,28 @@ matrix_to_axis_angle(const readable_matrix& m, Tol tolerance) return std::make_tuple(std::move(axis), std::move(angle)); } -} // namespace detail +} // namespace detail template -inline std::tuple< - vector, compiled<3>>, value_type_trait_of_t - > +inline std::tuple, compiled<3>>, + value_type_trait_of_t> matrix_to_axis_angle(const readable_matrix& m, Tol tolerance) { - typedef vector, compiled<3>> vector_type; + using vector_type = vector, compiled<3>>; return detail::matrix_to_axis_angle(m, tolerance); } template inline void -matrix_to_euler( - const readable_matrix& m, - E0& angle_0, E1& angle_1, E2& angle_2, euler_order order, - Tol tolerance, - enable_if_matrix_t* - ) +matrix_to_euler(const readable_matrix& m, E0& angle_0, E1& angle_1, + E2& angle_2, euler_order order, Tol tolerance, enable_if_matrix_t*) { - static_assert(cml::are_convertible< - value_type_trait_of_t, E0, E1, E2, Tol>::value, + static_assert( + cml::are_convertible, E0, E1, E2, Tol>::value, "incompatible scalar types"); - typedef value_type_trait_of_t value_type; - typedef scalar_traits value_traits; + using value_type = value_type_trait_of_t; + using value_traits = scalar_traits; cml::check_linear_3D(m); @@ -521,35 +519,35 @@ matrix_to_euler( cml::unpack_euler_order(order, i, j, k, odd, repeat); /* Detect repeated indices: */ - if (repeat) { - auto s1 = cml::length(m.basis_element(j,i), m.basis_element(k,i)); - auto c1 = m.basis_element(i,i); + if(repeat) { + auto s1 = cml::length(m.basis_element(j, i), m.basis_element(k, i)); + auto c1 = m.basis_element(i, i); angle_1 = E1(value_traits::atan2(s1, c1)); - if (s1 > tolerance) { - angle_0 = E0(value_traits::atan2( - m.basis_element(j,i), m.basis_element(k,i))); - angle_2 = E0(value_traits::atan2( - m.basis_element(i,j), -m.basis_element(i,k))); + if(s1 > tolerance) { + angle_0 = + E0(value_traits::atan2(m.basis_element(j, i), m.basis_element(k, i))); + angle_2 = + E0(value_traits::atan2(m.basis_element(i, j), -m.basis_element(i, k))); } else { angle_0 = E0(0); - angle_2 = E2(cml::sign(c1) * - value_traits::atan2(-m.basis_element(k,j),m.basis_element(j,j))); + angle_2 = E2(cml::sign(c1) + * value_traits::atan2(-m.basis_element(k, j), m.basis_element(j, j))); } } else { - auto s1 = -m.basis_element(i,k); - auto c1 = cml::length(m.basis_element(i,i), m.basis_element(i,j)); + auto s1 = -m.basis_element(i, k); + auto c1 = cml::length(m.basis_element(i, i), m.basis_element(i, j)); angle_1 = E1(value_traits::atan2(s1, c1)); - if (c1 > tolerance) { - angle_0 = E0(value_traits::atan2( - m.basis_element(j,k), m.basis_element(k,k))); - angle_2 = E2(value_traits::atan2( - m.basis_element(i,j), m.basis_element(i,i))); + if(c1 > tolerance) { + angle_0 = + E0(value_traits::atan2(m.basis_element(j, k), m.basis_element(k, k))); + angle_2 = + E2(value_traits::atan2(m.basis_element(i, j), m.basis_element(i, i))); } else { angle_0 = E0(0); - angle_2 = - E2(cml::sign(s1) * - value_traits::atan2(-m.basis_element(k,j), m.basis_element(j,j))); + angle_2 = -E2(cml::sign(s1) + * value_traits::atan2(-m.basis_element(k, j), m.basis_element(j, j))); } } @@ -562,48 +560,44 @@ matrix_to_euler( /* Done. */ } - namespace detail { /** Helper for the matrix_to_euler() overloads. */ -template inline VectorT -matrix_to_euler( - const readable_matrix& m, euler_order order, Tol tolerance - ) +template +inline VectorT +matrix_to_euler(const readable_matrix& m, euler_order order, Tol tolerance) { - static_assert(cml::are_convertible< - value_type_trait_of_t, value_type_trait_of_t, Tol>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t, Tol>::value, "incompatible scalar types"); - VectorT v; cml::detail::check_or_resize(v, int_c<3>()); + VectorT v; + cml::detail::check_or_resize(v, int_c<3>()); cml::matrix_to_euler(m, v[0], v[1], v[2], order, tolerance); return std::move(v); } -} // namespace detail +} // namespace detail template inline vector, compiled<3>> -matrix_to_euler( - const readable_matrix& m, euler_order order, Tol tolerance, - enable_if_matrix_t* - ) +matrix_to_euler(const readable_matrix& m, euler_order order, Tol tolerance, + enable_if_matrix_t*) { - typedef vector, compiled<3>> vector_type; + using vector_type = vector, compiled<3>>; return detail::matrix_to_euler(m, order, tolerance); } template inline VectorT -matrix_to_euler( - const readable_matrix& m, euler_order order, Tol tolerance, - enable_if_vector_t*, enable_if_matrix_t* - ) +matrix_to_euler(const readable_matrix& m, euler_order order, Tol tolerance, + enable_if_vector_t*, enable_if_matrix_t*) { return detail::matrix_to_euler(m, order, tolerance); } -} // namespace cml +} // namespace cml #if 0 @@ -918,26 +912,16 @@ matrix_scale_rotation_angle_2D( */ /** A fixed-size temporary 3x3 matrix */ -#define MAT_TEMP_3X3 matrix< \ - typename et::ScalarPromote< \ - typename MatT_1::value_type, \ - typename MatT_2::value_type \ - >::type, \ - fixed<3,3>, \ - typename MatT_1::basis_orient, \ - row_major \ -> +# define MAT_TEMP_3X3 \ + matrix::type, \ + fixed<3, 3>, typename MatT_1::basis_orient, row_major> /** A fixed-size temporary 2x2 matrix */ -#define MAT_TEMP_2X2 matrix< \ - typename et::ScalarPromote< \ - typename MatT_1::value_type, \ - typename MatT_2::value_type \ - >::type, \ - fixed<2,2>, \ - typename MatT_1::basis_orient, \ - row_major \ -> +# define MAT_TEMP_2X2 \ + matrix::type, \ + fixed<2, 2>, typename MatT_1::basis_orient, row_major> namespace detail { @@ -1036,8 +1020,8 @@ matrix_slerp_2D(const MatT_1& m1, const MatT_2& m2, E t, return detail::matrix_concat_rotations_2D(m1,m); } -#undef MAT_TEMP_3X3 -#undef MAT_TEMP_2X2 +# undef MAT_TEMP_3X3 +# undef MAT_TEMP_2X2 ////////////////////////////////////////////////////////////////////////////// // Conversions @@ -1053,7 +1037,4 @@ matrix_to_rotation_2D(const MatT& m) return std::atan2(m.basis_element(0,1),m.basis_element(0,0)); } -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +#endif \ No newline at end of file diff --git a/cml/mathlib/matrix/scale.h b/cml/mathlib/matrix/scale.h index 542b8cc..1750ba6 100644 --- a/cml/mathlib/matrix/scale.h +++ b/cml/mathlib/matrix/scale.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_matrix_scale_h -#define cml_mathlib_matrix_scale_h - #include #include @@ -28,8 +23,8 @@ namespace cml { * dynamically-sized, and is not sized for a 2D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_scale_2D( - writable_matrix& m, const E0& e0, const E1& e1); +template +void matrix_scale_2D(writable_matrix& m, const E0& e0, const E1& e1); /** Initialize a non-uniform 2D scaling matrix, taking scales from the * elements of @c v. @@ -41,8 +36,8 @@ template void matrix_scale_2D( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 2D. If @c v is fixed-size, the size is checked at compile-time. */ -template void matrix_scale_2D( - writable_matrix& m, const readable_vector& v); +template +void matrix_scale_2D(writable_matrix& m, const readable_vector& v); /** Initialize a uniform 2D scaling matrix with scale @c e0. * @@ -50,8 +45,8 @@ template void matrix_scale_2D( * dynamically-sized, and is not sized for a 2D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_uniform_scale_2D( - writable_matrix& m, const E0& e0); +template +void matrix_uniform_scale_2D(writable_matrix& m, const E0& e0); /** Initialize a non-uniform 2D scaling matrix with the reciprocals of * scales @c e0 and @c e1. @@ -60,8 +55,9 @@ template void matrix_uniform_scale_2D( * dynamically-sized, and is not sized for a 2D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_inverse_scale_2D( - writable_matrix& m, const E0& e0, const E1& e1); +template +void matrix_inverse_scale_2D(writable_matrix& m, const E0& e0, + const E1& e1); /** Initialize a non-uniform 2D scaling matrix, taking scales from reciprocals * of the elements of @c v. @@ -73,8 +69,9 @@ template void matrix_inverse_scale_2D( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 2D. If @c v is fixed-size, the size is checked at compile-time. */ -template void matrix_inverse_scale_2D( - writable_matrix& m, const readable_vector& v); +template +void matrix_inverse_scale_2D(writable_matrix& m, + const readable_vector& v); /*@}*/ @@ -89,8 +86,9 @@ template void matrix_inverse_scale_2D( * dynamically-sized, and is not sized for a 3D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_scale( - writable_matrix& m, const E0& e0, const E1& e1, const E2& e2); +template +void matrix_scale(writable_matrix& m, const E0& e0, const E1& e1, + const E2& e2); /** Initialize a non-uniform 3D scaling matrix, taking scales from the * elements of @c v. @@ -102,8 +100,8 @@ template void matrix_scale( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 3D. If @c v is fixed-size, the size is checked at compile-time. */ -template void matrix_scale( - writable_matrix& m, const readable_vector& v); +template +void matrix_scale(writable_matrix& m, const readable_vector& v); /** Initialize a uniform 3D scaling matrix with scale @c e0. * @@ -111,8 +109,8 @@ template void matrix_scale( * dynamically-sized, and is not sized for a 3D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_uniform_scale( - writable_matrix& m, const E0& e0); +template +void matrix_uniform_scale(writable_matrix& m, const E0& e0); /** Initialize a non-uniform 3D scaling matrix with the reciprocals of * scales @c e0, @c e1, and @c e2. @@ -121,8 +119,9 @@ template void matrix_uniform_scale( * dynamically-sized, and is not sized for a 3D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_inverse_scale( - writable_matrix& m, const E0& e0, const E1& e1, const E2& e2); +template +void matrix_inverse_scale(writable_matrix& m, const E0& e0, const E1& e1, + const E2& e2); /** Initialize a non-uniform 3D scaling matrix, taking scales from reciprocals * of the elements of @c v. @@ -134,20 +133,16 @@ template void matrix_inverse_scale( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 3D. If @c v is fixed-size, the size is checked at compile-time. */ -template void matrix_inverse_scale( - writable_matrix& m, const readable_vector& v); +template +void matrix_inverse_scale(writable_matrix& m, + const readable_vector& v); /*@}*/ /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_MATRIX_SCALE_TPP #include #undef __CML_MATHLIB_MATRIX_SCALE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/matrix/scale.tpp b/cml/mathlib/matrix/scale.tpp index 20c3167..3991414 100644 --- a/cml/mathlib/matrix/scale.tpp +++ b/cml/mathlib/matrix/scale.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_MATRIX_SCALE_TPP -#error "mathlib/matrix/scale.tpp not included correctly" +# error "mathlib/matrix/scale.tpp not included correctly" #endif #include @@ -16,62 +14,55 @@ namespace cml { /* 2D scale: */ -template inline void -matrix_scale_2D( - writable_matrix& m, const E0& e0, const E1& e1 - ) +template +inline void +matrix_scale_2D(writable_matrix& m, const E0& e0, const E1& e1) { - static_assert( - cml::are_convertible, E0, E1>::value, + static_assert(cml::are_convertible, E0, E1>::value, "incompatible scalar types"); cml::check_affine_2D(m); m.identity(); - m.set_basis_element(0,0, e0); - m.set_basis_element(1,1, e1); + m.set_basis_element(0, 0, e0); + m.set_basis_element(1, 1, e1); } -template inline void -matrix_scale_2D( - writable_matrix& m, const readable_vector& v - ) +template +inline void +matrix_scale_2D(writable_matrix& m, const readable_vector& v) { cml::check_size(v, int_c<2>()); matrix_scale_2D(m, v[0], v[1]); } -template inline void -matrix_uniform_scale_2D( - writable_matrix& m, const E0& e0 - ) +template +inline void +matrix_uniform_scale_2D(writable_matrix& m, const E0& e0) { matrix_scale_2D(m, e0, e0); } -template inline void -matrix_inverse_scale_2D( - writable_matrix& m, const E0& e0, const E1& e1 - ) +template +inline void +matrix_inverse_scale_2D(writable_matrix& m, const E0& e0, const E1& e1) { - matrix_scale_2D(m, E0(1)/e0, E1(1)/e1); + matrix_scale_2D(m, E0(1) / e0, E1(1) / e1); } -template inline void -matrix_inverse_scale_2D( - writable_matrix& m, const readable_vector& v - ) +template +inline void +matrix_inverse_scale_2D(writable_matrix& m, + const readable_vector& v) { cml::check_size(v, int_c<2>()); matrix_inverse_scale_2D(m, v[0], v[1]); } - /* 3D scaling: */ -template inline void -matrix_scale( - writable_matrix& m, const E0& e0, const E1& e1, const E2& e2 - ) +template +inline void +matrix_scale(writable_matrix& m, const E0& e0, const E1& e1, const E2& e2) { static_assert( cml::are_convertible, E0, E1, E2>::value, @@ -79,46 +70,43 @@ matrix_scale( cml::check_affine_3D(m); m.identity(); - m.set_basis_element(0,0, e0); - m.set_basis_element(1,1, e1); - m.set_basis_element(2,2, e2); + m.set_basis_element(0, 0, e0); + m.set_basis_element(1, 1, e1); + m.set_basis_element(2, 2, e2); } -template inline void -matrix_scale( - writable_matrix& m, const readable_vector& v - ) +template +inline void +matrix_scale(writable_matrix& m, const readable_vector& v) { cml::check_size(v, int_c<3>()); matrix_scale(m, v[0], v[1], v[2]); } -template inline void -matrix_uniform_scale( - writable_matrix& m, const E0& e0 - ) +template +inline void +matrix_uniform_scale(writable_matrix& m, const E0& e0) { matrix_scale(m, e0, e0, e0); } -template inline void -matrix_inverse_scale( - writable_matrix& m, const E0& e0, const E1& e1, const E2& e2 - ) +template +inline void +matrix_inverse_scale(writable_matrix& m, const E0& e0, const E1& e1, + const E2& e2) { - matrix_scale(m, E0(1)/e0, E1(1)/e1, E2(1)/e2); + matrix_scale(m, E0(1) / e0, E1(1) / e1, E2(1) / e2); } -template inline void -matrix_inverse_scale( - writable_matrix& m, const readable_vector& v - ) +template +inline void +matrix_inverse_scale(writable_matrix& m, const readable_vector& v) { cml::check_size(v, int_c<3>()); matrix_inverse_scale(m, v[0], v[1], v[2]); } -} // namespace cml +} // namespace cml #if 0 @@ -168,7 +156,4 @@ void matrix_scale_along_axis_2D(matrix& m, const VecT& axis, matrix_linear_transform_2D(m, outer_p); } -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +#endif \ No newline at end of file diff --git a/cml/mathlib/matrix/size_checking.h b/cml/mathlib/matrix/size_checking.h index 8d402f4..4ae0ada 100644 --- a/cml/mathlib/matrix/size_checking.h +++ b/cml/mathlib/matrix/size_checking.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_matrix_size_checking_h -#define cml_mathlib_matrix_size_checking_h - #include #include #include @@ -19,9 +14,11 @@ namespace cml { /** Exception thrown when run-time size checking is enabled, and a matrix * is not sized to hold an affine transformation. */ -struct affine_matrix_size_error : std::runtime_error { +struct affine_matrix_size_error : std::runtime_error +{ affine_matrix_size_error() - : std::runtime_error("incorrect affine matrix size") {} + : std::runtime_error("incorrect affine matrix size") + {} }; /** Front-end for both compile-time and run-time 2D affine matrix size @@ -82,13 +79,8 @@ template void check_linear_2D(const readable_matrix& m); */ template void check_linear_3D(const readable_matrix& m); -} // namespace cml +} // namespace cml #define __CML_MATHLIB_MATRIX_SIZE_CHECKING_TPP #include #undef __CML_MATHLIB_MATRIX_SIZE_CHECKING_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/matrix/size_checking.tpp b/cml/mathlib/matrix/size_checking.tpp index 09aa005..0fef830 100644 --- a/cml/mathlib/matrix/size_checking.tpp +++ b/cml/mathlib/matrix/size_checking.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_MATRIX_SIZE_CHECKING_TPP -#error "mathlib/matrix/size_checking.tpp not included correctly" +# error "mathlib/matrix/size_checking.tpp not included correctly" #endif #include @@ -14,115 +12,120 @@ namespace cml { namespace detail { /* No-op matrix size checking. */ -template inline void +template +inline void check_affine_2D(const readable_matrix&, any_basis) -{ -} +{} /* Size checking for a row-basis matrix: */ -template inline void +template +inline void check_affine_2D(const readable_matrix& m, row_basis) { cml::check_minimum_size(m, cml::int_c<3>(), cml::int_c<2>()); } /* Size checking for a column-basis matrix: */ -template inline void +template +inline void check_affine_2D(const readable_matrix& m, col_basis) { cml::check_minimum_size(m, cml::int_c<2>(), cml::int_c<3>()); } - /* No-op matrix size checking. */ -template inline void +template +inline void check_affine_3D(const readable_matrix&, any_basis) -{ -} +{} /* Size checking for a row-basis matrix: */ -template inline void +template +inline void check_affine_3D(const readable_matrix& m, row_basis) { cml::check_minimum_size(m, cml::int_c<4>(), cml::int_c<3>()); } /* Size checking for a column-basis matrix: */ -template inline void +template +inline void check_affine_3D(const readable_matrix& m, col_basis) { cml::check_minimum_size(m, cml::int_c<3>(), cml::int_c<4>()); } - /* Compile-time affine matrix size checking: */ -template inline void +template +inline void check_affine(const readable_matrix&, fixed_size_tag) { - typedef matrix_traits traits; + using traits = matrix_traits; /* If m is row basis, then rows == cols or rows == cols+1. Otherwise, m * is column basis, and cols == rows or cols == rows+1: */ - static const int M = is_row_basis::value - ? traits::array_rows : traits::array_cols; - static const int N = is_row_basis::value - ? traits::array_cols : traits::array_rows; - static_assert(M == N || M == N+1, "incorrect affine matrix size"); + static const int M = + is_row_basis::value ? traits::array_rows : traits::array_cols; + static const int N = + is_row_basis::value ? traits::array_cols : traits::array_rows; + static_assert(M == N || M == N + 1, "incorrect affine matrix size"); } /* Run-time affine matrix size checking: */ -template inline void +template +inline void check_affine(const readable_matrix& m, dynamic_size_tag) { - typedef matrix_traits traits; + using traits = matrix_traits; /* If m is row basis, then rows == cols or rows == cols+1. Otherwise, m * is column basis, and cols == rows or cols == rows+1: */ int M = is_row_basis::value ? m.rows() : m.cols(); int N = is_row_basis::value ? m.cols() : m.rows(); - cml_require(M == N || M == N+1, affine_matrix_size_error, /**/); + cml_require(M == N || M == N + 1, affine_matrix_size_error, /**/); } -} // namespace detail +} // namespace detail - -template inline void +template +inline void check_affine_2D(const readable_matrix& m) { - typedef basis_tag_of_t tag; + using tag = basis_tag_of_t; detail::check_affine_2D(m, tag()); } -template inline void +template +inline void check_affine_3D(const readable_matrix& m) { - typedef basis_tag_of_t tag; + using tag = basis_tag_of_t; detail::check_affine_3D(m, tag()); } -template inline void +template +inline void check_affine(const readable_matrix& m) { - typedef size_tag_of_t size_tag; + using size_tag = size_tag_of_t; static_assert(!is_any_basis::value, "row_basis or col_basis required"); detail::check_affine(m, size_tag()); } -template inline void +template +inline void check_linear_2D(const readable_matrix& m) { cml::check_minimum_size(m, cml::int_c<2>(), cml::int_c<2>()); } -template inline void +template +inline void check_linear_3D(const readable_matrix& m) { cml::check_minimum_size(m, cml::int_c<3>(), cml::int_c<3>()); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/mathlib/matrix/temporary.h b/cml/mathlib/matrix/temporary.h index ec615d3..57803dd 100644 --- a/cml/mathlib/matrix/temporary.h +++ b/cml/mathlib/matrix/temporary.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_temporary_h -#define cml_mathlib_temporary_h - #include #include #include @@ -22,56 +17,50 @@ template* = nullptr> struct n_basis_vector_of { /* Query the unbound storage type: */ - typedef matrix_traits traits; - typedef typename traits::value_type value_type; - typedef typename traits::storage_type matrix_storage_type; - typedef typename matrix_storage_type::unbound_type unbound_storage_type; + using traits = matrix_traits; + using value_type = typename traits::value_type; + using matrix_storage_type = typename traits::storage_type; + using unbound_storage_type = typename matrix_storage_type::unbound_type; /* Rebind to a proxy vector storage type with the requested size: */ - typedef resize_storage_t resized_type; - typedef rebind_vector_storage_t rebound_type; - typedef proxy_type_of_t storage_type; - typedef vector type; + using resized_type = resize_storage_t; + using rebound_type = rebind_vector_storage_t; + using storage_type = proxy_type_of_t; + using type = vector; }; /** Convenience alias for n_basis_vector_of. */ template - using n_basis_vector_of_t = typename n_basis_vector_of::type; - +using n_basis_vector_of_t = typename n_basis_vector_of::type; /** Deduce a temporary for basis vectors of @c Matrix. */ template* = nullptr> struct basis_vector_of { /* Query the unbound storage type: */ - typedef matrix_traits traits; - typedef typename traits::value_type value_type; - typedef typename traits::storage_type matrix_storage_type; - typedef typename traits::basis_tag basis_tag; - typedef typename matrix_storage_type::unbound_type unbound_storage_type; + using traits = matrix_traits; + using value_type = typename traits::value_type; + using matrix_storage_type = typename traits::storage_type; + using basis_tag = typename traits::basis_tag; + using unbound_storage_type = typename matrix_storage_type::unbound_type; /* any_basis is not allowed: */ static_assert(!is_any_basis::value, "any_basis invalid for basis vector type deduction"); /* Determine the vector size based on the basis: */ - static const int N = is_row_basis::value - ? traits::array_cols : traits::array_rows; + static const int N = + is_row_basis::value ? traits::array_cols : traits::array_rows; /* Rebind to a proxy vector storage type with the requested size: */ - typedef resize_storage_t resized_type; - typedef rebind_vector_storage_t rebound_type; - typedef proxy_type_of_t storage_type; - typedef vector type; + using resized_type = resize_storage_t; + using rebound_type = rebind_vector_storage_t; + using storage_type = proxy_type_of_t; + using type = vector; }; /** Convenience alias for basis_vector_of. */ template - using basis_vector_of_t = typename basis_vector_of::type; - -} // namespace cml - -#endif +using basis_vector_of_t = typename basis_vector_of::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/mathlib/matrix/transform.h b/cml/mathlib/matrix/transform.h index c59b642..87f16a6 100644 --- a/cml/mathlib/matrix/transform.h +++ b/cml/mathlib/matrix/transform.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_matrix_transform_h -#define cml_mathlib_matrix_transform_h - #include #include #include @@ -30,12 +25,11 @@ namespace cml { * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_look_at(writable_matrix& m, - const readable_vector& position, - const readable_vector& target, - const readable_vector& up, - AxisOrientation handedness); +template +void matrix_look_at(writable_matrix& m, + const readable_vector& position, + const readable_vector& target, const readable_vector& up, + AxisOrientation handedness); /** Build a matrix representing a left-handed 'look at' view transform * given the eye position, target, and reference up vector. @@ -44,11 +38,10 @@ matrix_look_at(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_look_at_LH(writable_matrix& m, - const readable_vector& position, - const readable_vector& target, - const readable_vector& up); +template +void matrix_look_at_LH(writable_matrix& m, + const readable_vector& position, + const readable_vector& target, const readable_vector& up); /** Build a matrix representing a right-handed 'look at' view transform * given the eye position, target, and reference up vector. @@ -57,11 +50,10 @@ matrix_look_at_LH(writable_matrix& m, * dynamically-sized, and is not at least 4x4. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -matrix_look_at_RH(writable_matrix& m, - const readable_vector& position, - const readable_vector& target, - const readable_vector& up); +template +void matrix_look_at_RH(writable_matrix& m, + const readable_vector& position, + const readable_vector& target, const readable_vector& up); /*@}*/ @@ -74,8 +66,9 @@ matrix_look_at_RH(writable_matrix& m, * dynamically-sized, and is not at least 3x3. If @c m is fixed-size, the * size is checked at compile-time. */ -template inline void matrix_linear_transform( - writable_matrix& m, const readable_matrix& l); +template +inline void matrix_linear_transform(writable_matrix& m, + const readable_matrix& l); /*@}*/ @@ -98,11 +91,10 @@ template inline void matrix_linear_transform( * dynamically-sized, and is not 3D. If @c translation is fixed-size, the * size is checked at compile-time. */ -template inline void -matrix_affine_transform(writable_matrix& m, - const readable_vector& axis, const E& angle, - const readable_vector& translation, - bool normalize = false); +template +inline void matrix_affine_transform(writable_matrix& m, + const readable_vector& axis, const E& angle, + const readable_vector& translation, bool normalize = false); /** Build an affine transform @c m from a linear matrix and a translation. * @@ -118,10 +110,10 @@ matrix_affine_transform(writable_matrix& m, * dynamically-sized, and is not 3D. If @c translation is fixed-size, the * size is checked at compile-time. */ -template inline void -matrix_affine_transform( - writable_matrix& m, const readable_matrix& linear, - const readable_vector& translation); +template +inline void matrix_affine_transform(writable_matrix& m, + const readable_matrix& linear, + const readable_vector& translation); /*@}*/ @@ -129,13 +121,8 @@ matrix_affine_transform( /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_MATRIX_TRANSFORM_TPP #include #undef __CML_MATHLIB_MATRIX_TRANSFORM_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/matrix/transform.tpp b/cml/mathlib/matrix/transform.tpp index 54af40d..6af62c2 100644 --- a/cml/mathlib/matrix/transform.tpp +++ b/cml/mathlib/matrix/transform.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_MATRIX_TRANSFORM_TPP -#error "mathlib/matrix/transform.tpp not included correctly" +# error "mathlib/matrix/transform.tpp not included correctly" #endif #include @@ -21,15 +19,13 @@ namespace cml { /* Look-at functions: */ -template inline void -matrix_look_at(writable_matrix& m, - const readable_vector& position, - const readable_vector& target, - const readable_vector& up, - const AxisOrientation handedness - ) +template +inline void +matrix_look_at(writable_matrix& m, const readable_vector& position, + const readable_vector& target, const readable_vector& up, + const AxisOrientation handedness) { - typedef value_type_trait_of_t value_type; + using value_type = value_type_trait_of_t; cml::check_affine_3D(m); @@ -42,35 +38,34 @@ matrix_look_at(writable_matrix& m, auto y = cross(z, x); matrix_set_transposed_basis_vectors(m, x, y, z); - matrix_set_translation(m, - -dot(position, x), -dot(position, y), -dot(position, z)); + matrix_set_translation(m, -dot(position, x), -dot(position, y), + -dot(position, z)); } -template inline void +template +inline void matrix_look_at_LH(writable_matrix& m, - const readable_vector& position, - const readable_vector& target, - const readable_vector& up) + const readable_vector& position, + const readable_vector& target, const readable_vector& up) { matrix_look_at(m, position, target, up, left_handed); } -template inline void +template +inline void matrix_look_at_RH(writable_matrix& m, - const readable_vector& position, - const readable_vector& target, - const readable_vector& up) + const readable_vector& position, + const readable_vector& target, const readable_vector& up) { matrix_look_at(m, position, target, up, right_handed); } - /* 3D Linear transform functions: */ -template inline void -matrix_linear_transform( - writable_matrix& m, const readable_matrix& l - ) +template +inline void +matrix_linear_transform(writable_matrix& m, + const readable_matrix& l) { cml::check_linear_3D(m); cml::check_linear_3D(l); @@ -81,20 +76,18 @@ matrix_linear_transform( /* Copy basis elements: */ for(int i = 0; i < 3; ++i) { for(int j = 0; j < 3; ++j) { - m.set_basis_element(i,j, l.basis_element(i,j)); + m.set_basis_element(i, j, l.basis_element(i, j)); } } } - /* 3D Affine transform functions: */ -template inline void -matrix_affine_transform( - writable_matrix& m, +template +inline void +matrix_affine_transform(writable_matrix& m, const readable_vector& axis, const E& angle, - const readable_vector& translation, bool normalize - ) + const readable_vector& translation, bool normalize) { cml::check_affine_3D(m); if(normalize) { @@ -105,19 +98,17 @@ matrix_affine_transform( cml::matrix_set_translation(m, translation); } -template inline void -matrix_affine_transform( - writable_matrix& m, - const readable_matrix& linear, - const readable_vector& translation - ) +template +inline void +matrix_affine_transform(writable_matrix& m, + const readable_matrix& linear, const readable_vector& translation) { cml::check_affine_3D(m); cml::matrix_linear_transform(m, linear); cml::matrix_set_translation(m, translation); } -} // namespace cml +} // namespace cml #if 0 @@ -811,7 +802,4 @@ void matrix_decompose_SRT_2D( m, scale_x, scale_y, rotation_matrix, translation); angle = matrix_to_rotation_2D(rotation_matrix); } -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +#endif \ No newline at end of file diff --git a/cml/mathlib/matrix/translation.h b/cml/mathlib/matrix/translation.h index fb44e75..c307883 100644 --- a/cml/mathlib/matrix/translation.h +++ b/cml/mathlib/matrix/translation.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_matrix_translation_h -#define cml_mathlib_matrix_translation_h - #include #include #include @@ -30,8 +25,9 @@ namespace cml { * dynamically-sized, and is not sized for a 2D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_set_translation_2D( - writable_matrix& m, const E0& e0, const E1& e1); +template +void matrix_set_translation_2D(writable_matrix& m, const E0& e0, + const E1& e1); /** Set the translation of a 2D affine transformation, @c m, to the 2D * vector @c v. @@ -43,8 +39,9 @@ template void matrix_set_translation_2D( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 2D. If @c v is fixed-size, the size is checked at compile-time. */ -template void matrix_set_translation_2D( - writable_matrix& m, const readable_vector& v); +template +void matrix_set_translation_2D(writable_matrix& m, + const readable_vector& v); /** Get the translation vector of a 2D affine transformation as two scalar @@ -54,8 +51,8 @@ template void matrix_set_translation_2D( * dynamically-sized, and is not sized for a 2D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_get_translation_2D( - const readable_matrix& m, E0& e0, E1& e1); +template +void matrix_get_translation_2D(const readable_matrix& m, E0& e0, E1& e1); /** Get the translation of a 2D affine transformation as a 2D vector. * @@ -63,8 +60,9 @@ template void matrix_get_translation_2D( * dynamically-sized, and is not sized for a 2D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template auto matrix_get_translation_2D( - const readable_matrix& m) -> n_basis_vector_of_t; +template +auto matrix_get_translation_2D(const readable_matrix& m) + -> n_basis_vector_of_t; /** Initialize a 2D translation matrix, @c m, from @c e0 and @c e1. @@ -73,8 +71,8 @@ template auto matrix_get_translation_2D( * dynamically-sized, and is not sized for a 2D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_translation_2D( - writable_matrix& m, const E0& e0, const E1& e1); +template +void matrix_translation_2D(writable_matrix& m, const E0& e0, const E1& e1); /** Initialize a 2D translation matrix, @c m, from the 2D vector @c v. * @@ -85,8 +83,9 @@ template void matrix_translation_2D( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 2D. If @c v is fixed-size, the size is checked at compile-time. */ -template void matrix_translation_2D( - writable_matrix& m, const readable_vector& v); +template +void matrix_translation_2D(writable_matrix& m, + const readable_vector& v); /*@}*/ @@ -101,8 +100,9 @@ template void matrix_translation_2D( * dynamically-sized, and is not sized for a 3D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_set_translation( - writable_matrix& m, const E0& e0, const E1& e1, const E2& e2); +template +void matrix_set_translation(writable_matrix& m, const E0& e0, const E1& e1, + const E2& e2); /** Set the translation of a 3D affine transformation, @c m, to @c e0, @c * e1, and 0. @@ -111,8 +111,9 @@ template void matrix_set_translation( * dynamically-sized, and is not sized for a 3D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_set_translation( - writable_matrix& m, const E0& e0, const E1& e1); +template +void matrix_set_translation(writable_matrix& m, const E0& e0, + const E1& e1); /** Set the translation of a 3D affine transformation, @c m, to the * 2D or 3D vector @c v (if @c v is 2D the last element is 0). @@ -125,8 +126,9 @@ template void matrix_set_translation( * is not 2D or 3D. If @c v is fixed-size, the size is checked at * compile-time. */ -template void matrix_set_translation( - writable_matrix& m, const readable_vector& v); +template +void matrix_set_translation(writable_matrix& m, + const readable_vector& v); /** Get the translation vector of a 3D affine transformation as three @@ -136,8 +138,9 @@ template void matrix_set_translation( * dynamically-sized, and is not sized for a 3D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_get_translation( - const readable_matrix& m, E0& e0, E1& e1, E2& e2); +template +void matrix_get_translation(const readable_matrix& m, E0& e0, E1& e1, + E2& e2); /** Get the translation of a 3D affine transformation as a 3D vector. * @@ -145,8 +148,9 @@ template void matrix_get_translation( * dynamically-sized, and is not sized for a 3D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template auto matrix_get_translation( - const readable_matrix& m) -> n_basis_vector_of_t; +template +auto matrix_get_translation(const readable_matrix& m) + -> n_basis_vector_of_t; /** Initialize a 3D translation matrix, @c m, from @c e0, @c e1, and @c e2. @@ -155,8 +159,9 @@ template auto matrix_get_translation( * dynamically-sized, and is not sized for a 3D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_translation( - writable_matrix& m, const E0& e0, const E1& e1, const E2& e2); +template +void matrix_translation(writable_matrix& m, const E0& e0, const E1& e1, + const E2& e2); /** Initialize a 3D translation matrix, @c m, from @c e0, @c e1, and 0. * @@ -164,8 +169,8 @@ template void matrix_translation( * dynamically-sized, and is not sized for a 3D affine transformation. If * @c m is fixed-size, the size is checked at compile-time. */ -template void matrix_translation( - writable_matrix& m, const E0& e0, const E1& e1); +template +void matrix_translation(writable_matrix& m, const E0& e0, const E1& e1); /** Initialize a 3D translation matrix, @c m, from the 3D vector @c v. * @@ -176,20 +181,16 @@ template void matrix_translation( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 3D. If @c v is fixed-size, the size is checked at compile-time. */ -template void matrix_translation( - writable_matrix& m, const readable_vector& v); +template +void matrix_translation(writable_matrix& m, + const readable_vector& v); /*@}*/ /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_MATRIX_TRANSLATION_TPP #include #undef __CML_MATHLIB_MATRIX_TRANSLATION_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/matrix/translation.tpp b/cml/mathlib/matrix/translation.tpp index a220704..c0a6dad 100644 --- a/cml/mathlib/matrix/translation.tpp +++ b/cml/mathlib/matrix/translation.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_MATRIX_TRANSLATION_TPP -#error "mathlib/matrix/translation.tpp not included correctly" +# error "mathlib/matrix/translation.tpp not included correctly" #endif #include @@ -16,7 +14,8 @@ namespace cml { namespace detail { /* Base case, set a single basis element (I,J): */ -template inline void +template +inline void matrix_set_basis(writable_matrix& m, const E& e) { m.set_basis_element(I, J, e); @@ -25,189 +24,175 @@ matrix_set_basis(writable_matrix& m, const E& e) /* Recursive case: set basis element (I,J) to e, then recursively set * (I,J+1): */ -template inline void +template +inline void matrix_set_basis(writable_matrix& m, const E& e, const Es&... es) { m.set_basis_element(I, J, e); - matrix_set_basis(m, es...); + matrix_set_basis(m, es...); } /* Entry case: set basis vector I from the items in Es: */ -template inline void +template +inline void matrix_set_basis(writable_matrix& m, const Es&... es) { - static_assert( - cml::are_convertible, Es...>::value, + static_assert(cml::are_convertible, Es...>::value, "incompatible scalar types"); /* Recursively set basis vector I, starting at element 0: */ - matrix_set_basis(m, es...); + matrix_set_basis(m, es...); } -} // namespace detail - +} // namespace detail /* 2D translation: */ -template inline void -matrix_set_translation_2D( - writable_matrix& m, const E0& e0, const E1& e1 - ) +template +inline void +matrix_set_translation_2D(writable_matrix& m, const E0& e0, const E1& e1) { cml::check_affine_2D(m); detail::matrix_set_basis<2>(m, e0, e1); } -template inline void -matrix_set_translation_2D( - writable_matrix& m, const readable_vector& v - ) +template +inline void +matrix_set_translation_2D(writable_matrix& m, + const readable_vector& v) { cml::check_size(v, int_c<2>()); cml::check_affine_2D(m); detail::matrix_set_basis<2>(m, v[0], v[1]); } - -template inline void -matrix_get_translation_2D( - const readable_matrix& m, E0& e0, E1& e1 - ) +template +inline void +matrix_get_translation_2D(const readable_matrix& m, E0& e0, E1& e1) { - static_assert( - cml::are_convertible, E0, E1>::value, + static_assert(cml::are_convertible, E0, E1>::value, "incompatible scalar types"); cml::check_affine_2D(m); - e0 = E0(m.basis_element(2,0)); - e1 = E1(m.basis_element(2,1)); + e0 = E0(m.basis_element(2, 0)); + e1 = E1(m.basis_element(2, 1)); } -template inline auto +template +inline auto matrix_get_translation_2D(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { cml::check_affine_2D(m); #if defined(_MSC_VER) && (_MSC_VER >= 1900) - return n_basis_vector_of_t( - m.basis_element(2,0), m.basis_element(2,1)); + return n_basis_vector_of_t(m.basis_element(2, 0), + m.basis_element(2, 1)); #else - return { m.basis_element(2,0), m.basis_element(2,1) }; + return {m.basis_element(2, 0), m.basis_element(2, 1)}; #endif } - -template inline void -matrix_translation_2D( - writable_matrix& m, const E0& e0, const E1& e1 - ) +template +inline void +matrix_translation_2D(writable_matrix& m, const E0& e0, const E1& e1) { m.identity(); matrix_set_translation_2D(m, e0, e1); } -template inline void -matrix_translation_2D( - writable_matrix& m, const readable_vector& v - ) +template +inline void +matrix_translation_2D(writable_matrix& m, const readable_vector& v) { m.identity(); matrix_set_translation_2D(m, v); } - /* 3D translation: */ -template inline void -matrix_set_translation( - writable_matrix& m, const E0& e0, const E1& e1, const E2& e2 - ) +template +inline void +matrix_set_translation(writable_matrix& m, const E0& e0, const E1& e1, + const E2& e2) { cml::check_affine_3D(m); detail::matrix_set_basis<3>(m, e0, e1, e2); } -template inline void -matrix_set_translation( - writable_matrix& m, const E0& e0, const E1& e1 - ) +template +inline void +matrix_set_translation(writable_matrix& m, const E0& e0, const E1& e1) { - typedef value_type_trait_of_t zero_type; + using zero_type = value_type_trait_of_t; cml::check_affine_3D(m); detail::matrix_set_basis<3>(m, e0, e1, zero_type(0)); } -template inline void -matrix_set_translation( - writable_matrix& m, const readable_vector& v - ) +template +inline void +matrix_set_translation(writable_matrix& m, const readable_vector& v) { - typedef value_type_trait_of_t zero_type; + using zero_type = value_type_trait_of_t; cml::check_size_range(v, int_c<2>(), int_c<3>()); cml::check_affine_3D(m); - detail::matrix_set_basis<3>( - m, v[0], v[1], ((v.size() == 3) ? zero_type(v[2]) : zero_type(0))); + detail::matrix_set_basis<3>(m, v[0], v[1], + ((v.size() == 3) ? zero_type(v[2]) : zero_type(0))); } - -template inline void -matrix_get_translation( - const readable_matrix& m, E0& e0, E1& e1, E2& e2 - ) +template +inline void +matrix_get_translation(const readable_matrix& m, E0& e0, E1& e1, E2& e2) { static_assert( cml::are_convertible, E0, E1, E2>::value, "incompatible scalar types"); cml::check_affine_3D(m); - e0 = E0(m.basis_element(3,0)); - e1 = E1(m.basis_element(3,1)); - e2 = E2(m.basis_element(3,2)); + e0 = E0(m.basis_element(3, 0)); + e1 = E1(m.basis_element(3, 1)); + e2 = E2(m.basis_element(3, 2)); } -template inline auto +template +inline auto matrix_get_translation(const readable_matrix& m) --> n_basis_vector_of_t + -> n_basis_vector_of_t { cml::check_affine_3D(m); #if defined(_MSC_VER) && (_MSC_VER >= 1900) - return n_basis_vector_of_t( - m.basis_element(3,0), m.basis_element(3,1), m.basis_element(3,2)); + return n_basis_vector_of_t(m.basis_element(3, 0), + m.basis_element(3, 1), m.basis_element(3, 2)); #else - return { m.basis_element(3,0), m.basis_element(3,1), m.basis_element(3,2) }; + return {m.basis_element(3, 0), m.basis_element(3, 1), m.basis_element(3, 2)}; #endif } - -template inline void -matrix_translation( - writable_matrix& m, const E0& e0, const E1& e1, const E2& e2 - ) +template +inline void +matrix_translation(writable_matrix& m, const E0& e0, const E1& e1, + const E2& e2) { m.identity(); matrix_set_translation(m, e0, e1, e2); } -template inline void -matrix_translation( - writable_matrix& m, const readable_vector& v - ) +template +inline void +matrix_translation(writable_matrix& m, const readable_vector& v) { m.identity(); matrix_set_translation(m, v); } -template inline void -matrix_translation( - writable_matrix& m, const E0& e0, const E1& e1 - ) +template +inline void +matrix_translation(writable_matrix& m, const E0& e0, const E1& e1) { m.identity(); matrix_set_translation(m, e0, e1); } -} // namespace cml - +} // namespace cml #if 0 @@ -230,7 +215,4 @@ matrix_get_view_translation(const MatT& m) return vector_type(-dot(p,x),-dot(p,y),-dot(p,z)); } -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +#endif \ No newline at end of file diff --git a/cml/mathlib/quaternion/basis.h b/cml/mathlib/quaternion/basis.h index e539dc5..6f6835f 100644 --- a/cml/mathlib/quaternion/basis.h +++ b/cml/mathlib/quaternion/basis.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_quaternion_basis_h -#define cml_mathlib_quaternion_basis_h - #include #include @@ -23,24 +18,24 @@ namespace cml { * * @throws std::invalid_argument if @c i < 0 or @c i > 2. */ -template auto -quaternion_get_basis_vector(const readable_quaternion& q, int i) --> temporary_of_t; +template +auto quaternion_get_basis_vector(const readable_quaternion& q, int i) + -> temporary_of_t; /** Get the x-basis vector of @c q. */ -template auto -quaternion_get_x_basis_vector(const readable_quaternion& q) --> temporary_of_t; +template +auto quaternion_get_x_basis_vector(const readable_quaternion& q) + -> temporary_of_t; /** Get the y-basis vector of @c q. */ -template auto -quaternion_get_y_basis_vector(const readable_quaternion& q) --> temporary_of_t; +template +auto quaternion_get_y_basis_vector(const readable_quaternion& q) + -> temporary_of_t; /** Get the z-basis vector of @c q. */ -template auto -quaternion_get_z_basis_vector(const readable_quaternion& q) --> temporary_of_t; +template +auto quaternion_get_z_basis_vector(const readable_quaternion& q) + -> temporary_of_t; /** Return the basis vectors of @c q as three vectors, @c x, @c y, and @c * z. @@ -50,21 +45,15 @@ quaternion_get_z_basis_vector(const readable_quaternion& q) * compile-time. */ template* = nullptr, - enable_if_vector_t* = nullptr, + enable_if_vector_t* = nullptr, enable_if_vector_t* = nullptr, enable_if_vector_t* = nullptr> -void quaternion_get_basis_vectors( - const readable_quaternion& q, XBasis& x, YBasis& y, ZBasis& z); +void quaternion_get_basis_vectors(const readable_quaternion& q, XBasis& x, + YBasis& y, ZBasis& z); /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_QUATERNION_BASIS_TPP #include #undef __CML_MATHLIB_QUATERNION_BASIS_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/quaternion/basis.tpp b/cml/mathlib/quaternion/basis.tpp index e523331..dec54b6 100644 --- a/cml/mathlib/quaternion/basis.tpp +++ b/cml/mathlib/quaternion/basis.tpp @@ -1,28 +1,27 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_QUATERNION_BASIS_TPP -#error "mathlib/quaternion/basis.tpp not included correctly" +# error "mathlib/quaternion/basis.tpp not included correctly" #endif #include namespace cml { -template auto +template +auto quaternion_get_basis_vector(const readable_quaternion& q, int i) --> temporary_of_t + -> temporary_of_t { - typedef value_type_trait_of_t value_type; - typedef order_type_trait_of_t order_type; - typedef temporary_of_t result_type; + using value_type = value_type_trait_of_t; + using order_type = order_type_trait_of_t; + using result_type = temporary_of_t; cml_require(0 <= i && i <= 2, std::invalid_argument, "invalid axis"); - int j = (i+1)%3, k = (i+2)%3; + int j = (i + 1) % 3, k = (i + 2) % 3; const auto W = order_type::W; const auto I = order_type::X + i; const auto J = order_type::X + j; @@ -39,42 +38,40 @@ quaternion_get_basis_vector(const readable_quaternion& q, int i) return basis; } -template auto +template +auto quaternion_get_x_basis_vector(const readable_quaternion& q) --> temporary_of_t + -> temporary_of_t { return quaternion_get_basis_vector(q, 0); } -template auto +template +auto quaternion_get_y_basis_vector(const readable_quaternion& q) --> temporary_of_t + -> temporary_of_t { return quaternion_get_basis_vector(q, 1); } -template auto +template +auto quaternion_get_z_basis_vector(const readable_quaternion& q) --> temporary_of_t + -> temporary_of_t { return quaternion_get_basis_vector(q, 2); } -template*, - enable_if_vector_t*, - enable_if_vector_t* -> void quaternion_get_basis_vectors( - const readable_quaternion& q, XBasis& x, YBasis& y, ZBasis& z - ) +template*, enable_if_vector_t*, + enable_if_vector_t*> +void +quaternion_get_basis_vectors(const readable_quaternion& q, XBasis& x, + YBasis& y, ZBasis& z) { x = quaternion_get_x_basis_vector(q); y = quaternion_get_y_basis_vector(q); z = quaternion_get_z_basis_vector(q); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/mathlib/quaternion/rotation.h b/cml/mathlib/quaternion/rotation.h index d164d20..83af97a 100644 --- a/cml/mathlib/quaternion/rotation.h +++ b/cml/mathlib/quaternion/rotation.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_quaternion_rotation_h -#define cml_mathlib_quaternion_rotation_h - #include #include #include @@ -38,20 +33,21 @@ namespace cml { * * @throws std::invalid_argument if @c axis < 0 or @c axis > 2. */ -template void -quaternion_rotation_world_axis(writable_quaternion& q, int axis, E angle); +template +void quaternion_rotation_world_axis(writable_quaternion& q, int axis, + E angle); /** Build a quaternion representing a rotation about world x-axis. */ -template void -quaternion_rotation_world_x(writable_quaternion& q, E angle); +template +void quaternion_rotation_world_x(writable_quaternion& q, E angle); /** Build a quaternion representing a rotation about world y-axis. */ -template void -quaternion_rotation_world_y(writable_quaternion& q, E angle); +template +void quaternion_rotation_world_y(writable_quaternion& q, E angle); /** Build a quaternion representing a rotation about world z-axis. */ -template void -quaternion_rotation_world_z(writable_quaternion& q, E angle); +template +void quaternion_rotation_world_z(writable_quaternion& q, E angle); /** Build a quaternion from an axis-angle pair. * @@ -59,9 +55,9 @@ quaternion_rotation_world_z(writable_quaternion& q, E angle); * and is not 3D. If @c axis is fixed-size, the size is checked at * compile-time. */ -template void -quaternion_rotation_axis_angle( - writable_quaternion& q, const readable_vector& axis, E angle); +template +void quaternion_rotation_axis_angle(writable_quaternion& q, + const readable_vector& axis, E angle); /** Build a quaternion from a rotation matrix. * @@ -69,9 +65,9 @@ quaternion_rotation_axis_angle( * dynamically-sized, and is not at least 3x3. If @c m is fixed-size, the * size is checked at compile-time. */ -template void -quaternion_rotation_matrix( - writable_quaternion& q, const readable_matrix& m); +template +void quaternion_rotation_matrix(writable_quaternion& q, + const readable_matrix& m); /** Compute a quaternion given three Euler angles and the required * order. @@ -97,17 +93,17 @@ quaternion_rotation_matrix( * R_y * R_z, where R_i is the rotation matrix above axis i (the row-basis * matrix would be R_z * R_y * R_x). */ -template void -quaternion_rotation_euler(writable_quaternion& q, - E0 angle_0, E1 angle_1, E2 angle_2, euler_order order); +template +void quaternion_rotation_euler(writable_quaternion& q, E0 angle_0, + E1 angle_1, E2 angle_2, euler_order order); /** Compute a quaternion given a vector containing the Euler angles. * * @throws vector_size_error at run-time if @c euler is dynamically-sized, * and is not 3D. If fixed-size, the sizs is checked at compile-time. */ -template void -quaternion_rotation_euler(writable_quaternion& q, +template +void quaternion_rotation_euler(writable_quaternion& q, const readable_vector& euler, euler_order order); /*@}*/ @@ -121,8 +117,8 @@ quaternion_rotation_euler(writable_quaternion& q, * * @note This uses matrix_rotation_align internally. */ -template void -quaternion_rotation_align(writable_quaternion& q, +template +void quaternion_rotation_align(writable_quaternion& q, const readable_vector& align, const readable_vector& reference, bool normalize = true, axis_order order = axis_order_zyx); @@ -131,8 +127,8 @@ quaternion_rotation_align(writable_quaternion& q, * * @note This uses matrix_rotation_aim_at internally. */ -template void -quaternion_rotation_aim_at(writable_quaternion& q, +template +void quaternion_rotation_aim_at(writable_quaternion& q, const readable_vector& pos, const readable_vector& target, const readable_vector& reference, axis_order order = axis_order_zyx); @@ -145,11 +141,10 @@ quaternion_rotation_aim_at(writable_quaternion& q, * * @note @c tolerance is used to detect a near-zero axis length. */ -template> void -quaternion_to_axis_angle( - const readable_quaternion& q, writable_vector& axis, - E& angle, Tol tolerance = scalar_traits::epsilon()); +template> +void quaternion_to_axis_angle(const readable_quaternion& q, + writable_vector& axis, E& angle, + Tol tolerance = scalar_traits::epsilon()); /** Convert a quaternion @c q to an axis-angle pair returned as a * std::tuple. @@ -157,22 +152,20 @@ quaternion_to_axis_angle( * @note @c tolerance is used to detect a near-zero axis length. */ template> -std::tuple< - vector, compiled<3>>, value_type_trait_of_t - > -quaternion_to_axis_angle( - const readable_quaternion& q, - Tol tolerance = scalar_traits::epsilon()); +std::tuple, compiled<3>>, + value_type_trait_of_t> +quaternion_to_axis_angle(const readable_quaternion& q, + Tol tolerance = scalar_traits::epsilon()); /** Convert a quaternion @c q to an Euler-angle triple. * * @note @c tolerance is used to detect degeneracies. */ template> void -quaternion_to_euler( - const readable_quaternion& q, E0& angle_0, E1& angle_1, E2& angle_2, - euler_order order, Tol tolerance = scalar_traits::epsilon(), + class Tol = value_type_trait_of_t> +void quaternion_to_euler(const readable_quaternion& q, E0& angle_0, + E1& angle_1, E2& angle_2, euler_order order, + Tol tolerance = scalar_traits::epsilon(), enable_if_quaternion_t* = nullptr); /** Convert a quaternion @c q to an Euler-angle triple, and return @@ -181,10 +174,9 @@ quaternion_to_euler( * @note @c tolerance is used to detect degeneracies. */ template> -vector, compiled<3>> -quaternion_to_euler( +vector, compiled<3>> quaternion_to_euler( const readable_quaternion& q, euler_order order, - Tol tolerance = scalar_traits::epsilon(), + Tol tolerance = scalar_traits::epsilon(), enable_if_quaternion_t* = nullptr); /** Convert a quaternion @c q to an Euler-angle triple, and return @@ -196,11 +188,9 @@ quaternion_to_euler( * storage (e.g. compiled<3> or allocated<>). The default is vector>, where T is the value_type of the matrix. */ -template> VectorT -quaternion_to_euler( - const readable_quaternion& q, euler_order order, - Tol tolerance = scalar_traits::epsilon(), +template> +VectorT quaternion_to_euler(const readable_quaternion& q, + euler_order order, Tol tolerance = scalar_traits::epsilon(), enable_if_vector_t* = nullptr, enable_if_quaternion_t* = nullptr); @@ -208,13 +198,8 @@ quaternion_to_euler( /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_QUATERNION_ROTATION_TPP #include #undef __CML_MATHLIB_QUATERNION_ROTATION_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/quaternion/rotation.tpp b/cml/mathlib/quaternion/rotation.tpp index 8e8bae2..98766e7 100644 --- a/cml/mathlib/quaternion/rotation.tpp +++ b/cml/mathlib/quaternion/rotation.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_QUATERNION_ROTATION_TPP -#error "mathlib/quaternion/rotation.tpp not included correctly" +# error "mathlib/quaternion/rotation.tpp not included correctly" #endif #include @@ -19,16 +17,15 @@ namespace cml { /* Builders: */ -template inline void -quaternion_rotation_world_axis( - writable_quaternion& q, int axis, E angle - ) +template +inline void +quaternion_rotation_world_axis(writable_quaternion& q, int axis, E angle) { - static_assert(cml::are_convertible< - value_type_trait_of_t, E>::value, "incompatible scalar types"); + static_assert(cml::are_convertible, E>::value, + "incompatible scalar types"); - typedef order_type_trait_of_t order_type; - typedef traits_of_t angle_traits; + using order_type = order_type_trait_of_t; + using angle_traits = traits_of_t; cml_require(0 <= axis && axis <= 2, std::invalid_argument, "invalid axis"); @@ -37,61 +34,65 @@ quaternion_rotation_world_axis( q[order_type::X + axis] = angle_traits::sin(angle / E(2)); } -template inline void +template +inline void quaternion_rotation_world_x(writable_quaternion& q, E angle) { quaternion_rotation_world_axis(q, 0, angle); } -template inline void +template +inline void quaternion_rotation_world_y(writable_quaternion& q, E angle) { quaternion_rotation_world_axis(q, 1, angle); } -template inline void +template +inline void quaternion_rotation_world_z(writable_quaternion& q, E angle) { quaternion_rotation_world_axis(q, 2, angle); } - template -inline void quaternion_rotation_axis_angle( - writable_quaternion& q, const readable_vector& axis, E angle - ) +inline void +quaternion_rotation_axis_angle(writable_quaternion& q, + const readable_vector& axis, E angle) { - static_assert(cml::are_convertible< - value_type_trait_of_t, value_type_trait_of_t, E>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t, E>::value, "incompatible scalar types"); - typedef traits_of_t angle_traits; + using angle_traits = traits_of_t; cml::check_size(axis, int_c<3>()); - q.set( - angle_traits::cos(angle / E(2)), + q.set(angle_traits::cos(angle / E(2)), angle_traits::sin(angle / E(2)) * axis); } template -inline void quaternion_rotation_matrix( - writable_quaternion& q, const readable_matrix& m - ) +inline void +quaternion_rotation_matrix(writable_quaternion& q, + const readable_matrix& m) { - static_assert(cml::are_convertible< - value_type_trait_of_t, value_type_trait_of_t>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t>::value, "incompatible scalar types"); - typedef order_type_trait_of_t order_type; - typedef value_type_trait_of_t value_type; - typedef traits_of_t value_traits; - typedef value_type_trait_of_t M_type; - typedef traits_of_t M_traits; + using order_type = order_type_trait_of_t; + using value_type = value_type_trait_of_t; + using value_traits = traits_of_t; + using M_type = value_type_trait_of_t; + using M_traits = traits_of_t; cml::check_minimum_size(m, int_c<3>(), int_c<3>()); /* Local version of the quaternion ordering: */ - enum { + enum + { W = order_type::W, X = order_type::X, Y = order_type::Y, @@ -102,40 +103,41 @@ inline void quaternion_rotation_matrix( if(tr >= value_type(0)) { q[W] = value_traits::sqrt(tr + value_type(1)) / value_type(2); value_type s = (value_type(1) / value_type(4)) / q[W]; - q[X] = (m.basis_element(1,2) - m.basis_element(2,1)) * s; - q[Y] = (m.basis_element(2,0) - m.basis_element(0,2)) * s; - q[Z] = (m.basis_element(0,1) - m.basis_element(1,0)) * s; + q[X] = (m.basis_element(1, 2) - m.basis_element(2, 1)) * s; + q[Y] = (m.basis_element(2, 0) - m.basis_element(0, 2)) * s; + q[Z] = (m.basis_element(0, 1) - m.basis_element(1, 0)) * s; } else { - int largest_diagonal_element = index_of_max( - m.basis_element(0,0), m.basis_element(1,1), m.basis_element(2,2)); + int largest_diagonal_element = index_of_max(m.basis_element(0, 0), + m.basis_element(1, 1), m.basis_element(2, 2)); int i, j, k; cyclic_permutation(largest_diagonal_element, i, j, k); const int I = X + i; const int J = X + j; const int K = X + k; - q[I] = value_type(M_traits::sqrt( - m.basis_element(i,i) - m.basis_element(j,j) - - m.basis_element(k,k) + value_type(1))) / value_type(2); + q[I] = + value_type(M_traits::sqrt(m.basis_element(i, i) - m.basis_element(j, j) + - m.basis_element(k, k) + value_type(1))) + / value_type(2); value_type s = (value_type(1) / value_type(4)) / q[I]; - q[J] = (m.basis_element(i,j) + m.basis_element(j,i)) * s; - q[K] = (m.basis_element(i,k) + m.basis_element(k,i)) * s; - q[W] = (m.basis_element(j,k) - m.basis_element(k,j)) * s; + q[J] = (m.basis_element(i, j) + m.basis_element(j, i)) * s; + q[K] = (m.basis_element(i, k) + m.basis_element(k, i)) * s; + q[W] = (m.basis_element(j, k) - m.basis_element(k, j)) * s; } } -template void -quaternion_rotation_euler(writable_quaternion& q, - E0 angle_0, E1 angle_1, E2 angle_2, euler_order order - ) +template +void +quaternion_rotation_euler(writable_quaternion& q, E0 angle_0, E1 angle_1, + E2 angle_2, euler_order order) { - static_assert(cml::are_convertible< - value_type_trait_of_t, E0, E1, E2>::value, + static_assert( + cml::are_convertible, E0, E1, E2>::value, "incompatible scalar types"); - typedef order_type_trait_of_t order_type; - typedef scalar_traits angle0_traits; - typedef scalar_traits angle1_traits; - typedef scalar_traits angle2_traits; + using order_type = order_type_trait_of_t; + using angle0_traits = scalar_traits; + using angle1_traits = scalar_traits; + using angle2_traits = scalar_traits; int i, j, k; bool odd, repeat; @@ -179,65 +181,58 @@ quaternion_rotation_euler(writable_quaternion& q, if(odd) q[J] = -q[J]; } -template void -quaternion_rotation_euler( - writable_quaternion& q, - const readable_vector& euler, euler_order order - ) +template +void +quaternion_rotation_euler(writable_quaternion& q, + const readable_vector& euler, euler_order order) { cml::check_size(euler, cml::int_c<3>()); quaternion_rotation_euler(q, euler[0], euler[1], euler[2], order); } - /* Alignment: */ -template inline void -quaternion_rotation_align( - writable_quaternion& q, +template +inline void +quaternion_rotation_align(writable_quaternion& q, const readable_vector& align, const readable_vector& reference, - bool normalize, axis_order order - ) + bool normalize, axis_order order) { - typedef value_type_trait_of_t value_type; - typedef matrix> temporary_type; + using value_type = value_type_trait_of_t; + using temporary_type = matrix>; temporary_type m; matrix_rotation_align(m, align, reference, normalize, order); quaternion_rotation_matrix(q, m); } -template void -quaternion_rotation_aim_at( - writable_quaternion& q, +template +void +quaternion_rotation_aim_at(writable_quaternion& q, const readable_vector& pos, const readable_vector& target, - const readable_vector& reference, - axis_order order - ) + const readable_vector& reference, axis_order order) { - typedef value_type_trait_of_t value_type; - typedef matrix> temporary_type; + using value_type = value_type_trait_of_t; + using temporary_type = matrix>; temporary_type m; matrix_rotation_aim_at(m, pos, target, reference, order); quaternion_rotation_matrix(q, m); } - /* Conversion: */ -template void -quaternion_to_axis_angle( - const readable_quaternion& q, - writable_vector& axis, E& angle, - Tol tolerance - ) +template +void +quaternion_to_axis_angle(const readable_quaternion& q, + writable_vector& axis, E& angle, Tol tolerance) { - static_assert(cml::are_convertible< - value_type_trait_of_t, value_type_trait_of_t, E, Tol>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t, E, Tol>::value, "incompatible scalar types"); - typedef scalar_traits angle_traits; + using angle_traits = scalar_traits; cml::detail::check_or_resize(axis, int_c<3>()); @@ -255,49 +250,44 @@ quaternion_to_axis_angle( namespace detail { /** Helper for the quaternion_to_axis_angle() overloads. */ -template +template inline std::tuple> quaternion_to_axis_angle(const readable_quaternion& q, Tol tolerance) { - static_assert(cml::are_convertible< - value_type_trait_of_t, value_type_trait_of_t, Tol>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t, Tol>::value, "incompatible scalar types"); - VectorT axis; cml::detail::check_or_resize(axis, int_c<3>()); + VectorT axis; + cml::detail::check_or_resize(axis, int_c<3>()); value_type_trait_of_t angle; cml::quaternion_to_axis_angle(q, axis, angle, tolerance); return std::make_tuple(axis, angle); } -} // namespace detail +} // namespace detail template -inline std::tuple< - vector, compiled<3>>, value_type_trait_of_t - > -quaternion_to_axis_angle( - const readable_quaternion& q, Tol tolerance - ) +inline std::tuple, compiled<3>>, + value_type_trait_of_t> +quaternion_to_axis_angle(const readable_quaternion& q, Tol tolerance) { - typedef vector, compiled<3>> vector_type; + using vector_type = vector, compiled<3>>; return detail::quaternion_to_axis_angle(q, tolerance); } template inline void -quaternion_to_euler( - const readable_quaternion& q, - E0& angle_0, E1& angle_1, E2& angle_2, euler_order order, - Tol tolerance, - enable_if_quaternion_t* - ) +quaternion_to_euler(const readable_quaternion& q, E0& angle_0, E1& angle_1, + E2& angle_2, euler_order order, Tol tolerance, enable_if_quaternion_t*) { - static_assert(cml::are_convertible< - value_type_trait_of_t, E0, E1, E2, Tol>::value, + static_assert( + cml::are_convertible, E0, E1, E2, Tol>::value, "incompatible scalar types"); - typedef value_type_trait_of_t value_type; - typedef matrix> temporary_type; + using value_type = value_type_trait_of_t; + using temporary_type = matrix>; temporary_type m; matrix_rotation_quaternion(m, q); @@ -306,14 +296,11 @@ quaternion_to_euler( template inline vector, compiled<3>> -quaternion_to_euler( - const readable_quaternion& q, - euler_order order, - Tol tolerance, enable_if_quaternion_t* - ) +quaternion_to_euler(const readable_quaternion& q, euler_order order, + Tol tolerance, enable_if_quaternion_t*) { - typedef value_type_trait_of_t value_type; - typedef matrix> temporary_type; + using value_type = value_type_trait_of_t; + using temporary_type = matrix>; temporary_type m; matrix_rotation_quaternion(m, q); @@ -322,21 +309,18 @@ quaternion_to_euler( template inline VectorT -quaternion_to_euler( - const readable_quaternion& q, euler_order order, - Tol tolerance, - enable_if_vector_t*, enable_if_quaternion_t* - ) +quaternion_to_euler(const readable_quaternion& q, euler_order order, + Tol tolerance, enable_if_vector_t*, enable_if_quaternion_t*) { - typedef value_type_trait_of_t value_type; - typedef matrix> temporary_type; + using value_type = value_type_trait_of_t; + using temporary_type = matrix>; temporary_type m; matrix_rotation_quaternion(m, q); return matrix_to_euler(m, order, tolerance); } -} // namespace cml +} // namespace cml #if 0 // XXX INCOMPLETE XXX @@ -683,7 +667,4 @@ quaternion_to_axis_angle( } } -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +#endif \ No newline at end of file diff --git a/cml/mathlib/random_unit.h b/cml/mathlib/random_unit.h index daafa3a..ed3c935 100644 --- a/cml/mathlib/random_unit.h +++ b/cml/mathlib/random_unit.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_random_unit_h -#define cml_mathlib_random_unit_h - #include namespace cml { @@ -34,8 +29,8 @@ namespace cml { * * @throws minimum_vector_size_error if @c n has zero size. */ -template void - random_unit(writable_vector& n, RNG& gen); +template +void random_unit(writable_vector& n, RNG& gen); /** Replace @c n with a uniformly random unit vector. * @@ -75,18 +70,14 @@ template void random_unit(writable_vector& n); * dynamically-sized, it will be resized to @c d.size(). If both @c n and * @c d are fixed-size, then the size is checked at compile-time. */ -template void random_unit( - writable_vector& n, const readable_vector& d, const Scalar& a); +template +void random_unit(writable_vector& n, const readable_vector& d, + const Scalar& a); /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_RANDOM_UNIT_TPP #include #undef __CML_MATHLIB_RANDOM_UNIT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/random_unit.tpp b/cml/mathlib/random_unit.tpp index ed02cd7..c2f325f 100644 --- a/cml/mathlib/random_unit.tpp +++ b/cml/mathlib/random_unit.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_RANDOM_UNIT_TPP -#error "mathlib/random_unit.tpp not included correctly" +# error "mathlib/random_unit.tpp not included correctly" #endif #include @@ -19,12 +17,12 @@ namespace detail { /** Generate a random 2D unit vector in a cone with direction @c d and * half-angle @c a, given in radians. */ -template void -random_unit(writable_vector& n, - const readable_vector& d, const Scalar& a, cml::int_c<2> - ) +template +void +random_unit(writable_vector& n, const readable_vector& d, + const Scalar& a, cml::int_c<2>) { - typedef scalar_traits theta_traits; + using theta_traits = scalar_traits; /* Generate a uniformly random angle in [-a,a]: */ auto theta = cml::random_real(-a, a); @@ -47,51 +45,52 @@ random_unit(writable_vector& n, * spherical cone cap. This seems to produce nice (uniform) 3D * distributions, at least visually. */ -template void -random_unit(writable_vector& n, - const readable_vector& d, const Scalar& a, cml::int_c - ) +template +void +random_unit(writable_vector& n, const readable_vector& d, + const Scalar& a, cml::int_c) { - typedef scalar_traits a_traits; + using a_traits = scalar_traits; /* Generate a uniformly random vector on the unit sphere: */ cml::random_unit(n); /* Reorient n to be within 90 degrees of d: */ - auto cos_O = dot(n,d); // [-1,1] + auto cos_O = dot(n, d); // [-1,1] if(cos_O < 0) { n = -n; - cos_O = - cos_O; + cos_O = -cos_O; } /* Compute the angle between d and n: */ auto O = acos_safe(cos_O); - typedef decltype(O) O_type; - typedef scalar_traits O_traits; - typedef scalar_traits Oa_traits; + using O_type = decltype(O); + using O_traits = scalar_traits; + using Oa_traits = scalar_traits; /* Use slerp between d (t=0) and n (t=1) to find the unit vector n_a * (t=a/O) lying on the cone between d and n: */ - auto n_a = (Oa_traits::sin(O - a)*d + a_traits::sin(a)*n) / O_traits::sin(O); + auto n_a = + (Oa_traits::sin(O - a) * d + a_traits::sin(a) * n) / O_traits::sin(O); /* Note: n_a is normalized by dividing by sin(O). */ /* Use a second slerp to "scale" the cone with half-angle O to the cone * with half-angle a, taking the random vector n along with it: */ auto t = O / constants::pi_over_2(); - n = (Oa_traits::sin((O_type(1) - t)*a)*d + Oa_traits::sin(t*a)*n_a) + n = (Oa_traits::sin((O_type(1) - t) * a) * d + Oa_traits::sin(t * a) * n_a) / a_traits::sin(a); /* Note: n is normalized by dividing by sin(a). */ } -} // namespace detail +} // namespace detail - -template inline void +template +inline void random_unit(writable_vector& n, RNG& gen) { - typedef value_type_trait_of_t value_type; + using value_type = value_type_trait_of_t; static_assert(std::is_floating_point::value, "floating-point coordinates required"); cml::check_minimum_size(n, cml::int_c<1>()); @@ -104,7 +103,7 @@ random_unit(writable_vector& n, RNG& gen) /* Generate coordinates, avoiding the (improbable) case of 0 length: */ value_type length(0); do { - for(int i = 0; i < n.size(); ++ i) n[i] = d(gen); + for(int i = 0; i < n.size(); ++i) n[i] = d(gen); length = n.length_squared(); } while(length == value_type(0)); @@ -112,7 +111,8 @@ random_unit(writable_vector& n, RNG& gen) n.normalize(); } -template inline void +template +inline void random_unit(writable_vector& n) { /* Use the default generator: */ @@ -123,11 +123,11 @@ random_unit(writable_vector& n) } template -void random_unit( - writable_vector& n, const readable_vector& d, const Scalar& a - ) +void +random_unit(writable_vector& n, const readable_vector& d, + const Scalar& a) { - typedef value_type_trait_of_t value_type; + using value_type = value_type_trait_of_t; static_assert(std::is_floating_point::value, "floating-point coordinates required"); cml_require(a > 0 && a <= constants::pi_over_2(), @@ -137,7 +137,4 @@ void random_unit( detail::random_unit(n, d, a, cml::int_c::value>()); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/mathlib/vector/angle.h b/cml/mathlib/vector/angle.h index d4fe1ec..5e1ff4b 100644 --- a/cml/mathlib/vector/angle.h +++ b/cml/mathlib/vector/angle.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_vector_angle_h -#define cml_mathlib_vector_angle_h - #include #include @@ -20,37 +15,32 @@ namespace cml { /*@{*/ /** Signed angle between two 2D vectors @c v1 and @c v2. */ -template inline auto signed_angle_2D( - const readable_vector& v1, const readable_vector& v2) --> value_type_trait_promote_t; +template +inline auto signed_angle_2D(const readable_vector& v1, + const readable_vector& v2) -> value_type_trait_promote_t; /** Unsigned angle between two 2D vectors @c v1 and @c v2. */ -template inline auto unsigned_angle_2D( - const readable_vector& v1, const readable_vector& v2) --> value_type_trait_promote_t; +template +inline auto unsigned_angle_2D(const readable_vector& v1, + const readable_vector& v2) -> value_type_trait_promote_t; /** Signed angle between two 3D vectors @c v1 and @c v2, relative @c * reference. */ -template inline auto signed_angle( - const readable_vector& v1, const readable_vector& v2, - const readable_vector& reference) --> value_type_trait_promote_t; +template +inline auto signed_angle(const readable_vector& v1, + const readable_vector& v2, const readable_vector& reference) + -> value_type_trait_promote_t; /** Unsigned angle between two 3D vectors @c v1 and @c v2. */ -template inline auto unsigned_angle( - const readable_vector& v1, const readable_vector& v2) --> value_type_trait_promote_t; +template +inline auto unsigned_angle(const readable_vector& v1, + const readable_vector& v2) -> value_type_trait_promote_t; /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_VECTOR_ANGLE_TPP #include #undef __CML_MATHLIB_VECTOR_ANGLE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/vector/angle.tpp b/cml/mathlib/vector/angle.tpp index 9d58a0f..5b726c6 100644 --- a/cml/mathlib/vector/angle.tpp +++ b/cml/mathlib/vector/angle.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_VECTOR_ANGLE_TPP -#error "mathlib/vector/angle.tpp not included correctly" +# error "mathlib/vector/angle.tpp not included correctly" #endif #include @@ -14,59 +12,48 @@ namespace cml { -template inline auto -signed_angle_2D( - const readable_vector& v1, - const readable_vector& v2 - ) --> value_type_trait_promote_t +template +inline auto +signed_angle_2D(const readable_vector& v1, + const readable_vector& v2) -> value_type_trait_promote_t { - typedef value_type_trait_promote_t value_type; - typedef scalar_traits value_traits; - return value_traits::atan2(perp_dot(v1,v2), dot(v1, v2)); + using value_type = value_type_trait_promote_t; + using value_traits = scalar_traits; + return value_traits::atan2(perp_dot(v1, v2), dot(v1, v2)); } -template inline auto -unsigned_angle_2D( - const readable_vector& v1, - const readable_vector& v2 - ) --> value_type_trait_promote_t +template +inline auto +unsigned_angle_2D(const readable_vector& v1, + const readable_vector& v2) -> value_type_trait_promote_t { - typedef value_type_trait_promote_t value_type; - typedef scalar_traits value_traits; + using value_type = value_type_trait_promote_t; + using value_traits = scalar_traits; return value_traits::fabs(signed_angle_2D(v1, v2)); } -template inline auto -signed_angle( - const readable_vector& v1, - const readable_vector& v2, - const readable_vector& reference - ) --> value_type_trait_promote_t +template +inline auto +signed_angle(const readable_vector& v1, const readable_vector& v2, + const readable_vector& reference) + -> value_type_trait_promote_t { - typedef value_type_trait_promote_t value_type; - typedef scalar_traits value_traits; + using value_type = value_type_trait_promote_t; + using value_traits = scalar_traits; auto c = cross(v1, v2); auto angle = value_traits::atan2(c.length(), dot(v1, v2)); return (dot(c, reference) < value_type(0)) ? -angle : angle; } -template inline auto -unsigned_angle( - const readable_vector& v1, - const readable_vector& v2 - ) --> value_type_trait_promote_t +template +inline auto +unsigned_angle(const readable_vector& v1, const readable_vector& v2) + -> value_type_trait_promote_t { - typedef value_type_trait_promote_t value_type; - typedef scalar_traits value_traits; - return value_traits::atan2(cross(v1,v2).length(), dot(v1, v2)); + using value_type = value_type_trait_promote_t; + using value_traits = scalar_traits; + return value_traits::atan2(cross(v1, v2).length(), dot(v1, v2)); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/mathlib/vector/generators.h b/cml/mathlib/vector/generators.h index e51e6df..f82c128 100644 --- a/cml/mathlib/vector/generators.h +++ b/cml/mathlib/vector/generators.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_vector_generators_h -#define cml_mathlib_vector_generators_h - #include /** @defgroup mathlib_vector_generators Vector Generator Functions */ @@ -22,20 +17,33 @@ namespace cml { /*@{*/ /** Return a fixed-size double-precision N-d zero vector. */ -template inline auto zero() --> vector> +template +inline auto +zero() -> vector> { return vector>().zero(); } /** Return the 2D zero vector */ -inline auto zero_2D() -> decltype(zero<2>()) { return zero<2>(); } +inline auto +zero_2D() -> decltype(zero<2>()) +{ + return zero<2>(); +} /** Return the 3D zero vector */ -inline auto zero_3D() -> decltype(zero<3>()) { return zero<3>(); } +inline auto +zero_3D() -> decltype(zero<3>()) +{ + return zero<3>(); +} /** Return the 4D zero vector */ -inline auto zero_4D() -> decltype(zero<4>()) { return zero<4>(); } +inline auto +zero_4D() -> decltype(zero<4>()) +{ + return zero<4>(); +} /*@}*/ @@ -43,44 +51,59 @@ inline auto zero_4D() -> decltype(zero<4>()) { return zero<4>(); } /*@{*/ /** Return a fixed-size double-precision N-d cardinal axis by index. */ -template inline auto axis(int i) --> vector> +template +inline auto +axis(int i) -> vector> { return vector>().cardinal(i); } /** Return a 2D cardinal axis by index. */ -inline auto axis_2D(int i) -> decltype(axis<2>(i)) { +inline auto +axis_2D(int i) -> decltype(axis<2>(i)) +{ return axis<2>(i); } /** Return the 2D x-axis. */ -inline auto x_axis_2D() -> decltype(axis<2>(0)) { +inline auto +x_axis_2D() -> decltype(axis<2>(0)) +{ return axis<2>(0); } /** Return the 2D y-axis. */ -inline auto y_axis_2D() -> decltype(axis<2>(1)) { +inline auto +y_axis_2D() -> decltype(axis<2>(1)) +{ return axis<2>(1); } /** Return a 3D cardinal axis by index. */ -inline auto axis_3D(int i) -> decltype(axis<3>(i)) { +inline auto +axis_3D(int i) -> decltype(axis<3>(i)) +{ return axis<3>(i); } /** Return the 3D x-axis. */ -inline auto x_axis_3D() -> decltype(axis<3>(0)) { +inline auto +x_axis_3D() -> decltype(axis<3>(0)) +{ return axis<3>(0); } /** Return the 3D y-axis. */ -inline auto y_axis_3D() -> decltype(axis<3>(1)) { +inline auto +y_axis_3D() -> decltype(axis<3>(1)) +{ return axis<3>(1); } /** Return the 3D z-axis. */ -inline auto z_axis_3D() -> decltype(axis<3>(2)) { +inline auto +z_axis_3D() -> decltype(axis<3>(2)) +{ return axis<3>(2); } @@ -88,9 +111,4 @@ inline auto z_axis_3D() -> decltype(axis<3>(2)) { /*@}*/ -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/mathlib/vector/misc.h b/cml/mathlib/vector/misc.h index 178c2ce..5a8f7ef 100644 --- a/cml/mathlib/vector/misc.h +++ b/cml/mathlib/vector/misc.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_vector_misc_h -#define cml_mathlib_vector_misc_h - #include #include #include @@ -30,9 +25,9 @@ namespace cml { * are different sizes, and at least one is dynamically-sized. If both * vectors are fixed-size, the size is checked at compile-time. */ -template auto project_to_vector( - const readable_vector& u, const readable_vector& v) --> vector_promote_t; +template +auto project_to_vector(const readable_vector& u, + const readable_vector& v) -> vector_promote_t; /** Project @c v onto a hyperplane with normal @c n. * @@ -46,9 +41,9 @@ template auto project_to_vector( * are different sizes, and at least one is dynamically-sized. If both * vectors are fixed-size, the size is checked at compile-time. */ -template auto project_to_hplane( - const readable_vector& v, const readable_vector& n) --> vector_promote_t; +template +auto project_to_hplane(const readable_vector& v, + const readable_vector& n) -> vector_promote_t; /** Return a vector counter-clockwise perpendicular to @c v. * @@ -56,8 +51,8 @@ template auto project_to_hplane( * is not a 2D vector. The size is checked at compile-time if @c v is * fixed-size. */ -template auto perp(const readable_vector& v) --> temporary_of_t; +template +auto perp(const readable_vector& v) -> temporary_of_t; /** Compute the Manhattan (city-block) distance between @c v1 and @c v2. * @@ -69,19 +64,14 @@ template auto perp(const readable_vector& v) * are different sizes, and at least one is dynamically-sized. If both * vectors are fixed-size, the size is checked at compile-time. */ -template auto manhattan_distance( - const readable_vector& v1, const readable_vector& v2) --> value_type_trait_promote_t; +template +auto manhattan_distance(const readable_vector& v1, + const readable_vector& v2) -> value_type_trait_promote_t; /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_VECTOR_MISC_TPP #include #undef __CML_MATHLIB_VECTOR_MISC_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/vector/misc.tpp b/cml/mathlib/vector/misc.tpp index 5f97cc5..5a4f6b7 100644 --- a/cml/mathlib/vector/misc.tpp +++ b/cml/mathlib/vector/misc.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_VECTOR_MISC_TPP -#error "mathlib/vector/misc.tpp not included correctly" +# error "mathlib/vector/misc.tpp not included correctly" #endif #include @@ -13,58 +11,52 @@ namespace cml { -template inline auto -project_to_vector( - const readable_vector& u, const readable_vector& v - ) --> vector_promote_t +template +inline auto +project_to_vector(const readable_vector& u, + const readable_vector& v) -> vector_promote_t { - typedef vector_promote_t result_type; - return result_type((dot(u,v) / length_squared(v)) * v); -} + using result_type = vector_promote_t; + return result_type((dot(u, v) / length_squared(v)) * v); +} -template inline auto -project_to_hplane( - const readable_vector& v, const readable_vector& n - ) --> vector_promote_t +template +inline auto +project_to_hplane(const readable_vector& v, + const readable_vector& n) -> vector_promote_t { - typedef vector_promote_t result_type; - return result_type(v - dot(v,n)*n); + using result_type = vector_promote_t; + return result_type(v - dot(v, n) * n); } -template inline auto +template +inline auto perp(const readable_vector& v) -> temporary_of_t { cml::check_size(v, cml::int_c<2>()); #if defined(_MSC_VER) && (_MSC_VER >= 1900) - return temporary_of_t(- v[1], v[0]); + return temporary_of_t(-v[1], v[0]); #else - return { - v[1], v[0] }; + return {-v[1], v[0]}; #endif } -template inline auto -manhattan_distance( - const readable_vector& v1, const readable_vector& v2 - ) --> value_type_trait_promote_t +template +inline auto +manhattan_distance(const readable_vector& v1, + const readable_vector& v2) -> value_type_trait_promote_t { - typedef value_type_trait_promote_t value_type; - typedef scalar_traits value_traits; + using value_type = value_type_trait_promote_t; + using value_traits = scalar_traits; cml::check_minimum_size(v1, cml::int_c<1>()); cml::check_minimum_size(v2, cml::int_c<1>()); - cml::check_same_size(v1,v2); + cml::check_same_size(v1, v2); auto fabs = &value_traits::fabs; auto sum = fabs(value_type(v1[0] - v2[0])); - for(int i = 1; i < v1.size(); ++ i) - sum += fabs(value_type(v1[i] - v2[i])); + for(int i = 1; i < v1.size(); ++i) sum += fabs(value_type(v1[i] - v2[i])); return sum; } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/mathlib/vector/orthonormal.h b/cml/mathlib/vector/orthonormal.h index ab40f94..90fad30 100644 --- a/cml/mathlib/vector/orthonormal.h +++ b/cml/mathlib/vector/orthonormal.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_vector_orthonormal_h -#define cml_mathlib_vector_orthonormal_h - #include #include @@ -23,9 +18,8 @@ namespace cml { /*@{*/ /** Build a 2D orthonormal basis. */ -template void -orthonormal_basis_2D( - const readable_vector& align, +template +void orthonormal_basis_2D(const readable_vector& align, writable_vector& x, writable_vector& y, bool normalize_align = true, axis_order2D order = axis_order_xy); @@ -46,23 +40,18 @@ orthonormal_basis_2D( * 'reference'; this should be checked for and handled externally if it's a * case that may occur. */ -template void -orthonormal_basis( - const readable_vector& align, const readable_vector& reference, - writable_vector& x, writable_vector& y, writable_vector& z, +template +void orthonormal_basis(const readable_vector& align, + const readable_vector& reference, writable_vector& x, + writable_vector& y, writable_vector& z, bool normalize_align = true, axis_order order = axis_order_zyx); /*@}*/ /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_VECTOR_ORTHONORMAL_TPP #include #undef __CML_MATHLIB_VECTOR_ORTHONORMAL_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/vector/orthonormal.tpp b/cml/mathlib/vector/orthonormal.tpp index 4c6ed12..abc0670 100644 --- a/cml/mathlib/vector/orthonormal.tpp +++ b/cml/mathlib/vector/orthonormal.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_VECTOR_ORTHONORMAL_TPP -#error "mathlib/vector/orthonormal.tpp not included correctly" +# error "mathlib/vector/orthonormal.tpp not included correctly" #endif #include @@ -15,18 +13,19 @@ namespace cml { -template void -orthonormal_basis_2D( - const readable_vector& align, - writable_vector& x, writable_vector& y, - bool normalize_align, axis_order2D order) +template +void +orthonormal_basis_2D(const readable_vector& align, + writable_vector& x, writable_vector& y, bool normalize_align, + axis_order2D order) { - static_assert(cml::are_convertible, - value_type_trait_of_t, value_type_trait_of_t>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t, value_type_trait_of_t>::value, "incompatible scalar types"); - typedef value_type_trait_of_t value_type; - typedef vector> temporary_type; + using value_type = value_type_trait_of_t; + using temporary_type = vector>; /* Checking handled by perp() and assignment to fixed<2>. */ @@ -36,7 +35,8 @@ orthonormal_basis_2D( temporary_type axes[2]; - axes[i] = align; if(normalize_align) axes[i].normalize(); + axes[i] = align; + if(normalize_align) axes[i].normalize(); axes[j] = cml::perp(axes[i]); if(odd) axes[j] = -axes[j]; @@ -45,38 +45,40 @@ orthonormal_basis_2D( y = axes[1]; } -template void -orthonormal_basis( - const readable_vector& align, const readable_vector& reference, - writable_vector& x, writable_vector& y, writable_vector& z, - bool normalize_align, axis_order order - ) +template +void +orthonormal_basis(const readable_vector& align, + const readable_vector& reference, writable_vector& x, + writable_vector& y, writable_vector& z, bool normalize_align, + axis_order order) { - static_assert(cml::are_convertible, - value_type_trait_of_t, value_type_trait_of_t, - value_type_trait_of_t, value_type_trait_of_t>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t, value_type_trait_of_t, + value_type_trait_of_t, value_type_trait_of_t>::value, "incompatible scalar types"); - typedef value_type_trait_of_t value_type; - typedef vector> temporary_type; + using value_type = value_type_trait_of_t; + using temporary_type = vector>; int i, j, k; bool odd; unpack_axis_order(order, i, j, k, odd); temporary_type axes[3]; - axes[i] = align; if(normalize_align) axes[i].normalize(); + axes[i] = align; + if(normalize_align) axes[i].normalize(); axes[k] = cml::cross(axes[i], reference).normalize(); axes[j] = cml::cross(axes[k], axes[i]); - - if(odd) axes[k] = - axes[k]; + + if(odd) axes[k] = -axes[k]; x = axes[0]; y = axes[1]; z = axes[2]; } -} // namespace cml +} // namespace cml #if 0 @@ -311,7 +313,4 @@ void orthonormal_basis_viewplane_RH( orthonormal_basis_viewplane( view_matrix,x,y,z,right_handed,order); } -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +#endif \ No newline at end of file diff --git a/cml/mathlib/vector/rotation.h b/cml/mathlib/vector/rotation.h index 88ff013..c7b2de7 100644 --- a/cml/mathlib/vector/rotation.h +++ b/cml/mathlib/vector/rotation.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_vector_rotation_h -#define cml_mathlib_vector_rotation_h - #include /** @defgroup mathlib_vector_rotation Vector Rotation Functions */ @@ -24,19 +19,15 @@ namespace cml { * dynamically-sized, and are not 3D. If fixed-size, the sizes are checked * at compile-time. */ -template auto rotate_vector( - const readable_vector& v, const readable_vector& n, - const E& angle) -> vector_promote_t; +template +auto rotate_vector(const readable_vector& v, + const readable_vector& n, const E& angle) + -> vector_promote_t; /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_VECTOR_ROTATION_TPP #include #undef __CML_MATHLIB_VECTOR_ROTATION_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/vector/rotation.tpp b/cml/mathlib/vector/rotation.tpp index 5bbd653..529f4e6 100644 --- a/cml/mathlib/vector/rotation.tpp +++ b/cml/mathlib/vector/rotation.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_VECTOR_ROTATION_TPP -#error "mathlib/vector/rotation.tpp not included correctly" +# error "mathlib/vector/rotation.tpp not included correctly" #endif #include @@ -14,28 +12,25 @@ namespace cml { -template inline auto -rotate_vector( - const readable_vector& v, const readable_vector& n, - const E& angle - ) -> vector_promote_t +template +inline auto +rotate_vector(const readable_vector& v, const readable_vector& n, + const E& angle) -> vector_promote_t { - static_assert(cml::are_convertible< - value_type_trait_of_t, value_type_trait_of_t, E>::value, + static_assert( + cml::are_convertible, + value_type_trait_of_t, E>::value, "incompatible scalar types"); - typedef scalar_traits angle_traits; + using angle_traits = scalar_traits; cml::check_size(v, cml::int_c<3>()); cml::check_size(n, cml::int_c<3>()); - auto parallel = dot(v,n)*n; + auto parallel = dot(v, n) * n; auto sin_angle = angle_traits::sin(angle); auto cos_angle = angle_traits::cos(angle); - return cos_angle*(v - parallel) + sin_angle*cross(n,v) + parallel; + return cos_angle * (v - parallel) + sin_angle * cross(n, v) + parallel; } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/mathlib/vector/transform.h b/cml/mathlib/vector/transform.h index d9ba99d..70fdee2 100644 --- a/cml/mathlib/vector/transform.h +++ b/cml/mathlib/vector/transform.h @@ -1,18 +1,12 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_mathlib_vector_transform_h -#define cml_mathlib_vector_transform_h - #include #include - /** @defgroup mathlib_vector_transform Vector Transformation Functions */ namespace cml { @@ -33,9 +27,9 @@ namespace cml { * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 2D. If @c v is fixed-size, the size is checked at compile-time. */ -template auto transform_vector_2D( - const readable_matrix& m, const readable_vector& v) - -> temporary_of_t; +template +auto transform_vector_2D(const readable_matrix& m, + const readable_vector& v) -> temporary_of_t; /** Apply a 2D affine transform to a 2D point, taking basis orientation * into account. @@ -47,9 +41,9 @@ template auto transform_vector_2D( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 2D. If @c v is fixed-size, the size is checked at compile-time. */ -template auto transform_point_2D( - const readable_matrix& m, const readable_vector& v) - -> temporary_of_t; +template +auto transform_point_2D(const readable_matrix& m, + const readable_vector& v) -> temporary_of_t; /*@}*/ @@ -67,9 +61,9 @@ template auto transform_point_2D( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 3D. If @c v is fixed-size, the size is checked at compile-time. */ -template auto transform_vector( - const readable_matrix& m, const readable_vector& v) - -> temporary_of_t; +template +auto transform_vector(const readable_matrix& m, + const readable_vector& v) -> temporary_of_t; /** Apply a 3D affine transform to a 3D point, taking basis orientation * into account. @@ -81,9 +75,9 @@ template auto transform_vector( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 3D. If @c v is fixed-size, the size is checked at compile-time. */ -template auto transform_point( - const readable_matrix& m, const readable_vector& v) - -> temporary_of_t; +template +auto transform_point(const readable_matrix& m, + const readable_vector& v) -> temporary_of_t; /** Apply a 3D homogeneous transformation to a 4D vector, taking basis * orientation into account. @@ -95,9 +89,9 @@ template auto transform_point( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 4D. If @c v is fixed-size, the size is checked at compile-time. */ -template auto transform_vector_4D( - const readable_matrix& m, const readable_vector& v) - -> temporary_of_t; +template +auto transform_vector_4D(const readable_matrix& m, + const readable_vector& v) -> temporary_of_t; /** Apply a 3D homogeneous transformation to a 3D point, taking basis * orientation into account. @@ -109,21 +103,16 @@ template auto transform_vector_4D( * @throws vector_size_error at run-time if @c v is dynamically-sized, and * is not 3D. If @c v is fixed-size, the size is checked at compile-time. */ -template auto transform_point_4D( - const readable_matrix& m, const readable_vector& v) - -> temporary_of_t; +template +auto transform_point_4D(const readable_matrix& m, + const readable_vector& v) -> temporary_of_t; /*@}*/ /*@}*/ -} // namespace cml +} // namespace cml #define __CML_MATHLIB_VECTOR_TRANSFORM_TPP #include #undef __CML_MATHLIB_VECTOR_TRANSFORM_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/mathlib/vector/transform.tpp b/cml/mathlib/vector/transform.tpp index 173cfd5..8525dca 100644 --- a/cml/mathlib/vector/transform.tpp +++ b/cml/mathlib/vector/transform.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATHLIB_VECTOR_TRANSFORM_TPP -#error "mathlib/vector/transform.tpp not included correctly" +# error "mathlib/vector/transform.tpp not included correctly" #endif #include @@ -16,180 +14,139 @@ namespace cml { namespace detail { /** Matrix-vector pre-multiplication. */ -template inline auto -transform_vector_4D( - const readable_matrix& m, const readable_vector& v, col_basis - ) -> temporary_of_t +template +inline auto +transform_vector_4D(const readable_matrix& m, + const readable_vector& v, col_basis) -> temporary_of_t { return m * v; } /** Matrix-vector post-multiplication. */ -template inline auto -transform_vector_4D( - const readable_matrix& m, const readable_vector& v, row_basis - ) -> temporary_of_t +template +inline auto +transform_vector_4D(const readable_matrix& m, + const readable_vector& v, row_basis) -> temporary_of_t { return v * m; } -} // namespace detail - +} // namespace detail /* 2D transformations: */ -template inline auto -transform_vector_2D( - const readable_matrix& m, const readable_vector& v - ) -> temporary_of_t +template +inline auto +transform_vector_2D(const readable_matrix& m, + const readable_vector& v) -> temporary_of_t { - typedef temporary_of_t result_type; - typedef value_type_trait_of_t value_type; + using result_type = temporary_of_t; + using value_type = value_type_trait_of_t; cml::check_minimum_size(m, int_c<2>(), int_c<2>()); cml::check_size(v, int_c<2>()); return result_type( - value_type(m.basis_element(0,0)*v[0] + m.basis_element(1,0)*v[1]), - value_type(m.basis_element(0,1)*v[0] + m.basis_element(1,1)*v[1]) - ); + value_type(m.basis_element(0, 0) * v[0] + m.basis_element(1, 0) * v[1]), + value_type(m.basis_element(0, 1) * v[0] + m.basis_element(1, 1) * v[1])); } -template inline auto -transform_point_2D( - const readable_matrix& m, const readable_vector& v - ) -> temporary_of_t +template +inline auto +transform_point_2D(const readable_matrix& m, + const readable_vector& v) -> temporary_of_t { - typedef temporary_of_t result_type; - typedef value_type_trait_of_t value_type; + using result_type = temporary_of_t; + using value_type = value_type_trait_of_t; cml::check_affine_2D(m); cml::check_size(v, int_c<2>()); return result_type( - value_type( - m.basis_element(0,0)*v[0] + - m.basis_element(1,0)*v[1] + - m.basis_element(2,0)), - - value_type( - m.basis_element(0,1)*v[0] + - m.basis_element(1,1)*v[1] + - m.basis_element(2,1)) - ); -} + value_type(m.basis_element(0, 0) * v[0] + m.basis_element(1, 0) * v[1] + + m.basis_element(2, 0)), + value_type(m.basis_element(0, 1) * v[0] + m.basis_element(1, 1) * v[1] + + m.basis_element(2, 1))); +} /* 3D transformations: */ -template inline auto -transform_vector( - const readable_matrix& m, const readable_vector& v - ) -> temporary_of_t +template +inline auto +transform_vector(const readable_matrix& m, const readable_vector& v) + -> temporary_of_t { - typedef temporary_of_t result_type; - typedef value_type_trait_of_t value_type; + using result_type = temporary_of_t; + using value_type = value_type_trait_of_t; cml::check_minimum_size(m, int_c<3>(), int_c<3>()); cml::check_size(v, int_c<3>()); return result_type( - value_type( - m.basis_element(0,0)*v[0] + - m.basis_element(1,0)*v[1] + - m.basis_element(2,0)*v[2]), - - value_type( - m.basis_element(0,1)*v[0] + - m.basis_element(1,1)*v[1] + - m.basis_element(2,1)*v[2]), - - value_type( - m.basis_element(0,2)*v[0] + - m.basis_element(1,2)*v[1] + - m.basis_element(2,2)*v[2]) - ); + value_type(m.basis_element(0, 0) * v[0] + m.basis_element(1, 0) * v[1] + + m.basis_element(2, 0) * v[2]), + + value_type(m.basis_element(0, 1) * v[0] + m.basis_element(1, 1) * v[1] + + m.basis_element(2, 1) * v[2]), + + value_type(m.basis_element(0, 2) * v[0] + m.basis_element(1, 2) * v[1] + + m.basis_element(2, 2) * v[2])); } -template inline auto -transform_point( - const readable_matrix& m, const readable_vector& v - ) -> temporary_of_t +template +inline auto +transform_point(const readable_matrix& m, const readable_vector& v) + -> temporary_of_t { - typedef temporary_of_t result_type; - typedef value_type_trait_of_t value_type; + using result_type = temporary_of_t; + using value_type = value_type_trait_of_t; cml::check_affine_3D(m); cml::check_size(v, int_c<3>()); return result_type( - value_type( - m.basis_element(0,0)*v[0] + - m.basis_element(1,0)*v[1] + - m.basis_element(2,0)*v[2] + - m.basis_element(3,0)), - - value_type( - m.basis_element(0,1)*v[0] + - m.basis_element(1,1)*v[1] + - m.basis_element(2,1)*v[2] + - m.basis_element(3,1)), - - value_type( - m.basis_element(0,2)*v[0] + - m.basis_element(1,2)*v[1] + - m.basis_element(2,2)*v[2] + - m.basis_element(3,2)) - ); + value_type(m.basis_element(0, 0) * v[0] + m.basis_element(1, 0) * v[1] + + m.basis_element(2, 0) * v[2] + m.basis_element(3, 0)), + + value_type(m.basis_element(0, 1) * v[0] + m.basis_element(1, 1) * v[1] + + m.basis_element(2, 1) * v[2] + m.basis_element(3, 1)), + + value_type(m.basis_element(0, 2) * v[0] + m.basis_element(1, 2) * v[1] + + m.basis_element(2, 2) * v[2] + m.basis_element(3, 2))); } -template inline auto -transform_vector_4D( - const readable_matrix& m, const readable_vector& v - ) -> temporary_of_t +template +inline auto +transform_vector_4D(const readable_matrix& m, + const readable_vector& v) -> temporary_of_t { - typedef basis_tag_of_t tag; + using tag = basis_tag_of_t; static_assert(tag::value != any_basis_c, "invalid matrix basis orientation"); cml::check_size(m, int_c<4>(), int_c<4>()); cml::check_size(v, int_c<4>()); return detail::transform_vector_4D(m, v, tag()); } -template inline auto -transform_point_4D( - const readable_matrix& m, const readable_vector& v - ) -> temporary_of_t +template +inline auto +transform_point_4D(const readable_matrix& m, + const readable_vector& v) -> temporary_of_t { - typedef temporary_of_t result_type; - typedef value_type_trait_of_t value_type; + using result_type = temporary_of_t; + using value_type = value_type_trait_of_t; cml::check_size(m, int_c<4>(), int_c<4>()); cml::check_size(v, int_c<3>()); /* 4D vector temporary: */ vector> h( - value_type( - m.basis_element(0,0)*v[0] + - m.basis_element(1,0)*v[1] + - m.basis_element(2,0)*v[2] + - m.basis_element(3,0)), - - value_type( - m.basis_element(0,1)*v[0] + - m.basis_element(1,1)*v[1] + - m.basis_element(2,1)*v[2] + - m.basis_element(3,1)), - - value_type( - m.basis_element(0,2)*v[0] + - m.basis_element(1,2)*v[1] + - m.basis_element(2,2)*v[2] + - m.basis_element(3,2)), - - value_type( - m.basis_element(0,3)*v[0] + - m.basis_element(1,3)*v[1] + - m.basis_element(2,3)*v[2] + - m.basis_element(3,3)) - ); + value_type(m.basis_element(0, 0) * v[0] + m.basis_element(1, 0) * v[1] + + m.basis_element(2, 0) * v[2] + m.basis_element(3, 0)), + + value_type(m.basis_element(0, 1) * v[0] + m.basis_element(1, 1) * v[1] + + m.basis_element(2, 1) * v[2] + m.basis_element(3, 1)), + + value_type(m.basis_element(0, 2) * v[0] + m.basis_element(1, 2) * v[1] + + m.basis_element(2, 2) * v[2] + m.basis_element(3, 2)), + + value_type(m.basis_element(0, 3) * v[0] + m.basis_element(1, 3) * v[1] + + m.basis_element(2, 3) * v[2] + m.basis_element(3, 3))); /* Return projection: */ return result_type(h[0] / h[3], h[1] / h[3], h[2] / h[3]); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix.h b/cml/matrix.h index b9b0df2..e2a5832 100644 --- a/cml/matrix.h +++ b/cml/matrix.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_h -#define cml_matrix_h - #include #include #include @@ -20,8 +15,3 @@ #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/array_size_of.h b/cml/matrix/array_size_of.h index 5b76683..989cdac 100644 --- a/cml/matrix/array_size_of.h +++ b/cml/matrix/array_size_of.h @@ -1,34 +1,24 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_array_size_of_h -#define cml_matrix_array_size_of_h - #include #include namespace cml { /** Specialize array_rows_of_c for vectors to return 1. */ -template -struct array_rows_of_c> { +template struct array_rows_of_c> +{ static const int value = 1; }; /** Specialize array_cols_of_c for vectors to return 1. */ -template -struct array_cols_of_c> { +template struct array_cols_of_c> +{ static const int value = 1; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/basis.h b/cml/matrix/basis.h index 7333c73..6ccc473 100644 --- a/cml/matrix/basis.h +++ b/cml/matrix/basis.h @@ -1,18 +1,8 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_basis_h -#define cml_matrix_basis_h - #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/basis_node.h b/cml/matrix/basis_node.h index 6b47c28..4962736 100644 --- a/cml/matrix/basis_node.h +++ b/cml/matrix/basis_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_basis_node_h -#define cml_matrix_basis_node_h - #include #include #include @@ -18,129 +13,115 @@ namespace cml { template class matrix_basis_node; /** matrix_basis_node<> traits. */ -template -struct vector_traits< matrix_basis_node > +template struct vector_traits> { - typedef matrix_basis_node vector_type; - typedef Sub sub_arg_type; - typedef cml::unqualified_type_t sub_type; - typedef matrix_traits sub_traits; - typedef typename sub_traits::element_traits element_traits; - typedef typename sub_traits::value_type value_type; - typedef typename sub_traits::immutable_value immutable_value; + using vector_type = matrix_basis_node; + using sub_arg_type = Sub; + using sub_type = cml::unqualified_type_t; + using sub_traits = matrix_traits; + using element_traits = typename sub_traits::element_traits; + using value_type = typename sub_traits::value_type; + using immutable_value = typename sub_traits::immutable_value; /* Propagate the column count from the subexpression: */ static const int array_size = sub_traits::array_cols; /* Deduce the vector storage type: */ - typedef typename sub_traits::storage_type sub_storage_type; - typedef typename sub_storage_type::unbound_type sub_unbound_type; - typedef resize_storage_t< - sub_unbound_type, array_size> resized_type; - typedef rebind_vector_storage_t storage_type; + using sub_storage_type = typename sub_traits::storage_type; + using sub_unbound_type = typename sub_storage_type::unbound_type; + using resized_type = resize_storage_t; + using storage_type = rebind_vector_storage_t; /* Take the size type from the storage type: */ - typedef typename storage_type::size_tag size_tag; + using size_tag = typename storage_type::size_tag; }; /** Represents a read-only matrix basis vector, specified at run-time by * its index, as a node in an expression tree. */ template -class matrix_basis_node -: public readable_vector< matrix_basis_node > +class matrix_basis_node +: public readable_vector> { public: - - typedef matrix_basis_node node_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::sub_arg_type sub_arg_type; - typedef typename traits_type::sub_type sub_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using node_type = matrix_basis_node; + using readable_type = readable_vector; + using traits_type = vector_traits; + using sub_arg_type = typename traits_type::sub_arg_type; + using sub_type = typename traits_type::sub_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** Constant containing the number of elements. */ - static const int array_size = traits_type::array_size; + /** Constant containing the number of elements. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped sub-expression and the basis index. @c + /** Construct from the wrapped sub-expression and the basis index. @c * sub must be an lvalue reference or rvalue reference type. * * @throws std::invalid_argument if @c i < 0. */ - explicit matrix_basis_node(Sub sub, int i); + explicit matrix_basis_node(Sub sub, int i); - /** Move constructor. */ - matrix_basis_node(node_type&& other); + /** Move constructor. */ + matrix_basis_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - matrix_basis_node(const node_type& other); + /** Copy constructor. */ + matrix_basis_node(const node_type& other); #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the size of the vector expression. */ - int i_size() const; + /** Return the size of the vector expression. */ + int i_size() const; - /** Return element @c (,j) of the matrix. */ - immutable_value i_get(int j) const; + /** Return element @c (,j) of the matrix. */ + immutable_value i_get(int j) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the subexpression. The expression is stored + /** The type used to store the subexpression. The expression is stored * as a copy if Sub is an rvalue reference (temporary), or by const * reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const sub_type&, sub_type> sub_wrap_type; + using sub_wrap_type = cml::if_t::value, const sub_type&, + sub_type>; protected: + /** The wrapped subexpression. */ + sub_wrap_type m_sub; - /** The wrapped subexpression. */ - sub_wrap_type m_sub; - - /** The basis index. */ - int m_i; + /** The basis index. */ + int m_i; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_basis_node(const node_type&); + // Not copy constructible. + matrix_basis_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_BASIS_NODE_TPP #include #undef __CML_MATRIX_BASIS_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/basis_node.tpp b/cml/matrix/basis_node.tpp index 0c7373e..8c392b6 100644 --- a/cml/matrix/basis_node.tpp +++ b/cml/matrix/basis_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_BASIS_NODE_TPP -#error "matrix/basis_node.tpp not included correctly" +# error "matrix/basis_node.tpp not included correctly" #endif namespace cml { @@ -13,45 +11,44 @@ namespace cml { /* matrix_basis_node 'structors: */ template -matrix_basis_node::matrix_basis_node(Sub sub, int i) -: m_sub(std::move(sub)), m_i(i) +matrix_basis_node::matrix_basis_node(Sub sub, int i) +: m_sub(std::move(sub)) +, m_i(i) { - cml_require(i >= 0, std::invalid_argument, "i < 0"); + cml_require(i >= 0, std::invalid_argument, "i < 0"); } template -matrix_basis_node::matrix_basis_node(node_type&& other) -: m_sub(std::move(other.m_sub)), m_i(other.m_i) -{ -} +matrix_basis_node::matrix_basis_node(node_type&& other) +: m_sub(std::move(other.m_sub)) +, m_i(other.m_i) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -matrix_basis_node::matrix_basis_node(const node_type& other) -: m_sub(other.m_sub), m_i(other.m_i) -{ -} +matrix_basis_node::matrix_basis_node(const node_type& other) +: m_sub(other.m_sub) +, m_i(other.m_i) +{} #endif - /* Internal methods: */ /* readable_vector interface: */ -template int -matrix_basis_node::i_size() const +template +int +matrix_basis_node::i_size() const { return this->m_sub.basis_size(); } -template auto -matrix_basis_node::i_get(int j) const -> immutable_value +template +auto +matrix_basis_node::i_get(int j) const -> immutable_value { - return this->m_sub.basis_element(this->m_i,j); + return this->m_sub.basis_element(this->m_i, j); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/basis_ops.h b/cml/matrix/basis_ops.h index 1862898..506be69 100644 --- a/cml/matrix/basis_ops.h +++ b/cml/matrix/basis_ops.h @@ -1,35 +1,26 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_basis_ops_h -#define cml_matrix_basis_ops_h - #include #include namespace cml { template* = nullptr> -inline auto basis(Sub&& sub, int i) --> matrix_basis_node, -1> +inline auto +basis(Sub&& sub, int i) + -> matrix_basis_node, -1> { - static_assert(std::is_same< - decltype(sub), decltype(std::forward(sub))>::value, + static_assert( + std::is_same(sub))>::value, "internal error: unexpected expression type"); /* Deduce the operand type of the subexpression (&, const&, &&): */ - typedef actual_operand_type_of_t sub_type; + using sub_type = actual_operand_type_of_t; return matrix_basis_node((sub_type) sub, i); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/binary_node.h b/cml/matrix/binary_node.h index 154649c..4fd7d1d 100644 --- a/cml/matrix/binary_node.h +++ b/cml/matrix/binary_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_binary_node_h -#define cml_matrix_binary_node_h - #include #include @@ -18,28 +13,27 @@ template class matrix_binary_node; /** matrix_binary_node<> traits. */ template -struct matrix_traits< matrix_binary_node > +struct matrix_traits> { - typedef matrix_binary_node matrix_type; - typedef Sub1 left_arg_type; - typedef Sub2 right_arg_type; - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef matrix_traits left_traits; - typedef matrix_traits right_traits; - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; + using matrix_type = matrix_binary_node; + using left_arg_type = Sub1; + using right_arg_type = Sub2; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = matrix_traits; + using right_traits = matrix_traits; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; /* Determine the common storage type for the node, based on the storage * types of its subexpressions: */ - typedef matrix_binary_storage_promote_t< - storage_type_of_t, - storage_type_of_t> storage_type; + using storage_type = matrix_binary_storage_promote_t, + storage_type_of_t>; /* Traits and types for the storage: */ - typedef typename storage_type::size_tag size_tag; + using size_tag = typename storage_type::size_tag; /* Array rows: */ static const int array_rows = storage_type::array_rows; @@ -48,14 +42,12 @@ struct matrix_traits< matrix_binary_node > static const int array_cols = storage_type::array_cols; /* Determine the common basis type: */ - typedef basis_tag_promote_t< - basis_tag_of_t, - basis_tag_of_t> basis_tag; + using basis_tag = basis_tag_promote_t, + basis_tag_of_t>; /* Determine the common layout type: */ - typedef layout_tag_promote_t< - layout_tag_of_t, - layout_tag_of_t> layout_tag; + using layout_tag = layout_tag_promote_t, + layout_tag_of_t>; /** Constant containing the matrix basis enumeration value. */ static const basis_kind matrix_basis = basis_tag::value; @@ -67,44 +59,41 @@ struct matrix_traits< matrix_binary_node > /** Represents a binary matrix operation in an expression tree. */ template class matrix_binary_node -: public readable_matrix< matrix_binary_node > +: public readable_matrix> { public: - - typedef matrix_binary_node node_type; - typedef readable_matrix readable_type; - typedef matrix_traits traits_type; - typedef typename traits_type::left_arg_type left_arg_type; - typedef typename traits_type::right_arg_type right_arg_type; - typedef typename traits_type::left_type left_type; - typedef typename traits_type::right_type right_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using node_type = matrix_binary_node; + using readable_type = readable_matrix; + using traits_type = matrix_traits; + using left_arg_type = typename traits_type::left_arg_type; + using right_arg_type = typename traits_type::right_arg_type; + using left_type = typename traits_type::left_type; + using right_type = typename traits_type::right_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; public: + /** Constant containing the number of rows. */ + static const int array_rows = traits_type::array_rows; - /** Constant containing the number of rows. */ - static const int array_rows = traits_type::array_rows; + /** Constant containing the number of columns. */ + static const int array_cols = traits_type::array_cols; - /** Constant containing the number of columns. */ - static const int array_cols = traits_type::array_cols; - - /** Constant containing the array layout enumeration value. */ - static const layout_kind array_layout = traits_type::array_layout; + /** Constant containing the array layout enumeration value. */ + static const layout_kind array_layout = traits_type::array_layout; - /** Constant containing the matrix basis enumeration value. */ - static const basis_kind matrix_basis = traits_type::matrix_basis; + /** Constant containing the matrix basis enumeration value. */ + static const basis_kind matrix_basis = traits_type::matrix_basis; public: - - /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be + /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be * lvalue reference or rvalue reference types. * * @throws incompatible_matrix_sizes at run-time if either Sub1 or Sub2 @@ -112,82 +101,73 @@ class matrix_binary_node * both Sub1 and Sub2 are fixed-size expressions, then the sizes are * checked at compile time. */ - matrix_binary_node(Sub1 left, Sub2 right); + matrix_binary_node(Sub1 left, Sub2 right); - /** Move constructor. */ - matrix_binary_node(node_type&& other); + /** Move constructor. */ + matrix_binary_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - matrix_binary_node(const node_type& other); + /** Copy constructor. */ + matrix_binary_node(const node_type& other); #endif protected: + /** @name readable_matrix Interface */ + /*@{*/ - /** @name readable_matrix Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the row size of the matrix expression. */ - int i_rows() const; + /** Return the row size of the matrix expression. */ + int i_rows() const; - /** Return the column size of the matrix expression. */ - int i_cols() const; + /** Return the column size of the matrix expression. */ + int i_cols() const; - /** Apply the operator to element @c (i,j) of the subexpressions and + /** Apply the operator to element @c (i,j) of the subexpressions and * return the result. */ - immutable_value i_get(int i, int j) const; + immutable_value i_get(int i, int j) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the left subexpression. The expression is + /** The type used to store the left subexpression. The expression is * stored as a copy if Sub1 is an rvalue reference (temporary), or by * const reference if Sub1 is an lvalue reference. */ - typedef cml::if_t::value, - const left_type&, left_type> left_wrap_type; + using left_wrap_type = cml::if_t::value, const left_type&, + left_type>; - /** The type used to store the right subexpression. The expression is + /** The type used to store the right subexpression. The expression is * stored as a copy if Sub2 is an rvalue reference (temporary), or by * const reference if Sub2 is an lvalue reference. */ - typedef cml::if_t::value, - const right_type&, right_type> right_wrap_type; + using right_wrap_type = cml::if_t::value, const right_type&, + right_type>; protected: + /** The wrapped left subexpression. */ + left_wrap_type m_left; - /** The wrapped left subexpression. */ - left_wrap_type m_left; - - /** The wrapped right subexpression. */ - right_wrap_type m_right; + /** The wrapped right subexpression. */ + right_wrap_type m_right; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_binary_node(const node_type&); + // Not copy constructible. + matrix_binary_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_BINARY_NODE_TPP #include #undef __CML_MATRIX_BINARY_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/binary_node.tpp b/cml/matrix/binary_node.tpp index 63651fb..bdb24ed 100644 --- a/cml/matrix/binary_node.tpp +++ b/cml/matrix/binary_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_BINARY_NODE_TPP -#error "matrix/binary_node.tpp not included correctly" +# error "matrix/binary_node.tpp not included correctly" #endif #include @@ -15,8 +13,9 @@ namespace cml { /* matrix_binary_node 'structors: */ template -matrix_binary_node::matrix_binary_node(Sub1 left, Sub2 right) -: m_left(std::move(left)), m_right(std::move(right)) +matrix_binary_node::matrix_binary_node(Sub1 left, Sub2 right) +: m_left(std::move(left)) +, m_right(std::move(right)) { cml::check_same_size(this->m_left, this->m_right); /* Note: this seems to be exception-safe since temporaries are stored by @@ -25,44 +24,43 @@ matrix_binary_node::matrix_binary_node(Sub1 left, Sub2 right) } template -matrix_binary_node::matrix_binary_node(node_type&& other) -: m_left(std::move(other.m_left)), m_right(std::move(other.m_right)) -{ -} +matrix_binary_node::matrix_binary_node(node_type&& other) +: m_left(std::move(other.m_left)) +, m_right(std::move(other.m_right)) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -matrix_binary_node::matrix_binary_node(const node_type& other) -: m_left(other.m_left), m_right(other.m_right) -{ -} +matrix_binary_node::matrix_binary_node(const node_type& other) +: m_left(other.m_left) +, m_right(other.m_right) +{} #endif - /* Internal methods: */ /* readable_matrix interface: */ -template int -matrix_binary_node::i_rows() const +template +int +matrix_binary_node::i_rows() const { return this->m_left.rows(); } -template int -matrix_binary_node::i_cols() const +template +int +matrix_binary_node::i_cols() const { return this->m_left.cols(); } -template auto -matrix_binary_node::i_get(int i, int j) const -> immutable_value +template +auto +matrix_binary_node::i_get(int i, int j) const -> immutable_value { - return Op().apply(this->m_left.get(i,j), this->m_right.get(i,j)); + return Op().apply(this->m_left.get(i, j), this->m_right.get(i, j)); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/binary_ops.h b/cml/matrix/binary_ops.h index 629d247..5b62e66 100644 --- a/cml/matrix/binary_ops.h +++ b/cml/matrix/binary_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_binary_ops_h -#define cml_matrix_binary_ops_h - #include #include @@ -17,53 +12,47 @@ namespace cml { /** Helper function to generate a matrix_binary_node from two matrix types * (i.e. derived from readable_matrix<>). */ -template* = nullptr, enable_if_matrix_t* = nullptr> +template* = nullptr, + enable_if_matrix_t* = nullptr> inline auto -make_matrix_binary_node(Sub1&& sub1, Sub2&& sub2) --> matrix_binary_node< -actual_operand_type_of_t, -actual_operand_type_of_t, -Op -> +make_matrix_binary_node(Sub1&& sub1, + Sub2&& sub2) -> matrix_binary_node, + actual_operand_type_of_t, Op> { - static_assert(std::is_same< - decltype(sub1), decltype(std::forward(sub1))>::value, + static_assert( + std::is_same(sub1))>::value, "internal error: unexpected expression type (sub1)"); - static_assert(std::is_same< - decltype(sub2), decltype(std::forward(sub2))>::value, + static_assert( + std::is_same(sub2))>::value, "internal error: unexpected expression type (sub2)"); /* Deduce the operand types of the subexpressions (&, const&, &&): */ - typedef actual_operand_type_of_t sub1_type; - typedef actual_operand_type_of_t sub2_type; - return matrix_binary_node< - sub1_type, sub2_type, Op>((sub1_type) sub1, (sub2_type) sub2); + using sub1_type = actual_operand_type_of_t; + using sub2_type = actual_operand_type_of_t; + return matrix_binary_node((sub1_type) sub1, + (sub2_type) sub2); } -template* = nullptr, enable_if_matrix_t* = nullptr> -inline auto operator-(Sub1&& sub1, Sub2&& sub2) --> decltype(make_matrix_binary_node>( +template* = nullptr, + enable_if_matrix_t* = nullptr> +inline auto +operator-(Sub1&& sub1, Sub2&& sub2) + -> decltype(make_matrix_binary_node>( std::forward(sub1), std::forward(sub2))) { - return make_matrix_binary_node> - (std::forward(sub1), std::forward(sub2)); + return make_matrix_binary_node>( + std::forward(sub1), std::forward(sub2)); } -template* = nullptr, enable_if_matrix_t* = nullptr> -inline auto operator+(Sub1&& sub1, Sub2&& sub2) --> decltype(make_matrix_binary_node>( +template* = nullptr, + enable_if_matrix_t* = nullptr> +inline auto +operator+(Sub1&& sub1, Sub2&& sub2) + -> decltype(make_matrix_binary_node>( std::forward(sub1), std::forward(sub2))) { - return make_matrix_binary_node> - (std::forward(sub1), std::forward(sub2)); + return make_matrix_binary_node>( + std::forward(sub1), std::forward(sub2)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/col_node.h b/cml/matrix/col_node.h index bbde7f4..5de21f2 100644 --- a/cml/matrix/col_node.h +++ b/cml/matrix/col_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_col_node_h -#define cml_matrix_col_node_h - #include #include #include @@ -18,129 +13,115 @@ namespace cml { template class matrix_col_node; /** matrix_col_node<> traits. */ -template -struct vector_traits< matrix_col_node > +template struct vector_traits> { - typedef matrix_col_node vector_type; - typedef Sub sub_arg_type; - typedef cml::unqualified_type_t sub_type; - typedef matrix_traits sub_traits; - typedef typename sub_traits::element_traits element_traits; - typedef typename sub_traits::value_type value_type; - typedef typename sub_traits::immutable_value immutable_value; + using vector_type = matrix_col_node; + using sub_arg_type = Sub; + using sub_type = cml::unqualified_type_t; + using sub_traits = matrix_traits; + using element_traits = typename sub_traits::element_traits; + using value_type = typename sub_traits::value_type; + using immutable_value = typename sub_traits::immutable_value; /* Propagate the column count from the subexpression: */ static const int array_size = sub_traits::array_rows; /* Deduce the vector storage type: */ - typedef typename sub_traits::storage_type sub_storage_type; - typedef typename sub_storage_type::unbound_type sub_unbound_type; - typedef resize_storage_t< - sub_unbound_type, array_size> resized_type; - typedef rebind_vector_storage_t storage_type; + using sub_storage_type = typename sub_traits::storage_type; + using sub_unbound_type = typename sub_storage_type::unbound_type; + using resized_type = resize_storage_t; + using storage_type = rebind_vector_storage_t; /* Take the size type from the storage type: */ - typedef typename storage_type::size_tag size_tag; + using size_tag = typename storage_type::size_tag; }; /** Represents a read-only matrix column, specified at run-time by its * index, as a node in an expression tree. */ template -class matrix_col_node -: public readable_vector< matrix_col_node > +class matrix_col_node +: public readable_vector> { public: - - typedef matrix_col_node node_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::sub_arg_type sub_arg_type; - typedef typename traits_type::sub_type sub_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using node_type = matrix_col_node; + using readable_type = readable_vector; + using traits_type = vector_traits; + using sub_arg_type = typename traits_type::sub_arg_type; + using sub_type = typename traits_type::sub_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** Constant containing the number of elements. */ - static const int array_size = traits_type::array_size; + /** Constant containing the number of elements. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped sub-expression and the column index. @c + /** Construct from the wrapped sub-expression and the column index. @c * sub must be an lvalue reference or rvalue reference type. * * @throws std::invalid_argument if @c col < 0. */ - explicit matrix_col_node(Sub sub, int col); + explicit matrix_col_node(Sub sub, int col); - /** Move constructor. */ - matrix_col_node(node_type&& other); + /** Move constructor. */ + matrix_col_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - matrix_col_node(const node_type& other); + /** Copy constructor. */ + matrix_col_node(const node_type& other); #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the size of the vector expression. */ - int i_size() const; + /** Return the size of the vector expression. */ + int i_size() const; - /** Return element @c (i,col) of the matrix. */ - immutable_value i_get(int i) const; + /** Return element @c (i,col) of the matrix. */ + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the subexpression. The expression is stored + /** The type used to store the subexpression. The expression is stored * as a copy if Sub is an rvalue reference (temporary), or by const * reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const sub_type&, sub_type> sub_wrap_type; + using sub_wrap_type = cml::if_t::value, const sub_type&, + sub_type>; protected: + /** The wrapped subexpression. */ + sub_wrap_type m_sub; - /** The wrapped subexpression. */ - sub_wrap_type m_sub; - - /** The column index. */ - int m_col; + /** The column index. */ + int m_col; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_col_node(const node_type&); + // Not copy constructible. + matrix_col_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_COL_NODE_TPP #include #undef __CML_MATRIX_COL_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/col_node.tpp b/cml/matrix/col_node.tpp index 3dcfda2..7feff5d 100644 --- a/cml/matrix/col_node.tpp +++ b/cml/matrix/col_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_COL_NODE_TPP -#error "matrix/col_node.tpp not included correctly" +# error "matrix/col_node.tpp not included correctly" #endif namespace cml { @@ -13,45 +11,44 @@ namespace cml { /* matrix_col_node 'structors: */ template -matrix_col_node::matrix_col_node(Sub sub, int col) -: m_sub(std::move(sub)), m_col(col) +matrix_col_node::matrix_col_node(Sub sub, int col) +: m_sub(std::move(sub)) +, m_col(col) { - cml_require(col >= 0, std::invalid_argument, "col < 0"); + cml_require(col >= 0, std::invalid_argument, "col < 0"); } template -matrix_col_node::matrix_col_node(node_type&& other) -: m_sub(std::move(other.m_sub)), m_col(other.m_col) -{ -} +matrix_col_node::matrix_col_node(node_type&& other) +: m_sub(std::move(other.m_sub)) +, m_col(other.m_col) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -matrix_col_node::matrix_col_node(const node_type& other) -: m_sub(other.m_sub), m_col(other.m_col) -{ -} +matrix_col_node::matrix_col_node(const node_type& other) +: m_sub(other.m_sub) +, m_col(other.m_col) +{} #endif - /* Internal methods: */ /* readable_vector interface: */ -template int -matrix_col_node::i_size() const +template +int +matrix_col_node::i_size() const { return this->m_sub.rows(); } -template auto -matrix_col_node::i_get(int i) const -> immutable_value +template +auto +matrix_col_node::i_get(int i) const -> immutable_value { - return this->m_sub.get(i,this->m_col); + return this->m_sub.get(i, this->m_col); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/col_ops.h b/cml/matrix/col_ops.h index 9994782..b960da6 100644 --- a/cml/matrix/col_ops.h +++ b/cml/matrix/col_ops.h @@ -1,35 +1,26 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_col_ops_h -#define cml_matrix_col_ops_h - #include #include namespace cml { template* = nullptr> -inline auto col(Sub&& sub, int row) --> matrix_col_node, -1> +inline auto +col(Sub&& sub, int row) + -> matrix_col_node, -1> { - static_assert(std::is_same< - decltype(sub), decltype(std::forward(sub))>::value, + static_assert( + std::is_same(sub))>::value, "internal error: unexpected expression type"); /* Deduce the operand type of the subexpression (&, const&, &&): */ - typedef actual_operand_type_of_t sub_type; + using sub_type = actual_operand_type_of_t; return matrix_col_node((sub_type) sub, row); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/comparison.h b/cml/matrix/comparison.h index a35210e..0762224 100644 --- a/cml/matrix/comparison.h +++ b/cml/matrix/comparison.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_comparison_h -#define cml_matrix_comparison_h - #include namespace cml { @@ -16,22 +11,19 @@ namespace cml { /** Returns true if the elements of @c left are all equal to the elements * of @c right. */ -template bool operator==( - const readable_matrix& left, const readable_matrix& right); +template +bool operator==(const readable_matrix& left, + const readable_matrix& right); /** Returns true if some element of @c left is not equal to the same element * of @c right. */ -template bool operator!=( - const readable_matrix& left, const readable_matrix& right); +template +bool operator!=(const readable_matrix& left, + const readable_matrix& right); -} // namespace cml +} // namespace cml #define __CML_MATRIX_COMPARISON_TPP #include #undef __CML_MATRIX_COMPARISON_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/comparison.tpp b/cml/matrix/comparison.tpp index fa1e549..97c4f7c 100644 --- a/cml/matrix/comparison.tpp +++ b/cml/matrix/comparison.tpp @@ -1,41 +1,39 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_COMPARISON_TPP -#error "matrix/comparison.tpp not included correctly" +# error "matrix/comparison.tpp not included correctly" #endif #include namespace cml { -template inline bool operator==( - const readable_matrix& left, const readable_matrix& right - ) +template +inline bool +operator==(const readable_matrix& left, + const readable_matrix& right) { /* Possibly equal only if the same dimensions: */ if(left.size() != right.size()) return false; - for(int i = 0; i < left.rows(); i ++) { - for(int j = 0; j < left.cols(); j ++) { - /**/ if(left(i, j) < right(i, j)) return false; // Strictly less. - else if(right(i, j) < left(i, j)) return false; // Strictly greater. - else continue; // Possibly equal. + for(int i = 0; i < left.rows(); i++) { + for(int j = 0; j < left.cols(); j++) { + /**/ if(left(i, j) < right(i, j)) + return false; // Strictly less. + else if(right(i, j) < left(i, j)) return false; // Strictly greater. + else continue; // Possibly equal. } } return true; } -template inline bool operator!=( - const readable_matrix& left, const readable_matrix& right - ) +template +inline bool +operator!=(const readable_matrix& left, + const readable_matrix& right) { return !(left == right); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/detail/apply.h b/cml/matrix/detail/apply.h index bbd2eda..5160934 100644 --- a/cml/matrix/detail/apply.h +++ b/cml/matrix/detail/apply.h @@ -1,47 +1,35 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_detail_apply_h -#define cml_matrix_detail_apply_h - #include -namespace cml { -namespace detail { +namespace cml::detail { /** Apply @c Op pairwise to @c left and @c right and assign the result to @c * left, where @c left is assumed to have a row-major layout. */ -template inline void apply( - writable_matrix& left, const Other& right, row_major - ) +template +inline void +apply(writable_matrix& left, const Other& right, row_major) { - for(int i = 0; i < left.rows(); ++ i) - for(int j = 0; j < left.cols(); ++ j) - left.put(i,j, Op().apply(left.get(i,j), get(right, i,j))); + for(int i = 0; i < left.rows(); ++i) + for(int j = 0; j < left.cols(); ++j) + left.put(i, j, Op().apply(left.get(i, j), get(right, i, j))); } /** Apply @c Op pairwise to @c left and @c right and assign the result to * @c left, where @c left is assumed to have a column-major layout. */ -template inline void apply( - writable_matrix& left, const Other& right, col_major - ) +template +inline void +apply(writable_matrix& left, const Other& right, col_major) { - for(int j = 0; j < left.cols(); ++ j) - for(int i = 0; i < left.rows(); ++ i) - left.put(i,j, Op().apply(left.get(i,j), get(right, i,j))); + for(int j = 0; j < left.cols(); ++j) + for(int i = 0; i < left.rows(); ++i) + left.put(i, j, Op().apply(left.get(i, j), get(right, i, j))); } -} // namespace detail -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/matrix/detail/check_or_resize.h b/cml/matrix/detail/check_or_resize.h index 34f636b..fabb7a0 100644 --- a/cml/matrix/detail/check_or_resize.h +++ b/cml/matrix/detail/check_or_resize.h @@ -1,52 +1,45 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_detail_check_or_resize_h -#define cml_matrix_detail_check_or_resize_h - #include #include -namespace cml { -namespace detail { +namespace cml::detail { /** Ensure non-resizable matrix @c left is the same size as @c right. */ -template inline void +template +inline void check_or_resize(const readable_matrix& left, const Other& right) { cml::check_same_size(left, right); } /** Ensure resizable matrix @c left is the same size as @c right. */ -template inline auto -check_or_resize( - writable_matrix& left, const readable_matrix& right - ) --> decltype(left.actual().resize(0,0), void()) +template +inline auto +check_or_resize(writable_matrix& left, const readable_matrix& right) + -> decltype(left.actual().resize(0, 0), void()) { - left.actual().resize(right.rows(),right.cols()); + left.actual().resize(right.rows(), right.cols()); } /** Ensure resizable matrix @c left is the same size as array @c right. */ -template inline auto -check_or_resize( - writable_matrix& left, Other const (&)[Rows][Cols] - ) --> decltype(left.actual().resize(0,0), void()) +template +inline auto +check_or_resize(writable_matrix& left, Other const (&)[Rows][Cols]) + -> decltype(left.actual().resize(0, 0), void()) { left.actual().resize(Rows, Cols); } - /* check_or_resize for a read-only matrix left and constant size RxC that * just forwards to check_size. */ -template inline void +template +inline void check_or_resize(const readable_matrix& sub, int_c, int_c) { cml::check_size(sub, int_c(), int_c()); @@ -55,7 +48,8 @@ check_or_resize(const readable_matrix& sub, int_c, int_c) /* check_or_resize for a read-only matrix left and run-time size RxC that * just forwards to check_size. */ -template inline void +template +inline void check_or_resize(const readable_matrix& sub, int R, int C) { cml::check_size(sub, R, C); @@ -64,27 +58,23 @@ check_or_resize(const readable_matrix& sub, int R, int C) /* check_or_resize for a resizable matrix left and compile-time size that * resizes the matrix to RxC. */ -template inline auto +template +inline auto check_or_resize(writable_matrix& sub, int_c, int_c) --> decltype(sub.actual().resize(0,0), void()) + -> decltype(sub.actual().resize(0, 0), void()) { - sub.actual().resize(R,C); + sub.actual().resize(R, C); } /* check_or_resize for a resizable matrix left and run-time size that * resizes the matrix to RxC. */ -template inline auto +template +inline auto check_or_resize(writable_matrix& sub, int R, int C) --> decltype(sub.actual().resize(0,0), void()) + -> decltype(sub.actual().resize(0, 0), void()) { - sub.actual().resize(R,C); + sub.actual().resize(R, C); } -} // namespace detail -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/matrix/detail/copy.h b/cml/matrix/detail/copy.h index aa146cf..dcca3fb 100644 --- a/cml/matrix/detail/copy.h +++ b/cml/matrix/detail/copy.h @@ -1,47 +1,33 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_detail_copy_h -#define cml_matrix_detail_copy_h - #include -namespace cml { -namespace detail { +namespace cml::detail { /** Assign @c left from the elements of @c right, where @c left is assumed * to have a row-major layout. */ -template inline void copy( - writable_matrix& left, const Other& right, row_major - ) +template +inline void +copy(writable_matrix& left, const Other& right, row_major) { - for(int i = 0; i < left.rows(); ++ i) - for(int j = 0; j < left.cols(); ++ j) - left.put(i,j, get(right, i,j)); + for(int i = 0; i < left.rows(); ++i) + for(int j = 0; j < left.cols(); ++j) left.put(i, j, get(right, i, j)); } /** Assign @c left from the elements of @c right, where @c left is assumed * to have a column-major layout. */ -template inline void copy( - writable_matrix& left, const Other& right, col_major - ) +template +inline void +copy(writable_matrix& left, const Other& right, col_major) { - for(int j = 0; j < left.cols(); ++ j) - for(int i = 0; i < left.rows(); ++ i) - left.put(i,j, get(right, i,j)); + for(int j = 0; j < left.cols(); ++j) + for(int i = 0; i < left.rows(); ++i) left.put(i, j, get(right, i, j)); } -} // namespace detail -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/matrix/detail/determinant.h b/cml/matrix/detail/determinant.h index 9df5598..9105fd6 100644 --- a/cml/matrix/detail/determinant.h +++ b/cml/matrix/detail/determinant.h @@ -1,35 +1,29 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_detail_determinant_h -#define cml_matrix_detail_determinant_h - #include #include #include -namespace cml { -namespace detail { +namespace cml::detail { /** 2x2 determinant implementation. */ -template inline auto -determinant(const readable_matrix& M, int_c<2>) --> value_type_trait_of_t; +template +inline auto determinant(const readable_matrix& M, int_c<2>) + -> value_type_trait_of_t; /** 3x3 determinant implementation. */ -template inline auto -determinant(const readable_matrix& M, int_c<3>) --> value_type_trait_of_t; +template +inline auto determinant(const readable_matrix& M, int_c<3>) + -> value_type_trait_of_t; /** 4x4 determinant implementation. */ -template inline auto -determinant(const readable_matrix& M, int_c<4>) --> value_type_trait_of_t; +template +inline auto determinant(const readable_matrix& M, int_c<4>) + -> value_type_trait_of_t; /** Determinant implementation for statically-sized square matrices with * dimension greater than 4, using a pivoting algorithm to compute the @@ -37,9 +31,9 @@ determinant(const readable_matrix& M, int_c<4>) * * @note It is up to the caller to ensure @c M is a square matrix. */ -template inline auto -determinant(const readable_matrix& M, int_c) --> value_type_trait_of_t; +template +inline auto determinant(const readable_matrix& M, int_c) + -> value_type_trait_of_t; /** Determinant implementation for dynamically-sized matrices. This * dispatches to a small matrix implementation when the dimension of @c M @@ -48,18 +42,12 @@ determinant(const readable_matrix& M, int_c) * * @note It is up to the caller to ensure @c M is a square matrix. */ -template inline auto -determinant(const readable_matrix& M, int_c<-1>) --> value_type_trait_of_t; +template +inline auto determinant(const readable_matrix& M, int_c<-1>) + -> value_type_trait_of_t; -} // namespace detail -} // namespace cml +} #define __CML_MATRIX_DETAIL_DETERMINANT_TPP #include #undef __CML_MATRIX_DETAIL_DETERMINANT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/detail/determinant.tpp b/cml/matrix/detail/determinant.tpp index 914505b..51e6bcc 100644 --- a/cml/matrix/detail/determinant.tpp +++ b/cml/matrix/detail/determinant.tpp @@ -1,87 +1,78 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_DETAIL_DETERMINANT_TPP -#error "matrix/detail/determinant.tpp not included correctly" +# error "matrix/detail/determinant.tpp not included correctly" #endif #include #include #include -namespace cml { -namespace detail { +namespace cml::detail { namespace { -template inline auto +template +inline auto diagonal_product(const Matrix& A) -> value_type_of_t { - auto D = A(0,0); - for(int i = 1; i < A.rows(); ++ i) D *= A(i,i); - return D; + auto D = A(0, 0); + for(int i = 1; i < A.rows(); ++i) D *= A(i, i); + return D; } -} // namespace +} // namespace /** 2x2 determinant implementation. */ -template inline auto +template +inline auto determinant(const readable_matrix& M, int_c<2>) --> value_type_trait_of_t + -> value_type_trait_of_t { - return M(0,0)*M(1,1) - M(1,0)*M(0,1); + return M(0, 0) * M(1, 1) - M(1, 0) * M(0, 1); } /** 3x3 determinant implementation. */ -template inline auto +template +inline auto determinant(const readable_matrix& M, int_c<3>) --> value_type_trait_of_t + -> value_type_trait_of_t { - return - M(0,0) * (M(1,1)*M(2,2) - M(1,2)*M(2,1)) + - M(0,1) * (M(1,2)*M(2,0) - M(1,0)*M(2,2)) + - M(0,2) * (M(1,0)*M(2,1) - M(1,1)*M(2,0)) - ; + return M(0, 0) * (M(1, 1) * M(2, 2) - M(1, 2) * M(2, 1)) + + M(0, 1) * (M(1, 2) * M(2, 0) - M(1, 0) * M(2, 2)) + + M(0, 2) * (M(1, 0) * M(2, 1) - M(1, 1) * M(2, 0)); } /** 4x4 determinant implementation. */ -template inline auto +template +inline auto determinant(const readable_matrix& M, int_c<4>) --> value_type_trait_of_t + -> value_type_trait_of_t { /* Common cofactors: */ - auto m_22_33_23_32 = M(2,2)*M(3,3) - M(2,3)*M(3,2); - auto m_23_30_20_33 = M(2,3)*M(3,0) - M(2,0)*M(3,3); - auto m_20_31_21_30 = M(2,0)*M(3,1) - M(2,1)*M(3,0); - auto m_21_32_22_31 = M(2,1)*M(3,2) - M(2,2)*M(3,1); - auto m_23_31_21_33 = M(2,3)*M(3,1) - M(2,1)*M(3,3); - auto m_20_32_22_30 = M(2,0)*M(3,2) - M(2,2)*M(3,0); - - auto d00 = M(0,0) *( - M(1,1) * m_22_33_23_32 + - M(1,2) * m_23_31_21_33 + - M(1,3) * m_21_32_22_31 - ); - - auto d01 = M(0,1) *( - M(1,0) * m_22_33_23_32 + - M(1,2) * m_23_30_20_33 + - M(1,3) * m_20_32_22_30 - ); - - auto d02 = M(0,2) *( - M(1,0) * -m_23_31_21_33 + - M(1,1) * m_23_30_20_33 + - M(1,3) * m_20_31_21_30 - ); - - auto d03 = M(0,3)*( - M(1,0) * m_21_32_22_31 + - M(1,1) * - m_20_32_22_30 + - M(1,2) * m_20_31_21_30 - ); + auto m_22_33_23_32 = M(2, 2) * M(3, 3) - M(2, 3) * M(3, 2); + auto m_23_30_20_33 = M(2, 3) * M(3, 0) - M(2, 0) * M(3, 3); + auto m_20_31_21_30 = M(2, 0) * M(3, 1) - M(2, 1) * M(3, 0); + auto m_21_32_22_31 = M(2, 1) * M(3, 2) - M(2, 2) * M(3, 1); + auto m_23_31_21_33 = M(2, 3) * M(3, 1) - M(2, 1) * M(3, 3); + auto m_20_32_22_30 = M(2, 0) * M(3, 2) - M(2, 2) * M(3, 0); + + auto d00 = M(0, 0) + * (M(1, 1) * m_22_33_23_32 + M(1, 2) * m_23_31_21_33 + + M(1, 3) * m_21_32_22_31); + + auto d01 = M(0, 1) + * (M(1, 0) * m_22_33_23_32 + M(1, 2) * m_23_30_20_33 + + M(1, 3) * m_20_32_22_30); + + auto d02 = M(0, 2) + * (M(1, 0) * -m_23_31_21_33 + M(1, 1) * m_23_30_20_33 + + M(1, 3) * m_20_31_21_30); + + auto d03 = M(0, 3) + * (M(1, 0) * m_21_32_22_31 + M(1, 1) * -m_20_32_22_30 + + M(1, 2) * m_20_31_21_30); return d00 - d01 + d02 - d03; } @@ -92,12 +83,13 @@ determinant(const readable_matrix& M, int_c<4>) * * @note It is up to the caller to ensure @c M is a square matrix. */ -template inline auto +template +inline auto determinant(const readable_matrix& M, int_c) --> value_type_trait_of_t + -> value_type_trait_of_t { temporary_of_t A(M); - std::array order; + std::array order; int sign = lu_pivot_inplace(A, order); /* Compute the determinant from the diagonals: */ @@ -111,9 +103,10 @@ determinant(const readable_matrix& M, int_c) * * @note It is up to the caller to ensure @c M is a square matrix. */ -template inline auto +template +inline auto determinant(const readable_matrix& M, int_c<-1>) --> value_type_trait_of_t + -> value_type_trait_of_t { /* Size of matrix */ int N = M.rows(); @@ -133,9 +126,4 @@ determinant(const readable_matrix& M, int_c<-1>) return sign * diagonal_product(A); } -} // namespace detail -} // namespace cml - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/matrix/detail/generate.h b/cml/matrix/detail/generate.h index 723e07d..0ada0bd 100644 --- a/cml/matrix/detail/generate.h +++ b/cml/matrix/detail/generate.h @@ -1,47 +1,35 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_detail_generate_h -#define cml_matrix_detail_generate_h - #include -namespace cml { -namespace detail { +namespace cml::detail { /** Assign the value of @c f(i,j) to the element @c (i,j) of row-major * matrix @c left. */ -template inline void generate( - writable_matrix& left, F&& f, row_major - ) +template +inline void +generate(writable_matrix& left, F&& f, row_major) { - for(int i = 0; i < left.rows(); ++ i) - for(int j = 0; j < left.cols(); ++ j) - left.put(i,j, (std::forward(f))(i,j)); + for(int i = 0; i < left.rows(); ++i) + for(int j = 0; j < left.cols(); ++j) + left.put(i, j, (std::forward(f))(i, j)); } /** Assign the value of @c f(i,j) to the element @c (i,j) of column-major * matrix @c left. */ -template inline void generate( - writable_matrix& left, F&& f, col_major - ) +template +inline void +generate(writable_matrix& left, F&& f, col_major) { - for(int j = 0; j < left.cols(); ++ j) - for(int i = 0; i < left.rows(); ++ i) - left.put(i,j, (std::forward(f))(i,j)); + for(int j = 0; j < left.cols(); ++j) + for(int i = 0; i < left.rows(); ++i) + left.put(i, j, (std::forward(f))(i, j)); } -} // namespace detail -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/matrix/detail/get.h b/cml/matrix/detail/get.h index 1cdc862..def74da 100644 --- a/cml/matrix/detail/get.h +++ b/cml/matrix/detail/get.h @@ -1,47 +1,38 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_detail_get_h -#define cml_matrix_detail_get_h - #include -namespace cml { -namespace detail { +namespace cml::detail { /** Helper to return the passed-in value in response to a matrix index @c * (i,j). */ template -inline auto get(const Other& v, int, int) -> const Other& +inline auto +get(const Other& v, int, int) -> const Other& { return v; } /** Helper to return element @c (i,j) of @c array. */ -template inline const Other& +template +inline const Other& get(Other const (&array)[Rows][Cols], int i, int j) { return array[i][j]; } /** Helper to return element @c (i,j) of @c sub. */ -template inline auto get( - const readable_matrix& sub, int i, int j - ) -> typename matrix_traits::immutable_value +template +inline auto +get(const readable_matrix& sub, int i, int j) -> + typename matrix_traits::immutable_value { - return sub.get(i,j); + return sub.get(i, j); } -} // namespace detail -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/matrix/detail/inverse.h b/cml/matrix/detail/inverse.h index 969bd76..315dec5 100644 --- a/cml/matrix/detail/inverse.h +++ b/cml/matrix/detail/inverse.h @@ -1,118 +1,149 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_detail_inverse_h -#define cml_matrix_detail_inverse_h - #include #include #include #include -namespace cml { -namespace detail { +namespace cml::detail { /** 2x2 inverse implementation. */ -template inline void +template +inline void inverse(writable_matrix& M, int_c<2>) { /* Compute determinant and inverse: */ - auto M00 = M(0,0), M01 = M(0,1); - auto M10 = M(1,0), M11 = M(1,1); - auto D = (M00*M11 - M01*M10); + auto M00 = M(0, 0), M01 = M(0, 1); + auto M10 = M(1, 0), M11 = M(1, 1); + auto D = (M00 * M11 - M01 * M10); /* Replace M: */ - M(0,0) = M11 / D; - M(0,1) = - M01 / D; - M(1,0) = - M10 / D; - M(1,1) = M00 / D; + M(0, 0) = M11 / D; + M(0, 1) = -M01 / D; + M(1, 0) = -M10 / D; + M(1, 1) = M00 / D; } /** 3x3 inverse implementation. */ -template inline void +template +inline void inverse(writable_matrix& M, int_c<3>) { /* Compute cofactors for each entry: */ - auto m_00 = M(1,1)*M(2,2) - M(1,2)*M(2,1); - auto m_01 = M(1,2)*M(2,0) - M(1,0)*M(2,2); - auto m_02 = M(1,0)*M(2,1) - M(1,1)*M(2,0); + auto m_00 = M(1, 1) * M(2, 2) - M(1, 2) * M(2, 1); + auto m_01 = M(1, 2) * M(2, 0) - M(1, 0) * M(2, 2); + auto m_02 = M(1, 0) * M(2, 1) - M(1, 1) * M(2, 0); - auto m_10 = M(0,2)*M(2,1) - M(0,1)*M(2,2); - auto m_11 = M(0,0)*M(2,2) - M(0,2)*M(2,0); - auto m_12 = M(0,1)*M(2,0) - M(0,0)*M(2,1); + auto m_10 = M(0, 2) * M(2, 1) - M(0, 1) * M(2, 2); + auto m_11 = M(0, 0) * M(2, 2) - M(0, 2) * M(2, 0); + auto m_12 = M(0, 1) * M(2, 0) - M(0, 0) * M(2, 1); - auto m_20 = M(0,1)*M(1,2) - M(0,2)*M(1,1); - auto m_21 = M(0,2)*M(1,0) - M(0,0)*M(1,2); - auto m_22 = M(0,0)*M(1,1) - M(0,1)*M(1,0); + auto m_20 = M(0, 1) * M(1, 2) - M(0, 2) * M(1, 1); + auto m_21 = M(0, 2) * M(1, 0) - M(0, 0) * M(1, 2); + auto m_22 = M(0, 0) * M(1, 1) - M(0, 1) * M(1, 0); /* Compute determinant from the minors: */ - auto D = (M(0,0)*m_00 + M(0,1)*m_01 + M(0,2)*m_02); + auto D = (M(0, 0) * m_00 + M(0, 1) * m_01 + M(0, 2) * m_02); /* Assign the inverse as (1/D) * (cofactor matrix)^T: */ - M(0,0) = m_00/D; M(0,1) = m_10/D; M(0,2) = m_20/D; - M(1,0) = m_01/D; M(1,1) = m_11/D; M(1,2) = m_21/D; - M(2,0) = m_02/D; M(2,1) = m_12/D; M(2,2) = m_22/D; + M(0, 0) = m_00 / D; + M(0, 1) = m_10 / D; + M(0, 2) = m_20 / D; + M(1, 0) = m_01 / D; + M(1, 1) = m_11 / D; + M(1, 2) = m_21 / D; + M(2, 0) = m_02 / D; + M(2, 1) = m_12 / D; + M(2, 2) = m_22 / D; } /** 4x4 inverse implementation. */ -template inline void +template +inline void inverse(writable_matrix& M, int_c<4>) { /* Common cofactors, rows 0,1: */ - auto m_22_33_23_32 = M(2,2)*M(3,3) - M(2,3)*M(3,2); - auto m_23_30_20_33 = M(2,3)*M(3,0) - M(2,0)*M(3,3); - auto m_20_31_21_30 = M(2,0)*M(3,1) - M(2,1)*M(3,0); - auto m_21_32_22_31 = M(2,1)*M(3,2) - M(2,2)*M(3,1); - auto m_23_31_21_33 = M(2,3)*M(3,1) - M(2,1)*M(3,3); - auto m_20_32_22_30 = M(2,0)*M(3,2) - M(2,2)*M(3,0); + auto m_22_33_23_32 = M(2, 2) * M(3, 3) - M(2, 3) * M(3, 2); + auto m_23_30_20_33 = M(2, 3) * M(3, 0) - M(2, 0) * M(3, 3); + auto m_20_31_21_30 = M(2, 0) * M(3, 1) - M(2, 1) * M(3, 0); + auto m_21_32_22_31 = M(2, 1) * M(3, 2) - M(2, 2) * M(3, 1); + auto m_23_31_21_33 = M(2, 3) * M(3, 1) - M(2, 1) * M(3, 3); + auto m_20_32_22_30 = M(2, 0) * M(3, 2) - M(2, 2) * M(3, 0); /* Compute minors: */ - auto d00 = M(1,1)*m_22_33_23_32+M(1,2)*m_23_31_21_33+M(1,3)*m_21_32_22_31; - auto d01 = M(1,0)*m_22_33_23_32+M(1,2)*m_23_30_20_33+M(1,3)*m_20_32_22_30; - auto d02 = M(1,0)*-m_23_31_21_33+M(1,1)*m_23_30_20_33+M(1,3)*m_20_31_21_30; - auto d03 = M(1,0)*m_21_32_22_31+M(1,1)*-m_20_32_22_30+M(1,2)*m_20_31_21_30; + auto d00 = + M(1, 1) * m_22_33_23_32 + M(1, 2) * m_23_31_21_33 + M(1, 3) * m_21_32_22_31; + auto d01 = + M(1, 0) * m_22_33_23_32 + M(1, 2) * m_23_30_20_33 + M(1, 3) * m_20_32_22_30; + auto d02 = M(1, 0) * -m_23_31_21_33 + M(1, 1) * m_23_30_20_33 + + M(1, 3) * m_20_31_21_30; + auto d03 = M(1, 0) * m_21_32_22_31 + M(1, 1) * -m_20_32_22_30 + + M(1, 2) * m_20_31_21_30; /* Compute minors: */ - auto d10 = M(0,1)*m_22_33_23_32+M(0,2)*m_23_31_21_33+M(0,3)*m_21_32_22_31; - auto d11 = M(0,0)*m_22_33_23_32+M(0,2)*m_23_30_20_33+M(0,3)*m_20_32_22_30; - auto d12 = M(0,0)*-m_23_31_21_33+M(0,1)*m_23_30_20_33+M(0,3)*m_20_31_21_30; - auto d13 = M(0,0)*m_21_32_22_31+M(0,1)*-m_20_32_22_30+M(0,2)*m_20_31_21_30; + auto d10 = + M(0, 1) * m_22_33_23_32 + M(0, 2) * m_23_31_21_33 + M(0, 3) * m_21_32_22_31; + auto d11 = + M(0, 0) * m_22_33_23_32 + M(0, 2) * m_23_30_20_33 + M(0, 3) * m_20_32_22_30; + auto d12 = M(0, 0) * -m_23_31_21_33 + M(0, 1) * m_23_30_20_33 + + M(0, 3) * m_20_31_21_30; + auto d13 = M(0, 0) * m_21_32_22_31 + M(0, 1) * -m_20_32_22_30 + + M(0, 2) * m_20_31_21_30; /* Common cofactors, rows 2,3: */ - auto m_02_13_03_12 = M(0,2)*M(1,3) - M(0,3)*M(1,2); - auto m_03_10_00_13 = M(0,3)*M(1,0) - M(0,0)*M(1,3); - auto m_00_11_01_10 = M(0,0)*M(1,1) - M(0,1)*M(1,0); - auto m_01_12_02_11 = M(0,1)*M(1,2) - M(0,2)*M(1,1); - auto m_03_11_01_13 = M(0,3)*M(1,1) - M(0,1)*M(1,3); - auto m_00_12_02_10 = M(0,0)*M(1,2) - M(0,2)*M(1,0); + auto m_02_13_03_12 = M(0, 2) * M(1, 3) - M(0, 3) * M(1, 2); + auto m_03_10_00_13 = M(0, 3) * M(1, 0) - M(0, 0) * M(1, 3); + auto m_00_11_01_10 = M(0, 0) * M(1, 1) - M(0, 1) * M(1, 0); + auto m_01_12_02_11 = M(0, 1) * M(1, 2) - M(0, 2) * M(1, 1); + auto m_03_11_01_13 = M(0, 3) * M(1, 1) - M(0, 1) * M(1, 3); + auto m_00_12_02_10 = M(0, 0) * M(1, 2) - M(0, 2) * M(1, 0); /* Compute minors (uses row 3 as the multipliers instead of row 0, * which uses the same signs as row 0): */ - auto d20 = M(3,1)*m_02_13_03_12+M(3,2)*m_03_11_01_13+M(3,3)*m_01_12_02_11; - auto d21 = M(3,0)*m_02_13_03_12+M(3,2)*m_03_10_00_13+M(3,3)*m_00_12_02_10; - auto d22 = M(3,0)*-m_03_11_01_13+M(3,1)*m_03_10_00_13+M(3,3)*m_00_11_01_10; - auto d23 = M(3,0)*m_01_12_02_11+M(3,1)*-m_00_12_02_10+M(3,2)*m_00_11_01_10; + auto d20 = + M(3, 1) * m_02_13_03_12 + M(3, 2) * m_03_11_01_13 + M(3, 3) * m_01_12_02_11; + auto d21 = + M(3, 0) * m_02_13_03_12 + M(3, 2) * m_03_10_00_13 + M(3, 3) * m_00_12_02_10; + auto d22 = M(3, 0) * -m_03_11_01_13 + M(3, 1) * m_03_10_00_13 + + M(3, 3) * m_00_11_01_10; + auto d23 = M(3, 0) * m_01_12_02_11 + M(3, 1) * -m_00_12_02_10 + + M(3, 2) * m_00_11_01_10; /* Compute minors: */ - auto d30 = M(2,1)*m_02_13_03_12+M(2,2)*m_03_11_01_13+M(2,3)*m_01_12_02_11; - auto d31 = M(2,0)*m_02_13_03_12+M(2,2)*m_03_10_00_13+M(2,3)*m_00_12_02_10; - auto d32 = M(2,0)*-m_03_11_01_13+M(2,1)*m_03_10_00_13+M(2,3)*m_00_11_01_10; - auto d33 = M(2,0)*m_01_12_02_11+M(2,1)*-m_00_12_02_10+M(2,2)*m_00_11_01_10; + auto d30 = + M(2, 1) * m_02_13_03_12 + M(2, 2) * m_03_11_01_13 + M(2, 3) * m_01_12_02_11; + auto d31 = + M(2, 0) * m_02_13_03_12 + M(2, 2) * m_03_10_00_13 + M(2, 3) * m_00_12_02_10; + auto d32 = M(2, 0) * -m_03_11_01_13 + M(2, 1) * m_03_10_00_13 + + M(2, 3) * m_00_11_01_10; + auto d33 = M(2, 0) * m_01_12_02_11 + M(2, 1) * -m_00_12_02_10 + + M(2, 2) * m_00_11_01_10; /* Finally, compute determinant from the minors, and assign the * inverse as (1/D) * (cofactor matrix)^T: */ - auto D = (M(0,0)*d00 - M(0,1)*d01 + M(0,2)*d02 - M(0,3)*d03); - M(0,0) = +d00/D; M(0,1) = -d10/D; M(0,2) = +d20/D; M(0,3) = -d30/D; - M(1,0) = -d01/D; M(1,1) = +d11/D; M(1,2) = -d21/D; M(1,3) = +d31/D; - M(2,0) = +d02/D; M(2,1) = -d12/D; M(2,2) = +d22/D; M(2,3) = -d32/D; - M(3,0) = -d03/D; M(3,1) = +d13/D; M(3,2) = -d23/D; M(3,3) = +d33/D; + auto D = (M(0, 0) * d00 - M(0, 1) * d01 + M(0, 2) * d02 - M(0, 3) * d03); + M(0, 0) = +d00 / D; + M(0, 1) = -d10 / D; + M(0, 2) = +d20 / D; + M(0, 3) = -d30 / D; + M(1, 0) = -d01 / D; + M(1, 1) = +d11 / D; + M(1, 2) = -d21 / D; + M(1, 3) = +d31 / D; + M(2, 0) = +d02 / D; + M(2, 1) = -d12 / D; + M(2, 2) = +d22 / D; + M(2, 3) = -d32 / D; + M(3, 0) = -d03 / D; + M(3, 1) = +d13 / D; + M(3, 2) = -d23 / D; + M(3, 3) = +d33 / D; } namespace { @@ -122,32 +153,31 @@ namespace { * std::vector<> or std::array<>). */ template -inline void inverse_pivot(writable_matrix& M, - RowIndexArray& row_index, ColIndexArray& col_index, Markers& pivoted - ) +inline void +inverse_pivot(writable_matrix& M, RowIndexArray& row_index, + ColIndexArray& col_index, Markers& pivoted) { - typedef value_type_trait_of_t value_type; - typedef traits_of_t value_traits; + using value_type = value_type_trait_of_t; + using value_traits = traits_of_t; /* For each column */ int N = M.rows(); - for(int i = 0; i < N; ++ i) { - + for(int i = 0; i < N; ++i) { /* Find the pivot */ int row = 0, col = 0; - auto pivot = value_traits::fabs(M(0,0)); - for(int j = 0; j < N; ++ j) { + auto pivot = value_traits::fabs(M(0, 0)); + for(int j = 0; j < N; ++j) { if(pivoted[j]) continue; - for(int k = 0; k < N; ++ k) { - if(pivoted[k]) continue; + for(int k = 0; k < N; ++k) { + if(pivoted[k]) continue; - value_type mag = value_traits::fabs(M(j,k)); - if(mag > pivot) { - pivot = mag; - row = j; - col = k; - } + value_type mag = value_traits::fabs(M(j, k)); + if(mag > pivot) { + pivot = mag; + row = j; + col = k; + } } } @@ -159,37 +189,36 @@ inline void inverse_pivot(writable_matrix& M, /* Swap rows if necessary */ if(row != col) { - for(int j = 0; j < N; ++ j) - std::swap(M(row,j), M(col,j)); + for(int j = 0; j < N; ++j) std::swap(M(row, j), M(col, j)); } /* Process pivot row */ pivoted[col] = true; - pivot = M(col,col); - M(col,col) = value_type(1); + pivot = M(col, col); + M(col, col) = value_type(1); value_type k = value_type(1) / pivot; - for(int j = 0; j < N; ++ j) M(col,j) *= k; + for(int j = 0; j < N; ++j) M(col, j) *= k; /* Process other rows */ - for(int j = 0; j < N; ++ j) { + for(int j = 0; j < N; ++j) { if(j == col) continue; - value_type mult = -M(j,col); - M(j,col) = value_type(0); - for(int k = 0; k < N; ++ k) M(j,k) += mult * M(col,k); + value_type mult = -M(j, col); + M(j, col) = value_type(0); + for(int k = 0; k < N; ++k) M(j, k) += mult * M(col, k); } } /* Swap columns if necessary */ - for(int i = 0; i < N; ++ i) { + for(int i = 0; i < N; ++i) { if(row_index[i] == col_index[i]) continue; - for(int j = 0; j < N; ++ j) - std::swap(M(j,row_index[i]), M(j,col_index[i])); + for(int j = 0; j < N; ++j) + std::swap(M(j, row_index[i]), M(j, col_index[i])); } } -} +} // namespace /** Inverse implementation for statically-sized square matrices with * dimension greater than 4, using a pivoting algorithm to compute the @@ -197,12 +226,14 @@ inline void inverse_pivot(writable_matrix& M, * * @note It is up to the caller to ensure @c M is a square matrix. */ -template inline void +template +inline void inverse(writable_matrix& M, int_c) { /* For tracking pivots */ std::array row_index, col_index; - std::array pivoted; pivoted.fill(false); + std::array pivoted; + pivoted.fill(false); /* Call the implementation: */ inverse_pivot(M, row_index, col_index, pivoted); @@ -215,15 +246,25 @@ inverse(writable_matrix& M, int_c) * * @note It is up to the caller to ensure @c M is a square matrix. */ -template inline void +template +inline void inverse(writable_matrix& M, int_c<-1>) { /* Use small matrix inverse if possible: */ int N = M.rows(); switch(N) { - case 2: inverse(M, int_c<2>()); return; break; - case 3: inverse(M, int_c<3>()); return; break; - case 4: inverse(M, int_c<4>()); return; break; + case 2: + inverse(M, int_c<2>()); + return; + break; + case 3: + inverse(M, int_c<3>()); + return; + break; + case 4: + inverse(M, int_c<4>()); + return; + break; } /* Otherwise, use the pivoting inverse: */ @@ -236,10 +277,4 @@ inverse(writable_matrix& M, int_c<-1>) inverse_pivot(M, row_index, col_index, pivoted); } -} // namespace detail -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/matrix/detail/lu.h b/cml/matrix/detail/lu.h index 2c93984..52431e9 100644 --- a/cml/matrix/detail/lu.h +++ b/cml/matrix/detail/lu.h @@ -1,18 +1,12 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_detail_lu_h -#define cml_matrix_detail_lu_h - #include -namespace cml { -namespace detail { +namespace cml::detail { /** In-place LU decomposition using Doolittle's method. * @@ -23,8 +17,7 @@ namespace detail { * * @note It is up to the caller to ensure @c M is a square matrix. */ -template inline void -lu_inplace(writable_matrix& M); +template inline void lu_inplace(writable_matrix& M); /** In-place LU decomposition using partial pivoting for non-singular * square matrices. @c order contains the new row order after pivoting, @@ -37,17 +30,11 @@ lu_inplace(writable_matrix& M); * @returns 1 if no pivots or an even number of pivots are performed, -1 if * an odd number of pivots are performed, 0 if M is singular. */ -template inline int -lu_pivot_inplace(writable_matrix& M, OrderArray& order); +template +inline int lu_pivot_inplace(writable_matrix& M, OrderArray& order); -} // namespace detail -} // namespace cml +} #define __CML_MATRIX_DETAIL_LU_TPP #include #undef __CML_MATRIX_DETAIL_LU_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/detail/lu.tpp b/cml/matrix/detail/lu.tpp index 555e916..fe3ae40 100644 --- a/cml/matrix/detail/lu.tpp +++ b/cml/matrix/detail/lu.tpp @@ -1,64 +1,61 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_DETAIL_LU_TPP -#error "matrix/detail/lu.tpp not included correctly" +# error "matrix/detail/lu.tpp not included correctly" #endif #include -namespace cml { -namespace detail { +namespace cml::detail { -template inline void +template +inline void lu_inplace(writable_matrix& M) { - typedef value_type_trait_of_t value_type; + using value_type = value_type_trait_of_t; int N = M.rows(); - for(int k = 0; k < N; ++ k) { - + for(int k = 0; k < N; ++k) { /* Compute the upper triangle: */ - for(int j = k; j < N; ++ j) { + for(int j = k; j < N; ++j) { value_type sum(0); - for(int p = 0; p < k; ++ p) sum += M(k,p)*M(p,j); - M(k,j) -= sum; + for(int p = 0; p < k; ++p) sum += M(k, p) * M(p, j); + M(k, j) -= sum; } /* Compute the lower triangle: */ - for(int i = k+1; i < N; ++ i) { + for(int i = k + 1; i < N; ++i) { value_type sum(0); - for(int p = 0; p < k; ++ p) sum += M(i,p)*M(p,k); - M(i,k) = (M(i,k) - sum) / M(k,k); + for(int p = 0; p < k; ++p) sum += M(i, p) * M(p, k); + M(i, k) = (M(i, k) - sum) / M(k, k); } } } -template inline int +template +inline int lu_pivot_inplace(writable_matrix& M, OrderArray& order) { - typedef value_type_trait_of_t value_type; - typedef traits_of_t value_traits; + using value_type = value_type_trait_of_t; + using value_traits = traits_of_t; /* Initialize the order: */ int N = M.rows(); - for(int i = 0; i < N; ++ i) order[i] = i; + for(int i = 0; i < N; ++i) order[i] = i; /* For each column: */ int flag = 1; - for(int k = 0; k < N-1; ++ k) { - + for(int k = 0; k < N - 1; ++k) { /* Find the next pivot row: */ int row = k; - value_type max = M(k,k); - for(int i = k+1; i < N; ++ i) { - value_type mag = value_traits::fabs(M(i,k)); + value_type max = M(k, k); + for(int i = k + 1; i < N; ++i) { + value_type mag = value_traits::fabs(M(i, k)); if(mag > max) { - max = mag; - row = i; + max = mag; + row = i; } } @@ -69,15 +66,14 @@ lu_pivot_inplace(writable_matrix& M, OrderArray& order) /* Update order and swap rows: */ if(row != k) { std::swap(order[k], order[row]); - for(int i = 0; i < N; ++ i) std::swap(M(k,i), M(row,i)); - flag = - flag; + for(int i = 0; i < N; ++i) std::swap(M(k, i), M(row, i)); + flag = -flag; } /* Compute the Schur complement: */ - for(int i = k+1; i < N; ++ i) { - M(i,k) /= M(k,k); - for(int j = k+1; j < N; ++ j) - M(i,j) -= M(i,k)*M(k,j); + for(int i = k + 1; i < N; ++i) { + M(i, k) /= M(k, k); + for(int j = k + 1; j < N; ++j) M(i, j) -= M(i, k) * M(k, j); } } @@ -85,8 +81,4 @@ lu_pivot_inplace(writable_matrix& M, OrderArray& order) return flag; } -} // namespace detail -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/matrix/detail/resize.h b/cml/matrix/detail/resize.h index e10e6bd..986326a 100644 --- a/cml/matrix/detail/resize.h +++ b/cml/matrix/detail/resize.h @@ -1,34 +1,26 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_detail_resize_h -#define cml_matrix_detail_resize_h - #include -namespace cml { -namespace detail { +namespace cml::detail { /** No-op for non-resizable matrices. */ -template inline void resize(readable_matrix&, int, int) {} +template +inline void +resize(readable_matrix&, int, int) +{} /** Resize matrices that implement resize(). */ -template inline auto +template +inline auto resize(writable_matrix& sub, int rows, int cols) --> decltype(sub.actual().resize(0,0), void()) + -> decltype(sub.actual().resize(0, 0), void()) { - sub.actual().resize(rows,cols); + sub.actual().resize(rows, cols); } -} // namespace detail -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/matrix/detail/transpose.h b/cml/matrix/detail/transpose.h index 131473f..a37b07f 100644 --- a/cml/matrix/detail/transpose.h +++ b/cml/matrix/detail/transpose.h @@ -1,46 +1,35 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_detail_transpose_h -#define cml_matrix_detail_transpose_h - #include #include #include #include -namespace cml { -namespace detail { +namespace cml::detail { /** Transpose a fixed-size square matrix. */ -template inline void +template +inline void transpose(writable_matrix& M, fixed_size_tag) { static const int rows = array_rows_of_c::value; static const int cols = array_cols_of_c::value; static_assert(rows == cols, "non-square fixed-size matrix"); - for(int i = 1; i < rows; ++ i) - for(int j = 0; j < i; ++ j) - std::swap(M.get(i,j), M.get(j,i)); + for(int i = 1; i < rows; ++i) + for(int j = 0; j < i; ++j) std::swap(M.get(i, j), M.get(j, i)); } /** Transpose a resizable matrix using a temporary. */ -template* = nullptr> inline void +template* = nullptr> +inline void transpose(writable_matrix& M, dynamic_size_tag) { temporary_of_t T(M); M = cml::transpose(T); } -} // namespace detail -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/matrix/determinant.h b/cml/matrix/determinant.h index beef78e..9b94bb2 100644 --- a/cml/matrix/determinant.h +++ b/cml/matrix/determinant.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_determinant_h -#define cml_matrix_determinant_h - #include #include @@ -23,16 +18,11 @@ namespace cml { * dynamically-sized and not square. Fixed-size matrices are checked at * compile-time. */ -template auto -determinant(const readable_matrix& M) -> value_type_trait_of_t; +template +auto determinant(const readable_matrix& M) -> value_type_trait_of_t; -} // namespace cml +} // namespace cml #define __CML_MATRIX_DETERMINANT_TPP #include #undef __CML_MATRIX_DETERMINANT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/determinant.tpp b/cml/matrix/determinant.tpp index c853ba4..99127d5 100644 --- a/cml/matrix/determinant.tpp +++ b/cml/matrix/determinant.tpp @@ -1,25 +1,20 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_DETERMINANT_TPP -#error "matrix/determinant.tpp not included correctly" +# error "matrix/determinant.tpp not included correctly" #endif #include namespace cml { -template inline auto -determinant(const readable_matrix& M) --> value_type_trait_of_t +template +inline auto +determinant(const readable_matrix& M) -> value_type_trait_of_t { return M.determinant(); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/dynamic.h b/cml/matrix/dynamic.h index eecf6ad..f4d5939 100644 --- a/cml/matrix/dynamic.h +++ b/cml/matrix/dynamic.h @@ -1,17 +1,7 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_dynamic_h -#define cml_matrix_dynamic_h - #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/dynamic_allocated.h b/cml/matrix/dynamic_allocated.h index fb897fc..3552738 100644 --- a/cml/matrix/dynamic_allocated.h +++ b/cml/matrix/dynamic_allocated.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_dynamic_allocated_h -#define cml_matrix_dynamic_allocated_h - #include #include #include @@ -19,26 +14,26 @@ namespace cml { template -struct matrix_traits< matrix, BasisOrient, Layout> > +struct matrix_traits, BasisOrient, Layout>> { /* The basis must be col_basis or row_basis: */ - static_assert(std::is_same::value - || std::is_same::value, "invalid basis"); + static_assert(std::is_same::value + || std::is_same::value, + "invalid basis"); /* Traits and types for the matrix element: */ - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef typename element_traits::pointer pointer; - typedef typename element_traits::reference reference; - typedef typename element_traits::const_pointer const_pointer; - typedef typename element_traits::const_reference const_reference; - typedef typename element_traits::mutable_value mutable_value; - typedef typename element_traits::immutable_value immutable_value; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using pointer = typename element_traits::pointer; + using reference = typename element_traits::reference; + using const_pointer = typename element_traits::const_pointer; + using const_reference = typename element_traits::const_reference; + using mutable_value = typename element_traits::mutable_value; + using immutable_value = typename element_traits::immutable_value; /* The matrix storage type: */ - typedef rebind_t< - allocated, matrix_storage_tag> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = rebind_t, matrix_storage_tag>; + using size_tag = typename storage_type::size_tag; static_assert(std::is_same::value, "invalid size tag"); @@ -51,10 +46,10 @@ struct matrix_traits< matrix, BasisOrient, Layout> > static_assert(array_cols == -1, "invalid column size"); /* Basis orientation: */ - typedef BasisOrient basis_tag; + using basis_tag = BasisOrient; /* Layout: */ - typedef Layout layout_tag; + using layout_tag = Layout; /** Constant containing the matrix basis enumeration value. */ static const basis_kind matrix_basis = basis_tag::value; @@ -67,287 +62,275 @@ struct matrix_traits< matrix, BasisOrient, Layout> > template class matrix, BasisOrient, Layout> : public writable_matrix< - matrix, BasisOrient, Layout>> + matrix, BasisOrient, Layout>> { protected: + /** The real allocator type. */ + using allocator_type = cml::rebind_alloc_t; - /** The real allocator type. */ - typedef cml::rebind_alloc_t allocator_type; - - /** Allocator traits. */ - typedef std::allocator_traits allocator_traits; + /** Allocator traits. */ + using allocator_traits = std::allocator_traits; - /** Require a stateless allocator. */ - static_assert(std::is_empty::value, - "cannot use a stateful allocator for dynamic<> matrices"); + /** Require a stateless allocator. */ + static_assert(std::is_empty::value, + "cannot use a stateful allocator for dynamic<> matrices"); public: - - typedef matrix, BasisOrient, Layout> matrix_type; - typedef readable_matrix readable_type; - typedef writable_matrix writable_type; - typedef matrix_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::pointer pointer; - typedef typename traits_type::reference reference; - typedef typename traits_type::const_pointer const_pointer; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using matrix_type = matrix, BasisOrient, Layout>; + using readable_type = readable_matrix; + using writable_type = writable_matrix; + using traits_type = matrix_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using pointer = typename traits_type::pointer; + using reference = typename traits_type::reference; + using const_pointer = typename traits_type::const_pointer; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; public: - - /* Include methods from writable_type: */ - using writable_type::operator(); + /* Include methods from writable_type: */ + using writable_type::operator(); #ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - using writable_type::operator=; + using writable_type::operator=; #endif public: + /** Constant containing the number of rows. */ + static const int array_rows = traits_type::array_rows; - /** Constant containing the number of rows. */ - static const int array_rows = traits_type::array_rows; - - /** Constant containing the number of columns. */ - static const int array_cols = traits_type::array_cols; + /** Constant containing the number of columns. */ + static const int array_cols = traits_type::array_cols; - /** Constant containing the matrix basis enumeration value. */ - static const basis_kind matrix_basis = traits_type::matrix_basis; + /** Constant containing the matrix basis enumeration value. */ + static const basis_kind matrix_basis = traits_type::matrix_basis; - /** Constant containing the array layout enumeration value. */ - static const layout_kind array_layout = traits_type::array_layout; + /** Constant containing the array layout enumeration value. */ + static const layout_kind array_layout = traits_type::array_layout; public: - - /** Default constructor. + /** Default constructor. * * @note The matrix has no elements. */ - matrix(); + matrix(); - /** Construct given a size. + /** Construct given a size. * * @throws std::invalid_argument if @c rows < 0 or @c cols < 0. */ - matrix(int rows, int cols); + matrix(int rows, int cols); - /** Copy constructor. */ - matrix(const matrix_type& other); + /** Copy constructor. */ + matrix(const matrix_type& other); - /** Move constructor. */ - matrix(matrix_type&& other); + /** Move constructor. */ + matrix(matrix_type&& other); - /** Construct from a readable_matrix. */ - template matrix(const readable_matrix& sub); + /** Construct from a readable_matrix. */ + template matrix(const readable_matrix& sub); - /** Construct from at least 1 value. + /** Construct from at least 1 value. * * @note This overload is enabled only if all of the arguments are * convertible to value_type. */ - template::value - && std::is_integral::value + /* Avoid implicit conversions, for example, from double: */ + /**/ std::is_integral::value + && std::is_integral::value - /* Require compatible values: */ - && cml::are_convertible::value - >* = nullptr> + /* Require compatible values: */ + && cml::are_convertible::value>* = nullptr> - matrix(RowsT rows, ColsT cols, const E0& e0, const Elements&... eN) - // XXX Should be in matrix/dynamic_allocated.tpp, but VC++12 has - // brain-dead out-of-line template argument matching... - : m_data(0), m_rows(0), m_cols(0) - { - this->resize_fast(rows,cols); - this->assign_elements(e0, eN...); - } + matrix(RowsT rows, ColsT cols, const E0& e0, const Elements&... eN) + // XXX Should be in matrix/dynamic_allocated.tpp, but VC++12 has + // brain-dead out-of-line template argument matching... + : m_data(0) + , m_rows(0) + , m_cols(0) + { + this->resize_fast(rows, cols); + this->assign_elements(e0, eN...); + } - /** Construct from an array type. */ - template* = nullptr> - matrix(int rows, int cols, const Array& array); + /** Construct from an array type. */ + template* = nullptr> + matrix(int rows, int cols, const Array& array); - /** Construct from a C-array type. */ - template - matrix(Other const (&array)[Rows][Cols]); + /** Construct from a C-array type. */ + template + matrix(Other const (&array)[Rows][Cols]); - /** Construct from a pointer to an array. */ - template* = nullptr> - matrix(int rows, int cols, const Pointer& array); + /** Construct from a pointer to an array. */ + template* = nullptr> + matrix(int rows, int cols, const Pointer& array); - /** Construct from a pointer to an array. */ - template* = nullptr> - matrix(const Pointer& array, int rows, int cols); + /** Construct from a pointer to an array. */ + template* = nullptr> + matrix(const Pointer& array, int rows, int cols); - /** Destructor. */ - ~matrix(); + /** Destructor. */ + ~matrix(); public: + /** Return access to the matrix data as a raw pointer. */ + pointer data(); - /** Return access to the matrix data as a raw pointer. */ - pointer data(); + /** Return const access to the matrix data as a raw pointer. */ + const_pointer data() const; - /** Return const access to the matrix data as a raw pointer. */ - const_pointer data() const; + /** Read-only iterator over the elements as a 1D array. */ + const_pointer begin() const; - /** Read-only iterator over the elements as a 1D array. */ - const_pointer begin() const; + /** Read-only iterator over the elements as a 1D array. */ + const_pointer end() const; - /** Read-only iterator over the elements as a 1D array. */ - const_pointer end() const; - - /** Resize the matrix to the specified size. + /** Resize the matrix to the specified size. * * @note This will reallocate the array and copy existing elements, if * any. * * @throws std::invalid_argument if @c rows or @c cols is negative. */ - void resize(int rows, int cols); + void resize(int rows, int cols); - /** Resize the matrix to the specified size without copying the old + /** Resize the matrix to the specified size without copying the old * elements. * * @throws std::invalid_argument if @c rows or @c cols is negative. */ - void resize_fast(int rows, int cols); + void resize_fast(int rows, int cols); public: + /** Copy assignment. */ + matrix_type& operator=(const matrix_type& other); - /** Copy assignment. */ - matrix_type& operator=(const matrix_type& other); - - /** Move assignment. */ - matrix_type& operator=(matrix_type&& other); + /** Move assignment. */ + matrix_type& operator=(matrix_type&& other); #ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline matrix_type& operator=(const readable_matrix& other) { - return this->assign(other); - } - - template* = nullptr> - inline matrix_type& operator=(const Array& array) { - return this->assign(array); - } - - template - inline matrix_type& operator=(Other const (&array)[Rows][Cols]) { - return this->assign(array); - } - - template - inline matrix_type& operator=(std::initializer_list l) { - return this->assign(l); - } + template + inline matrix_type& operator=(const readable_matrix& other) + { + return this->assign(other); + } + + template* = nullptr> + inline matrix_type& operator=(const Array& array) + { + return this->assign(array); + } + + template + inline matrix_type& operator=(Other const (&array)[Rows][Cols]) + { + return this->assign(array); + } + + template + inline matrix_type& operator=(std::initializer_list l) + { + return this->assign(l); + } #endif protected: - - /** No-op for trivially destructible elements + /** No-op for trivially destructible elements * (is_trivially_destructible). */ - void destruct(pointer, int, std::true_type); + void destruct(pointer, int, std::true_type); - /** Invoke non-trivial destructors for @c n elements starting at @c + /** Invoke non-trivial destructors for @c n elements starting at @c * data. */ - void destruct(pointer data, int n, std::false_type); + void destruct(pointer data, int n, std::false_type); protected: + /** @name readable_matrix Interface */ + /*@{*/ - /** @name readable_matrix Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the number of rows. */ - int i_rows() const; + /** Return the number of rows. */ + int i_rows() const; - /** Return the number of columns. */ - int i_cols() const; + /** Return the number of columns. */ + int i_cols() const; - /** Return matrix const element @c (i,j). */ - immutable_value i_get(int i, int j) const; + /** Return matrix const element @c (i,j). */ + immutable_value i_get(int i, int j) const; - /*@}*/ + /*@}*/ protected: + /** @name writeable_matrix Interface */ + /*@{*/ - /** @name writeable_matrix Interface */ - /*@{*/ - - friend writable_type; + friend writable_type; - /** Return matrix element @c (i,j). */ - mutable_value i_get(int i, int j); + /** Return matrix element @c (i,j). */ + mutable_value i_get(int i, int j); - /** Set element @c i. */ - template matrix_type& - i_put(int i, int j, const Other& v) __CML_REF; + /** Set element @c i. */ + template + matrix_type& i_put(int i, int j, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i on a temporary. */ - template matrix_type&& - i_put(int i, int j, const Other& v) &&; + /** Set element @c i on a temporary. */ + template matrix_type&& i_put(int i, int j, const Other& v) &&; #endif - /*@}*/ + /*@}*/ protected: - - /** Row-major access to const or non-const @c M. */ - template inline static auto s_access( - Matrix& M, int i, int j, row_major) -> decltype(M.m_data[0]) - { - return M.m_data[i*M.m_cols + j]; - } - - /** Column-major access to const or non-const @c M. */ - template inline static auto s_access( - Matrix& M, int i, int j, col_major) -> decltype(M.m_data[0]) - { - return M.m_data[j*M.m_rows + i]; - } + /** Row-major access to const or non-const @c M. */ + template + inline static auto s_access(Matrix& M, int i, int j, row_major) + -> decltype(M.m_data[0]) + { + return M.m_data[i * M.m_cols + j]; + } + + /** Column-major access to const or non-const @c M. */ + template + inline static auto s_access(Matrix& M, int i, int j, col_major) + -> decltype(M.m_data[0]) + { + return M.m_data[j * M.m_rows + i]; + } protected: + /** Dynamic storage. */ + pointer m_data; - /** Dynamic storage. */ - pointer m_data; + /** Matrix rows. */ + int m_rows; - /** Matrix rows. */ - int m_rows; - - /** Matrix columns. */ - int m_cols; + /** Matrix columns. */ + int m_cols; }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_DYNAMIC_ALLOCATED_TPP #include #undef __CML_MATRIX_DYNAMIC_ALLOCATED_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/dynamic_allocated.tpp b/cml/matrix/dynamic_allocated.tpp index a790d5a..6e0b2db 100644 --- a/cml/matrix/dynamic_allocated.tpp +++ b/cml/matrix/dynamic_allocated.tpp @@ -1,19 +1,17 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_dynamic_allocated_tpp -#define cml_matrix_dynamic_allocated_tpp +#ifndef cml_matrix_dynamic_allocated_tpp +# define cml_matrix_dynamic_allocated_tpp -#ifndef __CML_MATRIX_DYNAMIC_ALLOCATED_TPP -#error "matrix/dynamic_allocated.tpp not included correctly" -#endif +# ifndef __CML_MATRIX_DYNAMIC_ALLOCATED_TPP +# error "matrix/dynamic_allocated.tpp not included correctly" +# endif -#include +# include namespace cml { @@ -21,84 +19,96 @@ namespace cml { template matrix, BO, L>::matrix() -: m_data(0), m_rows(0), m_cols(0) -{ -} +: m_data(0) +, m_rows(0) +, m_cols(0) +{} template matrix, BO, L>::matrix(int rows, int cols) -: m_data(0), m_rows(0), m_cols(0) +: m_data(0) +, m_rows(0) +, m_cols(0) { - this->resize_fast(rows,cols); + this->resize_fast(rows, cols); } template matrix, BO, L>::matrix(const matrix_type& other) -: m_data(0), m_rows(0), m_cols(0) +: m_data(0) +, m_rows(0) +, m_cols(0) { this->assign(other); } template matrix, BO, L>::matrix(matrix_type&& other) -: m_data(0), m_rows(0), m_cols(0) +: m_data(0) +, m_rows(0) +, m_cols(0) { this->operator=(std::move(other)); } -template template +template +template matrix, BO, L>::matrix(const readable_matrix& sub) -: m_data(0), m_rows(0), m_cols(0) +: m_data(0) +, m_rows(0) +, m_cols(0) { this->assign(sub); } template template*> -matrix, BO, L>::matrix( - int rows, int cols, const Array& array - ) -: m_data(0), m_rows(0), m_cols(0) +matrix, BO, L>::matrix(int rows, int cols, const Array& array) +: m_data(0) +, m_rows(0) +, m_cols(0) { - this->resize_fast(rows,cols); + this->resize_fast(rows, cols); this->assign(array); } template template matrix, BO, L>::matrix(Other const (&array)[R][C]) -: m_data(0), m_rows(0), m_cols(0) +: m_data(0) +, m_rows(0) +, m_cols(0) { - this->assign(array); + this->assign(array); } template template*> -matrix, BO, L>::matrix( - int rows, int cols, const Pointer& array - ) -: m_data(0), m_rows(0), m_cols(0) +matrix, BO, L>::matrix(int rows, int cols, const Pointer& array) +: m_data(0) +, m_rows(0) +, m_cols(0) { - this->resize_fast(rows,cols); + this->resize_fast(rows, cols); this->assign(array); } template template*> -matrix, BO, L>::matrix( - const Pointer& array, int rows, int cols - ) -: m_data(0), m_rows(0), m_cols(0) +matrix, BO, L>::matrix(const Pointer& array, int rows, int cols) +: m_data(0) +, m_rows(0) +, m_cols(0) { - this->resize_fast(rows,cols); + this->resize_fast(rows, cols); this->assign(array); } template matrix, BO, L>::~matrix() { - typedef typename allocator_traits::size_type size_type; - int n = this->m_rows*this->m_cols; + using size_type = typename allocator_traits::size_type; + int n = this->m_rows * this->m_cols; this->destruct(this->m_data, n, typename std::is_trivially_destructible::type()); @@ -106,42 +116,45 @@ matrix, BO, L>::~matrix() allocator_traits::deallocate(allocator, this->m_data, size_type(n)); } - - /* Public methods: */ -template auto +template +auto matrix, BO, L>::data() -> pointer { return this->m_data; } -template auto +template +auto matrix, BO, L>::data() const -> const_pointer { return this->m_data; } -template auto +template +auto matrix, BO, L>::begin() const -> const_pointer { return this->m_data; } -template auto +template +auto matrix, BO, L>::end() const -> const_pointer { - return this->m_data + this->m_rows*this->m_cols; + return this->m_data + this->m_rows * this->m_cols; } -template void +template +void matrix, BO, L>::resize(int rows, int cols) { cml_require(rows >= 0, std::invalid_argument, "rows < 0"); cml_require(cols >= 0, std::invalid_argument, "cols < 0"); - int n_old = this->m_rows*this->m_cols; - int n_new = rows*cols; + int n_old = this->m_rows * this->m_cols; + int n_new = rows * cols; /* Short-circuit same size: */ if(n_new == n_old) { @@ -157,7 +170,6 @@ matrix, BO, L>::resize(int rows, int cols) pointer data = this->m_data; pointer copy = allocator_traits::allocate(allocator, n_new); try { - /* Destruct elements if necessary: */ this->destruct(data, n_old, typename std::is_trivially_destructible::type()); @@ -165,8 +177,8 @@ matrix, BO, L>::resize(int rows, int cols) /* Copy elements to the new array if necessary: */ if(data) { int to = std::min(n_old, n_new); - for(pointer src = data, dst = copy; src < data + to; ++ src, ++ dst) { - allocator_traits::construct(allocator, dst, *src); + for(pointer src = data, dst = copy; src < data + to; ++src, ++dst) { + allocator_traits::construct(allocator, dst, *src); } /* Deallocate the old array: */ @@ -183,14 +195,15 @@ matrix, BO, L>::resize(int rows, int cols) this->m_cols = cols; } -template void +template +void matrix, BO, L>::resize_fast(int rows, int cols) { cml_require(rows >= 0, std::invalid_argument, "rows < 0"); cml_require(cols >= 0, std::invalid_argument, "cols < 0"); - int n_old = this->m_rows*this->m_cols; - int n_new = rows*cols; + int n_old = this->m_rows * this->m_cols; + int n_new = rows * cols; /* Short-circuit same size: */ if(n_new == n_old) { @@ -206,15 +219,14 @@ matrix, BO, L>::resize_fast(int rows, int cols) pointer data = this->m_data; pointer copy = allocator_traits::allocate(allocator, n_new); try { - /* Destruct elements if necessary: */ this->destruct(data, n_old, typename std::is_trivially_destructible::type()); /* Deallocate the old array: */ - allocator_traits::deallocate(allocator,data,n_old); + allocator_traits::deallocate(allocator, data, n_old); } catch(...) { - allocator_traits::deallocate(allocator,copy,n_new); + allocator_traits::deallocate(allocator, copy, n_new); throw; } @@ -224,17 +236,17 @@ matrix, BO, L>::resize_fast(int rows, int cols) this->m_cols = cols; } - -template auto +template +auto matrix, BO, L>::operator=(const matrix_type& other) --> matrix_type& + -> matrix_type& { return this->assign(other); } -template auto -matrix, BO, L>::operator=(matrix_type&& other) --> matrix_type& +template +auto +matrix, BO, L>::operator=(matrix_type&& other) -> matrix_type& { /* Ensure deletion of the current array, if any: */ std::swap(this->m_data, other.m_data); @@ -245,17 +257,17 @@ matrix, BO, L>::operator=(matrix_type&& other) return *this; } - - /* Internal methods: */ -template void +template +void matrix, BO, L>::destruct(pointer, int, std::true_type) { /* Nothing to do. */ } -template void +template +void matrix, BO, L>::destruct(pointer data, int n, std::false_type) { /* Short-circuit null: */ @@ -264,64 +276,65 @@ matrix, BO, L>::destruct(pointer data, int n, std::false_type) /* Destruct each element: */ else { auto allocator = allocator_type(); - for(pointer e = data; e < data + n; ++ e) - allocator_traits::destroy(allocator, e); + for(pointer e = data; e < data + n; ++e) + allocator_traits::destroy(allocator, e); } } - /* readable_matrix interface: */ -template int +template +int matrix, BO, L>::i_rows() const { return this->m_rows; } -template int +template +int matrix, BO, L>::i_cols() const { return this->m_cols; } -template auto +template +auto matrix, BO, L>::i_get(int i, int j) const -> immutable_value { return s_access(*this, i, j, layout_tag()); } - /* writable_matrix interface: */ -template auto +template +auto matrix, BO, L>::i_get(int i, int j) -> mutable_value { return s_access(*this, i, j, layout_tag()); } template -template auto matrix, BO, L>::i_put( - int i, int j, const Other& v - ) __CML_REF -> matrix_type& +template +auto +matrix, BO, L>::i_put(int i, int j, + const Other& v) __CML_REF->matrix_type& { s_access(*this, i, j, layout_tag()) = value_type(v); return *this; } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS +# ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template auto matrix, BO, L>::i_put( - int i, int j, const Other& v - ) && -> matrix_type&& +template +auto +matrix, BO, L>::i_put(int i, int j, + const Other& v) && -> matrix_type&& { s_access(*this, i, j, layout_tag()) = value_type(v); return (matrix_type&&) *this; } -#endif - -} // namespace cml +# endif -#endif +} // namespace cml -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +#endif \ No newline at end of file diff --git a/cml/matrix/dynamic_external.h b/cml/matrix/dynamic_external.h index d678f04..60fb655 100644 --- a/cml/matrix/dynamic_external.h +++ b/cml/matrix/dynamic_external.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_dynamic_external_h -#define cml_matrix_dynamic_external_h - #include #include #include @@ -16,26 +11,26 @@ namespace cml { template -struct matrix_traits< - matrix, BasisOrient, Layout> > +struct matrix_traits, BasisOrient, Layout>> { /* The basis must be col_basis or row_basis: */ - static_assert(std::is_same::value - || std::is_same::value, "invalid basis"); + static_assert(std::is_same::value + || std::is_same::value, + "invalid basis"); /* Traits and types for the matrix element: */ - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef typename element_traits::pointer pointer; - typedef typename element_traits::reference reference; - typedef typename element_traits::const_pointer const_pointer; - typedef typename element_traits::const_reference const_reference; - typedef typename element_traits::mutable_value mutable_value; - typedef typename element_traits::immutable_value immutable_value; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using pointer = typename element_traits::pointer; + using reference = typename element_traits::reference; + using const_pointer = typename element_traits::const_pointer; + using const_reference = typename element_traits::const_reference; + using mutable_value = typename element_traits::mutable_value; + using immutable_value = typename element_traits::immutable_value; /* The matrix storage type: */ - typedef rebind_t, matrix_storage_tag> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = rebind_t, matrix_storage_tag>; + using size_tag = typename storage_type::size_tag; static_assert(std::is_same::value, "invalid size tag"); @@ -48,10 +43,10 @@ struct matrix_traits< static_assert(array_cols == -1, "invalid column size"); /* Basis orientation: */ - typedef BasisOrient basis_tag; + using basis_tag = BasisOrient; /* Layout: */ - typedef Layout layout_tag; + using layout_tag = Layout; /** Constant containing the array layout enumeration value. */ static const layout_kind array_layout = layout_tag::value; @@ -63,86 +58,82 @@ struct matrix_traits< /** Fixed-size matrix. */ template class matrix, BasisOrient, Layout> -: public writable_matrix< - matrix, BasisOrient, Layout>> +: public writable_matrix, BasisOrient, Layout>> { // The basis must be col_basis or row_basis (NOT is_basis_tag!): - static_assert(std::is_same::value - || std::is_same::value, "invalid basis"); + static_assert(std::is_same::value + || std::is_same::value, + "invalid basis"); // The layout must be col_major or row_major (NOT is_layout_tag!): - static_assert(std::is_same::value - || std::is_same::value, "invalid layout"); + static_assert(std::is_same::value + || std::is_same::value, + "invalid layout"); public: - - typedef matrix, BasisOrient, Layout> matrix_type; - typedef readable_matrix readable_type; - typedef writable_matrix writable_type; - typedef matrix_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::pointer pointer; - typedef typename traits_type::reference reference; - typedef typename traits_type::const_pointer const_pointer; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using matrix_type = matrix, BasisOrient, Layout>; + using readable_type = readable_matrix; + using writable_type = writable_matrix; + using traits_type = matrix_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using pointer = typename traits_type::pointer; + using reference = typename traits_type::reference; + using const_pointer = typename traits_type::const_pointer; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; public: - - /* Include methods from writable_type: */ - using writable_type::operator(); + /* Include methods from writable_type: */ + using writable_type::operator(); #ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - using writable_type::operator=; + using writable_type::operator=; #endif public: + /** Constant containing the number of rows. */ + static const int array_rows = traits_type::array_rows; - /** Constant containing the number of rows. */ - static const int array_rows = traits_type::array_rows; + /** Constant containing the number of columns. */ + static const int array_cols = traits_type::array_cols; - /** Constant containing the number of columns. */ - static const int array_cols = traits_type::array_cols; - - /** Constant containing the matrix basis enumeration value. */ - static const basis_kind matrix_basis = traits_type::matrix_basis; + /** Constant containing the matrix basis enumeration value. */ + static const basis_kind matrix_basis = traits_type::matrix_basis; - /** Constant containing the array layout enumeration value. */ - static const layout_kind array_layout = traits_type::array_layout; + /** Constant containing the array layout enumeration value. */ + static const layout_kind array_layout = traits_type::array_layout; public: - - /** Default construct with a null pointer and 0 size (rows, cols). + /** Default construct with a null pointer and 0 size (rows, cols). * * @warning The default constructor is enabled only if the compiler * supports rvalue references from *this. */ - matrix(); + matrix(); - /** Construct from the wrapped pointer and the dimensions. + /** Construct from the wrapped pointer and the dimensions. * * @note @c data will be referenced using the assigned matrix layout. * * @note This is for compatibility with CML1. */ - matrix(pointer data, int rows, int cols); + matrix(pointer data, int rows, int cols); - /** Construct from the wrapped pointer and the dimensions. + /** Construct from the wrapped pointer and the dimensions. * * @note @c data will be referenced using the assigned matrix layout. */ - matrix(int rows, int cols, pointer data); + matrix(int rows, int cols, pointer data); - /** Construct from a wrapped pointer to a 2D array of values with + /** Construct from a wrapped pointer to a 2D array of values with * dimensions N1xN2. * * @note The dimensions of @c array must take the matrix layout into @@ -151,27 +142,26 @@ class matrix, BasisOrient, Layout> * the initializer for a column-major matrix will have dimensions N1xN2 * = [2][3]. */ - template matrix(Other (&array)[N1][N2]); + template matrix(Other (&array)[N1][N2]); - /** Move constructor. */ - matrix(matrix_type&& other); + /** Move constructor. */ + matrix(matrix_type&& other); public: + /** Return access to the matrix data as a raw pointer. */ + pointer data(); - /** Return access to the matrix data as a raw pointer. */ - pointer data(); + /** Return const access to the matrix data as a raw pointer. */ + const_pointer data() const; - /** Return const access to the matrix data as a raw pointer. */ - const_pointer data() const; + /** Read-only iterator over the elements as a 1D array. */ + const_pointer begin() const; - /** Read-only iterator over the elements as a 1D array. */ - const_pointer begin() const; + /** Read-only iterator over the elements as a 1D array. */ + const_pointer end() const; - /** Read-only iterator over the elements as a 1D array. */ - const_pointer end() const; - - /** Resize (reshape) the matrix to the specified size. + /** Resize (reshape) the matrix to the specified size. * * @note The existing elements are not changed. * @@ -180,122 +170,116 @@ class matrix, BasisOrient, Layout> * @throws matrix_size_error if the number of elements in the resized * matrix would be different from the original. */ - void resize(int rows, int cols); + void resize(int rows, int cols); - /** Reset the matrix to have no elements and no external pointer. */ - void reset(); + /** Reset the matrix to have no elements and no external pointer. */ + void reset(); public: + /** Copy assignment. */ + matrix_type& operator=(const matrix_type& other); - /** Copy assignment. */ - matrix_type& operator=(const matrix_type& other); - - /** Move assignment. */ - matrix_type& operator=(matrix_type&& other); + /** Move assignment. */ + matrix_type& operator=(matrix_type&& other); #ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline matrix_type& operator=(const readable_matrix& other) { - return this->assign(other); - } - - template* = nullptr> - inline matrix_type& operator=(const Array& array) { - return this->assign(array); - } - - template - inline matrix_type& operator=(Other const (&array)[Rows][Cols]) { - return this->assign(array); - } - - template - inline matrix_type& operator=(std::initializer_list l) { - return this->assign(l); - } + template + inline matrix_type& operator=(const readable_matrix& other) + { + return this->assign(other); + } + + template* = nullptr> + inline matrix_type& operator=(const Array& array) + { + return this->assign(array); + } + + template + inline matrix_type& operator=(Other const (&array)[Rows][Cols]) + { + return this->assign(array); + } + + template + inline matrix_type& operator=(std::initializer_list l) + { + return this->assign(l); + } #endif protected: + /** @name readable_matrix Interface */ + /*@{*/ - /** @name readable_matrix Interface */ - /*@{*/ + friend readable_type; - friend readable_type; + /** Return the number of rows. */ + int i_rows() const; - /** Return the number of rows. */ - int i_rows() const; + /** Return the number of columns. */ + int i_cols() const; - /** Return the number of columns. */ - int i_cols() const; + /** Return matrix const element @c (i,j). */ + immutable_value i_get(int i, int j) const; - /** Return matrix const element @c (i,j). */ - immutable_value i_get(int i, int j) const; - - /*@}*/ + /*@}*/ protected: + /** @name writeable_matrix Interface */ + /*@{*/ - /** @name writeable_matrix Interface */ - /*@{*/ - - friend writable_type; + friend writable_type; - /** Return matrix element @c (i,j). */ - mutable_value i_get(int i, int j); + /** Return matrix element @c (i,j). */ + mutable_value i_get(int i, int j); - /** Set element @c i. */ - template matrix_type& - i_put(int i, int j, const Other& v) __CML_REF; + /** Set element @c i. */ + template + matrix_type& i_put(int i, int j, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i on a temporary. */ - template matrix_type&& - i_put(int i, int j, const Other& v) &&; + /** Set element @c i on a temporary. */ + template matrix_type&& i_put(int i, int j, const Other& v) &&; #endif - /*@}*/ + /*@}*/ protected: - - /** Row-major access to const or non-const @c M. */ - template inline static auto s_access( - Matrix& M, int i, int j, row_major) -> decltype(M.m_data[0]) - { - return M.m_data[i*M.m_cols + j]; - } - - /** Column-major access to const or non-const @c M. */ - template inline static auto s_access( - Matrix& M, int i, int j, col_major) -> decltype(M.m_data[0]) - { - return M.m_data[j*M.m_rows + i]; - } - + /** Row-major access to const or non-const @c M. */ + template + inline static auto s_access(Matrix& M, int i, int j, row_major) + -> decltype(M.m_data[0]) + { + return M.m_data[i * M.m_cols + j]; + } + + /** Column-major access to const or non-const @c M. */ + template + inline static auto s_access(Matrix& M, int i, int j, col_major) + -> decltype(M.m_data[0]) + { + return M.m_data[j * M.m_rows + i]; + } protected: + /** Wrapped pointer. */ + pointer m_data; - /** Wrapped pointer. */ - pointer m_data; + /** Row count. */ + int m_rows; - /** Row count. */ - int m_rows; - - /** Column count. */ - int m_cols; + /** Column count. */ + int m_cols; }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_DYNAMIC_EXTERNAL_TPP #include #undef __CML_MATRIX_DYNAMIC_EXTERNAL_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/dynamic_external.tpp b/cml/matrix/dynamic_external.tpp index 89e781a..027b2a5 100644 --- a/cml/matrix/dynamic_external.tpp +++ b/cml/matrix/dynamic_external.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_DYNAMIC_EXTERNAL_TPP -#error "matrix/dynamic_external.tpp not included correctly" +# error "matrix/dynamic_external.tpp not included correctly" #endif namespace cml { @@ -14,7 +12,9 @@ namespace cml { template matrix, BO, L>::matrix() -: m_data(0), m_rows(0), m_cols(0) +: m_data(0) +, m_rows(0) +, m_cols(0) { #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS static_assert(false, "external matrix default constructor not supported"); @@ -23,7 +23,9 @@ matrix, BO, L>::matrix() template matrix, BO, L>::matrix(pointer data, int rows, int cols) -: m_data(data), m_rows(rows), m_cols(cols) +: m_data(data) +, m_rows(rows) +, m_cols(cols) { cml_require(rows >= 0, std::invalid_argument, "rows < 0"); cml_require(cols >= 0, std::invalid_argument, "cols < 0"); @@ -31,7 +33,9 @@ matrix, BO, L>::matrix(pointer data, int rows, int cols) template matrix, BO, L>::matrix(int rows, int cols, pointer data) -: m_data(data), m_rows(rows), m_cols(cols) +: m_data(data) +, m_rows(rows) +, m_cols(cols) { cml_require(rows >= 0, std::invalid_argument, "rows < 0"); cml_require(cols >= 0, std::invalid_argument, "cols < 0"); @@ -43,8 +47,7 @@ matrix, BO, L>::matrix(Other (&array)[N1][N2]) : m_data(&array[0][0]) , m_rows(array_layout == row_major_c ? N1 : N2) , m_cols(array_layout == row_major_c ? N2 : N1) -{ -} +{} template matrix, BO, L>::matrix(matrix_type&& other) @@ -52,63 +55,66 @@ matrix, BO, L>::matrix(matrix_type&& other) this->operator=(std::move(other)); } - - - /* Public methods: */ -template auto +template +auto matrix, BO, L>::data() -> pointer { return this->m_data; } -template auto +template +auto matrix, BO, L>::data() const -> const_pointer { return this->m_data; } -template auto +template +auto matrix, BO, L>::begin() const -> const_pointer { return this->m_data; } -template auto +template +auto matrix, BO, L>::end() const -> const_pointer { - return this->m_data + this->m_rows*this->m_cols; + return this->m_data + this->m_rows * this->m_cols; } -template void +template +void matrix, BO, L>::resize(int rows, int cols) { cml_require(rows >= 0, std::invalid_argument, "rows < 0"); cml_require(cols >= 0, std::invalid_argument, "cols < 0"); - cml::check_linear_size(*this, rows*cols); + cml::check_linear_size(*this, rows * cols); this->m_rows = rows; this->m_cols = cols; } -template void +template +void matrix, BO, L>::reset() { this->m_rows = this->m_cols = 0; this->m_data = nullptr; } - -template auto +template +auto matrix, BO, L>::operator=(const matrix_type& other) --> matrix_type& + -> matrix_type& { return this->assign(other); } -template auto -matrix, BO, L>::operator=(matrix_type&& other) --> matrix_type& +template +auto +matrix, BO, L>::operator=(matrix_type&& other) -> matrix_type& { this->m_data = other.m_data; this->m_rows = other.m_rows; @@ -119,43 +125,45 @@ matrix, BO, L>::operator=(matrix_type&& other) return *this; } - - /* Internal methods: */ /* readable_matrix interface: */ -template int +template +int matrix, BO, L>::i_rows() const { return this->m_rows; } -template int +template +int matrix, BO, L>::i_cols() const { return this->m_cols; } -template auto +template +auto matrix, BO, L>::i_get(int i, int j) const -> immutable_value { return s_access(*this, i, j, layout_tag()); } - /* writable_matrix interface: */ -template auto +template +auto matrix, BO, L>::i_get(int i, int j) -> mutable_value { return s_access(*this, i, j, layout_tag()); } template -template auto matrix, BO, L>::i_put( - int i, int j, const Other& v - ) __CML_REF -> matrix_type& +template +auto +matrix, BO, L>::i_put(int i, int j, + const Other& v) __CML_REF->matrix_type& { s_access(*this, i, j, layout_tag()) = value_type(v); return *this; @@ -163,16 +171,14 @@ template auto matrix, BO, L>::i_put( #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template auto matrix, BO, L>::i_put( - int i, int j, const Other& v - ) && -> matrix_type&& +template +auto +matrix, BO, L>::i_put(int i, int j, + const Other& v) && -> matrix_type&& { s_access(*this, i, j, layout_tag()) = value_type(v); return (matrix_type&&) *this; } #endif -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/external.h b/cml/matrix/external.h index 9e6041c..680cb1f 100644 --- a/cml/matrix/external.h +++ b/cml/matrix/external.h @@ -1,18 +1,8 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_external_h -#define cml_matrix_external_h - #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/fixed.h b/cml/matrix/fixed.h index abe16bf..526bb8e 100644 --- a/cml/matrix/fixed.h +++ b/cml/matrix/fixed.h @@ -1,17 +1,7 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_fixed_h -#define cml_matrix_fixed_h - #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/fixed_compiled.h b/cml/matrix/fixed_compiled.h index 1193ae7..59b3f82 100644 --- a/cml/matrix/fixed_compiled.h +++ b/cml/matrix/fixed_compiled.h @@ -1,41 +1,37 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_fixed_compiled_h -#define cml_matrix_fixed_compiled_h - #include #include #include namespace cml { -template -struct matrix_traits< matrix, BasisOrient, Layout> > +template +struct matrix_traits, BasisOrient, Layout>> { /* The basis must be col_basis or row_basis: */ - static_assert(std::is_same::value - || std::is_same::value, "invalid basis"); + static_assert(std::is_same::value + || std::is_same::value, + "invalid basis"); /* Traits and types for the matrix element: */ - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef typename element_traits::pointer pointer; - typedef typename element_traits::reference reference; - typedef typename element_traits::const_pointer const_pointer; - typedef typename element_traits::const_reference const_reference; - typedef typename element_traits::mutable_value mutable_value; - typedef typename element_traits::immutable_value immutable_value; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using pointer = typename element_traits::pointer; + using reference = typename element_traits::reference; + using const_pointer = typename element_traits::const_pointer; + using const_reference = typename element_traits::const_reference; + using mutable_value = typename element_traits::mutable_value; + using immutable_value = typename element_traits::immutable_value; /* The matrix storage type: */ - typedef rebind_t, matrix_storage_tag> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = rebind_t, matrix_storage_tag>; + using size_tag = typename storage_type::size_tag; static_assert(std::is_same::value, "invalid size tag"); @@ -48,10 +44,10 @@ struct matrix_traits< matrix, BasisOrient, Layout> > static_assert(array_cols > 0, "invalid column size"); /* Basis orientation: */ - typedef BasisOrient basis_tag; + using basis_tag = BasisOrient; /* Layout: */ - typedef Layout layout_tag; + using layout_tag = Layout; /** Constant containing the matrix basis enumeration value. */ static const basis_kind matrix_basis = basis_tag::value; @@ -61,234 +57,222 @@ struct matrix_traits< matrix, BasisOrient, Layout> > }; /** Fixed-size matrix. */ -template -class matrix, BasisOrient, Layout> +template +class matrix, BasisOrient, Layout> : public writable_matrix< - matrix, BasisOrient, Layout>> + matrix, BasisOrient, Layout>> { public: - - typedef matrix, BasisOrient, Layout> matrix_type; - typedef readable_matrix readable_type; - typedef writable_matrix writable_type; - typedef matrix_traits traits_type; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::pointer pointer; - typedef typename traits_type::reference reference; - typedef typename traits_type::const_pointer const_pointer; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using matrix_type = matrix, BasisOrient, Layout>; + using readable_type = readable_matrix; + using writable_type = writable_matrix; + using traits_type = matrix_traits; + using storage_type = typename traits_type::storage_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using pointer = typename traits_type::pointer; + using reference = typename traits_type::reference; + using const_pointer = typename traits_type::const_pointer; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; + using immutable_value = typename traits_type::immutable_value; + using size_tag = typename traits_type::size_tag; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; public: - - /* Include methods from writable_matrix: */ - using writable_type::operator(); + /* Include methods from writable_matrix: */ + using writable_type::operator(); #ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - using writable_type::operator=; + using writable_type::operator=; #endif public: + /** Constant containing the number of rows. */ + static const int array_rows = traits_type::array_rows; - /** Constant containing the number of rows. */ - static const int array_rows = traits_type::array_rows; + /** Constant containing the number of columns. */ + static const int array_cols = traits_type::array_cols; - /** Constant containing the number of columns. */ - static const int array_cols = traits_type::array_cols; - - /** Constant containing the matrix basis enumeration value. */ - static const basis_kind matrix_basis = traits_type::matrix_basis; + /** Constant containing the matrix basis enumeration value. */ + static const basis_kind matrix_basis = traits_type::matrix_basis; - /** Constant containing the array layout enumeration value. */ - static const layout_kind array_layout = traits_type::array_layout; + /** Constant containing the array layout enumeration value. */ + static const layout_kind array_layout = traits_type::array_layout; public: - - /** Compiler-default constructor. + /** Compiler-default constructor. * * @note The matrix elements are uninitialized. */ - matrix() = default; + matrix() = default; - /** Compiler-default destructor. */ - ~matrix() = default; + /** Compiler-default destructor. */ + ~matrix() = default; - /** Compiler-default copy constructor. */ - matrix(const matrix_type& other) = default; + /** Compiler-default copy constructor. */ + matrix(const matrix_type& other) = default; #ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR - /** Compiler-default move constructor. */ - matrix(matrix_type&& other) = default; + /** Compiler-default move constructor. */ + matrix(matrix_type&& other) = default; #endif - /** Construct from a readable_matrix. */ - template matrix(const readable_matrix& sub); + /** Construct from a readable_matrix. */ + template matrix(const readable_matrix& sub); - /** Construct from at least 1 value. + /** Construct from at least 1 value. * * @note This overload is enabled only if all of the arguments are * convertible to value_type. */ - template::type* = nullptr> - matrix(const E0& e0, const Elements&... eN) - // XXX Should be in matrix/fixed.tpp, but VC++12 has brain-dead - // out-of-line template argument matching... - { - this->assign_elements(e0, eN...); - } + template::type* = + nullptr> + matrix(const E0& e0, const Elements&... eN) + // XXX Should be in matrix/fixed.tpp, but VC++12 has brain-dead + // out-of-line template argument matching... + { + this->assign_elements(e0, eN...); + } - /** Construct from an array type. */ - template* = nullptr> - matrix(const Array& array); + /** Construct from an array type. */ + template* = nullptr> + matrix(const Array& array); - /** Construct from a C-array type. */ - template - matrix(Other const (&array)[Rows2][Cols2]); + /** Construct from a C-array type. */ + template + matrix(Other const (&array)[Rows2][Cols2]); - /** Construct from a pointer to an array. */ - template* = nullptr> - matrix(const Pointer& array); + /** Construct from a pointer to an array. */ + template* = nullptr> + matrix(const Pointer& array); - /** Construct from std::initializer_list. */ - template matrix(std::initializer_list l); + /** Construct from std::initializer_list. */ + template matrix(std::initializer_list l); public: + /** Return access to the matrix data as a raw pointer. */ + pointer data(); - /** Return access to the matrix data as a raw pointer. */ - pointer data(); + /** Return const access to the matrix data as a raw pointer. */ + const_pointer data() const; - /** Return const access to the matrix data as a raw pointer. */ - const_pointer data() const; + /** Read-only iterator over the elements as a 1D array. */ + const_pointer begin() const; - /** Read-only iterator over the elements as a 1D array. */ - const_pointer begin() const; - - /** Read-only iterator over the elements as a 1D array. */ - const_pointer end() const; + /** Read-only iterator over the elements as a 1D array. */ + const_pointer end() const; public: + /** Copy assignment. */ + matrix_type& operator=(const matrix_type& other); - /** Copy assignment. */ - matrix_type& operator=(const matrix_type& other); - - /** Move assignment. */ - matrix_type& operator=(matrix_type&& other); + /** Move assignment. */ + matrix_type& operator=(matrix_type&& other); #ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline matrix_type& operator=(const readable_matrix& other) { - return this->assign(other); - } - - template* = nullptr> - inline matrix_type& operator=(const Array& array) { - return this->assign(array); - } - - template - inline matrix_type& operator=(Other const (&array)[Rows][Cols]) { - return this->assign(array); - } - - template - inline matrix_type& operator=(std::initializer_list l) { - return this->assign(l); - } + template + inline matrix_type& operator=(const readable_matrix& other) + { + return this->assign(other); + } + + template* = nullptr> + inline matrix_type& operator=(const Array& array) + { + return this->assign(array); + } + + template + inline matrix_type& operator=(Other const (&array)[Rows][Cols]) + { + return this->assign(array); + } + + template + inline matrix_type& operator=(std::initializer_list l) + { + return this->assign(l); + } #endif protected: + /** @name readable_matrix Interface */ + /*@{*/ - /** @name readable_matrix Interface */ - /*@{*/ + friend readable_type; - friend readable_type; + /** Return the number of rows. */ + int i_rows() const; - /** Return the number of rows. */ - int i_rows() const; + /** Return the number of columns. */ + int i_cols() const; - /** Return the number of columns. */ - int i_cols() const; + /** Return matrix const element @c (i,j). */ + immutable_value i_get(int i, int j) const; - /** Return matrix const element @c (i,j). */ - immutable_value i_get(int i, int j) const; - - /*@}*/ + /*@}*/ protected: + /** @name writeable_matrix Interface */ + /*@{*/ - /** @name writeable_matrix Interface */ - /*@{*/ - - friend writable_type; + friend writable_type; - /** Return matrix element @c (i,j). */ - mutable_value i_get(int i, int j); + /** Return matrix element @c (i,j). */ + mutable_value i_get(int i, int j); - /** Set element @c i. */ - template matrix_type& - i_put(int i, int j, const Other& v) __CML_REF; + /** Set element @c i. */ + template + matrix_type& i_put(int i, int j, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i on a temporary. */ - template matrix_type&& - i_put(int i, int j, const Other& v) &&; + /** Set element @c i on a temporary. */ + template matrix_type&& i_put(int i, int j, const Other& v) &&; #endif - /*@}*/ + /*@}*/ protected: - - /** Row-major access to const or non-const @c M. */ - template inline static auto s_access( - Matrix& M, int i, int j, row_major) -> decltype(M.m_data[0][0]) - { - return M.m_data[i][j]; - } - - /** Column-major access to const or non-const @c M. */ - template inline static auto s_access( - Matrix& M, int i, int j, col_major) -> decltype(M.m_data[0][0]) - { - return M.m_data[j][i]; - } + /** Row-major access to const or non-const @c M. */ + template + inline static auto s_access(Matrix& M, int i, int j, row_major) + -> decltype(M.m_data[0][0]) + { + return M.m_data[i][j]; + } + + /** Column-major access to const or non-const @c M. */ + template + inline static auto s_access(Matrix& M, int i, int j, col_major) + -> decltype(M.m_data[0][0]) + { + return M.m_data[j][i]; + } protected: + /** The matrix data type, depending upon the layout. */ + using matrix_data_type = if_t; - /** The matrix data type, depending upon the layout. */ - typedef if_t matrix_data_type; - - /** Fixed-size array, based on the layout. */ - matrix_data_type m_data; + /** Fixed-size array, based on the layout. */ + matrix_data_type m_data; }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_FIXED_COMPILED_TPP #include #undef __CML_MATRIX_FIXED_COMPILED_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/fixed_compiled.tpp b/cml/matrix/fixed_compiled.tpp index 67c0a7b..99e8342 100644 --- a/cml/matrix/fixed_compiled.tpp +++ b/cml/matrix/fixed_compiled.tpp @@ -1,134 +1,138 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_FIXED_COMPILED_TPP -#error "matrix/fixed_compiled.tpp not included correctly" +# error "matrix/fixed_compiled.tpp not included correctly" #endif namespace cml { /* fixed 'structors: */ -template template -matrix, BO, L>::matrix(const readable_matrix& sub) +template +template +matrix, BO, L>::matrix(const readable_matrix& sub) { this->assign(sub); } template template*> -matrix, BO, L>::matrix(const Array& array) +matrix, BO, L>::matrix(const Array& array) { this->assign(array); } template template -matrix, BO, L>::matrix(Other const (&array)[R2][C2]) +matrix, BO, L>::matrix(Other const (&array)[R2][C2]) { this->assign(array); } template template*> -matrix, BO, L>::matrix(const Pointer& array) +matrix, BO, L>::matrix(const Pointer& array) { this->assign(array); } -template template -matrix, BO, L>::matrix(std::initializer_list l) +template +template +matrix, BO, L>::matrix(std::initializer_list l) { this->assign(l); } - - /* Public methods: */ -template auto -matrix, BO, L>::data() -> pointer +template +auto +matrix, BO, L>::data() -> pointer { return &this->m_data[0][0]; } -template auto -matrix, BO, L>::data() const -> const_pointer +template +auto +matrix, BO, L>::data() const -> const_pointer { return &this->m_data[0][0]; } -template auto -matrix, BO, L>::begin() const -> const_pointer +template +auto +matrix, BO, L>::begin() const -> const_pointer { return &this->m_data[0][0]; } -template auto -matrix, BO, L>::end() const -> const_pointer +template +auto +matrix, BO, L>::end() const -> const_pointer { - return (&this->m_data[0][0]) + R*C; + return (&this->m_data[0][0]) + R * C; } - -template auto -matrix, BO, L>::operator=(const matrix_type& other) --> matrix_type& +template +auto +matrix, BO, L>::operator=(const matrix_type& other) + -> matrix_type& { return this->assign(other); } -template auto -matrix, BO, L>::operator=(matrix_type&& other) --> matrix_type& +template +auto +matrix, BO, L>::operator=(matrix_type&& other) -> matrix_type& { - for(int i = 0; i < R; ++ i) - for(int j = 0; j < C; ++ j) + for(int i = 0; i < R; ++i) + for(int j = 0; j < C; ++j) this->m_data[i][j] = std::move(other.m_data[i][j]); /* Note: the layout doesn't matter here. */ return *this; } - - /* Internal methods: */ /* readable_matrix interface: */ -template int -matrix, BO, L>::i_rows() const +template +int +matrix, BO, L>::i_rows() const { return R; } -template int -matrix, BO, L>::i_cols() const +template +int +matrix, BO, L>::i_cols() const { return C; } -template auto -matrix, BO, L>::i_get(int i, int j) const -> immutable_value +template +auto +matrix, BO, L>::i_get(int i, int j) const -> immutable_value { return s_access(*this, i, j, layout_tag()); } - /* writable_matrix interface: */ -template auto -matrix, BO, L>::i_get(int i, int j) -> mutable_value +template +auto +matrix, BO, L>::i_get(int i, int j) -> mutable_value { return s_access(*this, i, j, layout_tag()); } template -template auto matrix, BO, L>::i_put( - int i, int j, const Other& v - ) __CML_REF -> matrix_type& +template +auto +matrix, BO, L>::i_put(int i, int j, + const Other& v) __CML_REF->matrix_type& { s_access(*this, i, j, layout_tag()) = value_type(v); return *this; @@ -136,16 +140,14 @@ template auto matrix, BO, L>::i_put( #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template auto matrix, BO, L>::i_put( - int i, int j, const Other& v - ) && -> matrix_type&& +template +auto +matrix, BO, L>::i_put(int i, int j, + const Other& v) && -> matrix_type&& { s_access(*this, i, j, layout_tag()) = value_type(v); return (matrix_type&&) *this; } #endif -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/fixed_external.h b/cml/matrix/fixed_external.h index b4aa444..a444b06 100644 --- a/cml/matrix/fixed_external.h +++ b/cml/matrix/fixed_external.h @@ -1,42 +1,37 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_fixed_external_h -#define cml_matrix_fixed_external_h - #include #include #include namespace cml { -template -struct matrix_traits< - matrix, BasisOrient, Layout> > +template +struct matrix_traits, BasisOrient, Layout>> { /* The basis must be col_basis or row_basis: */ - static_assert(std::is_same::value - || std::is_same::value, "invalid basis"); + static_assert(std::is_same::value + || std::is_same::value, + "invalid basis"); /* Traits and types for the matrix element: */ - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef typename element_traits::pointer pointer; - typedef typename element_traits::reference reference; - typedef typename element_traits::const_pointer const_pointer; - typedef typename element_traits::const_reference const_reference; - typedef typename element_traits::mutable_value mutable_value; - typedef typename element_traits::immutable_value immutable_value; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using pointer = typename element_traits::pointer; + using reference = typename element_traits::reference; + using const_pointer = typename element_traits::const_pointer; + using const_reference = typename element_traits::const_reference; + using mutable_value = typename element_traits::mutable_value; + using immutable_value = typename element_traits::immutable_value; /* The matrix storage type: */ - typedef rebind_t, matrix_storage_tag> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = rebind_t, matrix_storage_tag>; + using size_tag = typename storage_type::size_tag; static_assert(std::is_same::value, "invalid size tag"); @@ -49,10 +44,10 @@ struct matrix_traits< static_assert(array_cols > 0, "invalid column size"); /* Basis orientation: */ - typedef BasisOrient basis_tag; + using basis_tag = BasisOrient; /* Layout: */ - typedef Layout layout_tag; + using layout_tag = Layout; /** Constant containing the matrix basis enumeration value. */ static const basis_kind matrix_basis = basis_tag::value; @@ -62,81 +57,74 @@ struct matrix_traits< }; /** Fixed-size matrix. */ -template -class matrix, BasisOrient, Layout> +template +class matrix, BasisOrient, Layout> : public writable_matrix< - matrix, BasisOrient, Layout>> + matrix, BasisOrient, Layout>> { public: - - typedef matrix, BasisOrient, Layout> matrix_type; - typedef readable_matrix readable_type; - typedef writable_matrix writable_type; - typedef matrix_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::pointer pointer; - typedef typename traits_type::reference reference; - typedef typename traits_type::const_pointer const_pointer; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using matrix_type = matrix, BasisOrient, Layout>; + using readable_type = readable_matrix; + using writable_type = writable_matrix; + using traits_type = matrix_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using pointer = typename traits_type::pointer; + using reference = typename traits_type::reference; + using const_pointer = typename traits_type::const_pointer; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; public: - - /** The matrix data type, depending upon the layout. */ - typedef if_t matrix_data_type; + /** The matrix data type, depending upon the layout. */ + using matrix_data_type = if_t; public: - - /* Include methods from writable_type: */ - using writable_type::operator(); + /* Include methods from writable_type: */ + using writable_type::operator(); #ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - using writable_type::operator=; + using writable_type::operator=; #endif public: + /** Constant containing the number of rows. */ + static const int array_rows = traits_type::array_rows; - /** Constant containing the number of rows. */ - static const int array_rows = traits_type::array_rows; - - /** Constant containing the number of columns. */ - static const int array_cols = traits_type::array_cols; + /** Constant containing the number of columns. */ + static const int array_cols = traits_type::array_cols; - /** Constant containing the matrix basis enumeration value. */ - static const basis_kind matrix_basis = traits_type::matrix_basis; + /** Constant containing the matrix basis enumeration value. */ + static const basis_kind matrix_basis = traits_type::matrix_basis; - /** Constant containing the array layout enumeration value. */ - static const layout_kind array_layout = traits_type::array_layout; + /** Constant containing the array layout enumeration value. */ + static const layout_kind array_layout = traits_type::array_layout; public: - - /** Default construct with a null pointer. + /** Default construct with a null pointer. * * @warning The default constructor is enabled only if the compiler * supports rvalue references from *this. */ - matrix(); + matrix(); - /** Construct from the wrapped pointer. + /** Construct from the wrapped pointer. * * @note @c data will be referenced using the assigned matrix layout. */ - explicit matrix(pointer data); + explicit matrix(pointer data); - /** Construct from a wrapped pointer to a 2D array of values. + /** Construct from a wrapped pointer to a 2D array of values. * * @note The dimensions of @c array must match those of the matrix, * taking the matrix layout into account. For example, the C-array @@ -144,130 +132,124 @@ class matrix, BasisOrient, Layout> * dimensions [3][2], but the initializer for a column-major matrix * will have dimensions [2][3]. */ - matrix(matrix_data_type& array); + matrix(matrix_data_type& array); - /** Move constructor. */ - matrix(matrix_type&& other); + /** Move constructor. */ + matrix(matrix_type&& other); public: + /** Return access to the matrix data as a raw pointer. */ + pointer data(); - /** Return access to the matrix data as a raw pointer. */ - pointer data(); - - /** Return const access to the matrix data as a raw pointer. */ - const_pointer data() const; + /** Return const access to the matrix data as a raw pointer. */ + const_pointer data() const; - /** Read-only iterator over the elements as a 1D array. */ - const_pointer begin() const; + /** Read-only iterator over the elements as a 1D array. */ + const_pointer begin() const; - /** Read-only iterator over the elements as a 1D array. */ - const_pointer end() const; + /** Read-only iterator over the elements as a 1D array. */ + const_pointer end() const; public: + /** Copy assignment. */ + matrix_type& operator=(const matrix_type& other); - /** Copy assignment. */ - matrix_type& operator=(const matrix_type& other); - - /** Move assignment. */ - matrix_type& operator=(matrix_type&& other); + /** Move assignment. */ + matrix_type& operator=(matrix_type&& other); #ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline matrix_type& operator=(const readable_matrix& other) { - return this->assign(other); - } - - template* = nullptr> - inline matrix_type& operator=(const Array& array) { - return this->assign(array); - } - - template - inline matrix_type& operator=(Other const (&array)[Rows][Cols]) { - return this->assign(array); - } - - template - inline matrix_type& operator=(std::initializer_list l) { - return this->assign(l); - } + template + inline matrix_type& operator=(const readable_matrix& other) + { + return this->assign(other); + } + + template* = nullptr> + inline matrix_type& operator=(const Array& array) + { + return this->assign(array); + } + + template + inline matrix_type& operator=(Other const (&array)[Rows][Cols]) + { + return this->assign(array); + } + + template + inline matrix_type& operator=(std::initializer_list l) + { + return this->assign(l); + } #endif protected: + /** @name readable_matrix Interface */ + /*@{*/ - /** @name readable_matrix Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the number of rows. */ - int i_rows() const; + /** Return the number of rows. */ + int i_rows() const; - /** Return the number of columns. */ - int i_cols() const; + /** Return the number of columns. */ + int i_cols() const; - /** Return matrix const element @c (i,j). */ - immutable_value i_get(int i, int j) const; + /** Return matrix const element @c (i,j). */ + immutable_value i_get(int i, int j) const; - /*@}*/ + /*@}*/ protected: + /** @name writeable_matrix Interface */ + /*@{*/ - /** @name writeable_matrix Interface */ - /*@{*/ - - friend writable_type; + friend writable_type; - /** Return matrix element @c (i,j). */ - mutable_value i_get(int i, int j); + /** Return matrix element @c (i,j). */ + mutable_value i_get(int i, int j); - /** Set element @c i. */ - template matrix_type& - i_put(int i, int j, const Other& v) __CML_REF; + /** Set element @c i. */ + template + matrix_type& i_put(int i, int j, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i on a temporary. */ - template matrix_type&& - i_put(int i, int j, const Other& v) &&; + /** Set element @c i on a temporary. */ + template matrix_type&& i_put(int i, int j, const Other& v) &&; #endif - /*@}*/ + /*@}*/ protected: - - /** Row-major access to const or non-const @c M. */ - template inline static auto s_access( - Matrix& M, int i, int j, row_major) -> decltype((*M.m_data)[0][0]) - { - return (*M.m_data)[i][j]; - } - - /** Column-major access to const or non-const @c M. */ - template inline static auto s_access( - Matrix& M, int i, int j, col_major) -> decltype((*M.m_data)[0][0]) - { - return (*M.m_data)[j][i]; - } + /** Row-major access to const or non-const @c M. */ + template + inline static auto s_access(Matrix& M, int i, int j, row_major) + -> decltype((*M.m_data)[0][0]) + { + return (*M.m_data)[i][j]; + } + + /** Column-major access to const or non-const @c M. */ + template + inline static auto s_access(Matrix& M, int i, int j, col_major) + -> decltype((*M.m_data)[0][0]) + { + return (*M.m_data)[j][i]; + } protected: - - /** Wrapped pointer. */ - matrix_data_type* m_data; + /** Wrapped pointer. */ + matrix_data_type* m_data; }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_FIXED_EXTERNAL_TPP #include #undef __CML_MATRIX_FIXED_EXTERNAL_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/fixed_external.tpp b/cml/matrix/fixed_external.tpp index 57ebf9d..5023940 100644 --- a/cml/matrix/fixed_external.tpp +++ b/cml/matrix/fixed_external.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_FIXED_EXTERNAL_TPP -#error "matrix/fixed_external.tpp not included correctly" +# error "matrix/fixed_external.tpp not included correctly" #endif namespace cml { @@ -13,7 +11,7 @@ namespace cml { /* fixed_external 'structors: */ template -matrix, BO, L>::matrix() +matrix, BO, L>::matrix() : m_data(0) { #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS @@ -22,105 +20,107 @@ matrix, BO, L>::matrix() } template -matrix, BO, L>::matrix(pointer data) +matrix, BO, L>::matrix(pointer data) : m_data(reinterpret_cast(data)) -{ -} +{} template -matrix, BO, L>::matrix(matrix_data_type& array) +matrix, BO, L>::matrix(matrix_data_type& array) : m_data(&array) -{ -} +{} template -matrix, BO, L>::matrix(matrix_type&& other) +matrix, BO, L>::matrix(matrix_type&& other) { this->operator=(std::move(other)); } - - - /* Public methods: */ -template auto -matrix, BO, L>::data() -> pointer +template +auto +matrix, BO, L>::data() -> pointer { return reinterpret_cast(this->m_data); } -template auto -matrix, BO, L>::data() const -> const_pointer +template +auto +matrix, BO, L>::data() const -> const_pointer { return reinterpret_cast(this->m_data); } -template auto -matrix, BO, L>::begin() const -> const_pointer +template +auto +matrix, BO, L>::begin() const -> const_pointer { return reinterpret_cast(this->m_data); } -template auto -matrix, BO, L>::end() const -> const_pointer +template +auto +matrix, BO, L>::end() const -> const_pointer { - return reinterpret_cast(this->m_data) + R*C; + return reinterpret_cast(this->m_data) + R * C; } - -template auto -matrix, BO, L>::operator=(const matrix_type& other) --> matrix_type& +template +auto +matrix, BO, L>::operator=(const matrix_type& other) + -> matrix_type& { return this->assign(other); } -template auto -matrix, BO, L>::operator=(matrix_type&& other) --> matrix_type& +template +auto +matrix, BO, L>::operator=(matrix_type&& other) -> matrix_type& { this->m_data = other.m_data; other.m_data = nullptr; return *this; } - /* Internal methods: */ /* readable_matrix interface: */ -template int -matrix, BO, L>::i_rows() const +template +int +matrix, BO, L>::i_rows() const { return R; } -template int -matrix, BO, L>::i_cols() const +template +int +matrix, BO, L>::i_cols() const { return C; } -template auto -matrix, BO, L>::i_get(int i, int j) const -> immutable_value +template +auto +matrix, BO, L>::i_get(int i, int j) const -> immutable_value { return s_access(*this, i, j, layout_tag()); } - /* writable_matrix interface: */ -template auto -matrix, BO, L>::i_get(int i, int j) -> mutable_value +template +auto +matrix, BO, L>::i_get(int i, int j) -> mutable_value { return s_access(*this, i, j, layout_tag()); } template -template auto matrix, BO, L>::i_put( - int i, int j, const Other& v - ) __CML_REF -> matrix_type& +template +auto +matrix, BO, L>::i_put(int i, int j, + const Other& v) __CML_REF->matrix_type& { s_access(*this, i, j, layout_tag()) = value_type(v); return *this; @@ -128,16 +128,14 @@ template auto matrix, BO, L>::i_put( #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template auto matrix, BO, L>::i_put( - int i, int j, const Other& v - ) && -> matrix_type&& +template +auto +matrix, BO, L>::i_put(int i, int j, + const Other& v) && -> matrix_type&& { s_access(*this, i, j, layout_tag()) = value_type(v); return (matrix_type&&) *this; } #endif -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/functions.h b/cml/matrix/functions.h index f1eb945..8b76b33 100644 --- a/cml/matrix/functions.h +++ b/cml/matrix/functions.h @@ -1,21 +1,11 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_functions_h -#define cml_matrix_functions_h - #include #include #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/fwd.h b/cml/matrix/fwd.h index 5f8ffc4..44b60b1 100644 --- a/cml/matrix/fwd.h +++ b/cml/matrix/fwd.h @@ -1,22 +1,12 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_fwd_h -#define cml_matrix_fwd_h - namespace cml { template class readable_matrix; template class writable_matrix; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/hadamard_product.h b/cml/matrix/hadamard_product.h index 3b93d01..c9e9c8c 100644 --- a/cml/matrix/hadamard_product.h +++ b/cml/matrix/hadamard_product.h @@ -1,32 +1,23 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_hadamard_product_h -#define cml_matrix_hadamard_product_h - #include namespace cml { /** Elementwise (Hadamard) product of two matrixs. */ -template* = nullptr, enable_if_matrix_t* = nullptr> -inline auto hadamard(Sub1&& sub1, Sub2&& sub2) --> decltype(make_matrix_binary_node>( +template* = nullptr, + enable_if_matrix_t* = nullptr> +inline auto +hadamard(Sub1&& sub1, Sub2&& sub2) + -> decltype(make_matrix_binary_node>( std::forward(sub1), std::forward(sub2))) { - return make_matrix_binary_node> - (std::forward(sub1), std::forward(sub2)); + return make_matrix_binary_node>( + std::forward(sub1), std::forward(sub2)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/inverse.h b/cml/matrix/inverse.h index 0a148e1..cd2f82b 100644 --- a/cml/matrix/inverse.h +++ b/cml/matrix/inverse.h @@ -1,30 +1,21 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_inverse_h -#define cml_matrix_inverse_h - #include #include namespace cml { /** Compute the inverse of @c M and return the result in a temporary. */ -template inline temporary_of_t +template +inline temporary_of_t inverse(const readable_matrix& M) { cml::check_square(M); return temporary_of_t(M).inverse(); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/lu.h b/cml/matrix/lu.h index e1db816..61ef404 100644 --- a/cml/matrix/lu.h +++ b/cml/matrix/lu.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_lu_h -#define cml_matrix_lu_h - #include #include #include @@ -29,22 +24,28 @@ struct lu_pivot_result>> { static const int N = array_rows_of_c>::value; - Matrix lu; - std::array order; - int sign; + Matrix lu; + std::array order; + int sign; - explicit lu_pivot_result(const Matrix& M) : lu(M), order() {} + explicit lu_pivot_result(const Matrix& M) + : lu(M) + , order() + {} }; /** Results from partial-pivoting LU decomposition of a dynamic-size matrix. */ template struct lu_pivot_result>> { - Matrix lu; - std::vector order; - int sign; - - explicit lu_pivot_result(const Matrix& M) : lu(M), order(M.rows()) {} + Matrix lu; + std::vector order; + int sign; + + explicit lu_pivot_result(const Matrix& M) + : lu(M) + , order(M.rows()) + {} }; @@ -53,17 +54,16 @@ struct lu_pivot_result>> * * @note if @c result.sign is 0, the input matrix is singular. */ -template auto -lu_pivot(const readable_matrix& M) --> lu_pivot_result< temporary_of_t >; +template +auto lu_pivot(const readable_matrix& M) + -> lu_pivot_result>; /** In-place computation of the partial-pivoting LU decomposition of @c * result.lu. * * @note if @c result.sign is 0, the input matrix is singular. */ -template void -lu_pivot(lu_pivot_result& result); +template void lu_pivot(lu_pivot_result& result); /** Compute the LU decomposition of @c M using Doolittle's method, * returning the result as a temporary matrix. @@ -73,8 +73,8 @@ lu_pivot(lu_pivot_result& result); * * @note This is for compatibility with CML1. */ -template auto -lu(const readable_matrix& M) -> temporary_of_t; +template +auto lu(const readable_matrix& M) -> temporary_of_t; /** Solve @c LUx = @c y for @c x, and return @c x as a temporary @@ -83,17 +83,17 @@ lu(const readable_matrix& M) -> temporary_of_t; * * @note This is for compatibility with CML1. */ -template auto -lu_solve(const readable_matrix& LU, const readable_vector& y) --> temporary_of_t; +template +auto lu_solve(const readable_matrix& LU, const readable_vector& y) + -> temporary_of_t; /** Solve @c LUx = @c b for @c x. @c LU must be a square LU * decomposition, and @c y and @c x must have the same number of elements * as @c LU has rows. */ -template void -lu_solve(const readable_matrix& LU, - writable_vector& x, const readable_vector& b); +template +void lu_solve(const readable_matrix& LU, writable_vector& x, + const readable_vector& b); /** Solve @c LUx = @c Pb for @c x, where the partial-pivot LU * decomposition is provided as lu_pivot_result, and @c x is returned as a @@ -102,9 +102,9 @@ lu_solve(const readable_matrix& LU, * * @throws std::invalid_argument @c lup.sign is 0. */ -template auto -lu_solve(const lu_pivot_result& lup, const readable_vector& b) --> temporary_of_t; +template +auto lu_solve(const lu_pivot_result& lup, + const readable_vector& b) -> temporary_of_t; /** Solve @c LUx = @c Pb for @c x, where the partial-pivot LU * decomposition is provided as lu_pivot_result. @c b and @c x must have @@ -114,17 +114,12 @@ lu_solve(const lu_pivot_result& lup, const readable_vector& b) * * @throws std::invalid_argument @c lup.sign is 0. */ -template void -lu_solve(const lu_pivot_result& lup, - writable_vector& x, const readable_vector& b); +template +void lu_solve(const lu_pivot_result& lup, writable_vector& x, + const readable_vector& b); -} // namespace cml +} // namespace cml #define __CML_MATRIX_LU_TPP #include #undef __CML_MATRIX_LU_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/lu.tpp b/cml/matrix/lu.tpp index a07c84f..108d358 100644 --- a/cml/matrix/lu.tpp +++ b/cml/matrix/lu.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_LU_TPP -#error "matrix/lu.tpp not included correctly" +# error "matrix/lu.tpp not included correctly" #endif #include @@ -14,9 +12,9 @@ namespace cml { -template inline auto -lu_pivot(const readable_matrix& M) --> lu_pivot_result< temporary_of_t > +template +inline auto +lu_pivot(const readable_matrix& M) -> lu_pivot_result> { cml::check_square(M); lu_pivot_result> result(M); @@ -24,14 +22,16 @@ lu_pivot(const readable_matrix& M) return result; } -template inline void +template +inline void lu_pivot(lu_pivot_result& result) { cml::check_square(result.lu); result.sign = detail::lu_pivot_inplace(result.lu, result.order); } -template inline auto +template +inline auto lu(const readable_matrix& M) -> temporary_of_t { cml::check_square(M); @@ -40,20 +40,23 @@ lu(const readable_matrix& M) -> temporary_of_t return LU; } -template inline auto +template +inline auto lu_solve(const readable_matrix& LU, const readable_vector& b) --> temporary_of_t + -> temporary_of_t { - temporary_of_t x; detail::check_or_resize(x, b); + temporary_of_t x; + detail::check_or_resize(x, b); lu_solve(LU, x, b); return x; } -template inline void -lu_solve(const readable_matrix& LU, - writable_vector& x, const readable_vector& b) +template +inline void +lu_solve(const readable_matrix& LU, writable_vector& x, + const readable_vector& b) { - typedef value_type_trait_of_t value_type; + using value_type = value_type_trait_of_t; cml::check_square(LU); cml::check_same_inner_size(LU, x); @@ -65,45 +68,48 @@ lu_solve(const readable_matrix& LU, * diagonal of LU correspond to L, understood to be below a diagonal of * 1's: */ - temporary_of_t y; detail::check_or_resize(y, b); - for(int i = 0; i < N; ++ i) { + temporary_of_t y; + detail::check_or_resize(y, b); + for(int i = 0; i < N; ++i) { value_type sum(0); - for(int j = 0; j < i; ++ j) sum += LU(i,j)*y[j]; + for(int j = 0; j < i; ++j) sum += LU(i, j) * y[j]; y[i] = b[i] - sum; } /* Solve Ux = y for x by backward substitution. The entries at and above * the diagonal of LU correspond to U: */ - for(int i = N-1; i >= 0; --i) { + for(int i = N - 1; i >= 0; --i) { value_type sum(0); - for(int j = i+1; j < N; ++j) sum += LU(i,j)*x[j]; - x[i] = (y[i] - sum)/LU(i,i); + for(int j = i + 1; j < N; ++j) sum += LU(i, j) * x[j]; + x[i] = (y[i] - sum) / LU(i, i); } /* Done. */ } - -template inline auto +template +inline auto lu_solve(const lu_pivot_result& lup, const readable_vector& b) --> temporary_of_t + -> temporary_of_t { - temporary_of_t x; detail::check_or_resize(x, b); + temporary_of_t x; + detail::check_or_resize(x, b); lu_solve(lup, x, b); return x; } -template inline void -lu_solve(const lu_pivot_result& lup, - writable_vector& x, const readable_vector& b) +template +inline void +lu_solve(const lu_pivot_result& lup, writable_vector& x, + const readable_vector& b) { - typedef value_type_trait_of_t value_type; + using value_type = value_type_trait_of_t; cml::check_same_inner_size(lup.lu, x); cml::check_same_inner_size(lup.lu, b); - cml_require(lup.sign != 0, - std::invalid_argument, "lup.sign == 0 (singular matrix?)"); + cml_require(lup.sign != 0, std::invalid_argument, + "lup.sign == 0 (singular matrix?)"); int N = b.size(); const auto& LU = lup.lu; @@ -113,26 +119,24 @@ lu_solve(const lu_pivot_result& lup, * diagonal of LU correspond to L, understood to be below a diagonal of * 1's: */ - temporary_of_t y; detail::check_or_resize(y, b); - for(int i = 0; i < N; ++ i) { + temporary_of_t y; + detail::check_or_resize(y, b); + for(int i = 0; i < N; ++i) { value_type sum(0); - for(int j = 0; j < i; ++ j) sum += LU(i,j)*y[j]; + for(int j = 0; j < i; ++j) sum += LU(i, j) * y[j]; y[i] = b[P[i]] - sum; } /* Solve Ux = c for x by backward substitution. The entries at and above * the diagonal of LU correspond to U: */ - for(int i = N-1; i >= 0; --i) { + for(int i = N - 1; i >= 0; --i) { value_type sum(0); - for(int j = i+1; j < N; ++j) sum += LU(i,j)*x[j]; - x[i] = (y[i] - sum)/LU(i,i); + for(int j = i + 1; j < N; ++j) sum += LU(i, j) * x[j]; + x[i] = (y[i] - sum) / LU(i, i); } /* Done. */ } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/matrix.h b/cml/matrix/matrix.h index 2e6befd..e934dfc 100644 --- a/cml/matrix/matrix.h +++ b/cml/matrix/matrix.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_matrix_h -#define cml_matrix_matrix_h - #include #include @@ -38,12 +33,8 @@ namespace cml { * * @sa scalar_traits */ -template class matrix; - -} // namespace cml - -#endif +template +class matrix; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/matrix_product.h b/cml/matrix/matrix_product.h index 1f831eb..44f2869 100644 --- a/cml/matrix/matrix_product.h +++ b/cml/matrix/matrix_product.h @@ -1,35 +1,23 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_matrix_product_h -#define cml_matrix_matrix_product_h - #include #include namespace cml { /** Multiply two matrices, and return the result as a temporary. */ -template* = nullptr, +template* = nullptr, enable_if_matrix_t* = nullptr> auto operator*(Sub1&& sub1, Sub2&& sub2) --> matrix_inner_product_promote_t< - actual_operand_type_of_t, - actual_operand_type_of_t>; + -> matrix_inner_product_promote_t, + actual_operand_type_of_t>; -} // namespace cml +} // namespace cml #define __CML_MATRIX_MATRIX_PRODUCT_TPP #include #undef __CML_MATRIX_MATRIX_PRODUCT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/matrix_product.tpp b/cml/matrix/matrix_product.tpp index 62a0c6c..959737b 100644 --- a/cml/matrix/matrix_product.tpp +++ b/cml/matrix/matrix_product.tpp @@ -1,43 +1,38 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_MATRIX_PRODUCT_TPP -#error "matrix/matrix_product.tpp not included correctly" +# error "matrix/matrix_product.tpp not included correctly" #endif #include namespace cml { -template*, enable_if_matrix_t*> -inline auto operator*(Sub1&& sub1, Sub2&& sub2) --> matrix_inner_product_promote_t< - actual_operand_type_of_t, - actual_operand_type_of_t> +template*, + enable_if_matrix_t*> +inline auto +operator*(Sub1&& sub1, Sub2&& sub2) + -> matrix_inner_product_promote_t, + actual_operand_type_of_t> { - typedef matrix_inner_product_promote_t< + using result_type = matrix_inner_product_promote_t< actual_operand_type_of_t, - actual_operand_type_of_t> result_type; + actual_operand_type_of_t>; cml::check_same_inner_size(sub1, sub2); result_type M; detail::resize(M, array_rows_of(sub1), array_cols_of(sub2)); - for(int i = 0; i < M.rows(); ++ i) { - for(int j = 0; j < M.cols(); ++ j) { - auto m = sub1(i,0) * sub2(0,j); - for(int k = 1; k < sub1.cols(); ++ k) m += sub1(i,k) * sub2(k,j); - M(i,j) = m; + for(int i = 0; i < M.rows(); ++i) { + for(int j = 0; j < M.cols(); ++j) { + auto m = sub1(i, 0) * sub2(0, j); + for(int k = 1; k < sub1.cols(); ++k) m += sub1(i, k) * sub2(k, j); + M(i, j) = m; } } return M; } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/ops.h b/cml/matrix/ops.h index 15d9656..610ce06 100644 --- a/cml/matrix/ops.h +++ b/cml/matrix/ops.h @@ -1,19 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_ops_h -#define cml_matrix_ops_h - #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/promotion.h b/cml/matrix/promotion.h index 579d4f4..271f7e3 100644 --- a/cml/matrix/promotion.h +++ b/cml/matrix/promotion.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_promotion_h -#define cml_matrix_promotion_h - #include #include #include @@ -27,106 +22,93 @@ namespace cml { * * @note This can be specialized to accomodate user-defined storage types. */ -template -struct matrix_binary_storage_promote +template struct matrix_binary_storage_promote { static_assert( - is_matrix_storage::value && - is_matrix_storage::value, + is_matrix_storage::value && is_matrix_storage::value, "expected matrix storage types for binary promotion"); /* Determine the common unbound storage type: */ - typedef storage_promote_t unbound_type; + using unbound_type = storage_promote_t; /* Determine the new row size: */ - static const int array_rows - = Storage1::array_rows > Storage2::array_rows - ? Storage1::array_rows : Storage2::array_rows; + static const int array_rows = Storage1::array_rows > Storage2::array_rows + ? Storage1::array_rows + : Storage2::array_rows; /* Determine the new column size: */ - static const int array_cols - = Storage1::array_cols > Storage2::array_cols - ? Storage1::array_cols : Storage2::array_cols; + static const int array_cols = Storage1::array_cols > Storage2::array_cols + ? Storage1::array_cols + : Storage2::array_cols; /* Resize: */ - typedef reshape_storage_t< - unbound_type, array_rows, array_cols> resized_type; + using resized_type = reshape_storage_t; /* Rebind to a matrix storage type: */ - typedef rebind_matrix_storage_t type; + using type = rebind_matrix_storage_t; }; /** Convenience alias for matrix_binary_storage_promote. */ template - using matrix_binary_storage_promote_t = - typename matrix_binary_storage_promote::type; +using matrix_binary_storage_promote_t = + typename matrix_binary_storage_promote::type; /** Specializable class to determine a temporary type that can store the * result of matrix/matrix or matrix/vector products. */ template - struct matrix_inner_product_promote; +struct matrix_inner_product_promote; /** Determine a matrix temporary type that can hold the result of * multiplying two matrix expressions @c Sub1 and @c Sub2. */ template struct matrix_inner_product_promote::value && is_matrix::value>::type - > + typename std::enable_if::value + && is_matrix::value>::type> { - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef matrix_traits left_traits; - typedef matrix_traits right_traits; - typedef value_type_of_t left_value_type; - typedef value_type_of_t right_value_type; - typedef storage_type_of_t left_storage_type; - typedef storage_type_of_t right_storage_type; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = matrix_traits; + using right_traits = matrix_traits; + using left_value_type = value_type_of_t; + using right_value_type = value_type_of_t; + using left_storage_type = storage_type_of_t; + using right_storage_type = storage_type_of_t; /* Deduce the element type: */ - typedef value_type_trait_promote_t< - left_value_type, right_value_type> value_type; + using value_type = value_type_trait_promote_t; /* Determine the common unbound storage type from the bound proxy types, * preferring a dynamic-size type unless the resulting matrix can be * fixed-size: */ - typedef rebind_matrix_storage_t< - proxy_type_of_t> left_proxy_type; - typedef rebind_matrix_storage_t< - proxy_type_of_t> right_proxy_type; + using left_proxy_type = rebind_matrix_storage_t>; + using right_proxy_type = rebind_matrix_storage_t>; static const int left_rows = left_proxy_type::array_rows; static const int right_cols = right_proxy_type::array_cols; static const bool is_fixed = left_rows > 0 && right_cols > 0; - typedef storage_promote_t< - left_proxy_type, right_proxy_type, !is_fixed> unbound_type; + using unbound_type = storage_promote_t; /* Determine the new matrix size: */ static const int array_rows = is_fixed ? left_rows : -1; static const int array_cols = is_fixed ? right_cols : -1; /* Determine the unbound proxy type: */ - typedef reshape_storage_t< - unbound_type, array_rows, array_cols> resized_type; - typedef proxy_type_of_t< - rebind_matrix_storage_t> proxy_type; + using resized_type = reshape_storage_t; + using proxy_type = proxy_type_of_t>; /* Determine the common basis type: */ - typedef basis_tag_promote_t< - basis_tag_of_t, - basis_tag_of_t> basis_tag; + using basis_tag = basis_tag_promote_t, + basis_tag_of_t>; /* Determine the common layout type: */ - typedef layout_tag_promote_t< - layout_tag_of_t, - layout_tag_of_t> layout_tag; + using layout_tag = layout_tag_promote_t, + layout_tag_of_t>; /* Build the temporary: */ - typedef matrix type; + using type = matrix; }; /** Determine a matrix temporary type that can hold the result of @@ -134,13 +116,11 @@ struct matrix_inner_product_promote struct matrix_inner_product_promote::value && is_matrix::value) - || (is_matrix::value && is_vector::value)>::type - > + typename std::enable_if<(is_vector::value && is_matrix::value) + || (is_matrix::value && is_vector::value)>::type> { - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; /* Figure out if pre- or post-multiplying: */ static const bool left_is_vector = is_vector::value; @@ -148,38 +128,36 @@ struct matrix_inner_product_promote vector_type; - typedef traits_of_t vector_traits; - typedef value_type_of_t vector_value_type; - typedef storage_type_of_t vector_storage_type; + using vector_type = cml::if_t; + using vector_traits = traits_of_t; + using vector_value_type = value_type_of_t; + using vector_storage_type = storage_type_of_t; /* Matrix traits and types: */ - typedef cml::if_t< - right_is_vector, left_type, right_type> matrix_type; - typedef traits_of_t matrix_traits; - typedef value_type_of_t matrix_value_type; - typedef storage_type_of_t matrix_storage_type; + using matrix_type = cml::if_t; + using matrix_traits = traits_of_t; + using matrix_value_type = value_type_of_t; + using matrix_storage_type = storage_type_of_t; /* Deduce the element type: */ - typedef value_type_trait_promote_t< - vector_value_type, matrix_value_type> value_type; + using value_type = value_type_trait_promote_t; /* The resulting vector size comes from the bound matrix proxy rows or * columns, depending on pre- or post-multiplication: */ - typedef proxy_type_of_t matrix_unbound_type; - typedef rebind_matrix_storage_t matrix_proxy_type; + using matrix_unbound_type = proxy_type_of_t; + using matrix_proxy_type = rebind_matrix_storage_t; static const int array_size = left_is_vector - ? matrix_proxy_type::array_cols : matrix_proxy_type::array_rows; + ? matrix_proxy_type::array_cols + : matrix_proxy_type::array_rows; /* Determine the unbound and bound vector proxy types by resizing the * original vector storage type: */ - typedef rebind_vector_storage_t< - resize_storage_t> vector_resized_type; - typedef proxy_type_of_t vector_unbound_type; - typedef rebind_vector_storage_t vector_proxy_type; + using vector_resized_type = rebind_vector_storage_t< + resize_storage_t>; + using vector_unbound_type = proxy_type_of_t; + using vector_proxy_type = rebind_vector_storage_t; /* Note: two rebinds are needed here, first to get the unbound proxy * type, then to get the bound proxy type for sizing. */ @@ -189,63 +167,58 @@ struct matrix_inner_product_promote 0; - typedef storage_promote_t< - vector_proxy_type, matrix_proxy_type, !is_fixed> unbound_type; - typedef resize_storage_t resized_type; + using unbound_type = storage_promote_t; + using resized_type = resize_storage_t; /* Prefer the unbound vector proxy type when possible: */ - typedef cml::if_t< - /**/ (is_fixed && is_fixed_size::value) - || (!is_fixed && is_dynamic_size::value) - , vector_unbound_type, resized_type> proxy_type; + using proxy_type = cml::if_t< + /**/ (is_fixed&& is_fixed_size::value) + || (!is_fixed && is_dynamic_size::value), + vector_unbound_type, resized_type>; /* Build the temporary: */ - typedef vector type; + using type = vector; }; /** Convenience alias for matrix_inner_product_promote. */ -template using matrix_inner_product_promote_t - = typename matrix_inner_product_promote::type; - +template +using matrix_inner_product_promote_t = + typename matrix_inner_product_promote::type; template struct matrix_outer_product_storage_promote { static_assert( - is_vector_storage::value && - is_vector_storage::value, + is_vector_storage::value && is_vector_storage::value, "expected vector storage types for outer product promotion"); /* Deduce the left matrix storage type from the vector storage: */ static const int left_size = Storage1::array_size; - typedef reshape_storage_t left_unbound_type; - typedef rebind_matrix_storage_t left_storage_type; + using left_unbound_type = reshape_storage_t; + using left_storage_type = rebind_matrix_storage_t; /* Deduce the right matrix storage type from the vector storage: */ static const int right_size = Storage2::array_size; - typedef reshape_storage_t right_unbound_type; - typedef rebind_matrix_storage_t right_storage_type; + using right_unbound_type = reshape_storage_t; + using right_storage_type = rebind_matrix_storage_t; /* Determine the common storage type, based on the storage types of its * subexpressions: */ - typedef matrix_binary_storage_promote_t< - left_storage_type, right_storage_type> type; + using type = matrix_binary_storage_promote_t; }; /** Convenience alias for matrix_outer_product_promote. */ template -using matrix_outer_product_storage_promote_t - = typename matrix_outer_product_storage_promote::type; +using matrix_outer_product_storage_promote_t = + typename matrix_outer_product_storage_promote::type; /** Specializable class to determine a temporary type that can store the * result of vector outer products. */ -template struct matrix_outer_product_promote; +template +struct matrix_outer_product_promote; /** Determine a matrix temporary type that can hold the result of the outer * product of two vector expressions @c Sub1 and @c Sub2. @@ -254,35 +227,34 @@ template struct matrix_outer_product_promote::value && is_vector::value)>::type - > + typename std::enable_if<(is_vector::value + && is_vector::value)>::type> { - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef vector_traits left_traits; - typedef vector_traits right_traits; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = vector_traits; + using right_traits = vector_traits; /* Deduce the element type: */ - typedef value_type_promote_t value_type; + using value_type = value_type_promote_t; /* Determine the common storage type for the temporary, based on the * storage types of its subexpressions: */ - typedef storage_type_of_t left_storage_type; - typedef storage_type_of_t right_storage_type; - typedef matrix_outer_product_storage_promote_t< - left_storage_type, right_storage_type> storage_type; - typedef proxy_type_of_t proxy_type; + using left_storage_type = storage_type_of_t; + using right_storage_type = storage_type_of_t; + using storage_type = matrix_outer_product_storage_promote_t; + using proxy_type = proxy_type_of_t; /* Build the temporary: */ - typedef matrix type; + using type = matrix; }; /** Convenience alias for matrix_outer_product_promote. */ template - using matrix_outer_product_promote_t - = typename matrix_outer_product_promote::type; +using matrix_outer_product_promote_t = + typename matrix_outer_product_promote::type; /** Determine the row vector temporary type for matrix type @c Sub. */ @@ -338,9 +310,4 @@ struct col_type_of using col_type_of_t = typename col_type_of::type; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/readable_matrix.h b/cml/matrix/readable_matrix.h index 984a295..83b80fb 100644 --- a/cml/matrix/readable_matrix.h +++ b/cml/matrix/readable_matrix.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_readable_matrix_h -#define cml_matrix_readable_matrix_h - #include #include #include @@ -17,7 +12,7 @@ namespace cml { /** Return type for readable_matrix<>::size(). */ -typedef std::pair matrix_size; +using matrix_size = std::pair; /** Base class for readable matrix types. Readable matrices support const * access to its elements. @@ -37,114 +32,104 @@ typedef std::pair matrix_size; * matrix_traits. Note that immutable_value is not necessarily a * reference or const type. */ -template -class readable_matrix +template class readable_matrix { public: - - typedef DerivedT matrix_type; - typedef matrix_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using matrix_type = DerivedT; + using traits_type = matrix_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; public: + /** Return a const reference to the matrix cast as DerivedT. */ + const DerivedT& actual() const; - /** Return a const reference to the matrix cast as DerivedT. */ - const DerivedT& actual() const; + /** Return the number of rows. */ + int rows() const; - /** Return the number of rows. */ - int rows() const; + /** Return the number of columns. */ + int cols() const; - /** Return the number of columns. */ - int cols() const; + /** Returns the matrix size as a std::pair<>. */ + matrix_size size() const; - /** Returns the matrix size as a std::pair<>. */ - matrix_size size() const; + /** Return const element at @c i, @c j. */ + immutable_value get(int i, int j) const; - /** Return const element at @c i, @c j. */ - immutable_value get(int i, int j) const; + /** Return const element at @c i, @c j. */ + immutable_value operator()(int i, int j) const; - /** Return const element at @c i, @c j. */ - immutable_value operator()(int i, int j) const; - - /** Returns element @c j of basis vector @c i. The returned value + /** Returns element @c j of basis vector @c i. The returned value * depends upon the basis orientation. */ - immutable_value basis_element(int i, int j) const; + immutable_value basis_element(int i, int j) const; - /** Returns the number of basis vectors. */ - int basis_count() const; + /** Returns the number of basis vectors. */ + int basis_count() const; - /** Returns the number of elements in a basis vector. */ - int basis_size() const; + /** Returns the number of elements in a basis vector. */ + int basis_size() const; - /** Compute the determinant of the matrix. + /** Compute the determinant of the matrix. * * @throws non_square_matrix_error at run-time if the matrix is * dynamically-sized and not square. Fixed-size matrices are checked * at compile-time. */ - value_type determinant() const; + value_type determinant() const; - /** Compute the trace of the matrix. + /** Compute the trace of the matrix. * * @throws non_square_matrix_error at run-time if the matrix is * dynamically-sized and not square. Fixed-size matrices are checked * at compile-time. */ - value_type trace() const; + value_type trace() const; protected: + /** Return basis element @c (i,j) for a row-basis matrix. */ + immutable_value basis_element(int i, int j, row_basis) const; - /** Return basis element @c (i,j) for a row-basis matrix. */ - immutable_value basis_element(int i, int j, row_basis) const; - - /** Return basis element @c (i,j) for a column-basis matrix. */ - immutable_value basis_element(int i, int j, col_basis) const; + /** Return basis element @c (i,j) for a column-basis matrix. */ + immutable_value basis_element(int i, int j, col_basis) const; - /** Return the number of basis vectors for a row_basis matrix. */ - int basis_count(row_basis) const; + /** Return the number of basis vectors for a row_basis matrix. */ + int basis_count(row_basis) const; - /** Return the number of basis vectors for a col_basis matrix. */ - int basis_count(col_basis) const; + /** Return the number of basis vectors for a col_basis matrix. */ + int basis_count(col_basis) const; - /** Return the number of elements in a basis vector for a row_basis + /** Return the number of elements in a basis vector for a row_basis * matrix. */ - int basis_size(row_basis) const; + int basis_size(row_basis) const; - /** Return the number of elements in a basis vectors for a col_basis + /** Return the number of elements in a basis vectors for a col_basis * matrix. */ - int basis_size(col_basis) const; + int basis_size(col_basis) const; protected: + // Use the compiler-generated default constructor: + readable_matrix() = default; - // Use the compiler-generated default constructor: - readable_matrix() = default; - - // Use the compiler-generated copy constructor: - readable_matrix(const readable_matrix&) = default; + // Use the compiler-generated copy constructor: + readable_matrix(const readable_matrix&) = default; #ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR - // Use the compiler-generated move constructor: - readable_matrix(readable_matrix&&) = default; + // Use the compiler-generated move constructor: + readable_matrix(readable_matrix&&) = default; #endif }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_READABLE_MATRIX_TPP #include #undef __CML_MATRIX_READABLE_MATRIX_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/readable_matrix.tpp b/cml/matrix/readable_matrix.tpp index 1645e3e..a9aa7a2 100644 --- a/cml/matrix/readable_matrix.tpp +++ b/cml/matrix/readable_matrix.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_READABLE_MATRIX_TPP -#error "matrix/readable_matrix.tpp not included correctly" +# error "matrix/readable_matrix.tpp not included correctly" #endif #include @@ -15,118 +13,131 @@ namespace cml { /* Public methods: */ -template const DT& +template +const DT& readable_matrix
::actual() const { return (const DT&) *this; } -template int +template +int readable_matrix
::rows() const { return this->actual().i_rows(); } -template int +template +int readable_matrix
::cols() const { return this->actual().i_cols(); } -template std::pair +template +std::pair readable_matrix
::size() const { return std::make_pair(this->rows(), this->cols()); } -template auto +template +auto readable_matrix
::get(int i, int j) const -> immutable_value { - return this->actual().i_get(i,j); + return this->actual().i_get(i, j); } -template auto +template +auto readable_matrix
::operator()(int i, int j) const -> immutable_value { - return this->get(i,j); + return this->get(i, j); } -template auto +template +auto readable_matrix
::basis_element(int i, int j) const -> immutable_value { - return this->basis_element(i,j, basis_tag()); + return this->basis_element(i, j, basis_tag()); } -template int +template +int readable_matrix
::basis_count() const { return this->basis_count(basis_tag()); } -template int +template +int readable_matrix
::basis_size() const { return this->basis_size(basis_tag()); } -template auto +template +auto readable_matrix
::determinant() const -> value_type { cml::check_square(*this); return detail::determinant(*this, cml::int_c()); } -template auto +template +auto readable_matrix
::trace() const -> value_type { cml::check_square(*this); - auto result = this->get(0,0); - for(int i = 1; i < this->rows(); ++ i) result += this->get(i,i); + auto result = this->get(0, 0); + for(int i = 1; i < this->rows(); ++i) result += this->get(i, i); return result; } - /* Internal methods: */ -template auto +template +auto readable_matrix
::basis_element(int i, int j, row_basis) const --> immutable_value + -> immutable_value { - return this->get(i,j); + return this->get(i, j); } -template auto +template +auto readable_matrix
::basis_element(int i, int j, col_basis) const --> immutable_value + -> immutable_value { - return this->get(j,i); + return this->get(j, i); } -template int +template +int readable_matrix
::basis_count(row_basis) const { return this->rows(); } -template int +template +int readable_matrix
::basis_count(col_basis) const { return this->cols(); } -template int +template +int readable_matrix
::basis_size(row_basis) const { return this->cols(); } -template int +template +int readable_matrix
::basis_size(col_basis) const { return this->rows(); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/row_col.h b/cml/matrix/row_col.h index 0fa318e..b25f704 100644 --- a/cml/matrix/row_col.h +++ b/cml/matrix/row_col.h @@ -1,20 +1,10 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_row_col_h -#define cml_matrix_row_col_h - #include #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/row_node.h b/cml/matrix/row_node.h index 14b8f82..0fab085 100644 --- a/cml/matrix/row_node.h +++ b/cml/matrix/row_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_row_node_h -#define cml_matrix_row_node_h - #include #include #include @@ -18,129 +13,115 @@ namespace cml { template class matrix_row_node; /** matrix_row_node<> traits. */ -template -struct vector_traits< matrix_row_node > +template struct vector_traits> { - typedef matrix_row_node vector_type; - typedef Sub sub_arg_type; - typedef cml::unqualified_type_t sub_type; - typedef matrix_traits sub_traits; - typedef typename sub_traits::element_traits element_traits; - typedef typename sub_traits::value_type value_type; - typedef typename sub_traits::immutable_value immutable_value; + using vector_type = matrix_row_node; + using sub_arg_type = Sub; + using sub_type = cml::unqualified_type_t; + using sub_traits = matrix_traits; + using element_traits = typename sub_traits::element_traits; + using value_type = typename sub_traits::value_type; + using immutable_value = typename sub_traits::immutable_value; /* Propagate the column count from the subexpression: */ static const int array_size = sub_traits::array_cols; /* Deduce the vector storage type: */ - typedef typename sub_traits::storage_type sub_storage_type; - typedef typename sub_storage_type::unbound_type sub_unbound_type; - typedef resize_storage_t< - sub_unbound_type, array_size> resized_type; - typedef rebind_vector_storage_t storage_type; + using sub_storage_type = typename sub_traits::storage_type; + using sub_unbound_type = typename sub_storage_type::unbound_type; + using resized_type = resize_storage_t; + using storage_type = rebind_vector_storage_t; /* Take the size type from the storage type: */ - typedef typename storage_type::size_tag size_tag; + using size_tag = typename storage_type::size_tag; }; /** Represents a read-only matrix row, specified at run-time by its index, * as a node in an expression tree. */ template -class matrix_row_node -: public readable_vector< matrix_row_node > +class matrix_row_node +: public readable_vector> { public: - - typedef matrix_row_node node_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::sub_arg_type sub_arg_type; - typedef typename traits_type::sub_type sub_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using node_type = matrix_row_node; + using readable_type = readable_vector; + using traits_type = vector_traits; + using sub_arg_type = typename traits_type::sub_arg_type; + using sub_type = typename traits_type::sub_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** Constant containing the number of elements. */ - static const int array_size = traits_type::array_size; + /** Constant containing the number of elements. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped sub-expression and the row index. @c + /** Construct from the wrapped sub-expression and the row index. @c * sub must be an lvalue reference or rvalue reference type. * * @throws std::invalid_argument if @c row < 0. */ - explicit matrix_row_node(Sub sub, int row); + explicit matrix_row_node(Sub sub, int row); - /** Move constructor. */ - matrix_row_node(node_type&& other); + /** Move constructor. */ + matrix_row_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - matrix_row_node(const node_type& other); + /** Copy constructor. */ + matrix_row_node(const node_type& other); #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the size of the vector expression. */ - int i_size() const; + /** Return the size of the vector expression. */ + int i_size() const; - /** Return element @c (row,j) of the matrix. */ - immutable_value i_get(int j) const; + /** Return element @c (row,j) of the matrix. */ + immutable_value i_get(int j) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the subexpression. The expression is stored + /** The type used to store the subexpression. The expression is stored * as a copy if Sub is an rvalue reference (temporary), or by const * reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const sub_type&, sub_type> sub_wrap_type; + using sub_wrap_type = cml::if_t::value, const sub_type&, + sub_type>; protected: + /** The wrapped subexpression. */ + sub_wrap_type m_sub; - /** The wrapped subexpression. */ - sub_wrap_type m_sub; - - /** The row index. */ - int m_row; + /** The row index. */ + int m_row; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_row_node(const node_type&); + // Not copy constructible. + matrix_row_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_ROW_NODE_TPP #include #undef __CML_MATRIX_ROW_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/row_node.tpp b/cml/matrix/row_node.tpp index 94f1a4a..960ee5e 100644 --- a/cml/matrix/row_node.tpp +++ b/cml/matrix/row_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_ROW_NODE_TPP -#error "matrix/row_node.tpp not included correctly" +# error "matrix/row_node.tpp not included correctly" #endif namespace cml { @@ -13,45 +11,44 @@ namespace cml { /* matrix_row_node 'structors: */ template -matrix_row_node::matrix_row_node(Sub sub, int row) -: m_sub(std::move(sub)), m_row(row) +matrix_row_node::matrix_row_node(Sub sub, int row) +: m_sub(std::move(sub)) +, m_row(row) { - cml_require(row >= 0, std::invalid_argument, "row < 0"); + cml_require(row >= 0, std::invalid_argument, "row < 0"); } template -matrix_row_node::matrix_row_node(node_type&& other) -: m_sub(std::move(other.m_sub)), m_row(other.m_row) -{ -} +matrix_row_node::matrix_row_node(node_type&& other) +: m_sub(std::move(other.m_sub)) +, m_row(other.m_row) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -matrix_row_node::matrix_row_node(const node_type& other) -: m_sub(other.m_sub), m_row(other.m_row) -{ -} +matrix_row_node::matrix_row_node(const node_type& other) +: m_sub(other.m_sub) +, m_row(other.m_row) +{} #endif - /* Internal methods: */ /* readable_vector interface: */ -template int -matrix_row_node::i_size() const +template +int +matrix_row_node::i_size() const { return this->m_sub.cols(); } -template auto -matrix_row_node::i_get(int j) const -> immutable_value +template +auto +matrix_row_node::i_get(int j) const -> immutable_value { - return this->m_sub.get(this->m_row,j); + return this->m_sub.get(this->m_row, j); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/row_ops.h b/cml/matrix/row_ops.h index a122ebe..a907b78 100644 --- a/cml/matrix/row_ops.h +++ b/cml/matrix/row_ops.h @@ -1,35 +1,26 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_row_ops_h -#define cml_matrix_row_ops_h - #include #include namespace cml { template* = nullptr> -inline auto row(Sub&& sub, int row) --> matrix_row_node, -1> +inline auto +row(Sub&& sub, int row) + -> matrix_row_node, -1> { - static_assert(std::is_same< - decltype(sub), decltype(std::forward(sub))>::value, + static_assert( + std::is_same(sub))>::value, "internal error: unexpected expression type"); /* Deduce the operand type of the subexpression (&, const&, &&): */ - typedef actual_operand_type_of_t sub_type; + using sub_type = actual_operand_type_of_t; return matrix_row_node((sub_type) sub, row); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/scalar_node.h b/cml/matrix/scalar_node.h index a0e6719..70b6e61 100644 --- a/cml/matrix/scalar_node.h +++ b/cml/matrix/scalar_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_scalar_node_h -#define cml_matrix_scalar_node_h - #include #include @@ -18,21 +13,21 @@ template class matrix_scalar_node; /** matrix_scalar_node<> traits. */ template -struct matrix_traits< matrix_scalar_node > +struct matrix_traits> { - typedef matrix_scalar_node matrix_type; - typedef Sub left_arg_type; - typedef Scalar right_arg_type; - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef matrix_traits left_traits; - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; - typedef typename left_traits::storage_type storage_type; - typedef typename left_traits::size_tag size_tag; - typedef typename left_traits::basis_tag basis_tag; - typedef typename left_traits::layout_tag layout_tag; + using matrix_type = matrix_scalar_node; + using left_arg_type = Sub; + using right_arg_type = Scalar; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = matrix_traits; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; + using storage_type = typename left_traits::storage_type; + using size_tag = typename left_traits::size_tag; + using basis_tag = typename left_traits::basis_tag; + using layout_tag = typename left_traits::layout_tag; /* Propagate the rows from the subexpression: */ static const int array_rows = left_traits::array_rows; @@ -52,115 +47,103 @@ struct matrix_traits< matrix_scalar_node > */ template class matrix_scalar_node -: public readable_matrix< matrix_scalar_node > +: public readable_matrix> { public: - - typedef matrix_scalar_node node_type; - typedef readable_matrix readable_type; - typedef matrix_traits traits_type; - typedef typename traits_type::left_arg_type left_arg_type; - typedef typename traits_type::right_arg_type right_arg_type; - typedef typename traits_type::left_type left_type; - typedef typename traits_type::right_type right_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using node_type = matrix_scalar_node; + using readable_type = readable_matrix; + using traits_type = matrix_traits; + using left_arg_type = typename traits_type::left_arg_type; + using right_arg_type = typename traits_type::right_arg_type; + using left_type = typename traits_type::left_type; + using right_type = typename traits_type::right_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; public: + /** Take the array row size from the subexpression. */ + static const int array_rows = left_type::array_rows; - /** Take the array row size from the subexpression. */ - static const int array_rows = left_type::array_rows; - - /** Take the array column size from the subexpression. */ - static const int array_cols = left_type::array_cols; + /** Take the array column size from the subexpression. */ + static const int array_cols = left_type::array_cols; - /** Constant containing the matrix basis enumeration value. */ - static const basis_kind matrix_basis = traits_type::matrix_basis; + /** Constant containing the matrix basis enumeration value. */ + static const basis_kind matrix_basis = traits_type::matrix_basis; - /** Constant containing the array layout enumeration value. */ - static const layout_kind array_layout = traits_type::array_layout; + /** Constant containing the array layout enumeration value. */ + static const layout_kind array_layout = traits_type::array_layout; public: - - /** Construct from the wrapped sub-expression and the scalar to apply. + /** Construct from the wrapped sub-expression and the scalar to apply. * @c left and @c right must be lvalue or rvalue references. */ - matrix_scalar_node(Sub left, Scalar right); + matrix_scalar_node(Sub left, Scalar right); - /** Move constructor. */ - matrix_scalar_node(node_type&& other); + /** Move constructor. */ + matrix_scalar_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - matrix_scalar_node(const node_type& other); + /** Copy constructor. */ + matrix_scalar_node(const node_type& other); #endif protected: + /** @name readable_matrix Interface */ + /*@{*/ - /** @name readable_matrix Interface */ - /*@{*/ + friend readable_type; - friend readable_type; + /** Return the row size of the matrix expression. */ + int i_rows() const; - /** Return the row size of the matrix expression. */ - int i_rows() const; + /** Return the column size of the matrix expression. */ + int i_cols() const; - /** Return the column size of the matrix expression. */ - int i_cols() const; - - /** Apply the operator to element @c (i,j) of the subexpressions and + /** Apply the operator to element @c (i,j) of the subexpressions and * return the result. */ - immutable_value i_get(int i, int j) const; + immutable_value i_get(int i, int j) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the left subexpression. The expression is + /** The type used to store the left subexpression. The expression is * stored as a copy if Sub is an rvalue reference (temporary), or by * const reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const left_type&, left_type> left_wrap_type; + using left_wrap_type = cml::if_t::value, const left_type&, + left_type>; protected: + /** The matrix operand. */ + left_wrap_type m_left; - /** The matrix operand. */ - left_wrap_type m_left; - - /** The scalar operand. */ - right_type m_right; + /** The scalar operand. */ + right_type m_right; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_scalar_node(const node_type&); + // Not copy constructible. + matrix_scalar_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_SCALAR_NODE_TPP #include #undef __CML_MATRIX_SCALAR_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/scalar_node.tpp b/cml/matrix/scalar_node.tpp index 21bcac7..da67925 100644 --- a/cml/matrix/scalar_node.tpp +++ b/cml/matrix/scalar_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_SCALAR_NODE_TPP -#error "matrix/scalar_node.tpp not included correctly" +# error "matrix/scalar_node.tpp not included correctly" #endif namespace cml { @@ -13,52 +11,50 @@ namespace cml { /* matrix_scalar_node 'structors: */ template -matrix_scalar_node::matrix_scalar_node( - Sub left, Scalar right - ) -: m_left(std::move(left)), m_right(std::move(right)) -{ -} +matrix_scalar_node::matrix_scalar_node(Sub left, Scalar right) +: m_left(std::move(left)) +, m_right(std::move(right)) +{} template -matrix_scalar_node::matrix_scalar_node(node_type&& other) -: m_left(std::move(other.m_left)), m_right(std::move(other.m_right)) -{ -} +matrix_scalar_node::matrix_scalar_node(node_type&& other) +: m_left(std::move(other.m_left)) +, m_right(std::move(other.m_right)) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -matrix_scalar_node::matrix_scalar_node(const node_type& other) -: m_left(other.m_left), m_right(other.m_right) -{ -} +matrix_scalar_node::matrix_scalar_node(const node_type& other) +: m_left(other.m_left) +, m_right(other.m_right) +{} #endif - /* Internal methods: */ /* readable_matrix interface: */ -template int -matrix_scalar_node::i_rows() const +template +int +matrix_scalar_node::i_rows() const { return this->m_left.rows(); } -template int -matrix_scalar_node::i_cols() const +template +int +matrix_scalar_node::i_cols() const { return this->m_left.cols(); } -template auto -matrix_scalar_node::i_get(int i, int j) const -> immutable_value +template +auto +matrix_scalar_node::i_get(int i, int j) const + -> immutable_value { - return Op().apply(this->m_left.get(i,j), this->m_right); + return Op().apply(this->m_left.get(i, j), this->m_right); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/scalar_ops.h b/cml/matrix/scalar_ops.h index 82196cd..5ad3608 100644 --- a/cml/matrix/scalar_ops.h +++ b/cml/matrix/scalar_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_scalar_ops_h -#define cml_matrix_scalar_ops_h - #include #include #include @@ -18,72 +13,61 @@ namespace cml { /** Helper function to generate a matrix_scalar_node from a matrix type * (i.e. derived from readable_matrix<>) and a scalar type. */ -template* = nullptr, - enable_if_arithmetic_t>* = nullptr -> inline auto -make_matrix_scalar_node(Sub&& sub, Scalar&& v) --> matrix_scalar_node< -actual_operand_type_of_t, -actual_operand_type_of_t, -Op -> +template* = nullptr, + enable_if_arithmetic_t>* = nullptr> +inline auto +make_matrix_scalar_node(Sub&& sub, + Scalar&& v) -> matrix_scalar_node, + actual_operand_type_of_t, Op> { - static_assert(std::is_same< - decltype(sub), decltype(std::forward(sub))>::value, + static_assert( + std::is_same(sub))>::value, "internal error: unexpected expression type (sub)"); - static_assert(std::is_same< - decltype(v), decltype(std::forward(v))>::value, + static_assert( + std::is_same(v))>::value, "internal error: unexpected expression type (v)"); /* Deduce the operand types of the scalar and the subexpression (&, * const&, &&): */ - typedef actual_operand_type_of_t sub_type; - typedef actual_operand_type_of_t scalar_type; - return matrix_scalar_node( - (sub_type) sub, (scalar_type) v); + using sub_type = actual_operand_type_of_t; + using scalar_type = actual_operand_type_of_t; + return matrix_scalar_node((sub_type) sub, + (scalar_type) v); } -template* = nullptr, - enable_if_arithmetic_t>* = nullptr -> -inline auto operator*(Sub&& sub, Scalar&& v) --> decltype(make_matrix_scalar_node>( +template* = nullptr, + enable_if_arithmetic_t>* = nullptr> +inline auto +operator*(Sub&& sub, Scalar&& v) + -> decltype(make_matrix_scalar_node>( std::forward(sub), std::forward(v))) { - return make_matrix_scalar_node>( + return make_matrix_scalar_node>( std::forward(sub), std::forward(v)); } template>* = nullptr, - enable_if_matrix_t* = nullptr -> -inline auto operator*(Scalar&& v, Sub&& sub) --> decltype(make_matrix_scalar_node>( + enable_if_matrix_t* = nullptr> +inline auto +operator*(Scalar&& v, Sub&& sub) + -> decltype(make_matrix_scalar_node>( std::forward(sub), std::forward(v))) { - return make_matrix_scalar_node>( + return make_matrix_scalar_node>( std::forward(sub), std::forward(v)); } -template* = nullptr, - enable_if_arithmetic_t>* = nullptr -> -inline auto operator/(Sub&& sub, Scalar&& v) --> decltype(make_matrix_scalar_node>( +template* = nullptr, + enable_if_arithmetic_t>* = nullptr> +inline auto +operator/(Sub&& sub, Scalar&& v) + -> decltype(make_matrix_scalar_node>( std::forward(sub), std::forward(v))) { - return make_matrix_scalar_node>( + return make_matrix_scalar_node>( std::forward(sub), std::forward(v)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/size_checking.h b/cml/matrix/size_checking.h index 715c0f3..0d5db22 100644 --- a/cml/matrix/size_checking.h +++ b/cml/matrix/size_checking.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_size_checking_h -#define cml_matrix_size_checking_h - #include #include #include @@ -20,64 +15,77 @@ namespace cml { /** Exception thrown when run-time size checking is enabled, and the * operands of a matrix expression have incompatible sizes. */ -struct incompatible_matrix_size_error : std::runtime_error { +struct incompatible_matrix_size_error : std::runtime_error +{ incompatible_matrix_size_error() - : std::runtime_error("incompatible matrix expression sizes") {} + : std::runtime_error("incompatible matrix expression sizes") + {} }; /** Exception thrown when run-time size checking is enabled, and the * operand of a matrix expression does not meet a minimum size. */ -struct minimum_matrix_size_error : std::runtime_error { +struct minimum_matrix_size_error : std::runtime_error +{ minimum_matrix_size_error() - : std::runtime_error("matrix expression too small") {} + : std::runtime_error("matrix expression too small") + {} }; /** Exception thrown when run-time size checking is enabled, and the * operand of a matrix expression does not have the required size. */ -struct matrix_size_error : std::runtime_error { +struct matrix_size_error : std::runtime_error +{ matrix_size_error() - : std::runtime_error("incorrect matrix expression size") {} + : std::runtime_error("incorrect matrix expression size") + {} }; /** Exception thrown when run-time size checking is enabled, and the row * size of a matrix operand does not match the (row) size of a second * operand. */ -struct incompatible_matrix_row_size_error : std::runtime_error { +struct incompatible_matrix_row_size_error : std::runtime_error +{ incompatible_matrix_row_size_error() - : std::runtime_error("incompatible matrix row sizes") {} + : std::runtime_error("incompatible matrix row sizes") + {} }; /** Exception thrown when run-time size checking is enabled, and the column * size of a matrix operand does not match the (row) size of a second * operand. */ -struct incompatible_matrix_col_size_error : std::runtime_error { +struct incompatible_matrix_col_size_error : std::runtime_error +{ incompatible_matrix_col_size_error() - : std::runtime_error("incompatible matrix column sizes") {} + : std::runtime_error("incompatible matrix column sizes") + {} }; /** Exception thrown when run-time size checking is enabled, and the * column size of a matrix operand does not match the row size of a second * operand. */ -struct incompatible_matrix_inner_size_error : std::runtime_error { +struct incompatible_matrix_inner_size_error : std::runtime_error +{ incompatible_matrix_inner_size_error() - : std::runtime_error("incompatible matrix inner product size") {} + : std::runtime_error("incompatible matrix inner product size") + {} }; /** Exception thrown when run-time size checking is enabled, and a matrix * operand is not square. */ -struct non_square_matrix_error : std::runtime_error { +struct non_square_matrix_error : std::runtime_error +{ non_square_matrix_error() - : std::runtime_error("non-square matrix") {} + : std::runtime_error("non-square matrix") + {} }; - /** Front-end for both compile-time and run-time matrix binary expression * linear size checking. Both expressions must derive from * readable_matrix. @@ -97,8 +105,9 @@ struct non_square_matrix_error : std::runtime_error { * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void check_same_linear_size( - const readable_matrix& left, const readable_matrix& right); +template +void check_same_linear_size(const readable_matrix& left, + const readable_matrix& right); /** Front-end for both compile-time and run-time matrix binary expression * size checking against a fixed-size array. The first expression must @@ -119,9 +128,9 @@ template void check_same_linear_size( * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void -check_same_linear_size(const readable_matrix& left, const Sub2& right, - enable_if_array_t* = 0); +template +void check_same_linear_size(const readable_matrix& left, + const Sub2& right, enable_if_array_t* = 0); /** Front-end for run-time matrix binary expression length checking. The * first expression must derive from readable_matrix, and the second must @@ -139,9 +148,9 @@ check_same_linear_size(const readable_matrix& left, const Sub2& right, * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template auto -check_same_linear_size(const readable_matrix& left, const Sub2& right) --> decltype(right.size(), void()); +template +auto check_same_linear_size(const readable_matrix& left, + const Sub2& right) -> decltype(right.size(), void()); /** Front-end for matrix expression size checking against a run-time linear @@ -155,8 +164,8 @@ check_same_linear_size(const readable_matrix& left, const Sub2& right) * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void check_linear_size( - const readable_matrix& left, int N); +template +void check_linear_size(const readable_matrix& left, int N); /** Front-end for compile-time and run-time matrix expression linear size * checking against an integer constant via int_c. The expression @@ -171,8 +180,8 @@ template void check_linear_size( * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void check_linear_size( - const readable_matrix& left, int_c); +template +void check_linear_size(const readable_matrix& left, int_c); /** Front-end for both compile-time and run-time matrix binary expression * size checking. Both expressions must derive from readable_matrix. @@ -191,8 +200,9 @@ template void check_linear_size( * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void check_same_size( - const readable_matrix& left, const readable_matrix& right); +template +void check_same_size(const readable_matrix& left, + const readable_matrix& right); /** Front-end for both compile-time and run-time matrix expression size * checking against a 2D C-array. @c left must derive from @@ -214,8 +224,9 @@ template void check_same_size( * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void check_same_size( - const readable_matrix& left, Other const (&array)[Rows][Cols]); +template +void check_same_size(const readable_matrix& left, + Other const (&array)[Rows][Cols]); /** Front-end for both compile-time and run-time matrix row size * checking against a vector expression. @c left must derive from @@ -235,8 +246,9 @@ template void check_same_size( * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void check_same_row_size( - const readable_matrix& left, const readable_vector& right); +template +void check_same_row_size(const readable_matrix& left, + const readable_vector& right); /** Front-end for both compile-time and run-time matrix column size * checking against a vector expression. @c left must derive from @@ -256,8 +268,9 @@ template void check_same_row_size( * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void check_same_col_size( - const readable_matrix& left, const readable_vector& right); +template +void check_same_col_size(const readable_matrix& left, + const readable_vector& right); /** Front-end for both compile-time and run-time compatible inner product @@ -274,8 +287,9 @@ template void check_same_col_size( * of columns as @c right has rows. If both are fixed-size expressions, * then the sizes are checked at compile time. */ -template void check_same_inner_size( - const readable_matrix& left, const readable_matrix& right); +template +void check_same_inner_size(const readable_matrix& left, + const readable_matrix& right); /** Front-end for both compile-time and run-time compatible inner product * size checking. @c left must derive from readable_matrix, and @c right @@ -292,8 +306,9 @@ template void check_same_inner_size( * of columns as @c right has elements. If both are fixed-size expressions, * then the sizes are checked at compile time. */ -template void check_same_inner_size( - const readable_matrix& left, const readable_vector& right); +template +void check_same_inner_size(const readable_matrix& left, + const readable_vector& right); /** Front-end for both compile-time and run-time compatible inner product * size checking. @c left must derive from readable_vector, and @c right @@ -310,8 +325,9 @@ template void check_same_inner_size( * of elements as @c right has rows. If both are fixed-size expressions, * then the sizes are checked at compile time. */ -template void check_same_inner_size( - const readable_vector& left, const readable_matrix& right); +template +void check_same_inner_size(const readable_vector& left, + const readable_matrix& right); /** Front-end for matrix expression size checking against a run-time @@ -327,8 +343,8 @@ template void check_same_inner_size( * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void check_size( - const readable_matrix& left, int R, int C); +template +void check_size(const readable_matrix& left, int R, int C); /** Front-end for compile-time and run-time matrix expression size checking * against integer constants via int_c and int_c. The expression @@ -343,8 +359,8 @@ template void check_size( * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void check_size( - const readable_matrix& left, cml::int_c, cml::int_c); +template +void check_size(const readable_matrix& left, cml::int_c, cml::int_c); /** Front-end for matrix expression minimum size checking against a @@ -361,8 +377,8 @@ template void check_size( * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void check_minimum_size( - const readable_matrix& left, int R, int C); +template +void check_minimum_size(const readable_matrix& left, int R, int C); /** Front-end for compile-time and run-time matrix expression minimum size * checking against integer constants via int_c and int_c. The @@ -378,8 +394,9 @@ template void check_minimum_size( * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_MATRIX_SIZE_CHECKS at compile time. */ -template void check_minimum_size( - const readable_matrix& left, cml::int_c, cml::int_c); +template +void check_minimum_size(const readable_matrix& left, cml::int_c, + cml::int_c); /** Front-end to check for a square matrix. @@ -394,13 +411,8 @@ template void check_minimum_size( */ template void check_square(const readable_matrix& left); -} // namespace cml +} // namespace cml #define __CML_MATRIX_SIZE_CHECKING_TPP #include #undef __CML_MATRIX_SIZE_CHECKING_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/size_checking.tpp b/cml/matrix/size_checking.tpp index 235aefc..b141925 100644 --- a/cml/matrix/size_checking.tpp +++ b/cml/matrix/size_checking.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_SIZE_CHECKING_TPP -#error "matrix/size_checking.tpp not included correctly" +# error "matrix/size_checking.tpp not included correctly" #endif #include @@ -21,14 +19,16 @@ template struct inner_rows_of_c; template struct inner_cols_of_c; /* Use the matrix row size for inner products: */ -template struct inner_rows_of_c +struct inner_rows_of_c::value != 0>::type> { static const int value = array_rows_of_c::value; }; /* Use the matrix column size for inner products: */ -template struct inner_cols_of_c +struct inner_cols_of_c::value != 0>::type> { static const int value = array_cols_of_c::value; @@ -43,113 +43,135 @@ struct inner_rows_of_c struct inner_cols_of_c +struct inner_cols_of_c::value != 0>::type> { static const int value = array_size_of_c::value; }; /* Run-time matrix row size for inner products: */ -template inline -int inner_rows_of(const readable_matrix& sub) { return sub.rows(); } +template +inline int +inner_rows_of(const readable_matrix& sub) +{ + return sub.rows(); +} /* Run-time matrix column size for inner products: */ -template inline -int inner_cols_of(const readable_matrix& sub) { return sub.cols(); } +template +inline int +inner_cols_of(const readable_matrix& sub) +{ + return sub.cols(); +} /* Run-time row size for vectors is the vector size: */ -template inline -int inner_rows_of(const readable_vector& sub) { return sub.size(); } +template +inline int +inner_rows_of(const readable_vector& sub) +{ + return sub.size(); +} /* Run-time column size for vectors is the vector size: */ -template inline -int inner_cols_of(const readable_vector& sub) { return sub.size(); } - +template +inline int +inner_cols_of(const readable_vector& sub) +{ + return sub.size(); +} /* No-op binary matrix expression linear size checking: */ -template inline void check_same_linear_size( - const readable_matrix&, const Sub2&, any_size_tag) {} +template +inline void +check_same_linear_size(const readable_matrix&, const Sub2&, any_size_tag) +{} /* Compile-time binary matrix expression linear size checking: */ -template inline void -check_same_linear_size( - const readable_matrix&, const Sub2&, fixed_size_tag - ) +template +inline void +check_same_linear_size(const readable_matrix&, const Sub2&, + fixed_size_tag) { - static_assert( - array_rows_of_c::value*array_cols_of_c::value - == array_size_of_c::value, + static_assert(array_rows_of_c::value * array_cols_of_c::value + == array_size_of_c::value, "incompatible matrix expression sizes"); } /* Run-time binary matrix expression linear size checking: */ -template inline void -check_same_linear_size( - const readable_matrix& left, const Sub2& right, dynamic_size_tag - ) +template +inline void +check_same_linear_size(const readable_matrix& left, const Sub2& right, + dynamic_size_tag) { #ifndef CML_NO_RUNTIME_MATRIX_SIZE_CHECKS - cml_require( - array_rows_of(left)*array_cols_of(left) == array_size_of(right), - incompatible_matrix_size_error, /**/); + cml_require(array_rows_of(left) * array_cols_of(left) == array_size_of(right), + incompatible_matrix_size_error, + /**/); #endif } - /* No-op matrix linear size checking. */ -template inline void -check_linear_size(const readable_matrix&, int, any_size_tag) {} +template +inline void +check_linear_size(const readable_matrix&, int, any_size_tag) +{} /* Compile-time matrix linear size checking. */ -template inline void +template +inline void check_linear_size(const readable_matrix&, cml::int_c, fixed_size_tag) { - static_assert(array_rows_of_c::value*array_cols_of_c::value == N, + static_assert(array_rows_of_c::value * array_cols_of_c::value == N, "incorrect matrix expression size"); } /* Run-time matrix linear size checking. */ -template inline void +template +inline void check_linear_size(const readable_matrix& sub, int N, SizeTag) { #ifndef CML_NO_RUNTIME_MATRIX_SIZE_CHECKS - cml_require( - array_rows_of(sub)*array_cols_of(sub) == N, matrix_size_error, /**/); + cml_require(array_rows_of(sub) * array_cols_of(sub) == N, matrix_size_error, + /**/); #endif } - /* No-op binary matrix expression size checking: */ -template inline void -check_same_size(const readable_matrix&, const Sub2&, any_size_tag) {} +template +inline void +check_same_size(const readable_matrix&, const Sub2&, any_size_tag) +{} /* Compile-time binary matrix expression size checking: */ -template inline void +template +inline void check_same_size(const readable_matrix&, const Sub2&, fixed_size_tag) { - static_assert( - (array_rows_of_c::value == array_rows_of_c::value) - && (array_cols_of_c::value == array_cols_of_c::value), + static_assert((array_rows_of_c::value == array_rows_of_c::value) + && (array_cols_of_c::value == array_cols_of_c::value), "incompatible matrix expression sizes"); } /* Run-time binary matrix expression size checking: */ -template inline void -check_same_size( - const readable_matrix& left, const Sub2& right, dynamic_size_tag - ) +template +inline void +check_same_size(const readable_matrix& left, const Sub2& right, + dynamic_size_tag) { #ifndef CML_NO_RUNTIME_MATRIX_SIZE_CHECKS cml_require(array_size_of(left) == array_size_of(right), - incompatible_matrix_size_error, /**/); + incompatible_matrix_size_error, + /**/); #endif } /* Compile-time binary matrix expression size checking against a C-array: */ -template inline void -check_same_size( - const readable_matrix&, Other const (&)[R][C], fixed_size_tag - ) +template +inline void +check_same_size(const readable_matrix&, Other const (&)[R][C], + fixed_size_tag) { static_assert( (array_rows_of_c::value == R) && (array_cols_of_c::value == C), @@ -157,29 +179,31 @@ check_same_size( } /* Run-time binary matrix expression size checking against a C-array: */ -template inline void -check_same_size( - const readable_matrix& left, Other const (&)[R][C], dynamic_size_tag - ) +template +inline void +check_same_size(const readable_matrix& left, Other const (&)[R][C], + dynamic_size_tag) { #ifndef CML_NO_RUNTIME_MATRIX_SIZE_CHECKS cml_require((array_rows_of(left) == R && array_cols_of(left) == C), - incompatible_matrix_size_error, /**/); + incompatible_matrix_size_error, + /**/); #endif } - /* No-op binary matrix expression row size checking: */ -template inline void -check_same_row_size(const readable_matrix&, const Sub2&, any_size_tag) {} +template +inline void +check_same_row_size(const readable_matrix&, const Sub2&, any_size_tag) +{} /* Compile-time binary matrix expression row size checking against a * fixed-size readable_vector: */ -template inline void -check_same_row_size( - const readable_matrix&, const readable_vector&, fixed_size_tag - ) +template +inline void +check_same_row_size(const readable_matrix&, const readable_vector&, + fixed_size_tag) { static_assert(array_rows_of_c::value == array_size_of_c::value, "incompatible matrix row sizes"); @@ -188,29 +212,31 @@ check_same_row_size( /* Run-time binary matrix expression row size checking against a * dynamic-size readable_vector: */ -template inline void +template +inline void check_same_row_size(const readable_matrix& left, - const readable_vector& right, dynamic_size_tag - ) + const readable_vector& right, dynamic_size_tag) { #ifndef CML_NO_RUNTIME_MATRIX_SIZE_CHECKS cml_require(array_rows_of(left) == array_size_of(right), - incompatible_matrix_row_size_error, /**/); + incompatible_matrix_row_size_error, + /**/); #endif } - /* No-op binary matrix expression column size checking: */ -template inline void -check_same_col_size(const readable_matrix&, const Sub2&, any_size_tag) {} +template +inline void +check_same_col_size(const readable_matrix&, const Sub2&, any_size_tag) +{} /* Compile-time binary matrix expression column size checking against a * fixed-size readable_vector: */ -template inline void -check_same_col_size( - const readable_matrix&, const readable_vector&, fixed_size_tag - ) +template +inline void +check_same_col_size(const readable_matrix&, const readable_vector&, + fixed_size_tag) { static_assert(array_cols_of_c::value == array_size_of_c::value, "incompatible matrix row sizes"); @@ -219,54 +245,60 @@ check_same_col_size( /* Run-time binary matrix expression column size checking against a * dynamic-size readable_vector: */ -template inline void +template +inline void check_same_col_size(const readable_matrix& left, - const readable_vector& right, dynamic_size_tag - ) + const readable_vector& right, dynamic_size_tag) { #ifndef CML_NO_RUNTIME_MATRIX_SIZE_CHECKS cml_require(array_cols_of(left) == array_size_of(right), - incompatible_matrix_col_size_error, /**/); + incompatible_matrix_col_size_error, + /**/); #endif } - /* No-op matrix inner product size checking: */ -template inline void -check_same_inner_size(const Sub1&, const Sub2&, any_size_tag) {} +template +inline void +check_same_inner_size(const Sub1&, const Sub2&, any_size_tag) +{} /* Compile-time matrix inner product size checking: */ -template inline void +template +inline void check_same_inner_size(const Sub1&, const Sub2&, fixed_size_tag) { - typedef traits_of_t left_traits; - typedef traits_of_t right_traits; + using left_traits = traits_of_t; + using right_traits = traits_of_t; static_assert( (inner_cols_of_c::value - == inner_rows_of_c::value), + == inner_rows_of_c::value), "incompatible matrix inner product size"); } /* Run-time matrix inner product size checking: */ -template inline void +template +inline void check_same_inner_size(const Sub1& left, const Sub2& right, dynamic_size_tag) { #ifndef CML_NO_RUNTIME_MATRIX_SIZE_CHECKS cml_require(inner_cols_of(left) == inner_rows_of(right), - incompatible_matrix_inner_size_error, /**/); + incompatible_matrix_inner_size_error, + /**/); #endif } - /* No-op matrix size checking. */ -template inline void -check_size(const readable_matrix&, int, int, any_size_tag) {} +template +inline void +check_size(const readable_matrix&, int, int, any_size_tag) +{} /* Compile-time checking against constant row and column sizes. */ -template inline void -check_size( - const readable_matrix&, cml::int_c, cml::int_c, fixed_size_tag - ) +template +inline void +check_size(const readable_matrix&, cml::int_c, cml::int_c, + fixed_size_tag) { static_assert( (array_rows_of_c::value == R) && (array_cols_of_c::value == C), @@ -274,28 +306,30 @@ check_size( } /* Run-time matrix size checking. */ -template inline void +template +inline void check_size(const readable_matrix& sub, int R, int C, SizeTag) { #ifndef CML_NO_RUNTIME_MATRIX_SIZE_CHECKS - cml_require( - (array_rows_of(sub) == R) && (array_cols_of(sub) == C), - matrix_size_error, /**/); + cml_require((array_rows_of(sub) == R) && (array_cols_of(sub) == C), + matrix_size_error, + /**/); #endif } - /* No-op minimum matrix size checking. */ -template inline void -check_minimum_size(const readable_matrix&, int, int, any_size_tag) {} +template +inline void +check_minimum_size(const readable_matrix&, int, int, any_size_tag) +{} /* Compile-time minimum size checking against constant row and column * sizes. */ -template inline void -check_minimum_size( - const readable_matrix&, cml::int_c, cml::int_c, fixed_size_tag - ) +template +inline void +check_minimum_size(const readable_matrix&, cml::int_c, cml::int_c, + fixed_size_tag) { static_assert( (array_rows_of_c::value >= R) && (array_cols_of_c::value >= C), @@ -303,231 +337,226 @@ check_minimum_size( } /* Run-time minimum matrix size checking. */ -template inline void +template +inline void check_minimum_size(const readable_matrix& sub, int R, int C, SizeTag) { #ifndef CML_NO_RUNTIME_MATRIX_SIZE_CHECKS - cml_require( - (array_rows_of(sub) >= R) && (array_cols_of(sub) >= C), - minimum_matrix_size_error, /**/); + cml_require((array_rows_of(sub) >= R) && (array_cols_of(sub) >= C), + minimum_matrix_size_error, + /**/); #endif } - /* No-op square matrix checking. */ -template inline void -check_square(const readable_matrix&, any_size_tag) {} +template +inline void +check_square(const readable_matrix&, any_size_tag) +{} /* Compile-time square matrix checking. */ -template inline void +template +inline void check_square(const readable_matrix&, fixed_size_tag) { - static_assert( - (array_rows_of_c::value == array_cols_of_c::value), + static_assert((array_rows_of_c::value == array_cols_of_c::value), "non-square matrix"); } /* Run-time square matrix checking. */ -template inline void +template +inline void check_square(const readable_matrix& sub, SizeTag) { #ifndef CML_NO_RUNTIME_MATRIX_SIZE_CHECKS cml_require( - (array_rows_of(sub) == array_cols_of(sub)), - non_square_matrix_error, /**/); + (array_rows_of(sub) == array_cols_of(sub)), non_square_matrix_error, /**/); #endif } -} // namespace detail - +} // namespace detail /* check_same_linear_size: */ -template inline void -check_same_linear_size( - const readable_matrix& left, const readable_matrix& right - ) +template +inline void +check_same_linear_size(const readable_matrix& left, + const readable_matrix& right) { - typedef size_tag_of_t tag1; - typedef size_tag_of_t tag2; - detail::check_same_linear_size( - left, right.actual(), size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = size_tag_of_t; + detail::check_same_linear_size(left, right.actual(), + size_check_promote_t()); } -template inline void -check_same_linear_size( - const readable_matrix& left, const Sub2& right, - enable_if_array_t* - ) +template +inline void +check_same_linear_size(const readable_matrix& left, const Sub2& right, + enable_if_array_t*) { - typedef size_tag_of_t tag1; - typedef tag1 tag2; // dynamic/dynamic or fixed/fixed. - detail::check_same_linear_size( - left, right, size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = tag1; // dynamic/dynamic or fixed/fixed. + detail::check_same_linear_size(left, right, + size_check_promote_t()); } -template inline auto +template +inline auto check_same_linear_size(const readable_matrix& left, const Sub2& right) --> decltype(right.size(), void()) + -> decltype(right.size(), void()) { - typedef size_tag_of_t tag1; - typedef dynamic_size_tag tag2; // dynamic/dynamic or fixed/dynamic. - detail::check_same_linear_size( - left, right, size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = dynamic_size_tag; // dynamic/dynamic or fixed/dynamic. + detail::check_same_linear_size(left, right, + size_check_promote_t()); } - /* check_linear_size: */ -template inline void +template +inline void check_linear_size(const readable_matrix& left, int n) { - typedef size_tag_of_t tag; + using tag = size_tag_of_t; detail::check_linear_size(left, n, tag()); } -template inline void +template +inline void check_linear_size(const readable_matrix& left, cml::int_c) { - typedef size_tag_of_t tag; + using tag = size_tag_of_t; detail::check_linear_size(left, cml::int_c(), tag()); } - /* check_same_size: */ -template inline void -check_same_size( - const readable_matrix& left, const readable_matrix& right - ) +template +inline void +check_same_size(const readable_matrix& left, + const readable_matrix& right) { - typedef size_tag_of_t tag1; - typedef size_tag_of_t tag2; - detail::check_same_size( - left, right.actual(), size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = size_tag_of_t; + detail::check_same_size(left, right.actual(), + size_check_promote_t()); } -template inline void -check_same_size( - const readable_matrix& left, Other const (&array)[R][C] - ) +template +inline void +check_same_size(const readable_matrix& left, Other const (&array)[R][C]) { - typedef size_tag_of_t tag1; - typedef fixed_size_tag tag2; - detail::check_same_size(left, array, size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = fixed_size_tag; + detail::check_same_size(left, array, size_check_promote_t()); } - /* check_same_row_size: */ -template inline void -check_same_row_size( - const readable_matrix& left, const readable_vector& right - ) +template +inline void +check_same_row_size(const readable_matrix& left, + const readable_vector& right) { - typedef size_tag_of_t tag1; - typedef size_tag_of_t tag2; - detail::check_same_row_size( - left, right.actual(), size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = size_tag_of_t; + detail::check_same_row_size(left, right.actual(), + size_check_promote_t()); } - /* check_same_col_size: */ -template inline void -check_same_col_size( - const readable_matrix& left, const readable_vector& right - ) +template +inline void +check_same_col_size(const readable_matrix& left, + const readable_vector& right) { - typedef size_tag_of_t tag1; - typedef size_tag_of_t tag2; - detail::check_same_col_size( - left, right.actual(), size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = size_tag_of_t; + detail::check_same_col_size(left, right.actual(), + size_check_promote_t()); } - /* check_same_inner_size: */ -template inline void -check_same_inner_size( - const readable_matrix& left, const readable_matrix& right - ) +template +inline void +check_same_inner_size(const readable_matrix& left, + const readable_matrix& right) { - typedef size_tag_of_t tag1; - typedef size_tag_of_t tag2; - detail::check_same_inner_size( - left.actual(), right.actual(), size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = size_tag_of_t; + detail::check_same_inner_size(left.actual(), right.actual(), + size_check_promote_t()); } -template inline void -check_same_inner_size( - const readable_matrix& left, const readable_vector& right - ) +template +inline void +check_same_inner_size(const readable_matrix& left, + const readable_vector& right) { - typedef size_tag_of_t tag1; - typedef size_tag_of_t tag2; - detail::check_same_inner_size( - left.actual(), right.actual(), size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = size_tag_of_t; + detail::check_same_inner_size(left.actual(), right.actual(), + size_check_promote_t()); } -template inline void -check_same_inner_size( - const readable_vector& left, const readable_matrix& right - ) +template +inline void +check_same_inner_size(const readable_vector& left, + const readable_matrix& right) { - typedef size_tag_of_t tag1; - typedef size_tag_of_t tag2; - detail::check_same_inner_size( - left.actual(), right.actual(), size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = size_tag_of_t; + detail::check_same_inner_size(left.actual(), right.actual(), + size_check_promote_t()); } - /* check_size: */ -template inline void +template +inline void check_size(const readable_matrix& left, int R, int C) { - typedef size_tag_of_t tag; + using tag = size_tag_of_t; detail::check_size(left, R, C, tag()); } -template inline void +template +inline void check_size(const readable_matrix& left, cml::int_c, cml::int_c) { - typedef size_tag_of_t tag; + using tag = size_tag_of_t; detail::check_size(left, cml::int_c(), cml::int_c(), tag()); } - /* check_minimum_size: */ -template inline void +template +inline void check_minimum_size(const readable_matrix& left, int R, int C) { - typedef size_tag_of_t tag; + using tag = size_tag_of_t; detail::check_minimum_size(left, R, C, tag()); } -template inline void -check_minimum_size( - const readable_matrix& left, cml::int_c, cml::int_c - ) +template +inline void +check_minimum_size(const readable_matrix& left, cml::int_c, + cml::int_c) { - typedef size_tag_of_t tag; + using tag = size_tag_of_t; detail::check_minimum_size(left, cml::int_c(), cml::int_c(), tag()); } - /* check_square: */ -template inline void +template +inline void check_square(const readable_matrix& left) { - typedef size_tag_of_t tag; + using tag = size_tag_of_t; detail::check_square(left, tag()); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/temporary.h b/cml/matrix/temporary.h index 738d69f..72a3a60 100644 --- a/cml/matrix/temporary.h +++ b/cml/matrix/temporary.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_temporary_h -#define cml_matrix_temporary_h - #include #include #include @@ -19,28 +14,22 @@ namespace cml { /** Deduce a temporary for a matrix expression. */ template -struct temporary_of< Matrix, cml::enable_if_matrix_t > +struct temporary_of> { - typedef cml::unqualified_type_t matrix_type; + using matrix_type = cml::unqualified_type_t; /* Propagate the element type of the original matrix: */ - typedef matrix_traits traits_type; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using traits_type = matrix_traits; + using value_type = typename traits_type::value_type; + using storage_type = typename traits_type::storage_type; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; /* Need the proxy for the storage type: */ - typedef typename storage_type::proxy_type proxy_type; + using proxy_type = typename storage_type::proxy_type; /* Build the temporary: */ - typedef matrix type; + using type = matrix; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/trace.h b/cml/matrix/trace.h index e973a63..1d38490 100644 --- a/cml/matrix/trace.h +++ b/cml/matrix/trace.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_trace_h -#define cml_matrix_trace_h - #include #include @@ -20,16 +15,11 @@ namespace cml { * dynamically-sized and not square. Fixed-size matrices are checked at * compile-time. */ -template auto -trace(const readable_matrix& M) -> value_type_trait_of_t; +template +auto trace(const readable_matrix& M) -> value_type_trait_of_t; -} // namespace cml +} // namespace cml #define __CML_MATRIX_TRACE_TPP #include #undef __CML_MATRIX_TRACE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/trace.tpp b/cml/matrix/trace.tpp index 90a8b7f..60f115c 100644 --- a/cml/matrix/trace.tpp +++ b/cml/matrix/trace.tpp @@ -1,25 +1,20 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_TRACE_TPP -#error "matrix/trace.tpp not included correctly" +# error "matrix/trace.tpp not included correctly" #endif #include namespace cml { -template inline auto -trace(const readable_matrix& M) --> value_type_trait_of_t +template +inline auto +trace(const readable_matrix& M) -> value_type_trait_of_t { return M.trace(); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/traits.h b/cml/matrix/traits.h index 9713129..ae3324e 100644 --- a/cml/matrix/traits.h +++ b/cml/matrix/traits.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_traits_h -#define cml_matrix_traits_h - #include #include @@ -23,14 +18,9 @@ namespace cml { template struct matrix_traits; /** traits_of for matrix types. */ -template -struct traits_of> { - typedef matrix_traits type; +template struct traits_of> +{ + using type = matrix_traits; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/transpose.h b/cml/matrix/transpose.h index d00b5af..18b54ee 100644 --- a/cml/matrix/transpose.h +++ b/cml/matrix/transpose.h @@ -1,18 +1,8 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_transpose_h -#define cml_matrix_transpose_h - #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/transpose_node.h b/cml/matrix/transpose_node.h index 8e9f008..58a03b8 100644 --- a/cml/matrix/transpose_node.h +++ b/cml/matrix/transpose_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_transpose_node_h -#define cml_matrix_transpose_node_h - #include #include @@ -17,20 +12,19 @@ namespace cml { template class matrix_transpose_node; /** matrix_transpose_node<> traits. */ -template -struct matrix_traits< matrix_transpose_node > +template struct matrix_traits> { - typedef matrix_transpose_node matrix_type; - typedef Sub sub_arg_type; - typedef cml::unqualified_type_t sub_type; - typedef matrix_traits sub_traits; - typedef typename sub_traits::element_traits element_traits; - typedef typename sub_traits::value_type value_type; - typedef typename sub_traits::immutable_value immutable_value; - typedef typename sub_traits::storage_type storage_type; - typedef typename sub_traits::size_tag size_tag; - typedef typename sub_traits::basis_tag basis_tag; - typedef typename sub_traits::layout_tag layout_tag; + using matrix_type = matrix_transpose_node; + using sub_arg_type = Sub; + using sub_type = cml::unqualified_type_t; + using sub_traits = matrix_traits; + using element_traits = typename sub_traits::element_traits; + using value_type = typename sub_traits::value_type; + using immutable_value = typename sub_traits::immutable_value; + using storage_type = typename sub_traits::storage_type; + using size_tag = typename sub_traits::size_tag; + using basis_tag = typename sub_traits::basis_tag; + using layout_tag = typename sub_traits::layout_tag; #if 0 /* Flip the layout: */ @@ -53,109 +47,96 @@ struct matrix_traits< matrix_transpose_node > /** Represents a transpose matrix operation in an expression tree. */ template -class matrix_transpose_node -: public readable_matrix< matrix_transpose_node > +class matrix_transpose_node : public readable_matrix> { public: - - typedef matrix_transpose_node node_type; - typedef readable_matrix readable_type; - typedef matrix_traits traits_type; - typedef typename traits_type::sub_arg_type sub_arg_type; - typedef typename traits_type::sub_type sub_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using node_type = matrix_transpose_node; + using readable_type = readable_matrix; + using traits_type = matrix_traits; + using sub_arg_type = typename traits_type::sub_arg_type; + using sub_type = typename traits_type::sub_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; public: + /** Constant containing the number of rows. */ + static const int array_rows = traits_type::array_rows; - /** Constant containing the number of rows. */ - static const int array_rows = traits_type::array_rows; - - /** Constant containing the number of columns. */ - static const int array_cols = traits_type::array_cols; + /** Constant containing the number of columns. */ + static const int array_cols = traits_type::array_cols; - /** Constant containing the matrix basis enumeration value. */ - static const basis_kind matrix_basis = traits_type::matrix_basis; + /** Constant containing the matrix basis enumeration value. */ + static const basis_kind matrix_basis = traits_type::matrix_basis; - /** Constant containing the array layout enumeration value. */ - static const layout_kind array_layout = traits_type::array_layout; + /** Constant containing the array layout enumeration value. */ + static const layout_kind array_layout = traits_type::array_layout; public: - - /** Construct from the wrapped sub-expression. @c sub must be an + /** Construct from the wrapped sub-expression. @c sub must be an * lvalue reference or rvalue reference type. */ - matrix_transpose_node(Sub sub); + matrix_transpose_node(Sub sub); - /** Move constructor. */ - matrix_transpose_node(node_type&& other); + /** Move constructor. */ + matrix_transpose_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - matrix_transpose_node(const node_type& other); + /** Copy constructor. */ + matrix_transpose_node(const node_type& other); #endif protected: + /** @name readable_matrix Interface */ + /*@{*/ - /** @name readable_matrix Interface */ - /*@{*/ + friend readable_type; - friend readable_type; + /** Return the row size of the transposed matrix expression. */ + int i_rows() const; - /** Return the row size of the transposed matrix expression. */ - int i_rows() const; + /** Return the column size of the transposed matrix expression. */ + int i_cols() const; - /** Return the column size of the transposed matrix expression. */ - int i_cols() const; + /** Return element @c (j,i) of the subexpression. */ + immutable_value i_get(int i, int j) const; - /** Return element @c (j,i) of the subexpression. */ - immutable_value i_get(int i, int j) const; - - /*@}*/ + /*@}*/ protected: - - /** The type used to store the subexpression. The expression is stored + /** The type used to store the subexpression. The expression is stored * as a copy if Sub is an rvalue reference (temporary), or by const * reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const sub_type&, sub_type> sub_wrap_type; + using sub_wrap_type = cml::if_t::value, const sub_type&, + sub_type>; protected: - - /** The wrapped subexpression. */ - sub_wrap_type m_sub; + /** The wrapped subexpression. */ + sub_wrap_type m_sub; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_transpose_node(const node_type&); + // Not copy constructible. + matrix_transpose_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_TRANSPOSE_NODE_TPP #include #undef __CML_MATRIX_TRANSPOSE_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/transpose_node.tpp b/cml/matrix/transpose_node.tpp index 0ea72d6..73de3a5 100644 --- a/cml/matrix/transpose_node.tpp +++ b/cml/matrix/transpose_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_TRANSPOSE_NODE_TPP -#error "matrix/transpose_node.tpp not included correctly" +# error "matrix/transpose_node.tpp not included correctly" #endif namespace cml { @@ -15,48 +13,44 @@ namespace cml { template matrix_transpose_node::matrix_transpose_node(Sub sub) : m_sub(std::move(sub)) -{ -} +{} template matrix_transpose_node::matrix_transpose_node(node_type&& other) : m_sub(std::move(other.m_sub)) -{ -} +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template matrix_transpose_node::matrix_transpose_node(const node_type& other) : m_sub(other.m_sub) -{ -} +{} #endif - /* Internal methods: */ /* readable_matrix interface: */ -template int +template +int matrix_transpose_node::i_rows() const { return this->m_sub.cols(); } -template int +template +int matrix_transpose_node::i_cols() const { return this->m_sub.rows(); } -template auto +template +auto matrix_transpose_node::i_get(int i, int j) const -> immutable_value { - return this->m_sub.get(j,i); + return this->m_sub.get(j, i); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/transpose_ops.h b/cml/matrix/transpose_ops.h index 4ba8202..e5ac618 100644 --- a/cml/matrix/transpose_ops.h +++ b/cml/matrix/transpose_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_transpose_ops_h -#define cml_matrix_transpose_ops_h - #include namespace cml { @@ -17,28 +12,25 @@ namespace cml { * (i.e. derived from readable_matrix<>). */ template* = nullptr> -inline auto make_matrix_transpose_node(Sub&& sub) --> matrix_transpose_node> +inline auto +make_matrix_transpose_node(Sub&& sub) + -> matrix_transpose_node> { - static_assert(std::is_same< - decltype(sub), decltype(std::forward(sub))>::value, + static_assert( + std::is_same(sub))>::value, "internal error: unexpected expression type"); /* Deduce the operand type of the subexpression (&, const&, &&): */ - typedef actual_operand_type_of_t sub_type; + using sub_type = actual_operand_type_of_t; return matrix_transpose_node((sub_type) sub); } template* = nullptr> -inline auto transpose(Sub&& sub) --> decltype(make_matrix_transpose_node(std::forward(sub))) +inline auto +transpose(Sub&& sub) + -> decltype(make_matrix_transpose_node(std::forward(sub))) { return make_matrix_transpose_node(std::forward(sub)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/type_util.h b/cml/matrix/type_util.h index ace3a55..e0af138 100644 --- a/cml/matrix/type_util.h +++ b/cml/matrix/type_util.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_type_util_h -#define cml_matrix_type_util_h - #include #include @@ -19,23 +14,21 @@ namespace cml { * otherwise. The static bool @c value is set to true or false to match @c * type. */ -template struct is_matrix { +template struct is_matrix +{ private: - /* Strip const, volatile, and reference from T to get the type to test: */ - typedef cml::unqualified_type_t naked_type; + using naked_type = cml::unqualified_type_t; /* Deduce the derived type (fails if T is not statically polymorphic): */ - typedef actual_type_of_t derived_type; + using derived_type = actual_type_of_t; public: - /* std::true_type if T is derived from readable_matrix<>, std::false_type * otherwise: */ - typedef std::is_base_of< - readable_matrix, naked_type> type; + using type = std::is_base_of, naked_type>; /* True or false, depending upon 'type': */ static const bool value = type::value; @@ -44,16 +37,12 @@ template struct is_matrix { /** Wrapper for enable_if to detect matrix types (derived from * readable_matrix). */ -template struct enable_if_matrix -: std::enable_if::value> {}; +template +struct enable_if_matrix : std::enable_if::value> +{}; /** Convenience alias for enable_if_matrix. */ -template using enable_if_matrix_t - = typename enable_if_matrix::type; - -} // namespace cml - -#endif +template +using enable_if_matrix_t = typename enable_if_matrix::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/types.h b/cml/matrix/types.h index dd35e78..70810df 100644 --- a/cml/matrix/types.h +++ b/cml/matrix/types.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_types_h -#define cml_matrix_types_h - #include #include @@ -18,133 +13,128 @@ namespace cml { /*@{*/ // Column-basis, row-major: -typedef matrix> matrix22i; -typedef matrix> matrix33i; -typedef matrix> matrix44i; -typedef matrix> matrix23i; -typedef matrix> matrix34i; -typedef matrix> matrixi; -typedef matrix> external22i; -typedef matrix> external33i; -typedef matrix> external44i; -typedef matrix> external23i; -typedef matrix> external34i; -typedef matrix> externalmni; - -typedef matrix> matrix22f; -typedef matrix> matrix33f; -typedef matrix> matrix44f; -typedef matrix> matrix32f; -typedef matrix> matrix34f; -typedef matrix> matrixf; -typedef matrix> external22f; -typedef matrix> external33f; -typedef matrix> external44f; -typedef matrix> external23f; -typedef matrix> external34f; -typedef matrix> externalmnf; - -typedef matrix> matrix22d; -typedef matrix> matrix33d; -typedef matrix> matrix44d; -typedef matrix> matrix23d; -typedef matrix> matrix34d; -typedef matrix> matrixd; -typedef matrix> external22d; -typedef matrix> external33d; -typedef matrix> external44d; -typedef matrix> external23d; -typedef matrix> external34d; -typedef matrix> externalmnd; +using matrix22i = matrix>; +using matrix33i = matrix>; +using matrix44i = matrix>; +using matrix23i = matrix>; +using matrix34i = matrix>; +using matrixi = matrix>; +using external22i = matrix>; +using external33i = matrix>; +using external44i = matrix>; +using external23i = matrix>; +using external34i = matrix>; +using externalmni = matrix>; + +using matrix22f = matrix>; +using matrix33f = matrix>; +using matrix44f = matrix>; +using matrix32f = matrix>; +using matrix34f = matrix>; +using matrixf = matrix>; +using external22f = matrix>; +using external33f = matrix>; +using external44f = matrix>; +using external23f = matrix>; +using external34f = matrix>; +using externalmnf = matrix>; + +using matrix22d = matrix>; +using matrix33d = matrix>; +using matrix44d = matrix>; +using matrix23d = matrix>; +using matrix34d = matrix>; +using matrixd = matrix>; +using external22d = matrix>; +using external33d = matrix>; +using external44d = matrix>; +using external23d = matrix>; +using external34d = matrix>; +using externalmnd = matrix>; // Row-basis, row-major: -typedef matrix, row_basis, row_major> matrix22i_r; -typedef matrix, row_basis, row_major> matrix33i_r; -typedef matrix, row_basis, row_major> matrix44i_r; -typedef matrix, row_basis, row_major> matrix32i_r; -typedef matrix, row_basis, row_major> matrix43i_r; -typedef matrix, row_basis, row_major> matrixi_r; -typedef matrix, row_basis, row_major> external22i_r; -typedef matrix, row_basis, row_major> external33i_r; -typedef matrix, row_basis, row_major> external44i_r; -typedef matrix, row_basis, row_major> external32i_r; -typedef matrix, row_basis, row_major> external43i_r; -typedef matrix, row_basis, row_major> externalmni_r; - - -typedef matrix, row_basis, row_major> matrix22f_r; -typedef matrix, row_basis, row_major> matrix33f_r; -typedef matrix, row_basis, row_major> matrix44f_r; -typedef matrix, row_basis, row_major> matrix32f_r; -typedef matrix, row_basis, row_major> matrix43f_r; -typedef matrix, row_basis, row_major> matrixf_r; -typedef matrix, row_basis, row_major> external22f_r; -typedef matrix, row_basis, row_major> external33f_r; -typedef matrix, row_basis, row_major> external44f_r; -typedef matrix, row_basis, row_major> external32f_r; -typedef matrix, row_basis, row_major> external43f_r; -typedef matrix, row_basis, row_major> externalmnf_r; - -typedef matrix, row_basis, row_major> matrix22d_r; -typedef matrix, row_basis, row_major> matrix33d_r; -typedef matrix, row_basis, row_major> matrix44d_r; -typedef matrix, row_basis, row_major> matrix32d_r; -typedef matrix, row_basis, row_major> matrix43d_r; -typedef matrix, row_basis, row_major> matrixd_r; -typedef matrix, row_basis, row_major> external22d_r; -typedef matrix, row_basis, row_major> external33d_r; -typedef matrix, row_basis, row_major> external44d_r; -typedef matrix, row_basis, row_major> external32d_r; -typedef matrix, row_basis, row_major> external43d_r; -typedef matrix, row_basis, row_major> externalmnd_r; +using matrix22i_r = matrix, row_basis, row_major>; +using matrix33i_r = matrix, row_basis, row_major>; +using matrix44i_r = matrix, row_basis, row_major>; +using matrix32i_r = matrix, row_basis, row_major>; +using matrix43i_r = matrix, row_basis, row_major>; +using matrixi_r = matrix, row_basis, row_major>; +using external22i_r = matrix, row_basis, row_major>; +using external33i_r = matrix, row_basis, row_major>; +using external44i_r = matrix, row_basis, row_major>; +using external32i_r = matrix, row_basis, row_major>; +using external43i_r = matrix, row_basis, row_major>; +using externalmni_r = matrix, row_basis, row_major>; + + +using matrix22f_r = matrix, row_basis, row_major>; +using matrix33f_r = matrix, row_basis, row_major>; +using matrix44f_r = matrix, row_basis, row_major>; +using matrix32f_r = matrix, row_basis, row_major>; +using matrix43f_r = matrix, row_basis, row_major>; +using matrixf_r = matrix, row_basis, row_major>; +using external22f_r = matrix, row_basis, row_major>; +using external33f_r = matrix, row_basis, row_major>; +using external44f_r = matrix, row_basis, row_major>; +using external32f_r = matrix, row_basis, row_major>; +using external43f_r = matrix, row_basis, row_major>; +using externalmnf_r = matrix, row_basis, row_major>; + +using matrix22d_r = matrix, row_basis, row_major>; +using matrix33d_r = matrix, row_basis, row_major>; +using matrix44d_r = matrix, row_basis, row_major>; +using matrix32d_r = matrix, row_basis, row_major>; +using matrix43d_r = matrix, row_basis, row_major>; +using matrixd_r = matrix, row_basis, row_major>; +using external22d_r = matrix, row_basis, row_major>; +using external33d_r = matrix, row_basis, row_major>; +using external44d_r = matrix, row_basis, row_major>; +using external32d_r = matrix, row_basis, row_major>; +using external43d_r = matrix, row_basis, row_major>; +using externalmnd_r = matrix, row_basis, row_major>; // Column-basis, column-major: -typedef matrix, col_basis, col_major> matrix22i_c; -typedef matrix, col_basis, col_major> matrix33i_c; -typedef matrix, col_basis, col_major> matrix44i_c; -typedef matrix, col_basis, col_major> matrix23i_c; -typedef matrix, col_basis, col_major> matrix34i_c; -typedef matrix, col_basis, col_major> matrixi_c; -typedef matrix, col_basis, col_major> external22i_c; -typedef matrix, col_basis, col_major> external33i_c; -typedef matrix, col_basis, col_major> external44i_c; -typedef matrix, col_basis, col_major> external23i_c; -typedef matrix, col_basis, col_major> external34i_c; -typedef matrix, col_basis, col_major> externalmni_c; - -typedef matrix, col_basis, col_major> matrix22f_c; -typedef matrix, col_basis, col_major> matrix33f_c; -typedef matrix, col_basis, col_major> matrix44f_c; -typedef matrix, col_basis, col_major> matrix23f_c; -typedef matrix, col_basis, col_major> matrix34f_c; -typedef matrix, col_basis, col_major> matrixf_c; -typedef matrix, col_basis, col_major> external22f_c; -typedef matrix, col_basis, col_major> external33f_c; -typedef matrix, col_basis, col_major> external44f_c; -typedef matrix, col_basis, col_major> external23f_c; -typedef matrix, col_basis, col_major> external34f_c; -typedef matrix, col_basis, col_major> externalmnf_c; - -typedef matrix, col_basis, col_major> matrix22d_c; -typedef matrix, col_basis, col_major> matrix33d_c; -typedef matrix, col_basis, col_major> matrix44d_c; -typedef matrix, col_basis, col_major> matrix23d_c; -typedef matrix, col_basis, col_major> matrix34d_c; -typedef matrix, col_basis, col_major> matrixd_c; -typedef matrix, col_basis, col_major> external22d_c; -typedef matrix, col_basis, col_major> external33d_c; -typedef matrix, col_basis, col_major> external44d_c; -typedef matrix, col_basis, col_major> external23d_c; -typedef matrix, col_basis, col_major> external34d_c; -typedef matrix, col_basis, col_major> externalmnd_c; +using matrix22i_c = matrix, col_basis, col_major>; +using matrix33i_c = matrix, col_basis, col_major>; +using matrix44i_c = matrix, col_basis, col_major>; +using matrix23i_c = matrix, col_basis, col_major>; +using matrix34i_c = matrix, col_basis, col_major>; +using matrixi_c = matrix, col_basis, col_major>; +using external22i_c = matrix, col_basis, col_major>; +using external33i_c = matrix, col_basis, col_major>; +using external44i_c = matrix, col_basis, col_major>; +using external23i_c = matrix, col_basis, col_major>; +using external34i_c = matrix, col_basis, col_major>; +using externalmni_c = matrix, col_basis, col_major>; + +using matrix22f_c = matrix, col_basis, col_major>; +using matrix33f_c = matrix, col_basis, col_major>; +using matrix44f_c = matrix, col_basis, col_major>; +using matrix23f_c = matrix, col_basis, col_major>; +using matrix34f_c = matrix, col_basis, col_major>; +using matrixf_c = matrix, col_basis, col_major>; +using external22f_c = matrix, col_basis, col_major>; +using external33f_c = matrix, col_basis, col_major>; +using external44f_c = matrix, col_basis, col_major>; +using external23f_c = matrix, col_basis, col_major>; +using external34f_c = matrix, col_basis, col_major>; +using externalmnf_c = matrix, col_basis, col_major>; + +using matrix22d_c = matrix, col_basis, col_major>; +using matrix33d_c = matrix, col_basis, col_major>; +using matrix44d_c = matrix, col_basis, col_major>; +using matrix23d_c = matrix, col_basis, col_major>; +using matrix34d_c = matrix, col_basis, col_major>; +using matrixd_c = matrix, col_basis, col_major>; +using external22d_c = matrix, col_basis, col_major>; +using external33d_c = matrix, col_basis, col_major>; +using external44d_c = matrix, col_basis, col_major>; +using external23d_c = matrix, col_basis, col_major>; +using external34d_c = matrix, col_basis, col_major>; +using externalmnd_c = matrix, col_basis, col_major>; /*@}*/ -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/unary_node.h b/cml/matrix/unary_node.h index 9f5ed09..49e194e 100644 --- a/cml/matrix/unary_node.h +++ b/cml/matrix/unary_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_unary_node_h -#define cml_matrix_unary_node_h - #include #include @@ -17,20 +12,19 @@ namespace cml { template class matrix_unary_node; /** matrix_unary_node<> traits. */ -template -struct matrix_traits< matrix_unary_node > +template struct matrix_traits> { - typedef matrix_unary_node matrix_type; - typedef Sub sub_arg_type; - typedef cml::unqualified_type_t sub_type; - typedef matrix_traits sub_traits; - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; - typedef typename sub_traits::storage_type storage_type; - typedef typename sub_traits::size_tag size_tag; - typedef typename sub_traits::basis_tag basis_tag; - typedef typename sub_traits::layout_tag layout_tag; + using matrix_type = matrix_unary_node; + using sub_arg_type = Sub; + using sub_type = cml::unqualified_type_t; + using sub_traits = matrix_traits; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; + using storage_type = typename sub_traits::storage_type; + using size_tag = typename sub_traits::size_tag; + using basis_tag = typename sub_traits::basis_tag; + using layout_tag = typename sub_traits::layout_tag; /* Propagate the rows from the subexpression: */ static const int array_rows = sub_traits::array_rows; @@ -47,111 +41,98 @@ struct matrix_traits< matrix_unary_node > /** Represents a unary matrix operation in an expression tree. */ template -class matrix_unary_node -: public readable_matrix< matrix_unary_node > +class matrix_unary_node : public readable_matrix> { public: - - typedef matrix_unary_node node_type; - typedef readable_matrix readable_type; - typedef matrix_traits traits_type; - typedef typename traits_type::sub_arg_type sub_arg_type; - typedef typename traits_type::sub_type sub_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using node_type = matrix_unary_node; + using readable_type = readable_matrix; + using traits_type = matrix_traits; + using sub_arg_type = typename traits_type::sub_arg_type; + using sub_type = typename traits_type::sub_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; public: + /** Constant containing the number of rows. */ + static const int array_rows = traits_type::array_rows; - /** Constant containing the number of rows. */ - static const int array_rows = traits_type::array_rows; - - /** Constant containing the number of columns. */ - static const int array_cols = traits_type::array_cols; + /** Constant containing the number of columns. */ + static const int array_cols = traits_type::array_cols; - /** Constant containing the matrix basis enumeration value. */ - static const basis_kind matrix_basis = traits_type::matrix_basis; + /** Constant containing the matrix basis enumeration value. */ + static const basis_kind matrix_basis = traits_type::matrix_basis; - /** Constant containing the array layout enumeration value. */ - static const layout_kind array_layout = traits_type::array_layout; + /** Constant containing the array layout enumeration value. */ + static const layout_kind array_layout = traits_type::array_layout; public: - - /** Construct from the wrapped sub-expression. @c sub must be an + /** Construct from the wrapped sub-expression. @c sub must be an * lvalue reference or rvalue reference type. */ - explicit matrix_unary_node(Sub sub); + explicit matrix_unary_node(Sub sub); - /** Move constructor. */ - matrix_unary_node(node_type&& other); + /** Move constructor. */ + matrix_unary_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - matrix_unary_node(const node_type& other); + /** Copy constructor. */ + matrix_unary_node(const node_type& other); #endif protected: + /** @name readable_matrix Interface */ + /*@{*/ - /** @name readable_matrix Interface */ - /*@{*/ + friend readable_type; - friend readable_type; + /** Return the row size of the matrix expression. */ + int i_rows() const; - /** Return the row size of the matrix expression. */ - int i_rows() const; + /** Return the column size of the matrix expression. */ + int i_cols() const; - /** Return the column size of the matrix expression. */ - int i_cols() const; - - /** Apply the operator to element @c (i,j) of the subexpressions and + /** Apply the operator to element @c (i,j) of the subexpressions and * return the result. */ - immutable_value i_get(int i, int j) const; + immutable_value i_get(int i, int j) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the subexpression. The expression is stored + /** The type used to store the subexpression. The expression is stored * as a copy if Sub is an rvalue reference (temporary), or by const * reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const sub_type&, sub_type> sub_wrap_type; + using sub_wrap_type = cml::if_t::value, const sub_type&, + sub_type>; protected: - - /** The wrapped subexpression. */ - sub_wrap_type m_sub; + /** The wrapped subexpression. */ + sub_wrap_type m_sub; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_unary_node(const node_type&); + // Not copy constructible. + matrix_unary_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_UNARY_NODE_TPP #include #undef __CML_MATRIX_UNARY_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/unary_node.tpp b/cml/matrix/unary_node.tpp index 0b31a9e..e32a9ec 100644 --- a/cml/matrix/unary_node.tpp +++ b/cml/matrix/unary_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_UNARY_NODE_TPP -#error "matrix/unary_node.tpp not included correctly" +# error "matrix/unary_node.tpp not included correctly" #endif namespace cml { @@ -13,50 +11,46 @@ namespace cml { /* matrix_unary_node 'structors: */ template -matrix_unary_node::matrix_unary_node(Sub sub) +matrix_unary_node::matrix_unary_node(Sub sub) : m_sub(std::move(sub)) -{ -} +{} template -matrix_unary_node::matrix_unary_node(node_type&& other) +matrix_unary_node::matrix_unary_node(node_type&& other) : m_sub(std::move(other.m_sub)) -{ -} +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -matrix_unary_node::matrix_unary_node(const node_type& other) +matrix_unary_node::matrix_unary_node(const node_type& other) : m_sub(other.m_sub) -{ -} +{} #endif - /* Internal methods: */ /* readable_matrix interface: */ -template int -matrix_unary_node::i_rows() const +template +int +matrix_unary_node::i_rows() const { return this->m_sub.rows(); } -template int -matrix_unary_node::i_cols() const +template +int +matrix_unary_node::i_cols() const { return this->m_sub.cols(); } -template auto -matrix_unary_node::i_get(int i, int j) const -> immutable_value +template +auto +matrix_unary_node::i_get(int i, int j) const -> immutable_value { - return Op().apply(this->m_sub.get(i,j)); + return Op().apply(this->m_sub.get(i, j)); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/unary_ops.h b/cml/matrix/unary_ops.h index 2bac8f7..46f594e 100644 --- a/cml/matrix/unary_ops.h +++ b/cml/matrix/unary_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_unary_ops_h -#define cml_matrix_unary_ops_h - #include #include @@ -18,35 +13,33 @@ namespace cml { * (i.e. derived from readable_matrix<>). */ template* = nullptr> -inline auto make_matrix_unary_node(Sub&& sub) --> matrix_unary_node, Op> +inline auto +make_matrix_unary_node(Sub&& sub) + -> matrix_unary_node, Op> { - static_assert(std::is_same< - decltype(sub), decltype(std::forward(sub))>::value, + static_assert( + std::is_same(sub))>::value, "internal error: unexpected expression type"); /* Deduce the operand type of the subexpression (&, const&, &&): */ - typedef actual_operand_type_of_t sub_type; + using sub_type = actual_operand_type_of_t; return matrix_unary_node((sub_type) sub); } template* = nullptr> -inline auto operator-(Sub&& sub) --> decltype(make_matrix_unary_node>(std::forward(sub))) +inline auto +operator-(Sub&& sub) -> decltype(make_matrix_unary_node>( + std::forward(sub))) { return make_matrix_unary_node>(std::forward(sub)); } template* = nullptr> -inline auto operator+(Sub&& sub) --> decltype(make_matrix_unary_node>(std::forward(sub))) +inline auto +operator+(Sub&& sub) + -> decltype(make_matrix_unary_node>(std::forward(sub))) { return make_matrix_unary_node>(std::forward(sub)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/matrix/vector_product.h b/cml/matrix/vector_product.h index 183c695..160a40b 100644 --- a/cml/matrix/vector_product.h +++ b/cml/matrix/vector_product.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_vector_product_h -#define cml_matrix_vector_product_h - #include namespace cml { @@ -16,32 +11,23 @@ namespace cml { /** Multiply a vector by a matrix, and return the vector result as a * temporary. */ -template* = nullptr, +template* = nullptr, enable_if_vector_t* = nullptr> auto operator*(Sub1&& sub1, Sub2&& sub2) --> matrix_inner_product_promote_t< - actual_operand_type_of_t, - actual_operand_type_of_t>; + -> matrix_inner_product_promote_t, + actual_operand_type_of_t>; /** Multiply a matrix by a vector, and return the vector result as a * temporary. */ -template* = nullptr, +template* = nullptr, enable_if_matrix_t* = nullptr> auto operator*(Sub1&& sub1, Sub2&& sub2) --> matrix_inner_product_promote_t< - actual_operand_type_of_t, - actual_operand_type_of_t>; + -> matrix_inner_product_promote_t, + actual_operand_type_of_t>; -} // namespace cml +} // namespace cml #define __CML_MATRIX_VECTOR_PRODUCT_TPP #include #undef __CML_MATRIX_VECTOR_PRPDUCT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/vector_product.tpp b/cml/matrix/vector_product.tpp index c549300..e62e96f 100644 --- a/cml/matrix/vector_product.tpp +++ b/cml/matrix/vector_product.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_VECTOR_PRODUCT_TPP -#error "matrix/vector_product.tpp not included correctly" +# error "matrix/vector_product.tpp not included correctly" #endif #include @@ -13,47 +11,47 @@ namespace cml { -template*, enable_if_vector_t*> -inline auto operator*(Sub1&& sub1, Sub2&& sub2) --> matrix_inner_product_promote_t< - actual_operand_type_of_t, - actual_operand_type_of_t> +template*, + enable_if_vector_t*> +inline auto +operator*(Sub1&& sub1, Sub2&& sub2) + -> matrix_inner_product_promote_t, + actual_operand_type_of_t> { - typedef matrix_inner_product_promote_t< + using result_type = matrix_inner_product_promote_t< actual_operand_type_of_t, - actual_operand_type_of_t> result_type; + actual_operand_type_of_t>; cml::check_same_inner_size(sub1, sub2); result_type v; detail::resize(v, array_rows_of(sub1)); - for(int i = 0; i < sub1.rows(); ++ i) { - auto m = sub1(i,0) * sub2[0]; - for(int k = 1; k < sub2.size(); ++ k) m += sub1(i,k) * sub2[k]; + for(int i = 0; i < sub1.rows(); ++i) { + auto m = sub1(i, 0) * sub2[0]; + for(int k = 1; k < sub2.size(); ++k) m += sub1(i, k) * sub2[k]; v[i] = m; } return v; } -template*, enable_if_matrix_t*> -inline auto operator*(Sub1&& sub1, Sub2&& sub2) --> matrix_inner_product_promote_t< - actual_operand_type_of_t, - actual_operand_type_of_t> +template*, + enable_if_matrix_t*> +inline auto +operator*(Sub1&& sub1, Sub2&& sub2) + -> matrix_inner_product_promote_t, + actual_operand_type_of_t> { - typedef matrix_inner_product_promote_t< + using result_type = matrix_inner_product_promote_t< actual_operand_type_of_t, - actual_operand_type_of_t> result_type; + actual_operand_type_of_t>; cml::check_same_inner_size(sub1, sub2); result_type v; detail::resize(v, array_cols_of(sub2)); - for(int j = 0; j < sub2.cols(); ++ j) { - auto m = sub1[0] * sub2(0,j); - for(int k = 1; k < sub1.size(); ++ k) m += sub1[k] * sub2(k,j); + for(int j = 0; j < sub2.cols(); ++j) { + auto m = sub1[0] * sub2(0, j); + for(int k = 1; k < sub1.size(); ++k) m += sub1[k] * sub2(k, j); v[j] = m; } return v; @@ -63,7 +61,4 @@ inline auto operator*(Sub1&& sub1, Sub2&& sub2) // expression node. This requires automatic temporary generation within // the expression tree first, though. -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/matrix/writable_matrix.h b/cml/matrix/writable_matrix.h index 54442e3..bb83bf9 100644 --- a/cml/matrix/writable_matrix.h +++ b/cml/matrix/writable_matrix.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_matrix_writable_matrix_h -#define cml_matrix_writable_matrix_h - #include #include #include @@ -40,333 +35,323 @@ namespace cml { * Note that mutable_value need not be a reference type. */ template -class writable_matrix -: public readable_matrix +class writable_matrix : public readable_matrix { public: - - typedef DerivedT matrix_type; - typedef readable_matrix readable_type; - typedef matrix_traits traits_type; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using matrix_type = DerivedT; + using readable_type = readable_matrix; + using traits_type = matrix_traits; + using value_type = typename traits_type::value_type; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; public: - - /* Disambiguate readable_matrix<> methods: */ - using readable_type::actual; - using readable_type::get; - using readable_type::operator(); + /* Disambiguate readable_matrix<> methods: */ + using readable_type::actual; + using readable_type::get; + using readable_type::operator(); public: + /** Return a mutable reference to the matrix cast as DerivedT. */ + DerivedT& actual(); - /** Return a mutable reference to the matrix cast as DerivedT. */ - DerivedT& actual(); - - /** Set element @c (i,j). */ - template DerivedT& - put(int i, int j, const Other& v) __CML_REF; + /** Set element @c (i,j). */ + template DerivedT& put(int i, int j, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c (i,j) on a temporary. */ - template DerivedT&& - put(int i, int j, const Other& v) &&; + /** Set element @c (i,j) on a temporary. */ + template DerivedT&& put(int i, int j, const Other& v) &&; #endif - /** Return mutable element @c (i,j). */ - mutable_value get(int i, int j); + /** Return mutable element @c (i,j). */ + mutable_value get(int i, int j); - /** Return a mutable reference to element @c (i,j). */ - mutable_value operator()(int i, int j); + /** Return a mutable reference to element @c (i,j). */ + mutable_value operator()(int i, int j); public: - - /** Set element @c j of basis vector @c i. */ - template DerivedT& - set_basis_element(int i, int j, const Other& v) __CML_REF; + /** Set element @c j of basis vector @c i. */ + template + DerivedT& set_basis_element(int i, int j, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c j of basis vector @c i on a temporary. */ - template DerivedT&& - set_basis_element(int i, int j, const Other& v) &&; + /** Set element @c j of basis vector @c i on a temporary. */ + template + DerivedT&& set_basis_element(int i, int j, const Other& v) &&; #endif - /** Copy @c v to row @c i of the matrix. + /** Copy @c v to row @c i of the matrix. * * @throws cml::incompatible_matrix_col_size_error if the matrix is * dynamic and the number of columns does not match the size of * @c v. The sizes are checked at compile time otherwise. */ - template DerivedT& - set_row(int i, const readable_vector& v) __CML_REF; + template + DerivedT& set_row(int i, const readable_vector& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy @c v to row @c i of a temporary matrix. + /** Copy @c v to row @c i of a temporary matrix. * * @throws cml::incompatible_matrix_col_size_error if the matrix is * dynamic and the number of columns does not match the size of * @c v. The sizes are checked at compile time otherwise. */ - template DerivedT&& - set_row(int i, const readable_vector& v) &&; + template + DerivedT&& set_row(int i, const readable_vector& v) &&; #endif - /** Copy @c v to column @c j of the matrix. + /** Copy @c v to column @c j of the matrix. * * @throws cml::incompatible_matrix_row_size_error if the matrix is * dynamic and the number of rows does not match the size of @c v. The * sizes are checked at compile time otherwise. */ - template DerivedT& - set_col(int j, const readable_vector& v) __CML_REF; + template + DerivedT& set_col(int j, const readable_vector& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy @c v to column @c j of a temporary matrix. + /** Copy @c v to column @c j of a temporary matrix. * * @throws cml::incompatible_matrix_row_size_error if the matrix is * dynamic and the number of rows does not match the size of @c v. The * sizes are checked at compile time otherwise. */ - template DerivedT&& - set_col(int j, const readable_vector& v) &&; + template + DerivedT&& set_col(int j, const readable_vector& v) &&; #endif - /** Zero the matrix elements. */ - DerivedT& zero() __CML_REF; + /** Zero the matrix elements. */ + DerivedT& zero() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Zero the matrix elements of a temporary. */ - DerivedT&& zero() &&; + /** Zero the matrix elements of a temporary. */ + DerivedT&& zero() &&; #endif - /** Set the matrix to the identity. */ - DerivedT& identity() __CML_REF; + /** Set the matrix to the identity. */ + DerivedT& identity() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set a temporary matrix to the identity. */ - DerivedT&& identity() &&; + /** Set a temporary matrix to the identity. */ + DerivedT&& identity() &&; #endif - /** Set elements to random values in the range @c[low,high]. */ - DerivedT& random(const_reference low, const_reference high) __CML_REF; + /** Set elements to random values in the range @c[low,high]. */ + DerivedT& random(const_reference low, const_reference high) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set elements of a temporary to random values in the range + /** Set elements of a temporary to random values in the range * @c[low,high]. */ - DerivedT&& random(const_reference low, const_reference high) &&; + DerivedT&& random(const_reference low, const_reference high) &&; #endif - /** Set all elements to a specific value. */ - DerivedT& fill(const_reference v) __CML_REF; + /** Set all elements to a specific value. */ + DerivedT& fill(const_reference v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set all elements of a temporary to a specific value. */ - DerivedT&& fill(const_reference v) &&; + /** Set all elements of a temporary to a specific value. */ + DerivedT&& fill(const_reference v) &&; #endif - /** Set the matrix to its inverse. + /** Set the matrix to its inverse. * * @throws non_square_matrix_error at run-time if the matrix is * dynamically sized and not square. */ - DerivedT& inverse() __CML_REF; + DerivedT& inverse() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set a temporary matrix to its inverse. + /** Set a temporary matrix to its inverse. * * @throws non_square_matrix_error at run-time if the matrix is * dynamically sized and not square. */ - DerivedT&& inverse() &&; + DerivedT&& inverse() &&; #endif - /** Set the matrix to its transpose. + /** Set the matrix to its transpose. * * @note This will raise a compile time error if the matrix is * fixed-size and non-square. Dynamic-size matrices will be assigned * from a temporary. */ - DerivedT& transpose() __CML_REF; + DerivedT& transpose() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set a temporary matrix to its inverse. + /** Set a temporary matrix to its inverse. * * @note This will raise a compile time error if the matrix is * fixed-size and non-square. Dynamic-size matrices will be assigned * from a temporary. */ - DerivedT&& transpose() &&; + DerivedT&& transpose() &&; #endif public: - - /** Assign from a readable_matrix. + /** Assign from a readable_matrix. * * @throws incompatible_matrix_size_error at run-time if the matrix is not * resizable, and if @c other.size() != this->size(). If both are * fixed-size, then the size is checked at compile time. */ - template DerivedT& - operator=(const readable_matrix& other) __CML_REF; + template + DerivedT& operator=(const readable_matrix& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Assign a temporary from a readable_matrix. + /** Assign a temporary from a readable_matrix. * * @throws incompatible_matrix_size_error at run-time if the matrix is not * resizable, and if @c other.size() != this->size(). If both are * fixed-size, then the size is checked at compile time. */ - template DerivedT&& - operator=(const readable_matrix& other) &&; + template + DerivedT&& operator=(const readable_matrix& other) &&; #endif - /** Assign from a fixed-length array type. + /** Assign from a fixed-length array type. * * @throws incompatible_matrix_size_error at run-time if @c * array_size_of_c::value != this->rows()*this->cols(). If both * are fixed-size, then the size is checked at compile time. */ - template* = nullptr> - DerivedT& operator=(const Array& array) __CML_REF; + template* = nullptr> + DerivedT& operator=(const Array& array) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Assign a temporary from a fixed-length array type. + /** Assign a temporary from a fixed-length array type. * * @throws incompatible_matrix_size_error at run-time if @c * array_size_of_c::value != this->rows()*this->cols(). If both * are fixed-size, then the size is checked at compile time. */ - template* = nullptr> - DerivedT&& operator=(const Array& array) &&; + template* = nullptr> + DerivedT&& operator=(const Array& array) &&; #endif - /** Assign from a 2D C-array. + /** Assign from a 2D C-array. * * @throws incompatible_matrix_size_error at run-time if the matrix is * not resizable and does not have the same size as @c array. If both * are fixed-size, then the size is checked at compile time. */ - template - DerivedT& operator=(Other const (&array)[Rows][Cols]) __CML_REF; + template + DerivedT& operator=(Other const (&array)[Rows][Cols]) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Assign a temporary from a fixed-length array type. + /** Assign a temporary from a fixed-length array type. * * @throws incompatible_matrix_size_error at run-time if the matrix is * not resizable and does not have the same size as @c array. If both * are fixed-size, then the size is checked at compile time. */ - template - DerivedT& operator=(Other const (&array)[Rows][Cols]) &&; + template + DerivedT& operator=(Other const (&array)[Rows][Cols]) &&; #endif - /** Assign from initializer list. + /** Assign from initializer list. * * @throws incompatible_matrix_size_error if the matrix is not * resizable, and if @c l.size() != this->size(). */ - template - DerivedT& operator=(std::initializer_list l) __CML_REF; + template + DerivedT& operator=(std::initializer_list l) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Assign a temporary from initializer list. + /** Assign a temporary from initializer list. * * @throws incompatible_matrix_size_error if the matrix is not * resizable, and if @c l.size() != this->size(). */ - template - DerivedT&& operator=(std::initializer_list l) &&; + template DerivedT&& operator=(std::initializer_list l) &&; #endif - /** Modify the matrix by addition of another matrix. + /** Modify the matrix by addition of another matrix. * * @throws incompatible_matrix_size_error at run-time if the matrix is * dynamically-sized, and if @c other.size() != this->size(). If both * are fixed-size expressions, then the size is checked at compile * time. */ - template DerivedT& - operator+=(const readable_matrix& other) __CML_REF; + template + DerivedT& operator+=(const readable_matrix& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Modify a temporary matrix by addition of another matrix. + /** Modify a temporary matrix by addition of another matrix. * * @throws incompatible_matrix_size_error at run-time if the matrix is * dynamically-sized, and if @c other.size() != this->size(). If both * are fixed-size expressions, then the size is checked at compile * time. */ - template DerivedT&& - operator+=(const readable_matrix& other) &&; + template + DerivedT&& operator+=(const readable_matrix& other) &&; #endif - /** Modify the matrix by subtraction of another matrix. + /** Modify the matrix by subtraction of another matrix. * * @throws incompatible_matrix_size_error at run-time if the matrix is * dynamically-sized, and if @c other.size() != this->size(). If both * are fixed-size expressions, then the size is checked at compile * time. */ - template DerivedT& - operator-=(const readable_matrix& other) __CML_REF; + template + DerivedT& operator-=(const readable_matrix& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Modify a temporary matrix by subtraction of another matrix. + /** Modify a temporary matrix by subtraction of another matrix. * * @throws incompatible_matrix_size_error at run-time if the matrix is * dynamically-sized, and if @c other.size() != this->size(). If both * are fixed-size expressions, then the size is checked at compile * time. */ - template DerivedT&& - operator-=(const readable_matrix& other) &&; + template + DerivedT&& operator-=(const readable_matrix& other) &&; #endif - /** Multiply the matrix by a scalar convertible to its value_type. */ - template::type* = nullptr> - DerivedT& operator*=(const ScalarT& v) __CML_REF; + /** Multiply the matrix by a scalar convertible to its value_type. */ + template::type* = nullptr> + DerivedT& operator*=(const ScalarT& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Multiply the matrix temporary by a scalar convertible to its + /** Multiply the matrix temporary by a scalar convertible to its * value_type. */ - template::type* = nullptr> - DerivedT&& operator*=(const ScalarT& v) &&; + template::type* = nullptr> + DerivedT&& operator*=(const ScalarT& v) &&; #endif - /** Divide the matrix by a scalar convertible to its value_type. */ - template::type* = nullptr> - DerivedT& operator/=(const ScalarT& v) __CML_REF; + /** Divide the matrix by a scalar convertible to its value_type. */ + template::type* = nullptr> + DerivedT& operator/=(const ScalarT& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Divide a temporary matrix by a scalar. + /** Divide a temporary matrix by a scalar. * * @note This depends upon implicit conversion of @c v to the * matrix value_type. */ - /** Divide the matrix temporary by a scalar convertible to its + /** Divide the matrix temporary by a scalar convertible to its * value_type. */ - template::type* = nullptr> - DerivedT&& operator/=(const ScalarT& v) &&; + template::type* = nullptr> + DerivedT&& operator/=(const ScalarT& v) &&; #endif protected: - - /** Assign from a readable_matrix. + /** Assign from a readable_matrix. * * @note This depends upon implicit conversion of the source matrix * elements to the matrix value_type. @@ -375,10 +360,10 @@ class writable_matrix * resizable, and if @c other.size() != this->size(). If both are * fixed-size expressions, then the size is checked at compile time. */ - template - DerivedT& assign(const readable_matrix& other); + template + DerivedT& assign(const readable_matrix& other); - /** Assign from an array type. + /** Assign from an array type. * * @note This depends upon implicit conversion of the array elements to * the matrix value_type. @@ -388,10 +373,10 @@ class writable_matrix * this->rows()*this->cols(). If both are fixed-size, then the size is * checked at compile time. */ - template* = nullptr> - DerivedT& assign(const Array& array); + template* = nullptr> + DerivedT& assign(const Array& array); - /** Assign from a 2D C-array type. + /** Assign from a 2D C-array type. * * @note This depends upon implicit conversion of the array elements to * the matrix value_type. @@ -400,10 +385,10 @@ class writable_matrix * not resizable and does not have the same size as @c array. If both * are fixed-size, then the size is checked at compile time. */ - template - DerivedT& assign(Other const (&array)[Rows][Cols]); + template + DerivedT& assign(Other const (&array)[Rows][Cols]); - /** Assign from a pointer to an array. + /** Assign from a pointer to an array. * * @note This depends upon implicit conversion of the array elements to * the matrix value_type. @@ -411,10 +396,10 @@ class writable_matrix * @note The number of elements read from @c array depends upon the * current size of the matrix. */ - template* = nullptr> - DerivedT& assign(const Pointer& array); + template* = nullptr> + DerivedT& assign(const Pointer& array); - /** Assign from an initializer_list. + /** Assign from an initializer_list. * * @note This depends upon implicit conversion of @c Other to the * matrix value_type. @@ -422,10 +407,9 @@ class writable_matrix * @throws incompatible_matrix_size_error if the matrix is not resizable, * and if @c l.size() != this->rows()*this->cols(). */ - template - DerivedT& assign(const std::initializer_list& l); + template DerivedT& assign(const std::initializer_list& l); - /** Construct from a variable list of values. If the matrix has more + /** Construct from a variable list of values. If the matrix has more * elements than the variable argument list, the remaining elements are * set to value_type(0). * @@ -439,45 +423,37 @@ class writable_matrix * not fixed-sized, and if @c sizeof...(eN) > @c (rows()*cols()). If * the matrix is fixed-size, then the size is checked at compile time. */ - template DerivedT& - assign_elements(const Elements&... eN); + template DerivedT& assign_elements(const Elements&... eN); protected: + /** Set basis element @c (i,j) for a row-basis matrix. */ + template + void set_basis_element(int i, int j, const Other& v, row_basis); - /** Set basis element @c (i,j) for a row-basis matrix. */ - template void set_basis_element( - int i, int j, const Other& v, row_basis); - - /** Set basis element @c (i,j) for a column-basis matrix. */ - template void set_basis_element( - int i, int j, const Other& v, col_basis); + /** Set basis element @c (i,j) for a column-basis matrix. */ + template + void set_basis_element(int i, int j, const Other& v, col_basis); protected: + // Use the compiler-generated default constructor: + writable_matrix() = default; - // Use the compiler-generated default constructor: - writable_matrix() = default; - - // Use the compiler-generated copy constructor: - writable_matrix(const writable_matrix&) = default; + // Use the compiler-generated copy constructor: + writable_matrix(const writable_matrix&) = default; #ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR - // Use the compiler-generated move constructor: - writable_matrix(writable_matrix&&) = default; + // Use the compiler-generated move constructor: + writable_matrix(writable_matrix&&) = default; #endif - // Force assignment through operator=(readable_matrix<>): - writable_matrix& operator=(const writable_matrix&) = delete; + // Force assignment through operator=(readable_matrix<>): + writable_matrix& operator=(const writable_matrix&) = delete; }; -} // namespace cml +} // namespace cml #define __CML_MATRIX_WRITABLE_MATRIX_TPP #include #undef __CML_MATRIX_WRITABLE_MATRIX_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/matrix/writable_matrix.tpp b/cml/matrix/writable_matrix.tpp index 4afcf92..ff4c9c6 100644 --- a/cml/matrix/writable_matrix.tpp +++ b/cml/matrix/writable_matrix.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_MATRIX_WRITABLE_MATRIX_TPP -#error "matrix/writable_matrix.tpp not included correctly" +# error "matrix/writable_matrix.tpp not included correctly" #endif #include @@ -22,7 +20,8 @@ namespace cml { namespace detail { /* Terminate the assignment recursion at the final element. */ -template inline void +template +inline void assign_elements(writable_matrix& sub, const E0& e0) { sub.put(I / sub.cols(), I % sub.cols(), e0); @@ -32,64 +31,70 @@ assign_elements(writable_matrix& sub, const E0& e0) * of the elements starting from I+1. */ template -inline void assign_elements( - writable_matrix& sub, const E0& e0, const Es&... eN - ) +inline void +assign_elements(writable_matrix& sub, const E0& e0, const Es&... eN) { sub.put(I / sub.cols(), I % sub.cols(), e0); - assign_elements(sub, eN...); + assign_elements(sub, eN...); } /* Assign elements of @c sub from @c eN, assuming @c eN is given in * row-major order. */ -template inline void +template +inline void assign_elements(writable_matrix& sub, const Es&... eN) { assign_elements<0>(sub, eN...); } -} // namespace detail - - +} // namespace detail /* Public methods: */ -template DT& +template +DT& writable_matrix
::actual() { return (DT&) *this; } -template auto +template +auto writable_matrix
::get(int i, int j) -> mutable_value { - return this->actual().i_get(i,j); + return this->actual().i_get(i, j); } -template template DT& +template +template +DT& writable_matrix
::put(int i, int j, const Other& v) __CML_REF { - return this->actual().i_put(i,j,v); + return this->actual().i_put(i, j, v); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_matrix
::put(int i, int j, const Other& v) && { - this->put(i,j,v); // Forward to put(...) & + this->put(i, j, v); // Forward to put(...) & return (DT&&) *this; } #endif -template auto +template +auto writable_matrix
::operator()(int i, int j) -> mutable_value { - return this->get(i,j); + return this->get(i, j); } - -template template DT& +template +template +DT& writable_matrix
::set_basis_element(int i, int j, const Other& v) __CML_REF { this->set_basis_element(i, j, v, basis_tag()); @@ -97,25 +102,31 @@ writable_matrix
::set_basis_element(int i, int j, const Other& v) __CML_REF } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_matrix
::set_basis_element(int i, int j, const Other& v) && { - this->set_basis_element(i,j,v); // Forward to set_basis_element(...) & + this->set_basis_element(i, j, v); // Forward to set_basis_element(...) & return (DT&&) *this; } #endif -template template DT& +template +template +DT& writable_matrix
::set_row(int i, const readable_vector& v) __CML_REF { cml::check_same_col_size(*this, v); - for(int j = 0; j < this->cols(); ++ j) this->put(i,j, v.get(j)); + for(int j = 0; j < this->cols(); ++j) this->put(i, j, v.get(j)); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_matrix
::set_row(int i, const readable_vector& v) && { this->set_row(i, v); @@ -123,16 +134,20 @@ writable_matrix
::set_row(int i, const readable_vector& v) && } #endif -template template DT& +template +template +DT& writable_matrix
::set_col(int j, const readable_vector& v) __CML_REF { cml::check_same_row_size(*this, v); - for(int i = 0; i < this->rows(); ++ i) this->put(i,j, v.get(i)); + for(int i = 0; i < this->rows(); ++i) this->put(i, j, v.get(i)); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_matrix
::set_col(int j, const readable_vector& v) && { this->set_col(j, v); @@ -141,25 +156,28 @@ writable_matrix
::set_col(int j, const readable_vector& v) && #endif -template DT& +template +DT& writable_matrix
::zero() __CML_REF { - auto zero_f = [](int,int) { return value_type(0); }; + auto zero_f = [](int, int) { return value_type(0); }; detail::generate(*this, zero_f, layout_tag()); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_matrix
::zero() && { - this->zero(); // Forward to zero & + this->zero(); // Forward to zero & return (DT&&) *this; } #endif -template DT& +template +DT& writable_matrix
::identity() __CML_REF { auto identity_f = [](int i, int j) { return value_type(i == j); }; @@ -168,33 +186,34 @@ writable_matrix
::identity() __CML_REF } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_matrix
::identity() && { - this->identity(); // Forward to zero & + this->identity(); // Forward to zero & return (DT&&) *this; } #endif -template DT& -writable_matrix
::random( - const_reference low, const_reference high - ) __CML_REF +template +DT& +writable_matrix
::random(const_reference low, const_reference high) __CML_REF { - typedef if_t::value - , std::uniform_int_distribution - , std::uniform_real_distribution> distribution_type; + using distribution_type = if_t::value, + std::uniform_int_distribution, + std::uniform_real_distribution>; - std::random_device rd; // Non-deterministic seed, if supported. + std::random_device rd; // Non-deterministic seed, if supported. std::default_random_engine gen(rd()); distribution_type d(low, high); - auto random_f = [&d,&gen](int,int) { return d(gen); }; + auto random_f = [&d, &gen](int, int) { return d(gen); }; detail::generate(*this, random_f, layout_tag()); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_matrix
::random(const_reference low, const_reference high) && { this->random(low, high); @@ -202,15 +221,18 @@ writable_matrix
::random(const_reference low, const_reference high) && } #endif -template DT& +template +DT& writable_matrix
::fill(const_reference v) __CML_REF { - detail::generate(*this, [&v](int,int) { return v; }, layout_tag()); + detail::generate( + *this, [&v](int, int) { return v; }, layout_tag()); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_matrix
::fill(const_reference v) && { this->fill(v); @@ -218,7 +240,8 @@ writable_matrix
::fill(const_reference v) && } #endif -template DT& +template +DT& writable_matrix
::inverse() __CML_REF { cml::check_square(*this); @@ -227,7 +250,8 @@ writable_matrix
::inverse() __CML_REF } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_matrix
::inverse() && { this->inverse(); @@ -235,16 +259,18 @@ writable_matrix
::inverse() && } #endif -template DT& +template +DT& writable_matrix
::transpose() __CML_REF { - typedef size_tag_of_t tag; + using tag = size_tag_of_t; detail::transpose(*this, tag()); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_matrix
::transpose() && { this->transpose(); @@ -253,14 +279,18 @@ writable_matrix
::transpose() && #endif -template template DT& +template +template +DT& writable_matrix
::operator=(const readable_matrix& other) __CML_REF { return this->assign(other); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_matrix
::operator=(const readable_matrix& other) && { this->operator=(other); @@ -268,14 +298,18 @@ writable_matrix
::operator=(const readable_matrix& other) && } #endif -template template*> DT& +template +template*> +DT& writable_matrix
::operator=(const Array& array) __CML_REF { return this->assign(array); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template*> DT&& +template +template*> +DT&& writable_matrix
::operator=(const Array& array) && { this->operator=(array); @@ -284,7 +318,8 @@ writable_matrix
::operator=(const Array& array) && #endif template -template DT& +template +DT& writable_matrix
::operator=(Other const (&array)[Rows][Cols]) __CML_REF { return this->assign(array); @@ -292,7 +327,8 @@ writable_matrix
::operator=(Other const (&array)[Rows][Cols]) __CML_REF #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template DT& +template +DT& writable_matrix
::operator=(Other const (&array)[Rows][Cols]) && { this->operator=(array); @@ -300,30 +336,38 @@ writable_matrix
::operator=(Other const (&array)[Rows][Cols]) && } #endif -template template DT& +template +template +DT& writable_matrix
::operator=(std::initializer_list l) __CML_REF { return this->assign(l); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_matrix
::operator=(std::initializer_list l) && { return this->assign(l); } #endif -template template DT& +template +template +DT& writable_matrix
::operator+=(const readable_matrix& other) __CML_REF { detail::check_or_resize(*this, other); - detail::apply< binary_plus_t >(*this, other, layout_tag()); + detail::apply>(*this, other, layout_tag()); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_matrix
::operator+=(const readable_matrix& other) && { this->operator+=(other); @@ -331,16 +375,20 @@ writable_matrix
::operator+=(const readable_matrix& other) && } #endif -template template DT& +template +template +DT& writable_matrix
::operator-=(const readable_matrix& other) __CML_REF { detail::check_or_resize(*this, other); - detail::apply< binary_minus_t >(*this, other, layout_tag()); + detail::apply>(*this, other, layout_tag()); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_matrix
::operator-=(const readable_matrix& other) && { this->operator-=(other); @@ -350,19 +398,21 @@ writable_matrix
::operator-=(const readable_matrix& other) && template -template::value_type, ScalarT>::type*> +template::value_type, + ScalarT>::type*> DT& writable_matrix
::operator*=(const ScalarT& v) __CML_REF { - detail::apply< binary_multiply_t >(*this, v, layout_tag()); + detail::apply>(*this, v, layout_tag()); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template::value_type, ScalarT>::type*> +template::value_type, + ScalarT>::type*> DT&& writable_matrix
::operator*=(const ScalarT& v) && { @@ -372,19 +422,21 @@ writable_matrix
::operator*=(const ScalarT& v) && #endif template -template::value_type, ScalarT>::type*> +template::value_type, + ScalarT>::type*> DT& writable_matrix
::operator/=(const ScalarT& v) __CML_REF { - detail::apply< binary_divide_t >(*this, v, layout_tag()); + detail::apply>(*this, v, layout_tag()); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template::value_type, ScalarT>::type*> +template::value_type, + ScalarT>::type*> DT&& writable_matrix
::operator/=(const ScalarT& v) && { @@ -394,10 +446,11 @@ writable_matrix
::operator/=(const ScalarT& v) && #endif - /* Internal methods: */ -template template DT& +template +template +DT& writable_matrix
::assign(const readable_matrix& other) { detail::check_or_resize(*this, other); @@ -405,18 +458,22 @@ writable_matrix
::assign(const readable_matrix& other) return this->actual(); } -template template*> DT& +template +template*> +DT& writable_matrix
::assign(const Array& array) { cml::check_same_linear_size(*this, array); int cols = this->cols(); - for(int i = 0; i < array_size_of_c::value; ++ i) { - this->put(i/cols, i%cols, array[i]); + for(int i = 0; i < array_size_of_c::value; ++i) { + this->put(i / cols, i % cols, array[i]); } return this->actual(); } -template template DT& +template +template +DT& writable_matrix
::assign(Other const (&array)[R][C]) { detail::check_or_resize(*this, array); @@ -425,25 +482,32 @@ writable_matrix
::assign(Other const (&array)[R][C]) } template -template*> DT& +template*> +DT& writable_matrix
::assign(const Pointer& array) { int rows = this->rows(), cols = this->cols(); - for(int i = 0; i < rows*cols; ++ i) - this->put(i/cols, i%cols, array[i]); + for(int i = 0; i < rows * cols; ++i) this->put(i / cols, i % cols, array[i]); return this->actual(); } -template template DT& +template +template +DT& writable_matrix
::assign(const std::initializer_list& l) { cml::check_same_linear_size(*this, l); int cols = this->cols(), i = 0; - for(Other v : l) { this->put(i/cols, i%cols, v); ++ i; } + for(Other v : l) { + this->put(i / cols, i % cols, v); + ++i; + } return this->actual(); } -template template DT& +template +template +DT& writable_matrix
::assign_elements(const Es&... eN) { static const int N = int(sizeof...(eN)); @@ -456,24 +520,20 @@ writable_matrix
::assign_elements(const Es&... eN) return this->actual(); } - -template template void -writable_matrix
::set_basis_element( - int i, int j, const Other& v, row_basis - ) +template +template +void +writable_matrix
::set_basis_element(int i, int j, const Other& v, row_basis) { this->put(i, j, v); } -template template void -writable_matrix
::set_basis_element( - int i, int j, const Other& v, col_basis - ) +template +template +void +writable_matrix
::set_basis_element(int i, int j, const Other& v, col_basis) { this->put(j, i, v); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion.h b/cml/quaternion.h index 20d747e..c7d107e 100644 --- a/cml/quaternion.h +++ b/cml/quaternion.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_h -#define cml_quaternion_h - #include #include #include @@ -20,8 +15,3 @@ #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/binary_node.h b/cml/quaternion/binary_node.h index 9deb117..486fd1f 100644 --- a/cml/quaternion/binary_node.h +++ b/cml/quaternion/binary_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_binary_node_h -#define cml_quaternion_binary_node_h - #include #include @@ -18,26 +13,25 @@ template class quaternion_binary_node; /** quaternion_binary_node<> traits. */ template -struct quaternion_traits< quaternion_binary_node > +struct quaternion_traits> { - typedef quaternion_binary_node quaternion_type; - typedef Sub1 left_arg_type; - typedef Sub2 right_arg_type; - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef quaternion_traits left_traits; - typedef quaternion_traits right_traits; - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; + using quaternion_type = quaternion_binary_node; + using left_arg_type = Sub1; + using right_arg_type = Sub2; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = quaternion_traits; + using right_traits = quaternion_traits; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; /* Determine the common storage type for the node, based on the storage * types of its subexpressions: */ - typedef quaternion_binary_storage_promote_t< - storage_type_of_t, - storage_type_of_t> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = quaternion_binary_storage_promote_t, + storage_type_of_t>; + using size_tag = typename storage_type::size_tag; static_assert(cml::is_fixed_size::value, "invalid size tag"); /* Array size: */ @@ -45,48 +39,43 @@ struct quaternion_traits< quaternion_binary_node > static_assert(array_size == 4, "invalid quaternion size"); /* Determine the common order type: */ - typedef order_type_promote_t< - order_type_of_t, - order_type_of_t> order_type; + using order_type = order_type_promote_t, + order_type_of_t>; /* Determine the common cross type: */ - typedef cross_type_promote_t< - cross_type_of_t, - cross_type_of_t> cross_type; + using cross_type = cross_type_promote_t, + cross_type_of_t>; }; /** Represents a binary quaternion operation in an expression tree. */ template class quaternion_binary_node -: public readable_quaternion< quaternion_binary_node > +: public readable_quaternion> { public: - - typedef quaternion_binary_node node_type; - typedef readable_quaternion readable_type; - typedef quaternion_traits traits_type; - typedef typename traits_type::left_arg_type left_arg_type; - typedef typename traits_type::right_arg_type right_arg_type; - typedef typename traits_type::left_type left_type; - typedef typename traits_type::right_type right_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::order_type order_type; - typedef typename traits_type::cross_type cross_type; + using node_type = quaternion_binary_node; + using readable_type = readable_quaternion; + using traits_type = quaternion_traits; + using left_arg_type = typename traits_type::left_arg_type; + using right_arg_type = typename traits_type::right_arg_type; + using left_type = typename traits_type::left_type; + using right_type = typename traits_type::right_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using order_type = typename traits_type::order_type; + using cross_type = typename traits_type::cross_type; public: - - /** Constant containing the array size. */ - static const int array_size = traits_type::array_size; + /** Constant containing the array size. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be + /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be * lvalue reference or rvalue reference types. * * @throws incompatible_quaternion_size_error at run-time if either Sub1 or @@ -94,76 +83,67 @@ class quaternion_binary_node * If both Sub1 and Sub2 are fixed-size expressions, then the sizes are * checked at compile time. */ - quaternion_binary_node(Sub1 left, Sub2 right); + quaternion_binary_node(Sub1 left, Sub2 right); - /** Move constructor. */ - quaternion_binary_node(node_type&& other); + /** Move constructor. */ + quaternion_binary_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - quaternion_binary_node(const node_type& other); + /** Copy constructor. */ + quaternion_binary_node(const node_type& other); #endif protected: + /** @name readable_quaternion Interface */ + /*@{*/ - /** @name readable_quaternion Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Apply the operator to element @c i of the subexpressions and return + /** Apply the operator to element @c i of the subexpressions and return * the result. */ - immutable_value i_get(int i) const; + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the left subexpression. The expression is + /** The type used to store the left subexpression. The expression is * stored as a copy if Sub1 is an rvalue reference (temporary), or by * const reference if Sub1 is an lvalue reference. */ - typedef cml::if_t::value, - const left_type&, left_type> left_wrap_type; + using left_wrap_type = cml::if_t::value, const left_type&, + left_type>; - /** The type used to store the right subexpression. The expression is + /** The type used to store the right subexpression. The expression is * stored as a copy if Sub2 is an rvalue reference (temporary), or by * const reference if Sub2 is an lvalue reference. */ - typedef cml::if_t::value, - const right_type&, right_type> right_wrap_type; + using right_wrap_type = cml::if_t::value, const right_type&, + right_type>; protected: + /** The wrapped left subexpression. */ + left_wrap_type m_left; - /** The wrapped left subexpression. */ - left_wrap_type m_left; - - /** The wrapped right subexpression. */ - right_wrap_type m_right; + /** The wrapped right subexpression. */ + right_wrap_type m_right; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - quaternion_binary_node(const node_type&); + // Not copy constructible. + quaternion_binary_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_BINARY_NODE_TPP #include #undef __CML_QUATERNION_BINARY_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/binary_node.tpp b/cml/quaternion/binary_node.tpp index 86e52cf..46551bc 100644 --- a/cml/quaternion/binary_node.tpp +++ b/cml/quaternion/binary_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_BINARY_NODE_TPP -#error "quaternion/binary_node.tpp not included correctly" +# error "quaternion/binary_node.tpp not included correctly" #endif namespace cml { @@ -13,24 +11,26 @@ namespace cml { /* quaternion_binary_node 'structors: */ template -quaternion_binary_node::quaternion_binary_node(Sub1 left, Sub2 right) -: m_left(std::move(left)), m_right(std::move(right)) -{ -} +quaternion_binary_node::quaternion_binary_node(Sub1 left, + Sub2 right) +: m_left(std::move(left)) +, m_right(std::move(right)) +{} template -quaternion_binary_node::quaternion_binary_node(node_type&& other) -: m_left(std::move(other.m_left)), m_right(std::move(other.m_right)) -{ -} +quaternion_binary_node::quaternion_binary_node( + node_type&& other) +: m_left(std::move(other.m_left)) +, m_right(std::move(other.m_right)) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -quaternion_binary_node -::quaternion_binary_node(const node_type& other) -: m_left(other.m_left), m_right(other.m_right) -{ -} +quaternion_binary_node::quaternion_binary_node( + const node_type& other) +: m_left(other.m_left) +, m_right(other.m_right) +{} #endif @@ -38,13 +38,11 @@ quaternion_binary_node /* readable_quaternion interface: */ -template auto -quaternion_binary_node::i_get(int i) const -> immutable_value +template +auto +quaternion_binary_node::i_get(int i) const -> immutable_value { return Op().apply(this->m_left.get(i), this->m_right.get(i)); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/binary_ops.h b/cml/quaternion/binary_ops.h index 1d51f6a..02f3c07 100644 --- a/cml/quaternion/binary_ops.h +++ b/cml/quaternion/binary_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_binary_ops_h -#define cml_quaternion_binary_ops_h - #include #include @@ -22,51 +17,43 @@ template* = nullptr> inline auto make_quaternion_binary_node(Sub1&& sub1, Sub2&& sub2) --> quaternion_binary_node< -actual_operand_type_of_t, -actual_operand_type_of_t, -Op -> + -> quaternion_binary_node, + actual_operand_type_of_t, Op> { - static_assert(std::is_same< - decltype(sub1), decltype(std::forward(sub1))>::value, + static_assert( + std::is_same(sub1))>::value, "internal error: unexpected expression type (sub1)"); - static_assert(std::is_same< - decltype(sub2), decltype(std::forward(sub2))>::value, + static_assert( + std::is_same(sub2))>::value, "internal error: unexpected expression type (sub2)"); /* Deduce the operand types of the subexpressions (&, const&, &&): */ - typedef actual_operand_type_of_t sub1_type; - typedef actual_operand_type_of_t sub2_type; - return quaternion_binary_node< - sub1_type, sub2_type, Op>((sub1_type) sub1, (sub2_type) sub2); + using sub1_type = actual_operand_type_of_t; + using sub2_type = actual_operand_type_of_t; + return quaternion_binary_node((sub1_type) sub1, + (sub2_type) sub2); } -template* = nullptr, -enable_if_quaternion_t* = nullptr> -inline auto operator-(Sub1&& sub1, Sub2&& sub2) --> decltype(make_quaternion_binary_node>( +template* = nullptr, + enable_if_quaternion_t* = nullptr> +inline auto +operator-(Sub1&& sub1, Sub2&& sub2) + -> decltype(make_quaternion_binary_node>( std::forward(sub1), std::forward(sub2))) { - return make_quaternion_binary_node> - (std::forward(sub1), std::forward(sub2)); + return make_quaternion_binary_node>( + std::forward(sub1), std::forward(sub2)); } -template* = nullptr, -enable_if_quaternion_t* = nullptr> -inline auto operator+(Sub1&& sub1, Sub2&& sub2) --> decltype(make_quaternion_binary_node>( +template* = nullptr, + enable_if_quaternion_t* = nullptr> +inline auto +operator+(Sub1&& sub1, Sub2&& sub2) + -> decltype(make_quaternion_binary_node>( std::forward(sub1), std::forward(sub2))) { - return make_quaternion_binary_node> - (std::forward(sub1), std::forward(sub2)); + return make_quaternion_binary_node>( + std::forward(sub1), std::forward(sub2)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/comparison.h b/cml/quaternion/comparison.h index cfc45fb..96ab96a 100644 --- a/cml/quaternion/comparison.h +++ b/cml/quaternion/comparison.h @@ -1,57 +1,53 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_comparison_h -#define cml_quaternion_comparison_h - #include namespace cml { /** Returns true if @c left is lexicographically less than @c right. */ -template bool operator<( - const readable_quaternion& left, const readable_quaternion& right); +template +bool operator<(const readable_quaternion& left, + const readable_quaternion& right); /** Returns true if @c left is lexicographically less than or equal to @c * right. */ -template bool operator<=( - const readable_quaternion& left, const readable_quaternion& right); +template +bool operator<=(const readable_quaternion& left, + const readable_quaternion& right); /** Returns true if @c left is lexicographically greater than @c right. */ -template bool operator>( - const readable_quaternion& left, const readable_quaternion& right); +template +bool operator>(const readable_quaternion& left, + const readable_quaternion& right); /** Returns true if @c left is lexicographically greater than or equal to * @c right. */ -template bool operator>=( - const readable_quaternion& left, const readable_quaternion& right); +template +bool operator>=(const readable_quaternion& left, + const readable_quaternion& right); /** Returns true if the elements of @c left are all equal to the elements * of @c right. */ -template bool operator==( - const readable_quaternion& left, const readable_quaternion& right); +template +bool operator==(const readable_quaternion& left, + const readable_quaternion& right); /** Returns true if some element of @c left is not equal to the * corresponding element of @c right. */ -template bool operator!=( - const readable_quaternion& left, const readable_quaternion& right); +template +bool operator!=(const readable_quaternion& left, + const readable_quaternion& right); -} // namespace cml +} // namespace cml #define __CML_QUATERNION_COMPARISON_TPP #include #undef __CML_QUATERNION_COMPARISON_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/comparison.tpp b/cml/quaternion/comparison.tpp index a91bb29..4445461 100644 --- a/cml/quaternion/comparison.tpp +++ b/cml/quaternion/comparison.tpp @@ -1,86 +1,92 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_COMPARISON_TPP -#error "quaternion/comparison.tpp not included correctly" +# error "quaternion/comparison.tpp not included correctly" #endif #include namespace cml { -template inline bool operator<( - const readable_quaternion& left, const readable_quaternion& right - ) +template +inline bool +operator<(const readable_quaternion& left, + const readable_quaternion& right) { - static_assert(std::is_same< - order_type_trait_of_t, order_type_trait_of_t>::value, + static_assert( + std::is_same, + order_type_trait_of_t>::value, "cannot compare quaternions with different orders"); - for(int i = 0; i < 4; i ++) { - /**/ if(left[i] < right[i]) return true; // Strictly less. - else if(left[i] > right[i]) return false; // Strictly greater. - else continue; // Equal. + for(int i = 0; i < 4; i++) { + /**/ if(left[i] < right[i]) + return true; // Strictly less. + else if(left[i] > right[i]) return false; // Strictly greater. + else continue; // Equal. } /* Equal. */ return false; } -template inline bool operator>( - const readable_quaternion& left, const readable_quaternion& right - ) +template +inline bool +operator>(const readable_quaternion& left, + const readable_quaternion& right) { - static_assert(std::is_same< - order_type_trait_of_t, order_type_trait_of_t>::value, + static_assert( + std::is_same, + order_type_trait_of_t>::value, "cannot compare quaternions with different orders"); - for(int i = 0; i < 4; i ++) { - /**/ if(left[i] > right[i]) return true; // Strictly greater. - else if(left[i] < right[i]) return false; // Strictly less. - else continue; // Equal. + for(int i = 0; i < 4; i++) { + /**/ if(left[i] > right[i]) + return true; // Strictly greater. + else if(left[i] < right[i]) return false; // Strictly less. + else continue; // Equal. } /* Equal. */ return false; } -template inline bool operator==( - const readable_quaternion& left, const readable_quaternion& right - ) +template +inline bool +operator==(const readable_quaternion& left, + const readable_quaternion& right) { - static_assert(std::is_same< - order_type_trait_of_t, order_type_trait_of_t>::value, + static_assert( + std::is_same, + order_type_trait_of_t>::value, "cannot compare quaternions with different orders"); - for(int i = 0; i < 4; i ++) { - if(!(left[i] == right[i])) return false; // Not equal. + for(int i = 0; i < 4; i++) { + if(!(left[i] == right[i])) return false; // Not equal. } return true; } -template inline bool operator<=( - const readable_quaternion& left, const readable_quaternion& right - ) +template +inline bool +operator<=(const readable_quaternion& left, + const readable_quaternion& right) { return !(left > right); } -template inline bool operator>=( - const readable_quaternion& left, const readable_quaternion& right - ) +template +inline bool +operator>=(const readable_quaternion& left, + const readable_quaternion& right) { return !(left < right); } -template inline bool operator!=( - const readable_quaternion& left, const readable_quaternion& right - ) +template +inline bool +operator!=(const readable_quaternion& left, + const readable_quaternion& right) { return !(left == right); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/conjugate.h b/cml/quaternion/conjugate.h index 73dbfb4..84ea247 100644 --- a/cml/quaternion/conjugate.h +++ b/cml/quaternion/conjugate.h @@ -1,18 +1,8 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_conjugate_h -#define cml_quaternion_conjugate_h - #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/conjugate_node.h b/cml/quaternion/conjugate_node.h index 595cb16..adb5e50 100644 --- a/cml/quaternion/conjugate_node.h +++ b/cml/quaternion/conjugate_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_conjugate_node_h -#define cml_quaternion_conjugate_node_h - #include namespace cml { @@ -16,20 +11,19 @@ namespace cml { template class conjugate_node; /** conjugate_node<> traits. */ -template -struct quaternion_traits< conjugate_node > +template struct quaternion_traits> { /* Figure out the basic type of Sub: */ - typedef conjugate_node quaternion_type; - typedef Sub sub_arg_type; - typedef cml::unqualified_type_t sub_type; - typedef quaternion_traits sub_traits; - typedef scalar_traits> element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; - typedef typename sub_traits::storage_type storage_type; - - typedef typename sub_traits::size_tag size_tag; + using quaternion_type = conjugate_node; + using sub_arg_type = Sub; + using sub_type = cml::unqualified_type_t; + using sub_traits = quaternion_traits; + using element_traits = scalar_traits>; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; + using storage_type = typename sub_traits::storage_type; + + using size_tag = typename sub_traits::size_tag; static_assert(cml::is_fixed_size::value, "invalid size tag"); /* Array size: */ @@ -37,95 +31,83 @@ struct quaternion_traits< conjugate_node > static_assert(array_size == 4, "invalid quaternion size"); /* Order and cross taken from the sub-expression: */ - typedef typename sub_traits::order_type order_type; - typedef typename sub_traits::cross_type cross_type; + using order_type = typename sub_traits::order_type; + using cross_type = typename sub_traits::cross_type; }; /** Represents the conjugate of a quaternion subexpression. */ template -class conjugate_node -: public readable_quaternion< conjugate_node > +class conjugate_node : public readable_quaternion> { public: - - typedef conjugate_node node_type; - typedef readable_quaternion readable_type; - typedef quaternion_traits traits_type; - typedef typename traits_type::sub_arg_type sub_arg_type; - typedef typename traits_type::sub_type sub_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using node_type = conjugate_node; + using readable_type = readable_quaternion; + using traits_type = quaternion_traits; + using sub_arg_type = typename traits_type::sub_arg_type; + using sub_type = typename traits_type::sub_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** The array size constant depends upon the subexpression size. */ - static const int array_size = traits_type::array_size; + /** The array size constant depends upon the subexpression size. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped quaternion expression. @c sub must be + /** Construct from the wrapped quaternion expression. @c sub must be * an lvalue reference or rvalue reference. */ - explicit conjugate_node(Sub sub); + explicit conjugate_node(Sub sub); - /** Move constructor. */ - conjugate_node(node_type&& other); + /** Move constructor. */ + conjugate_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - conjugate_node(const node_type& other); + /** Copy constructor. */ + conjugate_node(const node_type& other); #endif protected: + /** @name readable_quaternion Interface */ + /*@{*/ - /** @name readable_quaternion Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Apply the operator to element @c i and return the result. */ - immutable_value i_get(int i) const; + /** Apply the operator to element @c i and return the result. */ + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the subexpression. The expression is stored + /** The type used to store the subexpression. The expression is stored * as a copy if Sub is an rvalue reference (temporary), or by const * reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const sub_type&, sub_type> wrap_type; + using wrap_type = cml::if_t::value, const sub_type&, + sub_type>; - /** The wrapped subexpression. */ - wrap_type m_sub; + /** The wrapped subexpression. */ + wrap_type m_sub; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - conjugate_node(const node_type&); + // Not copy constructible. + conjugate_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_CONJUGATE_NODE_TPP #include #undef __CML_QUATERNION_CONJUGATE_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/conjugate_node.tpp b/cml/quaternion/conjugate_node.tpp index dbaeaaf..7615d66 100644 --- a/cml/quaternion/conjugate_node.tpp +++ b/cml/quaternion/conjugate_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_CONJUGATE_NODE_TPP -#error "quaternion/conjugate_node.tpp not included correctly" +# error "quaternion/conjugate_node.tpp not included correctly" #endif #include @@ -17,21 +15,18 @@ namespace cml { template conjugate_node::conjugate_node(Sub sub) : m_sub(std::move(sub)) -{ -} +{} template conjugate_node::conjugate_node(node_type&& other) : m_sub(std::move(other.m_sub)) -{ -} +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template conjugate_node::conjugate_node(const node_type& other) : m_sub(other.m_sub) -{ -} +{} #endif @@ -39,15 +34,13 @@ conjugate_node::conjugate_node(const node_type& other) /* readable_quaternion interface: */ -template auto +template +auto conjugate_node::i_get(int i) const -> immutable_value { - typedef order_type_trait_of_t order_type; - return (i == order_type::W) ? this->m_sub.get(i) : - this->m_sub.get(i); + using order_type = order_type_trait_of_t; + return (i == order_type::W) ? this->m_sub.get(i) : -this->m_sub.get(i); /* Note: W is either 0 (conjugate_first) or 3 (real_first). */ } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/conjugate_ops.h b/cml/quaternion/conjugate_ops.h index 2b119aa..ed63122 100644 --- a/cml/quaternion/conjugate_ops.h +++ b/cml/quaternion/conjugate_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_conjugate_ops_h -#define cml_quaternion_conjugate_ops_h - #include namespace cml { @@ -16,22 +11,17 @@ namespace cml { /** Return an expression node for the conjugate part of @c q. @c q is * stored by const reference in the node. */ -template auto conjugate(const readable_quaternion& q) --> conjugate_node; +template +auto conjugate(const readable_quaternion& q) -> conjugate_node; /** Return an expression node for conjugate part of the temporary * subexpression @c q. @c q is stored by value in the node (via std::move). */ -template auto conjugate(readable_quaternion&& q) --> conjugate_node; +template +auto conjugate(readable_quaternion&& q) -> conjugate_node; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_CONJUGATE_OPS_TPP #include #undef __CML_QUATERNION_CONJUGATE_OPS_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/conjugate_ops.tpp b/cml/quaternion/conjugate_ops.tpp index 2670886..ca29fbd 100644 --- a/cml/quaternion/conjugate_ops.tpp +++ b/cml/quaternion/conjugate_ops.tpp @@ -1,31 +1,26 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_CONJUGATE_OPS_TPP -#error "quaternion/conjugate_ops.tpp not included correctly" +# error "quaternion/conjugate_ops.tpp not included correctly" #endif namespace cml { -template inline auto -conjugate(const readable_quaternion& q) --> conjugate_node +template +inline auto +conjugate(const readable_quaternion& q) -> conjugate_node { return conjugate_node(q.actual()); } -template inline auto -conjugate(readable_quaternion&& q) --> conjugate_node +template +inline auto +conjugate(readable_quaternion&& q) -> conjugate_node { return conjugate_node((Sub&&) q); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/cross_tags.h b/cml/quaternion/cross_tags.h index 93716ed..9f6bc96 100644 --- a/cml/quaternion/cross_tags.h +++ b/cml/quaternion/cross_tags.h @@ -1,35 +1,32 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_cross_tags_h -#define cml_quaternion_cross_tags_h - namespace cml { /** Helper to specify v1^v2 multiplication cross. */ -struct positive_cross {}; +struct positive_cross +{}; /** Helper to specify v2^v1 multiplication cross. */ -struct negative_cross {}; +struct negative_cross +{}; /** Detect valid cross types. */ -template struct is_cross_type { - static const bool value - = std::is_same::value - || std::is_same::value - ; +template struct is_cross_type +{ + static const bool value = std::is_same::value + || std::is_same::value; }; /** Templated helper to determine the cross type of an expression that * defines the cross_type type. */ -template struct cross_type_of { - typedef typename T::cross_type type; +template struct cross_type_of +{ + using type = typename T::cross_type; static_assert(is_cross_type::value, "invalid cross type"); }; @@ -37,15 +34,15 @@ template struct cross_type_of { template using cross_type_of_t = typename cross_type_of::type; /** Retrieve the cross_type of @c T via traits. */ -template struct cross_type_trait_of { - typedef typename traits_of::type::cross_type type; +template struct cross_type_trait_of +{ + using type = typename traits_of::type::cross_type; static_assert(is_cross_type::value, "invalid cross type"); }; /** Convenience alias for cross_type_trait_of. */ template - using cross_type_trait_of_t = typename cross_type_trait_of::type; - +using cross_type_trait_of_t = typename cross_type_trait_of::type; /** Deduce the default cross tag needed to promote the result of combining * two expressions having crosss @c Tag1 and @c Tag2. By default: @@ -56,24 +53,17 @@ template */ template struct cross_type_promote { - static_assert(is_cross_type::value, - "invalid quaternion cross type"); - static_assert(is_cross_type::value, - "invalid quaternion cross type"); - static_assert(std::is_same::value, + static_assert(is_cross_type::value, "invalid quaternion cross type"); + static_assert(is_cross_type::value, "invalid quaternion cross type"); + static_assert(std::is_same::value, "mismatched quaternion cross types"); /* The tags are the same, so use the common type: */ - typedef Tag1 type; + using type = Tag1; }; /** Convenience alias for cross_type_promote. */ template - using cross_type_promote_t = typename cross_type_promote::type; - -} // namespace cml - -#endif +using cross_type_promote_t = typename cross_type_promote::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/dot.h b/cml/quaternion/dot.h index c4657db..74be7dc 100644 --- a/cml/quaternion/dot.h +++ b/cml/quaternion/dot.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_dot_h -#define cml_quaternion_dot_h - #include #include @@ -22,18 +17,13 @@ namespace cml { * @note Compilation will fail if @c Sub1 and @c Sub2 have different * quaternion orders. */ -template auto dot( - const readable_quaternion& left, const readable_quaternion& right - ) --> value_type_trait_promote_t; +template +auto dot(const readable_quaternion& left, + const readable_quaternion& right) + -> value_type_trait_promote_t; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_DOT_TPP #include #undef __CML_QUATERNION_DOT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/dot.tpp b/cml/quaternion/dot.tpp index 0700b09..2907266 100644 --- a/cml/quaternion/dot.tpp +++ b/cml/quaternion/dot.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_DOT_TPP -#error "quaternion/dot.tpp not included correctly" +# error "quaternion/dot.tpp not included correctly" #endif #include @@ -13,24 +11,20 @@ namespace cml { -template inline auto dot( - const readable_quaternion& left, const readable_quaternion& right - ) --> value_type_trait_promote_t +template +inline auto +dot(const readable_quaternion& left, + const readable_quaternion& right) + -> value_type_trait_promote_t { - typedef value_type_trait_promote_t value_type; + using value_type = value_type_trait_promote_t; - static_assert(std::is_same, - order_type_trait_of_t>::value, "mismatched quaternion order types"); - return value_type( - left.get(0)*right.get(0) + - left.get(1)*right.get(1) + - left.get(2)*right.get(2) + - left.get(3)*right.get(3)) - ; + static_assert( + std::is_same, + order_type_trait_of_t>::value, + "mismatched quaternion order types"); + return value_type(left.get(0) * right.get(0) + left.get(1) * right.get(1) + + left.get(2) * right.get(2) + left.get(3) * right.get(3)); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/fixed.h b/cml/quaternion/fixed.h index 3c1340d..aa00622 100644 --- a/cml/quaternion/fixed.h +++ b/cml/quaternion/fixed.h @@ -1,17 +1,7 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_fixed_h -#define cml_quaternion_fixed_h - #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/fixed_compiled.h b/cml/quaternion/fixed_compiled.h index ff610f9..174a690 100644 --- a/cml/quaternion/fixed_compiled.h +++ b/cml/quaternion/fixed_compiled.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_fixed_compiled_h -#define cml_quaternion_fixed_compiled_h - #include #include #include @@ -16,21 +11,21 @@ namespace cml { template -struct quaternion_traits< quaternion, Order, Cross> > +struct quaternion_traits, Order, Cross>> { /* Traits and types for the quaternion element: */ - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef typename element_traits::pointer pointer; - typedef typename element_traits::reference reference; - typedef typename element_traits::const_pointer const_pointer; - typedef typename element_traits::const_reference const_reference; - typedef typename element_traits::mutable_value mutable_value; - typedef typename element_traits::immutable_value immutable_value; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using pointer = typename element_traits::pointer; + using reference = typename element_traits::reference; + using const_pointer = typename element_traits::const_pointer; + using const_reference = typename element_traits::const_reference; + using mutable_value = typename element_traits::mutable_value; + using immutable_value = typename element_traits::immutable_value; /* The quaternion storage type: */ - typedef rebind_t, quaternion_storage_tag> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = rebind_t, quaternion_storage_tag>; + using size_tag = typename storage_type::size_tag; static_assert(std::is_same::value, "invalid size tag"); @@ -39,95 +34,91 @@ struct quaternion_traits< quaternion, Order, Cross> > static_assert(array_size == 4, "invalid quaternion size"); /** Quaternion order. */ - typedef Order order_type; + using order_type = Order; /** Quaternion cross type. */ - typedef Cross cross_type; + using cross_type = Cross; }; /** Fixed-length quaternion. */ template class quaternion, Order, Cross> -: public writable_quaternion< quaternion, Order, Cross> > +: public writable_quaternion, Order, Cross>> { public: - - typedef quaternion, Order, Cross> quaternion_type; - typedef readable_quaternion readable_type; - typedef writable_quaternion writable_type; - typedef quaternion_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::pointer pointer; - typedef typename traits_type::reference reference; - typedef typename traits_type::const_pointer const_pointer; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::order_type order_type; - typedef typename traits_type::cross_type cross_type; + using quaternion_type = quaternion, Order, Cross>; + using readable_type = readable_quaternion; + using writable_type = writable_quaternion; + using traits_type = quaternion_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using pointer = typename traits_type::pointer; + using reference = typename traits_type::reference; + using const_pointer = typename traits_type::const_pointer; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using order_type = typename traits_type::order_type; + using cross_type = typename traits_type::cross_type; public: - - /* Include methods from writable_type: */ - using writable_type::W; - using writable_type::X; - using writable_type::Y; - using writable_type::Z; + /* Include methods from writable_type: */ + using writable_type::W; + using writable_type::X; + using writable_type::Y; + using writable_type::Z; #ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - using writable_type::operator=; + using writable_type::operator=; #endif public: + /** Constant containing the array size. */ + static const int array_size = traits_type::array_size; - /** Constant containing the array size. */ - static const int array_size = traits_type::array_size; - - /** The dimension (same as array_size). */ - static const int dimension = array_size; + /** The dimension (same as array_size). */ + static const int dimension = array_size; public: - - /** Compiler-default constructor. + /** Compiler-default constructor. * * @note The quaternion elements are uninitialized. */ - quaternion() = default; + quaternion() = default; - /** Compiler-default destructor. */ - ~quaternion() = default; + /** Compiler-default destructor. */ + ~quaternion() = default; - /** Compiler-default copy constructor. */ - quaternion(const quaternion_type& other) = default; + /** Compiler-default copy constructor. */ + quaternion(const quaternion_type& other) = default; #ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR - /** Compiler-default move constructor. */ - quaternion(quaternion_type&& other) = default; + /** Compiler-default move constructor. */ + quaternion(quaternion_type&& other) = default; #endif - /** Construct from a readable_quaternion. */ - template quaternion(const readable_quaternion& sub); + /** Construct from a readable_quaternion. */ + template quaternion(const readable_quaternion& sub); - /** Construct from 4 values. + /** Construct from 4 values. * * @note This overload is enabled only if all of the arguments are * convertible to value_type. */ - template* = nullptr> - quaternion(const E0& e0, const E1& e1, const E2& e2, const E3& e3) - // XXX Should be in quaternion/fixed_compiled.tpp, but VC++12 has - // brain-dead out-of-line template argument matching... - { - this->assign_elements(e0, e1, e2, e3); - } - - /** Construct from a 3D readable_vector and one additional element. + template* = nullptr> + quaternion(const E0& e0, const E1& e1, const E2& e2, const E3& e3) + // XXX Should be in quaternion/fixed_compiled.tpp, but VC++12 has + // brain-dead out-of-line template argument matching... + { + this->assign_elements(e0, e1, e2, e3); + } + + /** Construct from a 3D readable_vector and one additional element. * * @note Although the imaginary part is specified first, the proper * coefficient order is maintained. @@ -135,16 +126,17 @@ class quaternion, Order, Cross> * @note This overload is enabled only if the value_type of @c sub and * the scalar argument are convertible to value_type. */ - template, E0>* = nullptr> - quaternion(const readable_vector& sub, const E0& e0) - // XXX Should be in quaternion/fixed_compiled.tpp, but VC++12 has - // brain-dead out-of-line template argument matching... - { - this->assign(sub, e0); - } - - /** Construct from one additional element and a 3D readable_vector. + template, E0>* = + nullptr> + quaternion(const readable_vector& sub, const E0& e0) + // XXX Should be in quaternion/fixed_compiled.tpp, but VC++12 has + // brain-dead out-of-line template argument matching... + { + this->assign(sub, e0); + } + + /** Construct from one additional element and a 3D readable_vector. * * @note Although the imaginary part is specified second, the proper * coefficient order is maintained. @@ -152,139 +144,128 @@ class quaternion, Order, Cross> * @note This overload is enabled only if the value_type of @c sub and * the scalar argument are convertible to value_type. */ - template, E0>* = nullptr> - quaternion(const E0& e0, const readable_vector& sub) - // XXX Should be in quaternion/fixed_compiled.tpp, but VC++12 has - // brain-dead out-of-line template argument matching... - { - this->assign(sub, e0); - } - - /** Construct from a 3-element array and one additional element. + template, E0>* = + nullptr> + quaternion(const E0& e0, const readable_vector& sub) + // XXX Should be in quaternion/fixed_compiled.tpp, but VC++12 has + // brain-dead out-of-line template argument matching... + { + this->assign(sub, e0); + } + + /** Construct from a 3-element array and one additional element. * * @note Although the imaginary part is specified first, the proper * coefficient order is maintained. */ - template* = nullptr> - quaternion(const Array& array, const E1& e1); + template* = nullptr> + quaternion(const Array& array, const E1& e1); - /** Construct from one additional element and a 3-element array. + /** Construct from one additional element and a 3-element array. * * @note Although the imaginary part is specified second, the proper * coefficient order is maintained. */ - template* = nullptr> - quaternion(const E0& e0, const Array& array); + template* = nullptr> + quaternion(const E0& e0, const Array& array); - /** Construct from an array type. */ - template* = nullptr> - quaternion(const Array& array); + /** Construct from an array type. */ + template* = nullptr> + quaternion(const Array& array); - /** Construct from a pointer to an array. */ - template* = nullptr> - quaternion(const Pointer& array); + /** Construct from a pointer to an array. */ + template* = nullptr> + quaternion(const Pointer& array); - /** Construct from std::initializer_list. */ - template quaternion(std::initializer_list l); + /** Construct from std::initializer_list. */ + template quaternion(std::initializer_list l); public: + /** Return the length of the quaternion. */ + int size() const; - /** Return the length of the quaternion. */ - int size() const; - - /** Return access to the quaternion data as a raw pointer. */ - pointer data(); + /** Return access to the quaternion data as a raw pointer. */ + pointer data(); - /** Return const access to the quaternion data as a raw pointer. */ - const_pointer data() const; + /** Return const access to the quaternion data as a raw pointer. */ + const_pointer data() const; - /** Read-only iterator. */ - const_pointer begin() const; + /** Read-only iterator. */ + const_pointer begin() const; - /** Read-only iterator. */ - const_pointer end() const; + /** Read-only iterator. */ + const_pointer end() const; public: + /** Copy assignment. */ + quaternion_type& operator=(const quaternion_type& other); - /** Copy assignment. */ - quaternion_type& operator=(const quaternion_type& other); - - /** Move assignment. */ - quaternion_type& operator=(quaternion_type&& other); + /** Move assignment. */ + quaternion_type& operator=(quaternion_type&& other); #ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - quaternion_type& operator=(const readable_quaternion& other) - { - return this->assign(other); - } - - template* = nullptr> - quaternion_type& operator=(const Array& array) - { - return this->assign(array); - } - - template - quaternion_type& operator=(std::initializer_list l) - { - return this->assign(l); - } + template + quaternion_type& operator=(const readable_quaternion& other) + { + return this->assign(other); + } + + template* = nullptr> + quaternion_type& operator=(const Array& array) + { + return this->assign(array); + } + + template + quaternion_type& operator=(std::initializer_list l) + { + return this->assign(l); + } #endif protected: + /** @name readable_quaternion Interface */ + /*@{*/ - /** @name readable_quaternion Interface */ - /*@{*/ + friend readable_type; - friend readable_type; + /** Return quaternion const element @c i. */ + immutable_value i_get(int i) const; - /** Return quaternion const element @c i. */ - immutable_value i_get(int i) const; - - /*@}*/ + /*@}*/ protected: + /** @name writable_quaternion Interface */ + /*@{*/ - /** @name writable_quaternion Interface */ - /*@{*/ - - friend writable_type; + friend writable_type; - /** Return quaternion element @c i. */ - mutable_value i_get(int i); + /** Return quaternion element @c i. */ + mutable_value i_get(int i); - /** Set element @c i. */ - template - quaternion_type& i_put(int i, const Other& v) __CML_REF; + /** Set element @c i. */ + template quaternion_type& i_put(int i, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i on a temporary. */ - template - quaternion_type&& i_put(int i, const Other& v) &&; + /** Set element @c i on a temporary. */ + template quaternion_type&& i_put(int i, const Other& v) &&; #endif - /*@}*/ + /*@}*/ protected: - - /** Fixed-length array. */ - value_type m_data[4]; + /** Fixed-length array. */ + value_type m_data[4]; }; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_FIXED_COMPILED_TPP #include #undef __CML_QUATERNION_FIXED_COMPILED_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/fixed_compiled.tpp b/cml/quaternion/fixed_compiled.tpp index b4db461..fdd91e3 100644 --- a/cml/quaternion/fixed_compiled.tpp +++ b/cml/quaternion/fixed_compiled.tpp @@ -1,21 +1,18 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_FIXED_COMPILED_TPP -#error "quaternion/fixed_compiled.tpp not included correctly" +# error "quaternion/fixed_compiled.tpp not included correctly" #endif namespace cml { /* fixed 'structors: */ -template template -quaternion, O, C>::quaternion( - const readable_quaternion& sub - ) +template +template +quaternion, O, C>::quaternion(const readable_quaternion& sub) { this->assign(sub); } @@ -48,56 +45,62 @@ quaternion, O, C>::quaternion(const Array& array, const E1& e1) this->assign(array, e1); } -template template +template +template quaternion, O, C>::quaternion(std::initializer_list l) { this->assign(l); } - - /* Public methods: */ -template int +template +int quaternion, O, C>::size() const { return 4; } -template auto +template +auto quaternion, O, C>::data() -> pointer { return &this->m_data[0]; } -template auto +template +auto quaternion, O, C>::data() const -> const_pointer { return &this->m_data[0]; } -template auto +template +auto quaternion, O, C>::begin() const -> const_pointer { return &this->m_data[0]; } -template auto +template +auto quaternion, O, C>::end() const -> const_pointer { return (&this->m_data[0]) + 4; } -template auto +template +auto quaternion, O, C>::operator=(const quaternion_type& other) --> quaternion_type& + -> quaternion_type& { return this->assign(other); } -template auto +template +auto quaternion, O, C>::operator=(quaternion_type&& other) --> quaternion_type& + -> quaternion_type& { this->m_data[W] = std::move(other.m_data[W]); this->m_data[X] = std::move(other.m_data[X]); @@ -106,48 +109,46 @@ quaternion, O, C>::operator=(quaternion_type&& other) return *this; } - - /* Internal methods: */ /* readable_quaternion interface: */ -template auto +template +auto quaternion, O, C>::i_get(int i) const -> immutable_value { return this->m_data[i]; } - /* writable_quaternion interface: */ -template auto +template +auto quaternion, O, C>::i_get(int i) -> mutable_value { return this->m_data[i]; } -template template auto -quaternion, O, C>::i_put( - int i, const Other& v - ) __CML_REF -> quaternion_type& +template +template +auto +quaternion, O, C>::i_put(int i, + const Other& v) __CML_REF->quaternion_type& { this->m_data[i] = value_type(v); return *this; } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template auto -quaternion, O, C>::i_put( - int i, const Other& v - ) && -> quaternion_type&& +template +template +auto +quaternion, O, C>::i_put(int i, + const Other& v) && -> quaternion_type&& { this->m_data[i] = value_type(v); return (quaternion_type&&) *this; } #endif -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/functions.h b/cml/quaternion/functions.h index 94f9224..43c5751 100644 --- a/cml/quaternion/functions.h +++ b/cml/quaternion/functions.h @@ -1,66 +1,54 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_functions_h -#define cml_quaternion_functions_h - #include #include namespace cml { /** Return the real part of quaternion @c q. */ -template auto -real(const readable_quaternion& q) --> value_type_trait_of_t; +template +auto real(const readable_quaternion& q) + -> value_type_trait_of_t; /** Return the squared length of @c q. */ -template auto -length_squared(const readable_quaternion& q) --> value_type_trait_of_t; +template +auto length_squared(const readable_quaternion& q) + -> value_type_trait_of_t; /** Return the length of @c q. */ -template auto -length(const readable_quaternion& q) --> value_type_trait_of_t; +template +auto length(const readable_quaternion& q) + -> value_type_trait_of_t; /** Return the Cayley norm (squared length) of @c q. */ -template auto -norm(const readable_quaternion& q) --> value_type_trait_of_t; +template +auto norm(const readable_quaternion& q) + -> value_type_trait_of_t; /** Return a normalized copy of @c q. */ -template auto -normalize(const readable_quaternion& q) --> temporary_of_t; +template +auto normalize(const readable_quaternion& q) + -> temporary_of_t; /** Return the multiplicative identity of quaternion @c q. */ -template auto -identity(const readable_quaternion& q) --> temporary_of_t; +template +auto identity(const readable_quaternion& q) + -> temporary_of_t; /** Return the log of @c q. */ -template auto -log(const readable_quaternion& q) --> temporary_of_t; +template +auto log(const readable_quaternion& q) -> temporary_of_t; /** Return the exponential of @c q. */ -template auto -exp(const readable_quaternion& q) --> temporary_of_t; +template +auto exp(const readable_quaternion& q) -> temporary_of_t; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_FUNCTIONS_TPP #include #undef __CML_QUATERNION_FUNCTIONS_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/functions.tpp b/cml/quaternion/functions.tpp index 57b11ac..f48b234 100644 --- a/cml/quaternion/functions.tpp +++ b/cml/quaternion/functions.tpp @@ -1,80 +1,75 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_FUNCTIONS_TPP -#error "quaternion/functions.tpp not included correctly" +# error "quaternion/functions.tpp not included correctly" #endif #include namespace cml { -template inline auto -real(const readable_quaternion
& q) --> value_type_trait_of_t
+template +inline auto +real(const readable_quaternion
& q) -> value_type_trait_of_t
{ return q.real(); } -template inline auto -length_squared(const readable_quaternion
& q) --> value_type_trait_of_t
+template +inline auto +length_squared(const readable_quaternion
& q) -> value_type_trait_of_t
{ return q.length_squared(); } -template inline auto -length(const readable_quaternion
& q) --> value_type_trait_of_t
+template +inline auto +length(const readable_quaternion
& q) -> value_type_trait_of_t
{ return q.length(); } -template inline auto -norm(const readable_quaternion
& q) --> value_type_trait_of_t
+template +inline auto +norm(const readable_quaternion
& q) -> value_type_trait_of_t
{ return q.norm(); } -template inline auto -normalize(const readable_quaternion& q) --> temporary_of_t +template +inline auto +normalize(const readable_quaternion& q) -> temporary_of_t { return q.normalize(); } -template inline auto -identity(const readable_quaternion& q) --> temporary_of_t +template +inline auto +identity(const readable_quaternion& q) -> temporary_of_t { temporary_of_t result(q); result.identity(); return result; } -template inline auto -log(const readable_quaternion& q) --> temporary_of_t +template +inline auto +log(const readable_quaternion& q) -> temporary_of_t { temporary_of_t result(q); result.log(); return result; } -template inline auto -exp(const readable_quaternion& q) --> temporary_of_t +template +inline auto +exp(const readable_quaternion& q) -> temporary_of_t { temporary_of_t result(q); result.exp(); return result; } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/fwd.h b/cml/quaternion/fwd.h index 7f54623..bd62245 100644 --- a/cml/quaternion/fwd.h +++ b/cml/quaternion/fwd.h @@ -1,22 +1,12 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_fwd_h -#define cml_quaternion_fwd_h - namespace cml { template class readable_quaternion; template class writable_quaternion; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/imaginary.h b/cml/quaternion/imaginary.h index f179e13..62b7c7a 100644 --- a/cml/quaternion/imaginary.h +++ b/cml/quaternion/imaginary.h @@ -1,18 +1,8 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_imaginary_h -#define cml_quaternion_imaginary_h - #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/imaginary_node.h b/cml/quaternion/imaginary_node.h index a976f15..9b3edfe 100644 --- a/cml/quaternion/imaginary_node.h +++ b/cml/quaternion/imaginary_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_imaginary_node_h -#define cml_quaternion_imaginary_node_h - #include #include @@ -17,30 +12,29 @@ namespace cml { template class imaginary_node; /** imaginary_node<> traits. */ -template -struct vector_traits< imaginary_node > +template struct vector_traits> { /* Figure out the basic type of Sub: */ - typedef imaginary_node vector_type; - typedef Sub sub_arg_type; - typedef cml::unqualified_type_t sub_type; - typedef quaternion_traits sub_traits; - typedef typename sub_traits::element_traits element_traits; - typedef typename sub_traits::value_type value_type; - typedef typename sub_traits::immutable_value immutable_value; + using vector_type = imaginary_node; + using sub_arg_type = Sub; + using sub_type = cml::unqualified_type_t; + using sub_traits = quaternion_traits; + using element_traits = typename sub_traits::element_traits; + using value_type = typename sub_traits::value_type; + using immutable_value = typename sub_traits::immutable_value; /* Resize the *unbound* storage type of the quaternion subexpression to a * vector storage type: */ - typedef typename sub_traits::storage_type bound_storage_type; - typedef typename bound_storage_type::unbound_type unbound_storage_type; - typedef resize_storage_t resized_type; + using bound_storage_type = typename sub_traits::storage_type; + using unbound_storage_type = typename bound_storage_type::unbound_type; + using resized_type = resize_storage_t; /* Rebind to vector storage: */ - typedef rebind_t storage_type; + using storage_type = rebind_t; /* Traits and types for the new storage: */ - typedef typename storage_type::size_tag size_tag; + using size_tag = typename storage_type::size_tag; static_assert(cml::is_fixed_size::value, "invalid size tag"); /* Array size: */ @@ -52,92 +46,80 @@ struct vector_traits< imaginary_node > * 3-element vector expression. */ template -class imaginary_node -: public readable_vector< imaginary_node > +class imaginary_node : public readable_vector> { public: - - typedef imaginary_node node_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::sub_arg_type sub_arg_type; - typedef typename traits_type::sub_type sub_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using node_type = imaginary_node; + using readable_type = readable_vector; + using traits_type = vector_traits; + using sub_arg_type = typename traits_type::sub_arg_type; + using sub_type = typename traits_type::sub_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** The array size constant depends upon the subexpression size. */ - static const int array_size = traits_type::array_size; + /** The array size constant depends upon the subexpression size. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped quaternion expression. @c sub must be + /** Construct from the wrapped quaternion expression. @c sub must be * an lvalue reference or rvalue reference. */ - explicit imaginary_node(Sub sub); + explicit imaginary_node(Sub sub); - /** Move constructor. */ - imaginary_node(node_type&& other); + /** Move constructor. */ + imaginary_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - imaginary_node(const node_type& other); + /** Copy constructor. */ + imaginary_node(const node_type& other); #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ + friend readable_type; - friend readable_type; + /** Return the size of the vector expression. */ + int i_size() const; - /** Return the size of the vector expression. */ - int i_size() const; + /** Apply the operator to element @c i and return the result. */ + immutable_value i_get(int i) const; - /** Apply the operator to element @c i and return the result. */ - immutable_value i_get(int i) const; - - /*@}*/ + /*@}*/ protected: - - /** The type used to store the subexpression. The expression is stored + /** The type used to store the subexpression. The expression is stored * as a copy if Sub is an rvalue reference (temporary), or by const * reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const sub_type&, sub_type> wrap_type; + using wrap_type = cml::if_t::value, const sub_type&, + sub_type>; - /** The wrapped subexpression. */ - wrap_type m_sub; + /** The wrapped subexpression. */ + wrap_type m_sub; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - imaginary_node(const node_type&); + // Not copy constructible. + imaginary_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_IMAGINARY_NODE_TPP #include #undef __CML_QUATERNION_IMAGINARY_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/imaginary_node.tpp b/cml/quaternion/imaginary_node.tpp index d7a1f0f..d6d8880 100644 --- a/cml/quaternion/imaginary_node.tpp +++ b/cml/quaternion/imaginary_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_IMAGINARY_NODE_TPP -#error "quaternion/imaginary_node.tpp not included correctly" +# error "quaternion/imaginary_node.tpp not included correctly" #endif #include @@ -17,44 +15,39 @@ namespace cml { template imaginary_node::imaginary_node(Sub sub) : m_sub(std::move(sub)) -{ -} +{} template imaginary_node::imaginary_node(node_type&& other) : m_sub(std::move(other.m_sub)) -{ -} +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template imaginary_node::imaginary_node(const node_type& other) : m_sub(other.m_sub) -{ -} +{} #endif - /* Internal methods: */ /* readable_vector interface: */ -template int +template +int imaginary_node::i_size() const { return 3; } -template auto +template +auto imaginary_node::i_get(int i) const -> immutable_value { - typedef order_type_trait_of_t order_type; + using order_type = order_type_trait_of_t; return this->m_sub.get(order_type::X + i); /* Note: X is either 0 (imaginary_first) or 1 (real_first). */ } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/imaginary_ops.h b/cml/quaternion/imaginary_ops.h index 7e6c6a6..7a5b10b 100644 --- a/cml/quaternion/imaginary_ops.h +++ b/cml/quaternion/imaginary_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_imaginary_ops_h -#define cml_quaternion_imaginary_ops_h - #include namespace cml { @@ -16,22 +11,17 @@ namespace cml { /** Return an expression node for the imaginary part of @c q. @c q is * stored by const reference in the node. */ -template auto imaginary(const readable_quaternion& q) --> imaginary_node; +template +auto imaginary(const readable_quaternion& q) -> imaginary_node; /** Return an expression node for imaginary part of the temporary * subexpression @c q. @c q is stored by value in the node (via std::move). */ -template auto imaginary(readable_quaternion&& q) --> imaginary_node; +template +auto imaginary(readable_quaternion&& q) -> imaginary_node; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_IMAGINARY_OPS_TPP #include #undef __CML_QUATERNION_IMAGINARY_OPS_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/imaginary_ops.tpp b/cml/quaternion/imaginary_ops.tpp index 559d618..e2e8912 100644 --- a/cml/quaternion/imaginary_ops.tpp +++ b/cml/quaternion/imaginary_ops.tpp @@ -1,31 +1,26 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_IMAGINARY_OPS_TPP -#error "quaternion/imaginary_ops.tpp not included correctly" +# error "quaternion/imaginary_ops.tpp not included correctly" #endif namespace cml { -template inline auto -imaginary(const readable_quaternion& q) --> imaginary_node +template +inline auto +imaginary(const readable_quaternion& q) -> imaginary_node { return imaginary_node(q.actual()); } -template inline auto -imaginary(readable_quaternion&& q) --> imaginary_node +template +inline auto +imaginary(readable_quaternion&& q) -> imaginary_node { return imaginary_node((Sub&&) q); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/inverse.h b/cml/quaternion/inverse.h index f774af7..1414cbf 100644 --- a/cml/quaternion/inverse.h +++ b/cml/quaternion/inverse.h @@ -1,18 +1,8 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_inverse_h -#define cml_quaternion_inverse_h - #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/inverse_node.h b/cml/quaternion/inverse_node.h index aeb7cd6..47d292a 100644 --- a/cml/quaternion/inverse_node.h +++ b/cml/quaternion/inverse_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_inverse_node_h -#define cml_quaternion_inverse_node_h - #include namespace cml { @@ -16,20 +11,19 @@ namespace cml { template class inverse_node; /** inverse_node<> traits. */ -template -struct quaternion_traits< inverse_node > +template struct quaternion_traits> { /* Figure out the basic type of Sub: */ - typedef inverse_node quaternion_type; - typedef Sub sub_arg_type; - typedef cml::unqualified_type_t sub_type; - typedef quaternion_traits sub_traits; - typedef scalar_traits> element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; - typedef typename sub_traits::storage_type storage_type; - - typedef typename sub_traits::size_tag size_tag; + using quaternion_type = inverse_node; + using sub_arg_type = Sub; + using sub_type = cml::unqualified_type_t; + using sub_traits = quaternion_traits; + using element_traits = scalar_traits>; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; + using storage_type = typename sub_traits::storage_type; + + using size_tag = typename sub_traits::size_tag; static_assert(cml::is_fixed_size::value, "invalid size tag"); /* Array size: */ @@ -37,98 +31,86 @@ struct quaternion_traits< inverse_node > static_assert(array_size == 4, "invalid quaternion size"); /* Order and cross taken from the sub-expression: */ - typedef typename sub_traits::order_type order_type; - typedef typename sub_traits::cross_type cross_type; + using order_type = typename sub_traits::order_type; + using cross_type = typename sub_traits::cross_type; }; /** Represents the inverse of a quaternion subexpression. */ template -class inverse_node -: public readable_quaternion< inverse_node > +class inverse_node : public readable_quaternion> { public: - - typedef inverse_node node_type; - typedef readable_quaternion readable_type; - typedef quaternion_traits traits_type; - typedef typename traits_type::sub_arg_type sub_arg_type; - typedef typename traits_type::sub_type sub_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using node_type = inverse_node; + using readable_type = readable_quaternion; + using traits_type = quaternion_traits; + using sub_arg_type = typename traits_type::sub_arg_type; + using sub_type = typename traits_type::sub_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** The array size constant depends upon the subexpression size. */ - static const int array_size = traits_type::array_size; + /** The array size constant depends upon the subexpression size. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped quaternion expression. @c sub must be + /** Construct from the wrapped quaternion expression. @c sub must be * an lvalue reference or rvalue reference. */ - explicit inverse_node(Sub sub); + explicit inverse_node(Sub sub); - /** Move constructor. */ - inverse_node(node_type&& other); + /** Move constructor. */ + inverse_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - inverse_node(const node_type& other); + /** Copy constructor. */ + inverse_node(const node_type& other); #endif protected: + /** @name readable_quaternion Interface */ + /*@{*/ - /** @name readable_quaternion Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Apply the operator to element @c i and return the result. */ - immutable_value i_get(int i) const; + /** Apply the operator to element @c i and return the result. */ + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the subexpression. The expression is stored + /** The type used to store the subexpression. The expression is stored * as a copy if Sub is an rvalue reference (temporary), or by const * reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const sub_type&, sub_type> wrap_type; + using wrap_type = cml::if_t::value, const sub_type&, + sub_type>; - /** The wrapped subexpression. */ - wrap_type m_sub; + /** The wrapped subexpression. */ + wrap_type m_sub; - /** The reciprocal of the subexpression norm. */ - value_type m_inv_norm; + /** The reciprocal of the subexpression norm. */ + value_type m_inv_norm; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - inverse_node(const node_type&); + // Not copy constructible. + inverse_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_INVERSE_NODE_TPP #include #undef __CML_QUATERNION_INVERSE_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/inverse_node.tpp b/cml/quaternion/inverse_node.tpp index 76f0b30..b09ccf7 100644 --- a/cml/quaternion/inverse_node.tpp +++ b/cml/quaternion/inverse_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_INVERSE_NODE_TPP -#error "quaternion/inverse_node.tpp not included correctly" +# error "quaternion/inverse_node.tpp not included correctly" #endif #include @@ -16,40 +14,37 @@ namespace cml { template inverse_node::inverse_node(Sub sub) -: m_sub(std::move(sub)), m_inv_norm(value_type(1) / sub.norm()) -{ -} +: m_sub(std::move(sub)) +, m_inv_norm(value_type(1) / sub.norm()) +{} template inverse_node::inverse_node(node_type&& other) -: m_sub(std::move(other.m_sub)), m_inv_norm(std::move(other.m_inv_norm)) -{ -} +: m_sub(std::move(other.m_sub)) +, m_inv_norm(std::move(other.m_inv_norm)) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template inverse_node::inverse_node(const node_type& other) -: m_sub(other.m_sub), m_inv_norm(other.m_inv_norm) -{ -} +: m_sub(other.m_sub) +, m_inv_norm(other.m_inv_norm) +{} #endif - /* Internal methods: */ /* readable_quaternion interface: */ -template auto +template +auto inverse_node::i_get(int i) const -> immutable_value { - typedef order_type_trait_of_t order_type; - return this->m_inv_norm*((i == order_type::W) - ? this->m_sub.get(i) : - this->m_sub.get(i)); + using order_type = order_type_trait_of_t; + return this->m_inv_norm + * ((i == order_type::W) ? this->m_sub.get(i) : -this->m_sub.get(i)); /* Note: W is either 0 (inverse_first) or 3 (real_first). */ } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/inverse_ops.h b/cml/quaternion/inverse_ops.h index a916a8d..c92cd12 100644 --- a/cml/quaternion/inverse_ops.h +++ b/cml/quaternion/inverse_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_inverse_ops_h -#define cml_quaternion_inverse_ops_h - #include namespace cml { @@ -16,22 +11,17 @@ namespace cml { /** Return an expression node for the inverse part of @c q. @c q is * stored by const reference in the node. */ -template auto inverse(const readable_quaternion& q) --> inverse_node; +template +auto inverse(const readable_quaternion& q) -> inverse_node; /** Return an expression node for inverse part of the temporary * subexpression @c q. @c q is stored by value in the node (via std::move). */ -template auto inverse(readable_quaternion&& q) --> inverse_node; +template +auto inverse(readable_quaternion&& q) -> inverse_node; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_INVERSE_OPS_TPP #include #undef __CML_QUATERNION_INVERSE_OPS_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/inverse_ops.tpp b/cml/quaternion/inverse_ops.tpp index 3ed25a0..224619e 100644 --- a/cml/quaternion/inverse_ops.tpp +++ b/cml/quaternion/inverse_ops.tpp @@ -1,31 +1,26 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_INVERSE_OPS_TPP -#error "quaternion/inverse_ops.tpp not included correctly" +# error "quaternion/inverse_ops.tpp not included correctly" #endif namespace cml { -template inline auto -inverse(const readable_quaternion& q) --> inverse_node +template +inline auto +inverse(const readable_quaternion& q) -> inverse_node { return inverse_node(q.actual()); } -template inline auto -inverse(readable_quaternion&& q) --> inverse_node +template +inline auto +inverse(readable_quaternion&& q) -> inverse_node { return inverse_node((Sub&&) q); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/ops.h b/cml/quaternion/ops.h index 83118b8..546b15d 100644 --- a/cml/quaternion/ops.h +++ b/cml/quaternion/ops.h @@ -1,19 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_ops_h -#define cml_quaternion_ops_h - #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/order_tags.h b/cml/quaternion/order_tags.h index d8bd0e3..5ba8eb1 100644 --- a/cml/quaternion/order_tags.h +++ b/cml/quaternion/order_tags.h @@ -1,41 +1,50 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_order_tags_h -#define cml_quaternion_order_tags_h - #include namespace cml { /** Helper to specify real-first quaternion element ordering. */ -struct real_first { - enum { W = 0, X = 1, Y = 2, Z = 3 }; +struct real_first +{ + enum + { + W = 0, + X = 1, + Y = 2, + Z = 3 + }; }; /** Helper to specify imaginary-first quaternion element ordering. */ -struct imaginary_first { - enum { X = 0, Y = 1, Z = 2, W = 3 }; +struct imaginary_first +{ + enum + { + X = 0, + Y = 1, + Z = 2, + W = 3 + }; }; /** Detect valid order types. */ -template struct is_order_type { - static const bool value - = std::is_same::value - || std::is_same::value - ; +template struct is_order_type +{ + static const bool value = std::is_same::value + || std::is_same::value; }; /** Templated helper to determine the order type of an expression that * defines the order_type type. */ -template struct order_type_of { - typedef typename T::order_type type; +template struct order_type_of +{ + using type = typename T::order_type; static_assert(is_order_type::value, "invalid order type"); }; @@ -43,15 +52,15 @@ template struct order_type_of { template using order_type_of_t = typename order_type_of::type; /** Retrieve the order_type of @c T via traits. */ -template struct order_type_trait_of { - typedef typename traits_of::type::order_type type; +template struct order_type_trait_of +{ + using type = typename traits_of::type::order_type; static_assert(is_order_type::value, "invalid order type"); }; /** Convenience alias for order_type_trait_of. */ template - using order_type_trait_of_t = typename order_type_trait_of::type; - +using order_type_trait_of_t = typename order_type_trait_of::type; /** Deduce the default order tag needed to promote the result of combining * two expressions having orders @c Tag1 and @c Tag2. By default: @@ -62,20 +71,18 @@ template */ template struct order_type_promote { - static_assert(is_order_type::value, - "invalid quaternion order type"); - static_assert(is_order_type::value, - "invalid quaternion order type"); - static_assert(std::is_same::value, + static_assert(is_order_type::value, "invalid quaternion order type"); + static_assert(is_order_type::value, "invalid quaternion order type"); + static_assert(std::is_same::value, "mismatched quaternion order types"); /* The tags are the same, so use the common type: */ - typedef Tag1 type; + using type = Tag1; }; /** Convenience alias for order_type_promote. */ template - using order_type_promote_t = typename order_type_promote::type; +using order_type_promote_t = typename order_type_promote::type; /** For CML1 compatibility. */ @@ -84,9 +91,4 @@ using scalar_first = real_first; /** For CML1 compatibility. */ using vector_first = imaginary_first; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/product.h b/cml/quaternion/product.h index 86c3c94..06cf62c 100644 --- a/cml/quaternion/product.h +++ b/cml/quaternion/product.h @@ -1,35 +1,23 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_product_h -#define cml_quaternion_product_h - #include #include namespace cml { /** Multiply two quaternions, and return the result as a temporary. */ -template* = nullptr, +template* = nullptr, enable_if_quaternion_t* = nullptr> -auto operator*(Sub1&& sub1, Sub2&& sub2) --> quaternion_promote_t< - actual_operand_type_of_t, +auto operator*(Sub1&& sub1, + Sub2&& sub2) -> quaternion_promote_t, actual_operand_type_of_t>; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_PRODUCT_TPP #include #undef __CML_QUATERNION_PRODUCT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/product.tpp b/cml/quaternion/product.tpp index c68a654..b7a5c75 100644 --- a/cml/quaternion/product.tpp +++ b/cml/quaternion/product.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_PRODUCT_TPP -#error "quaternion/product.tpp not included correctly" +# error "quaternion/product.tpp not included correctly" #endif #include @@ -15,21 +13,21 @@ namespace cml { -template*, enable_if_quaternion_t*> -inline auto operator*(Sub1&& sub1, Sub2&& sub2) --> quaternion_promote_t< - actual_operand_type_of_t, +template*, + enable_if_quaternion_t*> +inline auto +operator*(Sub1&& sub1, + Sub2&& sub2) -> quaternion_promote_t, actual_operand_type_of_t> { - typedef quaternion_promote_t< - actual_operand_type_of_t, - actual_operand_type_of_t> result_type; - typedef order_type_trait_of_t order_type; - typedef cross_type_trait_of_t cross_type; + using result_type = quaternion_promote_t, + actual_operand_type_of_t>; + using order_type = order_type_trait_of_t; + using cross_type = cross_type_trait_of_t; /* Local enum for the order: */ - enum { + enum + { W = order_type::W, X = order_type::X, Y = order_type::Y, @@ -43,20 +41,15 @@ inline auto operator*(Sub1&& sub1, Sub2&& sub2) * * {+/-} is determined by cross_type: */ - auto real - = sub1[W]*sub2[W] - cml::dot(sub1.imaginary(), sub2.imaginary()); + auto real = sub1[W] * sub2[W] - cml::dot(sub1.imaginary(), sub2.imaginary()); auto cross = std::is_same::value ? cml::cross(sub1.imaginary(), sub2.imaginary()) - : cml::cross(sub2.imaginary(), sub1.imaginary()) - ; - auto imaginary - = sub1[W]*sub2.imaginary() + sub2[W]*sub1.imaginary() + cross; + : cml::cross(sub2.imaginary(), sub1.imaginary()); + auto imaginary = + sub1[W] * sub2.imaginary() + sub2[W] * sub1.imaginary() + cross; /* Done: */ return result_type(real, imaginary); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/promotion.h b/cml/quaternion/promotion.h index 7859d40..e7a5ff7 100644 --- a/cml/quaternion/promotion.h +++ b/cml/quaternion/promotion.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_promotion_h -#define cml_quaternion_promotion_h - #include #include #include @@ -29,75 +24,65 @@ namespace cml { template struct quaternion_binary_storage_promote { - static_assert( - is_quaternion_storage::value && - is_quaternion_storage::value, + static_assert(is_quaternion_storage::value + && is_quaternion_storage::value, "expected quaternion storage types for binary promotion"); /* Determine the common unbound storage type: */ - typedef storage_promote_t unbound_type; + using unbound_type = storage_promote_t; /* Resize: */ - typedef resize_storage_t resized_type; + using resized_type = resize_storage_t; /* Rebind to a quaternion storage type: */ - typedef rebind_quaternion_storage_t type; + using type = rebind_quaternion_storage_t; }; /** Convenience alias for quaternion_binary_storage_promote. */ template - using quaternion_binary_storage_promote_t = - typename quaternion_binary_storage_promote::type; +using quaternion_binary_storage_promote_t = + typename quaternion_binary_storage_promote::type; /** Helper to deduce a reasonable quaternion type from two quaternion * subexpression types. This can be specialized for non-default behavior. */ -template - struct quaternion_promote; +template struct quaternion_promote; -template struct quaternion_promote< - Sub1, Sub2, typename std::enable_if< - is_quaternion::value && is_quaternion::value>::type> +template +struct quaternion_promote::value + && is_quaternion::value>::type> { - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef quaternion_traits left_traits; - typedef quaternion_traits right_traits; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = quaternion_traits; + using right_traits = quaternion_traits; /* Deduce the new quaternion element type: */ - typedef value_type_promote_t value_type; + using value_type = value_type_promote_t; /* Determine the new storage type: */ - typedef quaternion_binary_storage_promote_t< - storage_type_of_t, - storage_type_of_t> storage_type; + using storage_type = quaternion_binary_storage_promote_t, + storage_type_of_t>; /* Use the proxy type for the temporary: */ - typedef proxy_type_of_t proxy_type; + using proxy_type = proxy_type_of_t; /* Determine the common order type: */ - typedef order_type_promote_t< - order_type_of_t, - order_type_of_t> order_type; + using order_type = order_type_promote_t, + order_type_of_t>; /* Determine the common cross type: */ - typedef cross_type_promote_t< - cross_type_of_t, - cross_type_of_t> cross_type; + using cross_type = cross_type_promote_t, + cross_type_of_t>; /* Build the quaternion type: */ - typedef quaternion type; + using type = quaternion; }; /** Convenience alias for quaternion_promote<>. */ template - using quaternion_promote_t = typename quaternion_promote::type; - -} // namespace cml - -#endif +using quaternion_promote_t = typename quaternion_promote::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/quaternion.h b/cml/quaternion/quaternion.h index 6a2a19c..a945851 100644 --- a/cml/quaternion/quaternion.h +++ b/cml/quaternion/quaternion.h @@ -1,14 +1,10 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_quaternion_h -#define cml_quaternion_quaternion_h - +#include #include #include @@ -34,12 +30,7 @@ namespace cml { * left-handed (negative_cross) or right-handed (positive_cross). */ template, - class Order = imaginary_first, class Cross = positive_cross> - class quaternion; - -} // namespace cml - -#endif + class Order = imaginary_first, class Cross = positive_cross> +class quaternion; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/readable_quaternion.h b/cml/quaternion/readable_quaternion.h index 3ff5744..caa6675 100644 --- a/cml/quaternion/readable_quaternion.h +++ b/cml/quaternion/readable_quaternion.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_readable_quaternion_h -#define cml_quaternion_readable_quaternion_h - #include #include #include @@ -30,150 +25,143 @@ template class inverse_node; * by quaternion_traits. Note that immutable_value is not * necessarily a reference or const type. */ -template -class readable_quaternion +template class readable_quaternion { public: - - typedef DerivedT quaternion_type; - typedef quaternion_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::order_type order_type; - typedef typename traits_type::cross_type cross_type; + using quaternion_type = DerivedT; + using traits_type = quaternion_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using order_type = typename traits_type::order_type; + using cross_type = typename traits_type::cross_type; public: - - /** Localize the ordering as an enum. */ - enum { - W = order_type::W, - X = order_type::X, - Y = order_type::Y, - Z = order_type::Z - }; + /** Localize the ordering as an enum. */ + enum + { + W = order_type::W, + X = order_type::X, + Y = order_type::Y, + Z = order_type::Z + }; public: + /** Return a const reference to the quaternion cast as DerivedT. */ + const DerivedT& actual() const; - /** Return a const reference to the quaternion cast as DerivedT. */ - const DerivedT& actual() const; - - /** Return const element @c i. */ - immutable_value get(int i) const; + /** Return const element @c i. */ + immutable_value get(int i) const; - /** Return const element @c i. */ - immutable_value operator[](int i) const; + /** Return const element @c i. */ + immutable_value operator[](int i) const; - /** Return a const reference to the real part of the quaternion. */ - immutable_value w() const; + /** Return a const reference to the real part of the quaternion. */ + immutable_value w() const; - /** Return a const reference to the imaginary i coordinate */ - immutable_value x() const; + /** Return a const reference to the imaginary i coordinate */ + immutable_value x() const; - /** Return a const reference to the imaginary j coordinate */ - immutable_value y() const; + /** Return a const reference to the imaginary j coordinate */ + immutable_value y() const; - /** Return a const reference to the imaginary k coordinate */ - immutable_value z() const; + /** Return a const reference to the imaginary k coordinate */ + immutable_value z() const; public: + /** Return the array size. This is always 4. */ + int size() const; - /** Return the array size. This is always 4. */ - int size() const; - - /** Return the real part of the quaternion. */ - immutable_value real() const; + /** Return the real part of the quaternion. */ + immutable_value real() const; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Return the imaginary part of the quaternion as a vector expression. + /** Return the imaginary part of the quaternion as a vector expression. */ - imaginary_node imaginary() const &; + imaginary_node imaginary() const&; - /** Return the imaginary part of the quaternion as a vector expression, + /** Return the imaginary part of the quaternion as a vector expression, * moving the source into the node. */ - imaginary_node imaginary() const &&; + imaginary_node imaginary() const&&; #else - /** Return the imaginary part of the quaternion as a vector expression. */ - imaginary_node imaginary() const; + /** Return the imaginary part of the quaternion as a vector expression. */ + imaginary_node imaginary() const; #endif - /** Return the squared length of the quaternion. */ - value_type length_squared() const; + /** Return the squared length of the quaternion. */ + value_type length_squared() const; - /** Return the length of the quaternion. */ - value_type length() const; + /** Return the length of the quaternion. */ + value_type length() const; - /** Return the Cayley norm of the quaternion. */ - value_type norm() const; + /** Return the Cayley norm of the quaternion. */ + value_type norm() const; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Return the normalized quaternion as an expression node. */ - quaternion_scalar_node> normalize() const &; + /** Return the normalized quaternion as an expression node. */ + quaternion_scalar_node> + normalize() const&; - /** Return the normalized quaternion as an expression node, moving the + /** Return the normalized quaternion as an expression node, moving the * source into the node. */ - quaternion_scalar_node> normalize() const &&; + quaternion_scalar_node> + normalize() const&&; #else - /** Return the normalized quaternion as an expression node. */ - quaternion_scalar_node> normalize() const; + /** Return the normalized quaternion as an expression node. */ + quaternion_scalar_node> + normalize() const; #endif #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Return the conjugate as an expression node. */ - conjugate_node conjugate() const &; + /** Return the conjugate as an expression node. */ + conjugate_node conjugate() const&; - /** Return the conjugate as an expression node, moving the source into + /** Return the conjugate as an expression node, moving the source into * the node. */ - conjugate_node conjugate() const &&; + conjugate_node conjugate() const&&; #else - /** Return the conjugate as an expression node. */ - conjugate_node conjugate() const; + /** Return the conjugate as an expression node. */ + conjugate_node conjugate() const; #endif #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Return the inverse as an expression node. */ - inverse_node inverse() const &; + /** Return the inverse as an expression node. */ + inverse_node inverse() const&; - /** Return the inverse as an expression node, moving the source into + /** Return the inverse as an expression node, moving the source into * the node. */ - inverse_node inverse() const &&; + inverse_node inverse() const&&; #else - /** Return the inverse as an expression node. */ - inverse_node inverse() const; + /** Return the inverse as an expression node. */ + inverse_node inverse() const; #endif protected: + // Use the compiler-generated default constructor: + readable_quaternion() = default; - // Use the compiler-generated default constructor: - readable_quaternion() = default; - - // Use the compiler-generated copy constructor: - readable_quaternion(const readable_quaternion&) = default; + // Use the compiler-generated copy constructor: + readable_quaternion(const readable_quaternion&) = default; #ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR - // Use the compiler-generated move constructor: - readable_quaternion(readable_quaternion&&) = default; + // Use the compiler-generated move constructor: + readable_quaternion(readable_quaternion&&) = default; #endif }; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_READABLE_QUATERNION_TPP #include #undef __CML_QUATERNION_READABLE_QUATERNION_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/readable_quaternion.tpp b/cml/quaternion/readable_quaternion.tpp index 6d3792c..be6badf 100644 --- a/cml/quaternion/readable_quaternion.tpp +++ b/cml/quaternion/readable_quaternion.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_READABLE_QUATERNION_TPP -#error "quaternion/readable_quaternion.tpp not included correctly" +# error "quaternion/readable_quaternion.tpp not included correctly" #endif #include @@ -17,144 +15,163 @@ namespace cml { /* Public methods: */ -template const DT& +template +const DT& readable_quaternion
::actual() const { return (const DT&) *this; } -template auto +template +auto readable_quaternion
::get(int i) const -> immutable_value { return this->actual().i_get(i); } -template auto +template +auto readable_quaternion
::operator[](int i) const -> immutable_value { return this->get(i); } -template auto +template +auto readable_quaternion
::w() const -> immutable_value { return this->get(order_type::W); } -template auto +template +auto readable_quaternion
::x() const -> immutable_value { return this->get(order_type::X); } -template auto +template +auto readable_quaternion
::y() const -> immutable_value { return this->get(order_type::Y); } -template auto +template +auto readable_quaternion
::z() const -> immutable_value { return this->get(order_type::Z); } - -template int +template +int readable_quaternion
::size() const { return 4; } -template auto +template +auto readable_quaternion
::real() const -> immutable_value { return this->get(order_type::W); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template auto -readable_quaternion
::imaginary() const & -> imaginary_node +template +auto +readable_quaternion
::imaginary() const& -> imaginary_node { return imaginary_node((const DT&) *this); } -template auto -readable_quaternion
::imaginary() const && -> imaginary_node +template +auto +readable_quaternion
::imaginary() const&& -> imaginary_node { return imaginary_node((DT&&) *this); } #else -template auto +template +auto readable_quaternion
::imaginary() const -> imaginary_node
{ return imaginary_node
((const DT&) *this); } #endif -template auto +template +auto readable_quaternion
::length_squared() const -> value_type { value_type accum = cml::sqr(this->get(0)); - for(int i = 1; i < 4; ++ i) accum += cml::sqr(this->get(i)); + for(int i = 1; i < 4; ++i) accum += cml::sqr(this->get(i)); return accum; } -template auto +template +auto readable_quaternion
::length() const -> value_type { return element_traits::sqrt(this->length_squared()); } -template auto +template +auto readable_quaternion
::norm() const -> value_type { return this->length_squared(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template auto -readable_quaternion
::normalize() const & -> quaternion_scalar_node< - const DT&, value_type, op::binary_divide> +template +auto +readable_quaternion
::normalize() const& -> quaternion_scalar_node> { - return quaternion_scalar_node< - const DT&, value_type, op::binary_divide> - ((const DT&) *this, this->length()); + return quaternion_scalar_node>((const DT&) *this, + this->length()); } -template auto -readable_quaternion
::normalize() const && -> quaternion_scalar_node< - DT&&, value_type, op::binary_divide> +template +auto +readable_quaternion
::normalize() const&& -> quaternion_scalar_node> { - return quaternion_scalar_node< - DT&&, value_type, op::binary_divide> - ((DT&&) *this, this->length()); + return quaternion_scalar_node>((DT&&) *this, this->length()); } #else -template auto -readable_quaternion
::normalize() const -> quaternion_scalar_node< - DT, value_type, op::binary_divide> +template +auto +readable_quaternion
::normalize() const -> quaternion_scalar_node> { - return quaternion_scalar_node< - DT, value_type, op::binary_divide> - ((const DT&) *this, this->length()); + return quaternion_scalar_node>((const DT&) *this, + this->length()); } #endif #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template auto -readable_quaternion
::conjugate() const & -> conjugate_node +template +auto +readable_quaternion
::conjugate() const& -> conjugate_node { return conjugate_node((const DT&) *this); } -template auto -readable_quaternion
::conjugate() const && -> conjugate_node +template +auto +readable_quaternion
::conjugate() const&& -> conjugate_node { return conjugate_node((DT&&) *this); } #else -template auto +template +auto readable_quaternion
::conjugate() const -> conjugate_node
{ return conjugate_node
((const DT&) *this); @@ -162,26 +179,26 @@ readable_quaternion
::conjugate() const -> conjugate_node
#endif #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template auto -readable_quaternion
::inverse() const & -> inverse_node +template +auto +readable_quaternion
::inverse() const& -> inverse_node { return inverse_node((const DT&) *this); } -template auto -readable_quaternion
::inverse() const && -> inverse_node +template +auto +readable_quaternion
::inverse() const&& -> inverse_node { return inverse_node((DT&&) *this); } #else -template auto +template +auto readable_quaternion
::inverse() const -> inverse_node
{ return inverse_node
((const DT&) *this); } #endif -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/scalar_node.h b/cml/quaternion/scalar_node.h index fdad154..021baf1 100644 --- a/cml/quaternion/scalar_node.h +++ b/cml/quaternion/scalar_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_scalar_node_h -#define cml_quaternion_scalar_node_h - #include #include @@ -18,21 +13,21 @@ template class quaternion_scalar_node; /** quaternion_scalar_node<> traits. */ template -struct quaternion_traits< quaternion_scalar_node > +struct quaternion_traits> { /* Figure out the basic types of Sub and Scalar: */ - typedef quaternion_scalar_node quaternion_type; - typedef Sub left_arg_type; - typedef Scalar right_arg_type; - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef quaternion_traits left_traits; - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; - typedef typename left_traits::storage_type storage_type; - - typedef typename left_traits::size_tag size_tag; + using quaternion_type = quaternion_scalar_node; + using left_arg_type = Sub; + using right_arg_type = Scalar; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = quaternion_traits; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; + using storage_type = typename left_traits::storage_type; + + using size_tag = typename left_traits::size_tag; static_assert(cml::is_fixed_size::value, "invalid size tag"); /* Array size: */ @@ -40,8 +35,8 @@ struct quaternion_traits< quaternion_scalar_node > static_assert(array_size == 4, "invalid quaternion size"); /* Order and cross taken from the sub-expression: */ - typedef typename left_traits::order_type order_type; - typedef typename left_traits::cross_type cross_type; + using order_type = typename left_traits::order_type; + using cross_type = typename left_traits::cross_type; }; /** Represents a binary quaternion operation, where one operand is a scalar @@ -49,100 +44,88 @@ struct quaternion_traits< quaternion_scalar_node > */ template class quaternion_scalar_node -: public readable_quaternion< quaternion_scalar_node > +: public readable_quaternion> { public: - - typedef quaternion_scalar_node node_type; - typedef readable_quaternion readable_type; - typedef quaternion_traits traits_type; - typedef typename traits_type::left_arg_type left_arg_type; - typedef typename traits_type::right_arg_type right_arg_type; - typedef typename traits_type::left_type left_type; - typedef typename traits_type::right_type right_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::order_type order_type; - typedef typename traits_type::cross_type cross_type; + using node_type = quaternion_scalar_node; + using readable_type = readable_quaternion; + using traits_type = quaternion_traits; + using left_arg_type = typename traits_type::left_arg_type; + using right_arg_type = typename traits_type::right_arg_type; + using left_type = typename traits_type::left_type; + using right_type = typename traits_type::right_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using order_type = typename traits_type::order_type; + using cross_type = typename traits_type::cross_type; public: - - /** The array size constant is the same as the subexpression. */ - static const int array_size = traits_type::array_size; + /** The array size constant is the same as the subexpression. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped sub-expression and the scalar to apply. + /** Construct from the wrapped sub-expression and the scalar to apply. * @c left must be an lvalue reference or rvalue reference. */ - quaternion_scalar_node(Sub left, const right_type& right); + quaternion_scalar_node(Sub left, const right_type& right); - /** Move constructor. */ - quaternion_scalar_node(node_type&& other); + /** Move constructor. */ + quaternion_scalar_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - quaternion_scalar_node(const node_type& other); + /** Copy constructor. */ + quaternion_scalar_node(const node_type& other); #endif protected: + /** @name readable_quaternion Interface */ + /*@{*/ - /** @name readable_quaternion Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Apply the scalar operator to element @c i of the subexpression and + /** Apply the scalar operator to element @c i of the subexpression and * return the result. */ - immutable_value i_get(int i) const; + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the left subexpression. The expression is + /** The type used to store the left subexpression. The expression is * stored as a copy if Sub is an rvalue reference (temporary), or by * const reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const left_type&, left_type> left_wrap_type; + using left_wrap_type = cml::if_t::value, const left_type&, + left_type>; protected: + /** The quaternion operand. */ + left_wrap_type m_left; - /** The quaternion operand. */ - left_wrap_type m_left; - - /** The scalar operand. */ - right_type m_right; + /** The scalar operand. */ + right_type m_right; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - quaternion_scalar_node(const node_type&); + // Not copy constructible. + quaternion_scalar_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_SCALAR_NODE_TPP #include #undef __CML_QUATERNION_SCALAR_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/scalar_node.tpp b/cml/quaternion/scalar_node.tpp index 654c851..3bd988d 100644 --- a/cml/quaternion/scalar_node.tpp +++ b/cml/quaternion/scalar_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_SCALAR_NODE_TPP -#error "quaternion/scalar_node.tpp not included correctly" +# error "quaternion/scalar_node.tpp not included correctly" #endif namespace cml { @@ -13,42 +11,38 @@ namespace cml { /* quaternion_scalar_node 'structors: */ template -quaternion_scalar_node::quaternion_scalar_node( - Sub left, const right_type& right - ) -: m_left(std::move(left)), m_right(right) -{ -} +quaternion_scalar_node::quaternion_scalar_node(Sub left, + const right_type& right) +: m_left(std::move(left)) +, m_right(right) +{} template -quaternion_scalar_node -::quaternion_scalar_node(node_type&& other) -: m_left(std::move(other.m_left)), m_right(std::move(other.m_right)) -{ -} +quaternion_scalar_node::quaternion_scalar_node( + node_type&& other) +: m_left(std::move(other.m_left)) +, m_right(std::move(other.m_right)) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -quaternion_scalar_node -::quaternion_scalar_node(const node_type& other) -: m_left(other.m_left), m_right(other.m_right) -{ -} +quaternion_scalar_node::quaternion_scalar_node( + const node_type& other) +: m_left(other.m_left) +, m_right(other.m_right) +{} #endif - /* Internal methods: */ /* readable_quaternion interface: */ -template auto -quaternion_scalar_node::i_get(int i) const -> immutable_value +template +auto +quaternion_scalar_node::i_get(int i) const -> immutable_value { return Op().apply(this->m_left.get(i), this->m_right); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/scalar_ops.h b/cml/quaternion/scalar_ops.h index 631f926..c33adfc 100644 --- a/cml/quaternion/scalar_ops.h +++ b/cml/quaternion/scalar_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_scalar_ops_h -#define cml_quaternion_scalar_ops_h - #include #include #include @@ -20,70 +15,60 @@ namespace cml { */ template* = nullptr, - enable_if_arithmetic_t>* = nullptr -> inline auto -make_quaternion_scalar_node(Sub&& sub, Scalar&& v) --> quaternion_scalar_node< -actual_operand_type_of_t, -actual_operand_type_of_t, -Op -> + enable_if_arithmetic_t>* = nullptr> +inline auto +make_quaternion_scalar_node(Sub&& sub, + Scalar&& v) -> quaternion_scalar_node, + actual_operand_type_of_t, Op> { - static_assert(std::is_same< - decltype(sub), decltype(std::forward(sub))>::value, + static_assert( + std::is_same(sub))>::value, "internal error: unexpected expression type (sub)"); - static_assert(std::is_same< - decltype(v), decltype(std::forward(v))>::value, + static_assert( + std::is_same(v))>::value, "internal error: unexpected expression type (v)"); /* Deduce the operand types of the scalar and the subexpression (&, * const&, &&): */ - typedef actual_operand_type_of_t sub_type; - typedef actual_operand_type_of_t scalar_type; - return quaternion_scalar_node( - (sub_type) sub, (scalar_type) v); + using sub_type = actual_operand_type_of_t; + using scalar_type = actual_operand_type_of_t; + return quaternion_scalar_node((sub_type) sub, + (scalar_type) v); } -template* = nullptr, - enable_if_arithmetic_t>* = nullptr -> -inline auto operator*(Sub&& sub, Scalar&& v) --> decltype(make_quaternion_scalar_node>( +template* = nullptr, + enable_if_arithmetic_t>* = nullptr> +inline auto +operator*(Sub&& sub, Scalar&& v) + -> decltype(make_quaternion_scalar_node>( std::forward(sub), std::forward(v))) { - return make_quaternion_scalar_node>( + return make_quaternion_scalar_node>( std::forward(sub), std::forward(v)); } template>* = nullptr, - enable_if_quaternion_t* = nullptr -> -inline auto operator*(Scalar&& v, Sub&& sub) --> decltype(make_quaternion_scalar_node>( + enable_if_quaternion_t* = nullptr> +inline auto +operator*(Scalar&& v, Sub&& sub) + -> decltype(make_quaternion_scalar_node>( std::forward(sub), std::forward(v))) { - return make_quaternion_scalar_node>( + return make_quaternion_scalar_node>( std::forward(sub), std::forward(v)); } -template* = nullptr, - enable_if_arithmetic_t>* = nullptr -> -inline auto operator/(Sub&& sub, Scalar&& v) --> decltype(make_quaternion_scalar_node>( +template* = nullptr, + enable_if_arithmetic_t>* = nullptr> +inline auto +operator/(Sub&& sub, Scalar&& v) + -> decltype(make_quaternion_scalar_node>( std::forward(sub), std::forward(v))) { - return make_quaternion_scalar_node>( + return make_quaternion_scalar_node>( std::forward(sub), std::forward(v)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/size_checking.h b/cml/quaternion/size_checking.h index afd6159..4b6dd8a 100644 --- a/cml/quaternion/size_checking.h +++ b/cml/quaternion/size_checking.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_size_checking_h -#define cml_quaternion_size_checking_h - #include #include #include @@ -22,14 +17,11 @@ namespace cml { * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_QUATERNION_SIZE_CHECKS at compile time. */ -struct quaternion_size_error : std::runtime_error { +struct quaternion_size_error : std::runtime_error +{ quaternion_size_error() - : std::runtime_error("incorrect quaternion expression size") {} + : std::runtime_error("incorrect quaternion expression size") + {} }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/temporary.h b/cml/quaternion/temporary.h index b6911c0..715a963 100644 --- a/cml/quaternion/temporary.h +++ b/cml/quaternion/temporary.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_temporary_h -#define cml_quaternion_temporary_h - #include #include #include @@ -19,28 +14,22 @@ namespace cml { /** Deduce a temporary for a quaternion expression. */ template -struct temporary_of< Quaternion, cml::enable_if_quaternion_t > +struct temporary_of> { - typedef cml::unqualified_type_t quaternion_type; + using quaternion_type = cml::unqualified_type_t; /* Propagate the element type of the original quaternion: */ - typedef quaternion_traits traits_type; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::order_type order_type; - typedef typename traits_type::cross_type cross_type; + using traits_type = quaternion_traits; + using value_type = typename traits_type::value_type; + using storage_type = typename traits_type::storage_type; + using order_type = typename traits_type::order_type; + using cross_type = typename traits_type::cross_type; /* Need the proxy for the storage type: */ - typedef proxy_type_of_t proxy_type; + using proxy_type = proxy_type_of_t; /* Build the temporary: */ - typedef quaternion type; + using type = quaternion; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/traits.h b/cml/quaternion/traits.h index 478932a..ec883de 100644 --- a/cml/quaternion/traits.h +++ b/cml/quaternion/traits.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_traits_h -#define cml_quaternion_traits_h - #include #include @@ -24,13 +19,9 @@ template struct quaternion_traits; /** traits_of for quaternion types. */ template -struct traits_of> { - typedef quaternion_traits type; +struct traits_of> +{ + using type = quaternion_traits; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/type_util.h b/cml/quaternion/type_util.h index f7fe65c..c1eec0d 100644 --- a/cml/quaternion/type_util.h +++ b/cml/quaternion/type_util.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_type_util_h -#define cml_quaternion_type_util_h - #include #include @@ -19,23 +14,21 @@ namespace cml { * otherwise. The static bool @c value is set to true or false to match @c * type. */ -template struct is_quaternion { +template struct is_quaternion +{ private: - /* Strip const, volatile, and reference from T to get the type to test: */ - typedef cml::unqualified_type_t naked_type; + using naked_type = cml::unqualified_type_t; /* Deduce the derived type (fails if T is not statically polymorphic): */ - typedef actual_type_of_t derived_type; + using derived_type = actual_type_of_t; public: - /* std::true_type if T is derived from readable_quaternion<>, std::false_type * otherwise: */ - typedef std::is_base_of< - readable_quaternion, naked_type> type; + using type = std::is_base_of, naked_type>; /* True or false, depending upon 'type': */ static const bool value = type::value; @@ -44,16 +37,12 @@ template struct is_quaternion { /** Wrapper for enable_if to detect quaternion types (derived from * readable_quaternion). */ -template struct enable_if_quaternion -: std::enable_if::value> {}; +template +struct enable_if_quaternion : std::enable_if::value> +{}; /** Convenience alias for enable_if_quaternion. */ -template using enable_if_quaternion_t - = typename enable_if_quaternion::type; - -} // namespace cml - -#endif +template +using enable_if_quaternion_t = typename enable_if_quaternion::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/types.h b/cml/quaternion/types.h index 9e8b207..776ce50 100644 --- a/cml/quaternion/types.h +++ b/cml/quaternion/types.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_types_h -#define cml_quaternion_types_h - #include #include @@ -18,49 +13,32 @@ namespace cml { /*@{*/ // Imaginary first, positive cross: -typedef quaternion< - float, fixed<>, imaginary_first, positive_cross> quaternionf_ip; -typedef quaternion< - float, fixed<>, imaginary_first, positive_cross> quaternionf_p; -typedef quaternion quaternionf; +using quaternionf_ip = quaternion, imaginary_first, positive_cross>; +using quaternionf_p = quaternion, imaginary_first, positive_cross>; +using quaternionf = quaternion; -typedef quaternion< - double, fixed<>, imaginary_first, positive_cross> quaterniond_ip; -typedef quaternion< - double, fixed<>, imaginary_first, positive_cross> quaterniond_p; -typedef quaternion quaterniond; +using quaterniond_ip = quaternion, imaginary_first, positive_cross>; +using quaterniond_p = quaternion, imaginary_first, positive_cross>; +using quaterniond = quaternion; // Imaginary first, negative cross: -typedef quaternion< - float, fixed<>, imaginary_first, negative_cross> quaternionf_in; -typedef quaternion< - float, fixed<>, imaginary_first, negative_cross> quaternionf_n; +using quaternionf_in = quaternion, imaginary_first, negative_cross>; +using quaternionf_n = quaternion, imaginary_first, negative_cross>; -typedef quaternion< - double, fixed<>, imaginary_first, negative_cross> quaterniond_in; -typedef quaternion< - double, fixed<>, imaginary_first, negative_cross> quaterniond_n; +using quaterniond_in = quaternion, imaginary_first, negative_cross>; +using quaterniond_n = quaternion, imaginary_first, negative_cross>; // Real first, positive cross: -typedef quaternion< - float, fixed<>, real_first, positive_cross> quaternionf_rp; -typedef quaternion< - double, fixed<>, real_first, positive_cross> quaterniond_rp; +using quaternionf_rp = quaternion, real_first, positive_cross>; +using quaterniond_rp = quaternion, real_first, positive_cross>; // Real first, negative cross: -typedef quaternion< - float, fixed<>, real_first, negative_cross> quaternionf_rn; -typedef quaternion< - double, fixed<>, real_first, negative_cross> quaterniond_rn; +using quaternionf_rn = quaternion, real_first, negative_cross>; +using quaterniond_rn = quaternion, real_first, negative_cross>; /*@}*/ -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/unary_node.h b/cml/quaternion/unary_node.h index 5538e8f..8daa228 100644 --- a/cml/quaternion/unary_node.h +++ b/cml/quaternion/unary_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_unary_node_h -#define cml_quaternion_unary_node_h - #include #include @@ -18,19 +13,19 @@ template class quaternion_unary_node; /** quaternion_unary_node<> traits. */ template -struct quaternion_traits< quaternion_unary_node > +struct quaternion_traits> { /* Figure out the basic types of Sub: */ - typedef quaternion_unary_node quaternion_type; - typedef Sub sub_arg_type; - typedef cml::unqualified_type_t sub_type; - typedef quaternion_traits sub_traits; - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; - typedef typename sub_traits::storage_type storage_type; - - typedef typename sub_traits::size_tag size_tag; + using quaternion_type = quaternion_unary_node; + using sub_arg_type = Sub; + using sub_type = cml::unqualified_type_t; + using sub_traits = quaternion_traits; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; + using storage_type = typename sub_traits::storage_type; + + using size_tag = typename sub_traits::size_tag; static_assert(cml::is_fixed_size::value, "invalid size tag"); /* Array size: */ @@ -38,102 +33,90 @@ struct quaternion_traits< quaternion_unary_node > static_assert(array_size == 4, "invalid quaternion size"); /* Order and cross taken from the sub-expression: */ - typedef typename sub_traits::order_type order_type; - typedef typename sub_traits::cross_type cross_type; + using order_type = typename sub_traits::order_type; + using cross_type = typename sub_traits::cross_type; }; /** Represents a unary quaternion operation. */ template class quaternion_unary_node -: public readable_quaternion< quaternion_unary_node > +: public readable_quaternion> { public: - - typedef quaternion_unary_node node_type; - typedef readable_quaternion readable_type; - typedef quaternion_traits traits_type; - typedef typename traits_type::sub_arg_type sub_arg_type; - typedef typename traits_type::sub_type sub_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::order_type order_type; - typedef typename traits_type::cross_type cross_type; + using node_type = quaternion_unary_node; + using readable_type = readable_quaternion; + using traits_type = quaternion_traits; + using sub_arg_type = typename traits_type::sub_arg_type; + using sub_type = typename traits_type::sub_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using order_type = typename traits_type::order_type; + using cross_type = typename traits_type::cross_type; public: - - /** The array size constant is the same as the subexpression. */ - static const int array_size = traits_type::array_size; + /** The array size constant is the same as the subexpression. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped sub-expression. @c sub must be an + /** Construct from the wrapped sub-expression. @c sub must be an * lvalue reference or rvalue reference. */ - quaternion_unary_node(Sub sub); + quaternion_unary_node(Sub sub); - /** Move constructor. */ - quaternion_unary_node(node_type&& other); + /** Move constructor. */ + quaternion_unary_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - quaternion_unary_node(const node_type& other); + /** Copy constructor. */ + quaternion_unary_node(const node_type& other); #endif protected: + /** @name readable_quaternion Interface */ + /*@{*/ - /** @name readable_quaternion Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Apply the unary operator to element @c i of the subexpression and + /** Apply the unary operator to element @c i of the subexpression and * return the result. */ - immutable_value i_get(int i) const; + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the subexpression. The expression is stored + /** The type used to store the subexpression. The expression is stored * as a copy if Sub is an rvalue reference (temporary), or by const * reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const sub_type&, sub_type> sub_wrap_type; + using sub_wrap_type = cml::if_t::value, const sub_type&, + sub_type>; protected: - - /** The subexpression. */ - sub_wrap_type m_sub; + /** The subexpression. */ + sub_wrap_type m_sub; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - quaternion_unary_node(const node_type&); + // Not copy constructible. + quaternion_unary_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_UNARY_NODE_TPP #include #undef __CML_QUATERNION_UNARY_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/unary_node.tpp b/cml/quaternion/unary_node.tpp index ea9678e..0edf294 100644 --- a/cml/quaternion/unary_node.tpp +++ b/cml/quaternion/unary_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_UNARY_NODE_TPP -#error "quaternion/unary_node.tpp not included correctly" +# error "quaternion/unary_node.tpp not included correctly" #endif namespace cml { @@ -13,38 +11,32 @@ namespace cml { /* quaternion_unary_node 'structors: */ template -quaternion_unary_node::quaternion_unary_node(Sub sub) +quaternion_unary_node::quaternion_unary_node(Sub sub) : m_sub(std::move(sub)) -{ -} +{} template -quaternion_unary_node::quaternion_unary_node(node_type&& other) +quaternion_unary_node::quaternion_unary_node(node_type&& other) : m_sub(std::move(other.m_sub)) -{ -} +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -quaternion_unary_node::quaternion_unary_node(const node_type& other) +quaternion_unary_node::quaternion_unary_node(const node_type& other) : m_sub(other.m_sub) -{ -} +{} #endif - /* Internal methods: */ /* readable_quaternion interface: */ -template auto -quaternion_unary_node::i_get(int i) const -> immutable_value +template +auto +quaternion_unary_node::i_get(int i) const -> immutable_value { return Op().apply(this->m_sub.get(i)); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/quaternion/unary_ops.h b/cml/quaternion/unary_ops.h index 4896c3d..44d086f 100644 --- a/cml/quaternion/unary_ops.h +++ b/cml/quaternion/unary_ops.h @@ -1,15 +1,10 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_unary_ops_h -#define cml_quaternion_unary_ops_h - #include #include @@ -19,35 +14,33 @@ namespace cml { * type (i.e. derived from readable_quaternion<>). */ template* = nullptr> -inline auto make_quaternion_unary_node(Sub&& sub) --> quaternion_unary_node, Op> +inline auto +make_quaternion_unary_node(Sub&& sub) + -> quaternion_unary_node, Op> { - static_assert(std::is_same< - decltype(sub), decltype(std::forward(sub))>::value, + static_assert( + std::is_same(sub))>::value, "internal error: unexpected expression type"); /* Deduce the operand type of the subexpression (&, const&, &&): */ - typedef actual_operand_type_of_t sub_type; + using sub_type = actual_operand_type_of_t; return quaternion_unary_node((sub_type) sub); } template* = nullptr> -inline auto operator-(Sub&& sub) -> decltype( - make_quaternion_unary_node>(std::forward(sub))) +inline auto +operator-(Sub&& sub) -> decltype(make_quaternion_unary_node>( + std::forward(sub))) { return make_quaternion_unary_node>(std::forward(sub)); } template* = nullptr> -inline auto operator+(Sub&& sub) -> decltype( - make_quaternion_unary_node>(std::forward(sub))) +inline auto +operator+(Sub&& sub) -> decltype(make_quaternion_unary_node>( + std::forward(sub))) { return make_quaternion_unary_node>(std::forward(sub)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/quaternion/writable_quaternion.h b/cml/quaternion/writable_quaternion.h index 7498329..41f443a 100644 --- a/cml/quaternion/writable_quaternion.h +++ b/cml/quaternion/writable_quaternion.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_quaternion_writable_quaternion_h -#define cml_quaternion_writable_quaternion_h - #include #include #include @@ -41,165 +36,159 @@ namespace cml { * Note that mutable_value need not be a reference type. */ template -class writable_quaternion -: public readable_quaternion +class writable_quaternion : public readable_quaternion { public: - - typedef DerivedT quaternion_type; - typedef readable_quaternion readable_type; - typedef quaternion_traits traits_type; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; - typedef typename traits_type::order_type order_type; + using quaternion_type = DerivedT; + using readable_type = readable_quaternion; + using traits_type = quaternion_traits; + using value_type = typename traits_type::value_type; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; + using order_type = typename traits_type::order_type; public: - - /* Disambiguate readable_quaternion<> methods: */ - using readable_type::W; - using readable_type::X; - using readable_type::Y; - using readable_type::Z; - using readable_type::actual; - using readable_type::get; - using readable_type::normalize; - using readable_type::conjugate; - using readable_type::inverse; - using readable_type::operator[]; - using readable_type::x; - using readable_type::y; - using readable_type::z; - using readable_type::w; + /* Disambiguate readable_quaternion<> methods: */ + using readable_type::W; + using readable_type::X; + using readable_type::Y; + using readable_type::Z; + using readable_type::actual; + using readable_type::get; + using readable_type::normalize; + using readable_type::conjugate; + using readable_type::inverse; + using readable_type::operator[]; + using readable_type::x; + using readable_type::y; + using readable_type::z; + using readable_type::w; public: + /** Return a mutable reference to the quaternion cast as DerivedT. */ + DerivedT& actual(); - /** Return a mutable reference to the quaternion cast as DerivedT. */ - DerivedT& actual(); - - /** Set element @c i. */ - template DerivedT& put(int i, const Other& v) __CML_REF; + /** Set element @c i. */ + template DerivedT& put(int i, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i on a temporary. */ - template DerivedT&& put(int i, const Other& v) &&; + /** Set element @c i on a temporary. */ + template DerivedT&& put(int i, const Other& v) &&; #endif - /** Return mutable element @c i. */ - mutable_value get(int i); + /** Return mutable element @c i. */ + mutable_value get(int i); - /** Return a mutable reference to element @c i. */ - mutable_value operator[](int i); + /** Return a mutable reference to element @c i. */ + mutable_value operator[](int i); - /** Return a mutable reference to the real part of the quaternion. */ - mutable_value w(); + /** Return a mutable reference to the real part of the quaternion. */ + mutable_value w(); - /** Return a mutable reference to the imaginary i coordinate. */ - mutable_value x(); + /** Return a mutable reference to the imaginary i coordinate. */ + mutable_value x(); - /** Return a mutable reference to the imaginary j coordinate. */ - mutable_value y(); + /** Return a mutable reference to the imaginary j coordinate. */ + mutable_value y(); - /** Return a mutable reference to the imaginary k coordinate. */ - mutable_value z(); + /** Return a mutable reference to the imaginary k coordinate. */ + mutable_value z(); public: - - /** Set the scalar of the quaternion to @c s, and the imaginary + /** Set the scalar of the quaternion to @c s, and the imaginary * vector to @c v. * * @note This functin is enabled only if the value_type of @c v and @c * E are convertible to value_type. */ - template* = nullptr> auto - set(const readable_vector& v, const E& s) __CML_REF - -> enable_if_t, E>::value, DerivedT&>; + template* = nullptr> + auto set(const readable_vector& v, const E& s) __CML_REF->enable_if_t< + are_convertible, E>::value, + DerivedT&>; - /** Set the scalar of the quaternion to @c s, and the imaginary + /** Set the scalar of the quaternion to @c s, and the imaginary * vector to @c v. * * @note This functin is enabled only if the value_type of @c v and @c * E are convertible to value_type. */ - template* = nullptr> auto - set(const E& s, const readable_vector& v) __CML_REF - -> enable_if_t, E>::value, DerivedT&>; + template* = nullptr> + auto set(const E& s, const readable_vector& v) __CML_REF->enable_if_t< + are_convertible, E>::value, + DerivedT&>; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set the scalar of the temporary quaternion to @c s, and the + /** Set the scalar of the temporary quaternion to @c s, and the * imaginary vector to @c v. * * @note This functin is enabled only if the value_type of @c v and @c * E are convertible to value_type. */ - template* = nullptr> auto - set(const readable_vector& v, const E& s) && - -> enable_if_t, E>::value, DerivedT&&>; + template* = nullptr> + auto set(const readable_vector& v, const E& s) && -> enable_if_t< + are_convertible, E>::value, + DerivedT&&>; - /** Set the scalar of the temporary quaternion to @c s, and the + /** Set the scalar of the temporary quaternion to @c s, and the * imaginary vector to @c v. * * @note This functin is enabled only if the value_type of @c v and @c * E are convertible to value_type. */ - template* = nullptr> auto - set(const E& s, const readable_vector& v) && - -> enable_if_t, E>::value, DerivedT&&>; + template* = nullptr> + auto set(const E& s, const readable_vector& v) && -> enable_if_t< + are_convertible, E>::value, + DerivedT&&>; #endif public: - - /** Divide the quaternion elements by the length of the quaternion. */ - DerivedT& normalize() __CML_REF; + /** Divide the quaternion elements by the length of the quaternion. */ + DerivedT& normalize() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Divide the quaternion elements of a temporary by the length of the + /** Divide the quaternion elements of a temporary by the length of the * quaternion. */ - DerivedT&& normalize() &&; + DerivedT&& normalize() &&; #endif - /** Zero the quaternion elements. */ - DerivedT& zero() __CML_REF; + /** Zero the quaternion elements. */ + DerivedT& zero() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Zero the quaternion elements of a temporary. */ - DerivedT&& zero() &&; + /** Zero the quaternion elements of a temporary. */ + DerivedT&& zero() &&; #endif - /** Set the quaternion to the identity. */ - DerivedT& identity() __CML_REF; + /** Set the quaternion to the identity. */ + DerivedT& identity() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set a temporary to the identity. */ - DerivedT&& identity() &&; + /** Set a temporary to the identity. */ + DerivedT&& identity() &&; #endif - /** Set the quaternion to its conjugate. */ - DerivedT& conjugate() __CML_REF; + /** Set the quaternion to its conjugate. */ + DerivedT& conjugate() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set a temporary to its conjugate. */ - DerivedT&& conjugate() &&; + /** Set a temporary to its conjugate. */ + DerivedT&& conjugate() &&; #endif - /** Set the quaternion to its inverse. */ - DerivedT& inverse() __CML_REF; + /** Set the quaternion to its inverse. */ + DerivedT& inverse() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set a temporary to its inverse. */ - DerivedT&& inverse() &&; + /** Set a temporary to its inverse. */ + DerivedT&& inverse() &&; #endif - /** Set the quaternion to its natural logarithm. + /** Set the quaternion to its natural logarithm. * * @note It is up to the caller to ensure the quaternion has a usable * non-zero length. @@ -207,10 +196,10 @@ class writable_quaternion * @breaking In CML1, this function returns a temporary. Use cml::log() * as a replacement. */ - DerivedT& log() __CML_REF; + DerivedT& log() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set a temporary to its natural logarithm. + /** Set a temporary to its natural logarithm. * * @note It is up to the caller to ensure the quaternion has a usable * non-zero length. @@ -218,23 +207,23 @@ class writable_quaternion * @breaking In CML1, this function returns a temporary. Use cml::log() * as a replacement. */ - DerivedT&& log() &&; + DerivedT&& log() &&; #endif - /** Set the quaternion to its exponential. + /** Set the quaternion to its exponential. * * @breaking In CML1, this function returns a temporary. Use cml::exp() * as a replacement. */ - DerivedT& exp() __CML_REF; + DerivedT& exp() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set a temporary to its exponential. + /** Set a temporary to its exponential. * * @breaking In CML1, this function returns a temporary. Use cml::exp() * as a replacement. */ - DerivedT&& exp() &&; + DerivedT&& exp() &&; #endif @@ -245,203 +234,198 @@ class writable_quaternion */ DerivedT& random(const_reference low, const_reference high) __CML_REF; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS +# ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set elements of a temporary to random values in the range * @c[low,high]. */ DerivedT&& random(const_reference low, const_reference high) &&; -#endif +# endif #endif public: - - /** Assign from a readable_quaternion. */ - template DerivedT& - operator=(const readable_quaternion& other) __CML_REF; + /** Assign from a readable_quaternion. */ + template + DerivedT& operator=( + const readable_quaternion& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Assign a temporary from a readable_quaternion. */ - template DerivedT&& - operator=(const readable_quaternion& other) &&; + /** Assign a temporary from a readable_quaternion. */ + template + DerivedT&& operator=(const readable_quaternion& other) &&; #endif - /** Assign from a fixed-length array type. + /** Assign from a fixed-length array type. * * @throws incompatible_quaternion_size_error if @c * array_size_of_c::value != 4. */ - template* = nullptr> - DerivedT& operator=(const Array& array) __CML_REF; + template* = nullptr> + DerivedT& operator=(const Array& array) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Assign a temporary from a fixed-length array type. + /** Assign a temporary from a fixed-length array type. * * @throws incompatible_quaternion_size_error if @c * array_size_of_c::value != 4. */ - template* = nullptr> - DerivedT&& operator=(const Array& array) &&; + template* = nullptr> + DerivedT&& operator=(const Array& array) &&; #endif - /** Assign from initializer list. + /** Assign from initializer list. * * @throws incompatible_quaternion_size_error if if @c l.size() != 4. */ - template - DerivedT& operator=(std::initializer_list l) __CML_REF; + template + DerivedT& operator=(std::initializer_list l) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Assign a temporary from initializer list. + /** Assign a temporary from initializer list. * * @throws incompatible_quaternion_size_error if if @c l.size() != 4. */ - template - DerivedT&& operator=(std::initializer_list l) &&; + template DerivedT&& operator=(std::initializer_list l) &&; #endif - /** Modify the quaternion by addition of another quaternion. */ - template DerivedT& - operator+=(const readable_quaternion& other) __CML_REF; + /** Modify the quaternion by addition of another quaternion. */ + template + DerivedT& operator+=( + const readable_quaternion& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Modify a temporary quaternion by addition of another quaternion. */ - template DerivedT&& - operator+=(const readable_quaternion& other) &&; + /** Modify a temporary quaternion by addition of another quaternion. */ + template + DerivedT&& operator+=(const readable_quaternion& other) &&; #endif - /** Modify the quaternion by subtraction of another quaternion. */ - template DerivedT& - operator-=(const readable_quaternion& other) __CML_REF; + /** Modify the quaternion by subtraction of another quaternion. */ + template + DerivedT& operator-=( + const readable_quaternion& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Modify a temporary quaternion by subtraction of another quaternion. */ - template DerivedT&& - operator-=(const readable_quaternion& other) &&; + /** Modify a temporary quaternion by subtraction of another quaternion. */ + template + DerivedT&& operator-=(const readable_quaternion& other) &&; #endif - /** Modify the quaternion by multiplication of another quaternion. */ - template DerivedT& - operator*=(const readable_quaternion& other) __CML_REF; + /** Modify the quaternion by multiplication of another quaternion. */ + template + DerivedT& operator*=( + const readable_quaternion& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Modify a temporary quaternion by multiplication of another + /** Modify a temporary quaternion by multiplication of another * quaternion. */ - template DerivedT&& - operator*=(const readable_quaternion& other) &&; + template + DerivedT&& operator*=(const readable_quaternion& other) &&; #endif - /** Multiply the quaternion by a scalar convertible to its value_type. */ - template::type* = nullptr> - DerivedT& operator*=(const ScalarT& v) __CML_REF; + /** Multiply the quaternion by a scalar convertible to its value_type. */ + template::type* = nullptr> + DerivedT& operator*=(const ScalarT& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Multiply the temporary quaternion by a scalar convertible to its + /** Multiply the temporary quaternion by a scalar convertible to its * value_type. */ - template::type* = nullptr> - DerivedT&& operator*=(const ScalarT& v) &&; + template::type* = nullptr> + DerivedT&& operator*=(const ScalarT& v) &&; #endif - /** Divide the quaternion by a scalar convertible to its value_type. */ - template::type* = nullptr> - DerivedT& operator/=(const ScalarT& v) __CML_REF; + /** Divide the quaternion by a scalar convertible to its value_type. */ + template::type* = nullptr> + DerivedT& operator/=(const ScalarT& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Divide the quaternion temporary by a scalar convertible to its + /** Divide the quaternion temporary by a scalar convertible to its * value_type. */ - template::type* = nullptr> - DerivedT&& operator/=(const ScalarT& v) &&; + template::type* = nullptr> + DerivedT&& operator/=(const ScalarT& v) &&; #endif protected: - - /** Assign from a readable_quaternion. + /** Assign from a readable_quaternion. * * @note This depends upon implicit conversion of the source quaternion * elements to the quaternion value_type. */ - template - DerivedT& assign(const readable_quaternion& other); + template + DerivedT& assign(const readable_quaternion& other); - /** Assign from a readable_vector and a scalar. */ - template DerivedT& - assign(const readable_vector& other, const E0& e0); + /** Assign from a readable_vector and a scalar. */ + template + DerivedT& assign(const readable_vector& other, const E0& e0); - /** Construct from a fixed-length array of values. The assignment + /** Construct from a fixed-length array of values. The assignment * order is determined by the quaternion order. * * @note This depends upon implicit conversions of the elements to the * quaternion value_type. */ - template* = nullptr> - DerivedT& assign(const Array& array); + template* = nullptr> + DerivedT& assign(const Array& array); - /** Assign from a pointer to an array. + /** Assign from a pointer to an array. * * @note This depends upon implicit conversion of the array elements to * the quaternion value_type. */ - template* = nullptr> - DerivedT& assign(const Pointer& array); + template* = nullptr> + DerivedT& assign(const Pointer& array); - /** Construct from an array of 3 values and one additional element. + /** Construct from an array of 3 values and one additional element. * The assignment order is determined by the quaternion order. * * @note This depends upon implicit conversions of the elements to the * quaternion value_type. */ - template* = nullptr> - DerivedT& assign(const Array& array, const E0& e0); + template* = nullptr> + DerivedT& assign(const Array& array, const E0& e0); - /** Construct from an initializer_list. + /** Construct from an initializer_list. * * @note This depends upon implicit conversions of the elements to the * quaternion value_type. */ - template - DerivedT& assign(const std::initializer_list& l); + template DerivedT& assign(const std::initializer_list& l); - /** Construct from a list of 4 values. + /** Construct from a list of 4 values. * * @note This depends upon implicit conversions of the elements to the * quaternion value_type. */ - template DerivedT& - assign_elements(const E0& e0, const E1& e1, const E2& e2, const E3& e3); + template + DerivedT& assign_elements(const E0& e0, const E1& e1, const E2& e2, + const E3& e3); protected: + // Use the compiler-generated default constructor: + writable_quaternion() = default; - // Use the compiler-generated default constructor: - writable_quaternion() = default; - - // Use the compiler-generated copy constructor: - writable_quaternion(const writable_quaternion&) = default; + // Use the compiler-generated copy constructor: + writable_quaternion(const writable_quaternion&) = default; #ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR - // Use the compiler-generated move constructor: - writable_quaternion(writable_quaternion&&) = default; + // Use the compiler-generated move constructor: + writable_quaternion(writable_quaternion&&) = default; #endif - // Force assignment through operator=(readable_quaternion<>): - writable_quaternion& operator=(const writable_quaternion&) = delete; + // Force assignment through operator=(readable_quaternion<>): + writable_quaternion& operator=(const writable_quaternion&) = delete; }; -} // namespace cml +} // namespace cml #define __CML_QUATERNION_WRITABLE_QUATERNION_TPP #include #undef __CML_QUATERNION_WRITABLE_QUATERNION_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/quaternion/writable_quaternion.tpp b/cml/quaternion/writable_quaternion.tpp index 1ec27d2..3dc115c 100644 --- a/cml/quaternion/writable_quaternion.tpp +++ b/cml/quaternion/writable_quaternion.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_QUATERNION_WRITABLE_QUATERNION_TPP -#error "quaternion/writable_quaternion.tpp not included correctly" +# error "quaternion/writable_quaternion.tpp not included correctly" #endif #include @@ -17,96 +15,111 @@ namespace cml { /* Public methods: */ -template DT& +template +DT& writable_quaternion
::actual() { return (DT&) *this; } -template auto +template +auto writable_quaternion
::get(int i) -> mutable_value { return this->actual().i_get(i); } -template template DT& +template +template +DT& writable_quaternion
::put(int i, const Other& v) __CML_REF { - return this->actual().i_put(i,v); + return this->actual().i_put(i, v); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_quaternion
::put(int i, const Other& v) && { - this->put(i,v); + this->put(i, v); return (DT&&) *this; } #endif -template auto +template +auto writable_quaternion
::operator[](int i) -> mutable_value { return this->get(i); } -template auto +template +auto writable_quaternion
::w() -> mutable_value { return this->get(order_type::W); } -template auto +template +auto writable_quaternion
::x() -> mutable_value { return this->get(order_type::X); } -template auto +template +auto writable_quaternion
::y() -> mutable_value { return this->get(order_type::Y); } -template auto +template +auto writable_quaternion
::z() -> mutable_value { return this->get(order_type::Z); } - -template DT& +template +DT& writable_quaternion
::normalize() __CML_REF { return this->operator/=(this->length()); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_quaternion
::normalize() && { - this->normalize(); // Forward to normalize & + this->normalize(); // Forward to normalize & return (DT&&) *this; } #endif -template DT& +template +DT& writable_quaternion
::zero() __CML_REF { - for(int i = 0; i < 4; ++ i) this->put(i, value_type(0)); + for(int i = 0; i < 4; ++i) this->put(i, value_type(0)); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_quaternion
::zero() && { - this->zero(); // Forward to zero & + this->zero(); // Forward to zero & return (DT&&) *this; } #endif -template DT& +template +DT& writable_quaternion
::identity() __CML_REF { this->put(W, value_type(1)); @@ -117,61 +130,67 @@ writable_quaternion
::identity() __CML_REF } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_quaternion
::identity() && { - this->identity(); // Forward to identity & + this->identity(); // Forward to identity & return (DT&&) *this; } #endif -template DT& +template +DT& writable_quaternion
::conjugate() __CML_REF { - this->put(W, this->get(W)); - this->put(X, - this->get(X)); - this->put(Y, - this->get(Y)); - this->put(Z, - this->get(Z)); + this->put(W, this->get(W)); + this->put(X, -this->get(X)); + this->put(Y, -this->get(Y)); + this->put(Z, -this->get(Z)); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_quaternion
::conjugate() && { - this->conjugate(); // Forward to conjugate & + this->conjugate(); // Forward to conjugate & return (DT&&) *this; } #endif -template DT& +template +DT& writable_quaternion
::inverse() __CML_REF { /* Cayley norm (squared length). */ auto n = this->norm(); /* The inverse is conjugate() / norm(): */ - this->put(W, this->get(W) / n); - this->put(X, - this->get(X) / n); - this->put(Y, - this->get(Y) / n); - this->put(Z, - this->get(Z) / n); + this->put(W, this->get(W) / n); + this->put(X, -this->get(X) / n); + this->put(Y, -this->get(Y) / n); + this->put(Z, -this->get(Z) / n); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_quaternion
::inverse() && { - this->inverse(); // Forward to inverse & + this->inverse(); // Forward to inverse & return (DT&&) *this; } #endif -template DT& +template +DT& writable_quaternion
::log() __CML_REF { /* Shorthand: */ - typedef typename traits_type::element_traits element_traits; + using element_traits = typename traits_type::element_traits; /* The natural log of q is: * @@ -183,24 +202,26 @@ writable_quaternion
::log() __CML_REF auto v = this->imaginary(); auto lv = v.length(); auto c = element_traits::acos(this->real() / lq) / lv; - this->assign(c*v, element_traits::log(lq)); + this->assign(c * v, element_traits::log(lq)); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_quaternion
::log() && { - this->log(); // Forward to log & + this->log(); // Forward to log & return (DT&&) *this; } #endif -template DT& +template +DT& writable_quaternion
::exp() __CML_REF { /* Shorthand: */ - typedef typename traits_type::element_traits element_traits; + using element_traits = typename traits_type::element_traits; /* The exponential of q is: * @@ -212,15 +233,16 @@ writable_quaternion
::exp() __CML_REF auto lv = v.length(); auto x = element_traits::exp(this->real()); auto c = element_traits::sin(lv) / lv; - this->assign(x*c*v, x*element_traits::cos(lv)); + this->assign(x * c * v, x * element_traits::cos(lv)); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_quaternion
::exp() && { - this->exp(); // Forward to exp & + this->exp(); // Forward to exp & return (DT&&) *this; } #endif @@ -242,38 +264,32 @@ writable_quaternion
::random( return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS +# ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_quaternion
::random(const_reference low, const_reference high) && { this->random(low, high); return (DT&&) *this; } -#endif +# endif #endif template -template*> auto -writable_quaternion
::set( - const readable_vector& v, const E& s - ) __CML_REF --> enable_if_t< - are_convertible, E>::value, - DT& - > +template*> +auto +writable_quaternion
::set(const readable_vector& v, const E& s) + __CML_REF->enable_if_t< + are_convertible, E>::value, DT&> { return this->assign(v, s); } template -template*> auto -writable_quaternion
::set( - const E& s, const readable_vector& v - ) __CML_REF --> enable_if_t< - are_convertible, E>::value, - DT& - > +template*> +auto +writable_quaternion
::set(const E& s, const readable_vector& v) + __CML_REF->enable_if_t< + are_convertible, E>::value, DT&> { return this->assign(v, s); } @@ -281,28 +297,22 @@ writable_quaternion
::set( #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template*> auto -writable_quaternion
::set( - const readable_vector& v, const E& s - ) && --> enable_if_t< - are_convertible, E>::value, - DT&& - > +template*> +auto +writable_quaternion
:: + set(const readable_vector& v, const E& s) && -> enable_if_t< + are_convertible, E>::value, DT&&> { this->assign(v, s); return (DT&&) *this; } template -template*> auto -writable_quaternion
::set( - const E& s, const readable_vector& v - ) && --> enable_if_t< - are_convertible, E>::value, - DT&& - > +template*> +auto +writable_quaternion
:: + set(const E& s, const readable_vector& v) && -> enable_if_t< + are_convertible, E>::value, DT&&> { this->assign(v, s); return (DT&&) *this; @@ -310,16 +320,19 @@ writable_quaternion
::set( #endif -template template DT& +template +template +DT& writable_quaternion
::operator=( - const readable_quaternion& other - ) __CML_REF + const readable_quaternion& other) __CML_REF { return this->assign(other); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_quaternion
::operator=(const readable_quaternion& other) && { this->operator=(other); @@ -328,7 +341,8 @@ writable_quaternion
::operator=(const readable_quaternion& other) && #endif template -template*> DT& +template*> +DT& writable_quaternion
::operator=(const Array& array) __CML_REF { return this->assign(array); @@ -336,7 +350,8 @@ writable_quaternion
::operator=(const Array& array) __CML_REF #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template*> DT&& +template*> +DT&& writable_quaternion
::operator=(const Array& array) && { this->operator=(array); @@ -344,33 +359,40 @@ writable_quaternion
::operator=(const Array& array) && } #endif -template template DT& +template +template +DT& writable_quaternion
::operator=(std::initializer_list l) __CML_REF { return this->assign(l); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_quaternion
::operator=(std::initializer_list l) && { return this->assign(l); } #endif -template template DT& +template +template +DT& writable_quaternion
::operator+=( - const readable_quaternion& other - ) __CML_REF + const readable_quaternion& other) __CML_REF { - typedef binary_plus_t op_type; - for(int i = 0; i < 4; ++ i) + using op_type = binary_plus_t; + for(int i = 0; i < 4; ++i) this->put(i, op_type().apply(this->get(i), other.get(i))); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_quaternion
::operator+=(const readable_quaternion& other) && { this->operator+=(other); @@ -378,19 +400,22 @@ writable_quaternion
::operator+=(const readable_quaternion& other) && } #endif -template template DT& +template +template +DT& writable_quaternion
::operator-=( - const readable_quaternion& other - ) __CML_REF + const readable_quaternion& other) __CML_REF { - typedef binary_minus_t op_type; - for(int i = 0; i < 4; ++ i) + using op_type = binary_minus_t; + for(int i = 0; i < 4; ++i) this->put(i, op_type().apply(this->get(i), other.get(i))); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_quaternion
::operator-=(const readable_quaternion& other) && { this->operator-=(other); @@ -398,17 +423,20 @@ writable_quaternion
::operator-=(const readable_quaternion& other) && } #endif -template template DT& +template +template +DT& writable_quaternion
::operator*=( - const readable_quaternion& other - ) __CML_REF + const readable_quaternion& other) __CML_REF { return this->assign((*this) * other); /* Note: operator*() returns a temporary here. */ } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_quaternion
::operator*=(const readable_quaternion& other) && { this->operator*=(other); @@ -417,21 +445,22 @@ writable_quaternion
::operator*=(const readable_quaternion& other) && #endif template -template::value_type, ScalarT>::type*> +template::value_type, + ScalarT>::type*> DT& writable_quaternion
::operator*=(const ScalarT& v) __CML_REF { - typedef binary_multiply_t op_type; - for(int i = 0; i < 4; ++ i) - this->put(i, op_type().apply(this->get(i), v)); + using op_type = binary_multiply_t; + for(int i = 0; i < 4; ++i) this->put(i, op_type().apply(this->get(i), v)); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template::value_type, ScalarT>::type*> +template::value_type, + ScalarT>::type*> DT&& writable_quaternion
::operator*=(const ScalarT& v) && { @@ -441,21 +470,22 @@ writable_quaternion
::operator*=(const ScalarT& v) && #endif template -template::value_type, ScalarT>::type*> +template::value_type, + ScalarT>::type*> DT& writable_quaternion
::operator/=(const ScalarT& v) __CML_REF { - typedef binary_divide_t op_type; - for(int i = 0; i < 4; ++ i) - this->put(i, op_type().apply(this->get(i), v)); + using op_type = binary_divide_t; + for(int i = 0; i < 4; ++i) this->put(i, op_type().apply(this->get(i), v)); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template::value_type, ScalarT>::type*> +template::value_type, + ScalarT>::type*> DT&& writable_quaternion
::operator/=(const ScalarT& v) && { @@ -465,10 +495,11 @@ writable_quaternion
::operator/=(const ScalarT& v) && #endif - /* Internal methods: */ -template template DT& +template +template +DT& writable_quaternion
::assign(const readable_quaternion& other) { this->put(W, other.get(W)); @@ -478,10 +509,10 @@ writable_quaternion
::assign(const readable_quaternion& other) return this->actual(); } -template template DT& -writable_quaternion
::assign( - const readable_vector& other, const E0& e0 - ) +template +template +DT& +writable_quaternion
::assign(const readable_vector& other, const E0& e0) { cml::check_size(other, cml::int_c<3>()); this->put(W, e0); @@ -492,7 +523,8 @@ writable_quaternion
::assign( } template -template*> DT& +template*> +DT& writable_quaternion
::assign(const Array& array) { static const int N = array_size_of_c::value; @@ -505,7 +537,8 @@ writable_quaternion
::assign(const Array& array) } template -template*> DT& +template*> +DT& writable_quaternion
::assign(const Pointer& array) { this->put(W, array[W]); @@ -516,7 +549,8 @@ writable_quaternion
::assign(const Pointer& array) } template -template*> DT& +template*> +DT& writable_quaternion
::assign(const Array& array, const E0& e0) { static const int N = array_size_of_c::value; @@ -528,7 +562,9 @@ writable_quaternion
::assign(const Array& array, const E0& e0) return this->actual(); } -template template DT& +template +template +DT& writable_quaternion
::assign(const std::initializer_list& l) { #ifndef CML_NO_RUNTIME_QUATERNION_SIZE_CHECKS @@ -543,10 +579,10 @@ writable_quaternion
::assign(const std::initializer_list& l) } template -template DT& -writable_quaternion
::assign_elements( - const E0& e0, const E1& e1, const E2& e2, const E3& e3 - ) +template +DT& +writable_quaternion
::assign_elements(const E0& e0, const E1& e1, + const E2& e2, const E3& e3) { this->put(W, item_at(e0, e1, e2, e3)); this->put(X, item_at(e0, e1, e2, e3)); @@ -555,7 +591,4 @@ writable_quaternion
::assign_elements( return this->actual(); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/scalar/binary_ops.h b/cml/scalar/binary_ops.h index c881ace..d2a0c32 100644 --- a/cml/scalar/binary_ops.h +++ b/cml/scalar/binary_ops.h @@ -1,26 +1,24 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_scalar_binary_ops_h -#define cml_scalar_binary_ops_h - #include #include namespace cml { namespace op { -#define __cml_binary_op(_name_, _op_) \ -template struct _name_ { \ - typedef value_type_trait_promote_t result_type; \ - result_type apply(const Scalar1& a, const Scalar2& b) const { \ - return result_type(a _op_ b); } \ -} +#define __cml_binary_op(_name_, _op_) \ + template struct _name_ \ + { \ + typedef value_type_trait_promote_t result_type; \ + result_type apply(const Scalar1& a, const Scalar2& b) const \ + { \ + return result_type(a _op_ b); \ + } \ + } /** Binary minus (subtraction). */ __cml_binary_op(binary_minus, -); @@ -36,12 +34,11 @@ __cml_binary_op(binary_divide, /); #undef __cml_binary_op -} // namespace op +} // namespace op -#define __cml_binary_op_alias(_name_) \ -template \ - using _name_ ## _t = op:: _name_ < \ - value_type_trait_of_t>, \ +#define __cml_binary_op_alias(_name_) \ + template \ + using _name_##_t = op::_name_>, \ value_type_trait_of_t>> /** Convenience alias to create binary_minus from the value_type traits of @@ -65,9 +62,4 @@ __cml_binary_op_alias(binary_multiply); __cml_binary_op_alias(binary_divide); #undef __cml_binary_op_alias -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/scalar/constants.h b/cml/scalar/constants.h index 3b7c859..8df1470 100644 --- a/cml/scalar/constants.h +++ b/cml/scalar/constants.h @@ -1,26 +1,21 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_scalar_constants_h -#define cml_scalar_constants_h - #include #if !defined(M_PI) -#define M_PI 3.14159265358979323846 +# define M_PI 3.14159265358979323846 #endif #if !defined(M_SQRT2) -#define M_SQRT2 1.41421356237309504880 +# define M_SQRT2 1.41421356237309504880 #endif #if !defined(M_E) -#define M_E 2.71828182845904523536 +# define M_E 2.71828182845904523536 #endif namespace cml { @@ -29,28 +24,33 @@ namespace cml { * * Either float or double can be used. */ -template -struct constants { - static inline Float pi() { return Float(M_PI); } - static inline Float two_pi() { return Float(2.*M_PI); } - static inline Float inv_pi() { return Float(1./M_PI); } - static inline Float inv_two_pi() { return Float(1./(2.*M_PI)); } - static inline Float pi_over_2() { return Float(M_PI/2.); } - static inline Float pi_over_4() { return Float(M_PI/4.); } - static inline Float e() { return Float(M_E); } - - static inline Float deg_per_rad() { return Float(180./M_PI); } - static inline Float rad_per_deg() { return Float(M_PI/180.); } - - static inline Float sqrt_2() { return Float(M_SQRT2); } - static inline Float sqrt_3() { return Float(1.73205080756887729353); } - static inline Float sqrt_5() { return Float(2.23606797749978969641); } - static inline Float sqrt_6() { return Float(2.44948974278317809820); } -}; +template struct constants +{ + static inline Float pi() { return Float(M_PI); } -} // namespace cml + static inline Float two_pi() { return Float(2. * M_PI); } -#endif + static inline Float inv_pi() { return Float(1. / M_PI); } + + static inline Float inv_two_pi() { return Float(1. / (2. * M_PI)); } + + static inline Float pi_over_2() { return Float(M_PI / 2.); } + + static inline Float pi_over_4() { return Float(M_PI / 4.); } + + static inline Float e() { return Float(M_E); } + + static inline Float deg_per_rad() { return Float(180. / M_PI); } + + static inline Float rad_per_deg() { return Float(M_PI / 180.); } + + static inline Float sqrt_2() { return Float(M_SQRT2); } + + static inline Float sqrt_3() { return Float(1.73205080756887729353); } + + static inline Float sqrt_5() { return Float(2.23606797749978969641); } + + static inline Float sqrt_6() { return Float(2.44948974278317809820); } +}; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/scalar/functions.h b/cml/scalar/functions.h index 5ed70ab..f701b73 100644 --- a/cml/scalar/functions.h +++ b/cml/scalar/functions.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_scalar_functions_h -#define cml_scalar_functions_h - #include #include #include @@ -17,117 +12,185 @@ namespace cml { /** Sign (-1, 0, 1) of @c value as type @c T. */ -template inline T sign(T value) { +template +inline T +sign(T value) +{ return value < T(0) ? (-T(1)) : (value > T(0) ? T(1) : T(0)); } /** Clamp input value to the range [min, max]. */ -template inline T clamp(T value, T min, T max) { - return std::max((std::min) (value, max), min); +template +inline T +clamp(T value, T min, T max) +{ + return std::max((std::min)(value, max), min); } /** Wrap input value to the range [min,max]. */ -template inline T wrap(T value, T min, T max) { +template +inline T +wrap(T value, T min, T max) +{ max -= min; value = scalar_traits::fmod(value - min, max); - if (value < T(0)) { value += max; } + if(value < T(0)) { + value += max; + } return min + value; } /** Test input value for inclusion in [min, max]. */ -template inline bool in_range(T value, T min, T max) { +template +inline bool +in_range(T value, T min, T max) +{ return !(value < min) && !(value > max); } /** Map input value from [min1, max1] to [min2, max2]. */ -template inline T map_range( - T value, T min1, T max1, T min2, T max2 - ) +template +inline T +map_range(T value, T min1, T max1, T min2, T max2) { return min2 + ((value - min1) / (max1 - min1)) * (max2 - min2); } /** Wrap scalar_traits::acos() and clamp argument to [-1, 1]. */ -template inline T acos_safe(T theta) { +template +inline T +acos_safe(T theta) +{ return T(scalar_traits::acos(clamp(theta, T(-1), T(1)))); } /** Wrap scalar_traits::asin() and clamp argument to [-1, 1]. */ -template inline T asin_safe(T theta) { +template +inline T +asin_safe(T theta) +{ return T(scalar_traits::asin(clamp(theta, T(-1), T(1)))); } /** Wrap scalar_traits::sqrt() and clamp argument to [0, inf). */ -template inline T sqrt_safe(T value) { +template +inline T +sqrt_safe(T value) +{ return T(scalar_traits::sqrt(std::max(value, T(0)))); } - /** Square a value. */ -template inline T sqr(T value) { return value * value; } +template +inline T +sqr(T value) +{ + return value * value; +} /** Cube a value. */ -template inline T cub(T value) { return value * value * value; } +template +inline T +cub(T value) +{ + return value * value * value; +} /** Inverse square root. */ -template inline T inv_sqrt(T value) { +template +inline T +inv_sqrt(T value) +{ return T(1) / scalar_traits::sqrt(value); } - /** Convert radians to degrees. */ -template inline T deg(T theta) { +template +inline T +deg(T theta) +{ return theta * constants::deg_per_rad(); } /** Convert degrees to radians. */ -template inline T rad(T theta) { +template +inline T +rad(T theta) +{ return theta * constants::rad_per_deg(); } - /** Uniformly random integer in the range [min, max]. */ -template inline T random_integer(T min, T max) { +template +inline T +random_integer(T min, T max) +{ std::default_random_engine gen(std::rand()); - std::uniform_int_distribution dis(min,max); + std::uniform_int_distribution dis(min, max); return dis(gen); } /** Uniformly random binary (0,1) value. */ -inline int random_binary() { return random_integer(0,1); } +inline int +random_binary() +{ + return random_integer(0, 1); +} /** Uniformly random polar (-1,1) value. */ -inline int random_polar() { return random_binary() ? 1 : -1; } +inline int +random_polar() +{ + return random_binary() ? 1 : -1; +} /* Uniformly distributed random real number in the range [min, max] */ -template inline T random_real(T min, T max) { +template +inline T +random_real(T min, T max) +{ std::default_random_engine gen(std::rand()); - std::uniform_real_distribution dis(min,max); + std::uniform_real_distribution dis(min, max); return dis(gen); } /** Uniformly distributed random real in [0,1]. */ -inline double random_unit() { return random_real(0., 1.); } - +inline double +random_unit() +{ + return random_real(0., 1.); +} /** Squared length in R2. */ -template inline T length_squared(T x, T y) { +template +inline T +length_squared(T x, T y) +{ return x * x + y * y; } /** Squared length in R3. */ -template inline T length_squared(T x, T y, T z) { +template +inline T +length_squared(T x, T y, T z) +{ return x * x + y * y + z * z; } /** Length in R2. */ -template inline T length(T x, T y) { - return scalar_traits::sqrt(length_squared(x,y)); +template +inline T +length(T x, T y) +{ + return scalar_traits::sqrt(length_squared(x, y)); } /** Length in R3. */ -template inline T length(T x, T y, T z) { - return scalar_traits::sqrt(length_squared(x,y,z)); +template +inline T +length(T x, T y, T z) +{ + return scalar_traits::sqrt(length_squared(x, y, z)); } /** @defgroup cml_scalar_indexing Indexing Functions @@ -142,23 +205,30 @@ template inline T length(T x, T y, T z) { /*@{*/ /** Return next, with cycling, in a series of N non-negative integers. */ -inline int next(int i, int N) { +inline int +next(int i, int N) +{ return (i + 1) % N; } /** Return previous, with cycling, in a series of N non-negative integers. */ -inline int prev(int i, int N) { +inline int +prev(int i, int N) +{ return i ? (i - 1) : (N - 1); } /** Cyclic permutation of the set { 0, 1 }, starting with 'first'. */ -inline void cyclic_permutation(int first, int& i, int& j) { +inline void +cyclic_permutation(int first, int& i, int& j) +{ i = first; j = next(i, 2); } /** Cyclic permutation of the set { 0, 1, 2 }, starting with 'first'. */ -inline void cyclic_permutation(int first, int& i, int& j, int& k) +inline void +cyclic_permutation(int first, int& i, int& j, int& k) { i = first; j = next(i, 3); @@ -166,8 +236,8 @@ inline void cyclic_permutation(int first, int& i, int& j, int& k) } /** Cyclic permutation of the set { 0, 1, 2, 3 }, starting with 'first'. */ -inline void cyclic_permutation( - int first, int& i, int& j, int& k, int& l) +inline void +cyclic_permutation(int first, int& i, int& j, int& k, int& l) { i = first; j = next(i, 4); @@ -179,51 +249,78 @@ inline void cyclic_permutation( /** Index of maximum of 2 values. */ -template inline int index_of_max(T a, T b) { +template +inline int +index_of_max(T a, T b) +{ return a > b ? 0 : 1; } /** Index of maximum of 2 values by magnitude. */ -template inline int index_of_max_abs(T a, T b) { +template +inline int +index_of_max_abs(T a, T b) +{ auto fabs = &scalar_traits::fabs; return index_of_max(fabs(a), fabs(b)); } /** Index of minimum of 2 values. */ -template inline int index_of_min(T a, T b) { +template +inline int +index_of_min(T a, T b) +{ return a < b ? 0 : 1; } /** Index of minimum of 2 values by magnitude. */ -template inline int index_of_min_abs(T a, T b) { +template +inline int +index_of_min_abs(T a, T b) +{ auto fabs = &scalar_traits::fabs; return index_of_min(fabs(a), fabs(b)); } /** Index of maximum of 3 values. */ -template inline int index_of_max(T a, T b, T c) { +template +inline int +index_of_max(T a, T b, T c) +{ return a > b ? (c > a ? 2 : 0) : (b > c ? 1 : 2); } /** Index of maximum of 3 values by magnitude. */ -template inline int index_of_max_abs(T a, T b, T c) { +template +inline int +index_of_max_abs(T a, T b, T c) +{ auto fabs = &scalar_traits::fabs; return index_of_max(fabs(a), fabs(b), fabs(c)); } /** Index of minimum of 3 values. */ -template inline int index_of_min(T a, T b, T c) { +template +inline int +index_of_min(T a, T b, T c) +{ return a < b ? (c < a ? 2 : 0) : (b < c ? 1 : 2); } /** Index of minimum of 3 values by magnitude. */ -template inline int index_of_min_abs(T a, T b, T c) { +template +inline int +index_of_min_abs(T a, T b, T c) +{ auto fabs = &scalar_traits::fabs; return index_of_min(fabs(a), fabs(b), fabs(c)); } /** Index of maximum of 4 values. */ -template inline int index_of_max(T a, T b, T c, T d) { +template +inline int +index_of_max(T a, T b, T c, T d) +{ if(a > b) { return (c > d) ? ((a > c) ? 0 : 2) : ((a > d) ? 0 : 3); } else { @@ -232,13 +329,19 @@ template inline int index_of_max(T a, T b, T c, T d) { } /** Index of maximum of 4 values by magnitude. */ -template inline int index_of_max_abs(T a, T b, T c, T d) { +template +inline int +index_of_max_abs(T a, T b, T c, T d) +{ auto fabs = &scalar_traits::fabs; return index_of_max(fabs(a), fabs(b), fabs(c), fabs(d)); } /** Index of minimum of 3 values. */ -template inline int index_of_min(T a, T b, T c, T d) { +template +inline int +index_of_min(T a, T b, T c, T d) +{ if(a < b) { return (c < d) ? ((a < c) ? 0 : 2) : ((a < d) ? 0 : 3); } else { @@ -247,14 +350,12 @@ template inline int index_of_min(T a, T b, T c, T d) { } /** Index of minimum of 4 values by magnitude. */ -template inline int index_of_min_abs(T a, T b, T c, T d) { +template +inline int +index_of_min_abs(T a, T b, T c, T d) +{ auto fabs = &scalar_traits::fabs; return index_of_min(fabs(a), fabs(b), fabs(c), fabs(d)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/scalar/promotion.h b/cml/scalar/promotion.h index 5baa789..c73a05b 100644 --- a/cml/scalar/promotion.h +++ b/cml/scalar/promotion.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_scalar_promotion_h -#define cml_scalar_promotion_h - #include #include @@ -17,45 +12,42 @@ namespace cml { /** Use C++ type deduction via std::common_type to determine the result of * combining N scalars. */ -template using - scalar_promote = std::common_type; +template using scalar_promote = std::common_type; /** Use C++ type deduction via std::common_type to determine the result of * combining N scalars. */ -template using scalar_promote_t - = typename scalar_promote::type; +template +using scalar_promote_t = typename scalar_promote::type; /** Helper to simplify scalar promotion from objects with a value_type * typedef. */ -template struct value_type_promote { - typedef typename scalar_promote...>::type type; +template struct value_type_promote +{ + using type = typename scalar_promote...>::type; }; // XXX This could be a template alias, except VC++12 can't grok it. // Moreover, without value_type_of_t, even this fails to compile... /** Convenience alias for value_type_trait_promote<>::type. */ -template using value_type_promote_t - = typename value_type_promote::type; +template +using value_type_promote_t = typename value_type_promote::type; /** Helper to simplify scalar promotion from objects that implement a * traits class with a value_type typedef. */ -template struct value_type_trait_promote { - typedef typename scalar_promote...>::type type; +template struct value_type_trait_promote +{ + using type = typename scalar_promote...>::type; }; // XXX This could be a template alias, except VC++12 can't grok it. // Moreover, without value_type_trait_of_t, even this fails to // compile... /** Convenience alias for value_type_trait_promote<>::type. */ -template using value_type_trait_promote_t - = typename value_type_trait_promote::type; - -} // namespace cml - -#endif +template +using value_type_trait_promote_t = + typename value_type_trait_promote::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/scalar/traits.h b/cml/scalar/traits.h index c301743..0df0d26 100644 --- a/cml/scalar/traits.h +++ b/cml/scalar/traits.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_scalar_traits_h -#define cml_scalar_traits_h - #include #include #include @@ -28,65 +23,77 @@ namespace detail { * * @note default_integral_traits inherits from std::numeric_limits by default. */ -template struct default_integral_traits -: std::numeric_limits +template +struct default_integral_traits : std::numeric_limits { - typedef Scalar value_type; - typedef value_type* pointer; - typedef value_type& reference; - typedef value_type const* const_pointer; - typedef value_type const& const_reference; - typedef reference& mutable_value; - typedef const_reference immutable_value; + using value_type = Scalar; + using pointer = value_type*; + using reference = value_type&; + using const_pointer = value_type const*; + using const_reference = value_type const&; + using mutable_value = reference&; + using immutable_value = const_reference; /** @name Basic Functions */ /*@{*/ - static inline value_type fabs(const value_type& v) { + static inline value_type fabs(const value_type& v) + { return (value_type) std::fabs(double(v)); } - static inline value_type fmod(const value_type& v, const value_type& w) { + static inline value_type fmod(const value_type& v, const value_type& w) + { return (value_type) std::fmod(double(v), double(w)); } - static constexpr value_type sqrt(const value_type& v) { + static constexpr value_type sqrt(const value_type& v) + { return (value_type) std::sqrt(double(v)); } - static inline value_type cos(const value_type& v) { + static inline value_type cos(const value_type& v) + { return (value_type) std::cos(double(v)); } - static inline value_type sin(const value_type& v) { + static inline value_type sin(const value_type& v) + { return (value_type) std::sin(double(v)); } - static inline value_type tan(const value_type& v) { + static inline value_type tan(const value_type& v) + { return (value_type) std::tan(double(v)); } - static inline value_type acos(const value_type& v) { + static inline value_type acos(const value_type& v) + { return (value_type) std::acos(double(v)); } - static inline value_type asin(const value_type& v) { + static inline value_type asin(const value_type& v) + { return (value_type) std::asin(double(v)); } - static inline value_type atan(const value_type& v) { + static inline value_type atan(const value_type& v) + { return (value_type) std::atan(double(v)); } - static inline value_type atan2(const value_type& x, const value_type& y) { - return (value_type) std::atan2(double(x),double(y)); + static inline value_type atan2(const value_type& x, const value_type& y) + { + return (value_type) std::atan2(double(x), double(y)); } - static inline value_type log(const value_type& v) { + static inline value_type log(const value_type& v) + { return (value_type) std::log(double(v)); } - static inline value_type exp(const value_type& v) { + static inline value_type exp(const value_type& v) + { return (value_type) std::exp(double(v)); } @@ -99,80 +106,63 @@ template struct default_integral_traits * * @note default_scalar_traits inherits from std::numeric_limits by default. */ -template struct default_floating_point_traits -: std::numeric_limits +template +struct default_floating_point_traits : std::numeric_limits { - typedef Scalar value_type; - typedef value_type* pointer; - typedef value_type& reference; - typedef value_type const* const_pointer; - typedef value_type const& const_reference; - typedef reference& mutable_value; - typedef const_reference immutable_value; + using value_type = Scalar; + using pointer = value_type*; + using reference = value_type&; + using const_pointer = value_type const*; + using const_reference = value_type const&; + using mutable_value = reference&; + using immutable_value = const_reference; /** @name Basic Functions */ /*@{*/ - static inline value_type fabs(const value_type& v) { - return std::fabs(v); - } + static inline value_type fabs(const value_type& v) { return std::fabs(v); } - static inline value_type fmod(const value_type& v, const value_type& w) { + static inline value_type fmod(const value_type& v, const value_type& w) + { return std::fmod(v, w); } - static constexpr value_type sqrt(const value_type& v) { - return std::sqrt(v); - } + static constexpr value_type sqrt(const value_type& v) { return std::sqrt(v); } - static inline value_type cos(const value_type& v) { - return std::cos(v); - } + static inline value_type cos(const value_type& v) { return std::cos(v); } - static inline value_type sin(const value_type& v) { - return std::sin(v); - } + static inline value_type sin(const value_type& v) { return std::sin(v); } - static inline value_type tan(const value_type& v) { - return std::tan(v); - } + static inline value_type tan(const value_type& v) { return std::tan(v); } - static inline value_type acos(const value_type& v) { - return std::acos(v); - } + static inline value_type acos(const value_type& v) { return std::acos(v); } - static inline value_type asin(const value_type& v) { - return std::asin(v); - } + static inline value_type asin(const value_type& v) { return std::asin(v); } - static inline value_type atan(const value_type& v) { - return std::atan(v); - } + static inline value_type atan(const value_type& v) { return std::atan(v); } - static inline value_type atan2(const value_type& x, const value_type& y) { - return std::atan2(x,y); + static inline value_type atan2(const value_type& x, const value_type& y) + { + return std::atan2(x, y); } - static inline value_type log(const value_type& v) { - return std::log(v); - } + static inline value_type log(const value_type& v) { return std::log(v); } - static inline value_type exp(const value_type& v) { - return std::exp(v); - } + static inline value_type exp(const value_type& v) { return std::exp(v); } /*@}*/ }; -} // namespace detail +} // namespace detail /** Specializable class aggregating scalar properties. */ template struct scalar_traits; /** Specialization of scalar traits for integral types. */ -template struct scalar_traits< -Scalar, typename std::enable_if::value>::type> +template +struct scalar_traits::value>::type> : detail::default_integral_traits { /** Returns 0. */ @@ -180,62 +170,68 @@ Scalar, typename std::enable_if::value>::type> }; /** Specialization of scalar_traits for floating-point types. */ -template struct scalar_traits< -Scalar, typename std::enable_if::value>::type> +template +struct scalar_traits::value>::type> : detail::default_floating_point_traits { /** Returns sqrt(numeric_limits::epsilon()). */ - static constexpr double sqrt_epsilon() { + static constexpr double sqrt_epsilon() + { return detail::default_floating_point_traits::sqrt( std::numeric_limits::epsilon()); } }; /** Specialization of scalar_traits for float. */ -template<> struct scalar_traits -: detail::default_floating_point_traits +template<> +struct scalar_traits : detail::default_floating_point_traits { /** Returns a constant for sqrt(numeric_limits::epsilon()). */ - static constexpr float sqrt_epsilon() { - return 3.452669831e-4f; // 10 digits + static constexpr float sqrt_epsilon() + { + return 3.452669831e-4f; // 10 digits } }; /** Specialization of scalar_traits for double. */ -template<> struct scalar_traits -: detail::default_floating_point_traits +template<> +struct scalar_traits : detail::default_floating_point_traits { /** Returns a constant for sqrt(numeric_limits::epsilon()). */ - static constexpr double sqrt_epsilon() { - return 1.49011611938476563e-8; // 18 digits + static constexpr double sqrt_epsilon() + { + return 1.49011611938476563e-8; // 18 digits } }; /** Returns eps for type S. */ -template constexpr S epsilon() { +template +constexpr S +epsilon() +{ return scalar_traits::epsilon(); } /** Returns sqrt(eps) for type S. */ -template constexpr S sqrt_epsilon() { +template +constexpr S +sqrt_epsilon() +{ return scalar_traits::sqrt_epsilon(); } /** traits_of for arithmetic scalars. */ -template struct traits_of> { - typedef scalar_traits type; +template struct traits_of> +{ + using type = scalar_traits; }; /** temporary_of for arithmetic scalars. */ -template struct temporary_of< -Scalar, cml::enable_if_arithmetic_t> +template +struct temporary_of> { - typedef cml::value_type_trait_of_t type; + using type = cml::value_type_trait_of_t; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/scalar/unary_ops.h b/cml/scalar/unary_ops.h index 2b95936..fbdbc0d 100644 --- a/cml/scalar/unary_ops.h +++ b/cml/scalar/unary_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_scalar_unary_ops_h -#define cml_scalar_unary_ops_h - #include #include @@ -16,36 +11,37 @@ namespace cml { namespace op { /** Unary minus (negation). */ -template struct unary_minus { - typedef value_type_trait_of_t value_type; - typedef decltype(- value_type()) result_type; - result_type apply(const value_type& v) const { return - v; } +template struct unary_minus +{ + using value_type = value_type_trait_of_t; + using result_type = decltype(-value_type()); + + result_type apply(const value_type& v) const { return -v; } }; /** Unary plus. */ -template struct unary_plus { - typedef value_type_trait_of_t value_type; - typedef decltype(+ value_type()) result_type; - result_type apply(const value_type& v) const { return + v; } +template struct unary_plus +{ + using value_type = value_type_trait_of_t; + using result_type = decltype(+value_type()); + + result_type apply(const value_type& v) const { return +v; } }; -} // namespace op +} // namespace op /** Convenience alias to create unary_minus from the value_type trait of * @c Sub as an unqualified type. */ -template using unary_minus_t - = op::unary_minus>>; +template +using unary_minus_t = + op::unary_minus>>; /** Convenience alias to create unary_plus from the value_type trait of * @c Sub as an unqualified type. */ -template using unary_plus_t - = op::unary_plus>>; - -} // namespace cml - -#endif +template +using unary_plus_t = + op::unary_plus>>; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/storage/allocated_selector.h b/cml/storage/allocated_selector.h index 0c147be..97f028e 100644 --- a/cml/storage/allocated_selector.h +++ b/cml/storage/allocated_selector.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_storage_allocated_selector_h -#define cml_storage_allocated_selector_h - #include #include #include @@ -22,8 +17,9 @@ namespace cml { /* Forward declarations: */ -template, - int Size1 = -1, int Size2 = -1, class Tag = void> struct allocated; +template, int Size1 = -1, + int Size2 = -1, class Tag = void> +struct allocated; /** Base selector to choose dynamically-allocated types (types with runtime * storage and either fixed or dynamic size). @@ -43,18 +39,21 @@ template struct allocated { /** Rebind the base selector to the required type. */ - template struct rebind { - typedef allocated other; + template struct rebind + { + using other = allocated; }; /** Make a partially bound selector with size @c N. */ - template struct resize { - typedef allocated type; + template struct resize + { + using type = allocated; }; /** Make a partially bound selector with size @c R x @c C. */ - template struct reshape { - typedef allocated type; + template struct reshape + { + using type = allocated; }; }; @@ -62,19 +61,20 @@ struct allocated template struct allocated { - typedef allocated<> selector_type; - typedef allocated unbound_type; - typedef allocated proxy_type; - typedef vector_storage_tag storage_tag; - typedef dynamic_size_tag size_tag; - typedef allocated_memory_tag memory_tag; + using selector_type = allocated<>; + using unbound_type = allocated; + using proxy_type = allocated; + using storage_tag = vector_storage_tag; + using size_tag = dynamic_size_tag; + using memory_tag = allocated_memory_tag; /** Unspecified array size. */ static const int array_size = -1; /** Make a partially bound selector with size @c N. */ - template struct resize { - typedef allocated type; + template struct resize + { + using type = allocated; }; }; @@ -86,20 +86,21 @@ struct allocated template struct allocated { - typedef allocated<> selector_type; - typedef allocated unbound_type; + using selector_type = allocated<>; + using unbound_type = allocated; //XXX typedef allocated proxy_type; - typedef compiled proxy_type; - typedef vector_storage_tag storage_tag; - typedef fixed_size_tag size_tag; - typedef allocated_memory_tag memory_tag; + using proxy_type = compiled; + using storage_tag = vector_storage_tag; + using size_tag = fixed_size_tag; + using memory_tag = allocated_memory_tag; /** Constant for the array size. */ static const int array_size = Size; /** Make a partially bound selector with size @c N. */ - template struct resize { - typedef allocated type; + template struct resize + { + using type = allocated; }; }; @@ -107,12 +108,12 @@ struct allocated template struct allocated { - typedef allocated<> selector_type; - typedef allocated unbound_type; - typedef allocated proxy_type; - typedef matrix_storage_tag storage_tag; - typedef dynamic_size_tag size_tag; - typedef allocated_memory_tag memory_tag; + using selector_type = allocated<>; + using unbound_type = allocated; + using proxy_type = allocated; + using storage_tag = matrix_storage_tag; + using size_tag = dynamic_size_tag; + using memory_tag = allocated_memory_tag; /** Unspecified array rows. */ static const int array_rows = -1; @@ -121,8 +122,9 @@ struct allocated static const int array_cols = -1; /** Make a partially bound selector with size @c R x @c C. */ - template struct reshape { - typedef allocated type; + template struct reshape + { + using type = allocated; }; }; @@ -134,13 +136,13 @@ struct allocated template struct allocated { - typedef allocated<> selector_type; - typedef allocated unbound_type; + using selector_type = allocated<>; + using unbound_type = allocated; //XXX typedef allocated proxy_type; - typedef compiled proxy_type; - typedef matrix_storage_tag storage_tag; - typedef fixed_size_tag size_tag; - typedef allocated_memory_tag memory_tag; + using proxy_type = compiled; + using storage_tag = matrix_storage_tag; + using size_tag = fixed_size_tag; + using memory_tag = allocated_memory_tag; /** Constant for the number of array rows. */ static const int array_rows = Size1; @@ -149,8 +151,9 @@ struct allocated static const int array_cols = Size2; /** Make a partially bound selector with size @c R x @c C. */ - template struct resize { - typedef allocated type; + template struct resize + { + using type = allocated; }; }; @@ -162,27 +165,29 @@ struct allocated template struct allocated { - typedef allocated<> selector_type; - typedef allocated unbound_type; + using selector_type = allocated<>; + using unbound_type = allocated; //XXX typedef allocated proxy_type; - typedef compiled<4> proxy_type; - typedef quaternion_storage_tag storage_tag; - typedef fixed_size_tag size_tag; - typedef allocated_memory_tag memory_tag; + using proxy_type = compiled<4>; + using storage_tag = quaternion_storage_tag; + using size_tag = fixed_size_tag; + using memory_tag = allocated_memory_tag; /** Constant for the array size. */ static const int array_size = 4; /** Make a partially bound selector with size @c N. */ - template struct resize { + template struct resize + { static_assert(N == 4, "invalid quaternion storage size"); - typedef allocated type; + using type = allocated; }; }; /** is_storage_selector for allocated<>. */ template -struct is_storage_selector> { +struct is_storage_selector> +{ static const bool value = true; }; @@ -193,63 +198,50 @@ struct is_storage_selector> { * @note This can be specialized for user-defined allocators if the default * disambiguation strategy fails to yield the proper type. */ -template< - class Allocator1, int R1, int C1, class Tag1, - class Allocator2, int R2, int C2, class Tag2> -struct storage_disambiguate< - allocated, +template +struct storage_disambiguate, allocated> { /* Rebind the allocators to void* to compare them: */ - typedef std::allocator_traits left_traits; - typedef std::allocator_traits right_traits; - typedef typename left_traits::template rebind_alloc left_type; - typedef typename right_traits::template rebind_alloc right_type; + using left_traits = std::allocator_traits; + using right_traits = std::allocator_traits; + using left_type = typename left_traits::template rebind_alloc; + using right_type = typename right_traits::template rebind_alloc; /* True if the unbound allocators are the same: */ - static const bool is_same - = std::is_same::value; + static const bool is_same = std::is_same::value; /* True if the left and/or right allocators are the default: */ - static const bool left_is_default - = std::is_same>::value; - static const bool right_is_default - = std::is_same>::value; + static const bool left_is_default = + std::is_same>::value; + static const bool right_is_default = + std::is_same>::value; /* Prefer the left allocator if it is not the default allocator: */ - static const bool prefer_left - = !left_is_default && right_is_default; + static const bool prefer_left = !left_is_default && right_is_default; /* Prefer the right allocator if it is not the default allocator: */ - static const bool prefer_right - = !right_is_default && left_is_default; + static const bool prefer_right = !right_is_default && left_is_default; /* Use std::allocator<> if the best cannot be determined: */ - static const bool prefer_default - = !(is_same || prefer_left || prefer_right); + static const bool prefer_default = !(is_same || prefer_left || prefer_right); static_assert(is_same || prefer_left || prefer_right || prefer_default, "unexpected storage_disambiguate result"); /* Determine the preferred allocator type: */ - typedef - cml::if_t - >>> allocator_type; + using allocator_type = cml::if_t>>>; /* Build the disambiguated unbound storage type: */ - typedef allocated type; + using type = allocated; }; /** For compatibility with CML1. */ template> - using dynamic = allocated; - -} // namespace cml - -#endif +using dynamic = allocated; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/storage/any_selector.h b/cml/storage/any_selector.h index 52b3bb7..0afb727 100644 --- a/cml/storage/any_selector.h +++ b/cml/storage/any_selector.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_storage_any_selector_h -#define cml_storage_any_selector_h - #include #include #include @@ -22,36 +17,40 @@ namespace cml { * vector_storage_tag). This is set by instantiating @c rebind with the * required tag. */ -template struct any_storage { - +template struct any_storage +{ /** Rebind the base selector to the required type. */ - template struct rebind { - typedef any_storage other; + template struct rebind + { + using other = any_storage; }; /** Make a partially bound selector by resizing. The new size is ignored * for any_storage<>. */ - template struct resize { - typedef any_storage<> type; + template struct resize + { + using type = any_storage<>; }; /** Make a partially bound selector by reshaping. The new shape is ignored * for any_storage<>. */ - template struct reshape { - typedef any_storage<> type; + template struct reshape + { + using type = any_storage<>; }; }; /** Specialized selector for any vector storage. */ -template<> struct any_storage { - typedef any_storage<> selector_type; - typedef any_storage<> unbound_type; - typedef any_storage<> proxy_type; - typedef vector_storage_tag storage_tag; - typedef any_size_tag size_tag; - typedef any_memory_tag memory_tag; +template<> struct any_storage +{ + using selector_type = any_storage<>; + using unbound_type = any_storage<>; + using proxy_type = any_storage<>; + using storage_tag = vector_storage_tag; + using size_tag = any_size_tag; + using memory_tag = any_memory_tag; /** Unspecified array size. */ static const int array_size = -1; @@ -59,19 +58,21 @@ template<> struct any_storage { /** Rebind to a new vector any_storage<> selector (the template parameter * is ignored). */ - template struct resize { - typedef any_storage<> type; + template struct resize + { + using type = any_storage<>; }; }; /** Specialized selector for any matrix storage. */ -template<> struct any_storage { - typedef any_storage<> selector_type; - typedef any_storage<> unbound_type; - typedef any_storage<> proxy_type; - typedef matrix_storage_tag storage_tag; - typedef any_size_tag size_tag; - typedef any_memory_tag memory_tag; +template<> struct any_storage +{ + using selector_type = any_storage<>; + using unbound_type = any_storage<>; + using proxy_type = any_storage<>; + using storage_tag = matrix_storage_tag; + using size_tag = any_size_tag; + using memory_tag = any_memory_tag; /** Unspecified number of array rows. */ static const int array_rows = -1; @@ -82,19 +83,21 @@ template<> struct any_storage { /** Rebind to a new matrix any_storage<> selector (the template * parameters are ignored). */ - template struct reshape { - typedef any_storage<> type; + template struct reshape + { + using type = any_storage<>; }; }; /** Specialized selector for any quaternion storage. */ -template<> struct any_storage { - typedef any_storage<> selector_type; - typedef any_storage<> unbound_type; - typedef any_storage<> proxy_type; - typedef quaternion_storage_tag storage_tag; - typedef any_size_tag size_tag; - typedef any_memory_tag memory_tag; +template<> struct any_storage +{ + using selector_type = any_storage<>; + using unbound_type = any_storage<>; + using proxy_type = any_storage<>; + using storage_tag = quaternion_storage_tag; + using size_tag = any_size_tag; + using memory_tag = any_memory_tag; /** Unspecified array size. */ static const int array_size = -1; @@ -102,34 +105,30 @@ template<> struct any_storage { /** Rebind to a new vector any_storage<> selector (the template parameter * is ignored). */ - template struct resize { - typedef any_storage<> type; + template struct resize + { + using type = any_storage<>; }; }; /** is_storage_selector for any_storage<>. */ -template -struct is_storage_selector> { +template struct is_storage_selector> +{ static const bool value = true; }; /** Helper to detect any_storage<> types. */ -template -struct is_any_storage { - static const bool value - = std::is_same>::value; +template struct is_any_storage +{ + static const bool value = + std::is_same>::value; }; /** Helper to disambiguate any_storage<> types. */ template struct storage_disambiguate, any_storage> { - typedef any_storage<> type; + using type = any_storage<>; }; - -} // namespace cml - -#endif -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/storage/compiled_selector.h b/cml/storage/compiled_selector.h index 4ca11bc..ee67bfc 100644 --- a/cml/storage/compiled_selector.h +++ b/cml/storage/compiled_selector.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_storage_compiled_selector_h -#define cml_storage_compiled_selector_h - #include #include #include @@ -29,55 +24,56 @@ template struct compiled; * vector_storage_tag). This is set by instantiating @c rebind with the * required tag. */ -template -struct compiled +template struct compiled { /** Rebind the base selector to the required type. */ - template struct rebind { - typedef compiled other; + template struct rebind + { + using other = compiled; }; /** Make a partially bound selector with size @c N. */ - template struct resize { - typedef compiled type; + template struct resize + { + using type = compiled; }; /** Make a partially bound selector with size @c R x @c C. */ - template struct reshape { - typedef compiled type; + template struct reshape + { + using type = compiled; }; }; /** Specialized selector for fixed-size compiled vectors. */ -template -struct compiled +template struct compiled { - typedef compiled<> selector_type; - typedef compiled<> unbound_type; - typedef compiled proxy_type; - typedef vector_storage_tag storage_tag; - typedef fixed_size_tag size_tag; - typedef compiled_memory_tag memory_tag; + using selector_type = compiled<>; + using unbound_type = compiled<>; + using proxy_type = compiled; + using storage_tag = vector_storage_tag; + using size_tag = fixed_size_tag; + using memory_tag = compiled_memory_tag; /** Constant for the array size. */ static const int array_size = Size; /** Make a partially bound selector with size @c N. */ - template struct resize { - typedef compiled type; + template struct resize + { + using type = compiled; }; }; /** Specialized selector for fixed-size compiled matrices. */ -template -struct compiled +template struct compiled { - typedef compiled<> selector_type; - typedef compiled<> unbound_type; - typedef compiled proxy_type; - typedef matrix_storage_tag storage_tag; - typedef fixed_size_tag size_tag; - typedef compiled_memory_tag memory_tag; + using selector_type = compiled<>; + using unbound_type = compiled<>; + using proxy_type = compiled; + using storage_tag = matrix_storage_tag; + using size_tag = fixed_size_tag; + using memory_tag = compiled_memory_tag; /** Constant for the number of array rows. */ static const int array_rows = Size1; @@ -86,35 +82,37 @@ struct compiled static const int array_cols = Size2; /** Make a partially bound selector with size @c R x @c C. */ - template struct reshape { - typedef compiled type; + template struct reshape + { + using type = compiled; }; }; /** Specialized selector for quaternions. */ -template<> -struct compiled<4, -1, quaternion_storage_tag> +template<> struct compiled<4, -1, quaternion_storage_tag> { - typedef compiled<> selector_type; - typedef compiled<> unbound_type; - typedef compiled<> proxy_type; - typedef quaternion_storage_tag storage_tag; - typedef fixed_size_tag size_tag; - typedef compiled_memory_tag memory_tag; + using selector_type = compiled<>; + using unbound_type = compiled<>; + using proxy_type = compiled<>; + using storage_tag = quaternion_storage_tag; + using size_tag = fixed_size_tag; + using memory_tag = compiled_memory_tag; /** Constant for the array size. */ static const int array_size = 4; /** Make a partially bound selector with size @c N. */ - template struct resize { + template struct resize + { static_assert(N == 4, "invalid quaternion storage size"); - typedef compiled<4> type; + using type = compiled<4>; }; }; /** is_storage_selector for compiled<>. */ template -struct is_storage_selector> { +struct is_storage_selector> +{ static const bool value = true; }; @@ -122,16 +120,10 @@ struct is_storage_selector> { template struct storage_disambiguate, compiled> { - typedef compiled<> type; + using type = compiled<>; }; - /** For compatibility with CML1. */ template using fixed = compiled; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/storage/external_selector.h b/cml/storage/external_selector.h index f767a55..7f6a51a 100644 --- a/cml/storage/external_selector.h +++ b/cml/storage/external_selector.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_storage_external_selector_h -#define cml_storage_external_selector_h - #include #include @@ -31,70 +26,73 @@ template struct external; template struct external { /** Rebind the base selector to the required type. */ - template struct rebind { - typedef external other; + template struct rebind + { + using other = external; }; /** Make a partially bound selector with size @c N. */ - template struct resize { - typedef external type; + template struct resize + { + using type = external; }; /** Make a partially bound selector with size @c R x @c C. */ - template struct reshape { - typedef external type; + template struct reshape + { + using type = external; }; }; /** Specialized selector for dynamic-size external vectors. */ -template<> -struct external<-1, -1, vector_storage_tag> +template<> struct external<-1, -1, vector_storage_tag> { - typedef external<> selector_type; - typedef external<> unbound_type; - typedef allocated<> proxy_type; - typedef vector_storage_tag storage_tag; - typedef dynamic_size_tag size_tag; - typedef external_memory_tag memory_tag; + using selector_type = external<>; + using unbound_type = external<>; + using proxy_type = allocated<>; + using storage_tag = vector_storage_tag; + using size_tag = dynamic_size_tag; + using memory_tag = external_memory_tag; /** Unspecified array size. */ static const int array_size = -1; /** Make a partially bound selector with size @c N. */ - template struct resize { - typedef external type; + template struct resize + { + using type = external; }; }; /** Specialized selector for fixed-size external vectors. */ -template -struct external +template struct external { - typedef external<> selector_type; - typedef external<> unbound_type; - typedef compiled proxy_type; - typedef vector_storage_tag storage_tag; - typedef fixed_size_tag size_tag; - typedef external_memory_tag memory_tag; + using selector_type = external<>; + using unbound_type = external<>; + using proxy_type = compiled; + using storage_tag = vector_storage_tag; + using size_tag = fixed_size_tag; + using memory_tag = external_memory_tag; /** Constant for the array size. */ static const int array_size = Size; /** Make a partially bound selector with size @c N. */ - template struct resize { - typedef external type; + template struct resize + { + using type = external; }; }; /** Specialized selector for dynamic-size external matrices. */ template<> struct external<-1, -1, matrix_storage_tag> { - typedef external<> selector_type; - typedef external<> unbound_type; - typedef allocated<> proxy_type; - typedef matrix_storage_tag storage_tag; - typedef dynamic_size_tag size_tag; - typedef external_memory_tag memory_tag; + using selector_type = external<>; + using unbound_type = external<>; + using proxy_type = allocated<>; + using storage_tag = matrix_storage_tag; + using size_tag = dynamic_size_tag; + using memory_tag = external_memory_tag; /** Unspecified array rows. */ static const int array_rows = -1; @@ -103,21 +101,21 @@ template<> struct external<-1, -1, matrix_storage_tag> static const int array_cols = -1; /** Make a partially bound selector with size @c R x @c C. */ - template struct reshape { - typedef external type; + template struct reshape + { + using type = external; }; }; /** Specialized selector for fixed-size external matrices. */ -template -struct external +template struct external { - typedef external<> selector_type; - typedef external<> unbound_type; - typedef compiled proxy_type; - typedef matrix_storage_tag storage_tag; - typedef fixed_size_tag size_tag; - typedef external_memory_tag memory_tag; + using selector_type = external<>; + using unbound_type = external<>; + using proxy_type = compiled; + using storage_tag = matrix_storage_tag; + using size_tag = fixed_size_tag; + using memory_tag = external_memory_tag; /** Constant for the number of array rows. */ static const int array_rows = Size1; @@ -126,35 +124,37 @@ struct external static const int array_cols = Size2; /** Make a partially bound selector with size @c R x @c C. */ - template struct reshape { - typedef external type; + template struct reshape + { + using type = external; }; }; /** Specialized selector for external quaternions. */ -template<> -struct external<4, -1, quaternion_storage_tag> +template<> struct external<4, -1, quaternion_storage_tag> { - typedef external<> selector_type; - typedef external<> unbound_type; - typedef compiled<4> proxy_type; - typedef quaternion_storage_tag storage_tag; - typedef fixed_size_tag size_tag; - typedef external_memory_tag memory_tag; + using selector_type = external<>; + using unbound_type = external<>; + using proxy_type = compiled<4>; + using storage_tag = quaternion_storage_tag; + using size_tag = fixed_size_tag; + using memory_tag = external_memory_tag; /** Constant for the array size. */ static const int array_size = 4; /** Make a partially bound selector with size @c N. */ - template struct resize { + template struct resize + { static_assert(N == 4, "invalid quaternion storage size"); - typedef external<4> type; + using type = external<4>; }; }; /** is_storage_selector for external<>. */ template -struct is_storage_selector> { +struct is_storage_selector> +{ static const bool value = true; }; @@ -162,12 +162,7 @@ struct is_storage_selector> { template struct storage_disambiguate, external> { - typedef external<> type; + using type = external<>; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/storage/promotion.h b/cml/storage/promotion.h index c34cd67..e595209 100644 --- a/cml/storage/promotion.h +++ b/cml/storage/promotion.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_storage_promotion_h -#define cml_storage_promotion_h - #include #include @@ -25,85 +20,83 @@ struct storage_promote { /* Map selector types to the preferred selector: */ template - using selector_map = type_table_item; + using selector_map = type_table_item; /* True if PreferDynamic is false, or if both Storage1 and Storage2 are * fixed-size types: */ - static const bool is_fixed - = !PreferDynamic + static const bool is_fixed = !PreferDynamic || (is_fixed_size::value && is_fixed_size::value); /* Build the symmetric type table for the built-in types, giving * preference to dynamic-size types if PreferDynamic is true: */ - typedef cml::type_table< - /**/ selector_map< compiled<>, compiled<>, compiled<> > + using selector_table = cml::type_table< + /**/ selector_map, compiled<>, compiled<>> /* Override and select allocated<> if PreferDynamic is true and the * original storage types are not both fixed-size: */ - , selector_map< compiled<>, allocated<>, - cml::if_t, allocated<>> - > + , + selector_map, allocated<>, + cml::if_t, allocated<>>> /* Override and select external<> if PreferDynamic is true and the * original storage types are not both fixed-size: */ - , selector_map< compiled<>, external<>, - cml::if_t, external<>> - > + , + selector_map, external<>, + cml::if_t, external<>>> - , selector_map< compiled<>, any_storage<>, compiled<> > + , + selector_map, any_storage<>, compiled<>> - , selector_map< allocated<>, allocated<>, allocated<> > + , + selector_map, allocated<>, allocated<>> - , selector_map< allocated<>, external<>, allocated<> > + , + selector_map, external<>, allocated<>> - , selector_map< allocated<>, any_storage<>, allocated<> > + , + selector_map, any_storage<>, allocated<>> - , selector_map< external<>, external<>, external<> > + , + selector_map, external<>, external<>> - , selector_map< external<>, any_storage<>, external<> > + , + selector_map, any_storage<>, external<>> - , selector_map< any_storage<>, any_storage<>, any_storage<> > - > selector_table; + , + selector_map, any_storage<>, any_storage<>>>; /* Lookup the storage selector for the passed-in types: */ - typedef typename Storage1::selector_type left_selector; - typedef typename Storage2::selector_type right_selector; - typedef typename selector_table::template find< - left_selector, right_selector>::type result; - typedef typename result::type selector_type; + using left_selector = typename Storage1::selector_type; + using right_selector = typename Storage2::selector_type; + using result = typename selector_table::template find::type; + using selector_type = typename result::type; static_assert(result::value, "no common storage selector found"); /* True if the resulting selector matches the left and/or right * selectors: */ - static const bool is_left - = std::is_same::value; - static const bool is_right - = std::is_same::value; + static const bool is_left = std::is_same::value; + static const bool is_right = + std::is_same::value; static const bool is_same = is_left && is_right; static_assert(is_left || is_right, "unexpected storage_promote result"); /* Determine the final selector type: */ - typedef typename Storage1::unbound_type left_unbound; - typedef typename Storage2::unbound_type right_unbound; - typedef - cml::if_t, - cml::if_t> type; + using left_unbound = typename Storage1::unbound_type; + using right_unbound = typename Storage2::unbound_type; + using type = cml::if_t, + cml::if_t>; }; /** Convenience alias for storage_selector_promote. */ template - using storage_promote_t - = typename storage_promote::type; - -} // namespace cml - -#endif +using storage_promote_t = + typename storage_promote::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/storage/resize.h b/cml/storage/resize.h index 64540fa..85bb813 100644 --- a/cml/storage/resize.h +++ b/cml/storage/resize.h @@ -1,48 +1,35 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_storage_resize_h -#define cml_storage_resize_h - #include namespace cml { /** Compute a new storage type by changing the size of @c Storage to @c N. */ -template -struct resize_storage +template struct resize_storage { /* Determine the new storage type: */ - typedef typename Storage::template resize::type type; + using type = typename Storage::template resize::type; }; /** Convenience alias for resize_storage. */ -template using resize_storage_t - = typename resize_storage::type; - +template +using resize_storage_t = typename resize_storage::type; /** Compute a new storage type by changing the shape of @c Storage to @c R x * @c C. */ -template -struct reshape_storage +template struct reshape_storage { /* Determine the new storage type: */ - typedef typename Storage::template reshape::type type; + using type = typename Storage::template reshape::type; }; /** Convenience alias for reshape_storage. */ -template using reshape_storage_t - = typename reshape_storage::type; - -} // namespace cml - -#endif +template +using reshape_storage_t = typename reshape_storage::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/storage/selectors.h b/cml/storage/selectors.h index 29531da..d807a23 100644 --- a/cml/storage/selectors.h +++ b/cml/storage/selectors.h @@ -1,20 +1,10 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_storage_selectors_h -#define cml_storage_selectors_h - #include #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/storage/type_util.h b/cml/storage/type_util.h index 4eb9a89..097ee8a 100644 --- a/cml/storage/type_util.h +++ b/cml/storage/type_util.h @@ -1,115 +1,104 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_storage_type_util_h -#define cml_storage_type_util_h - #include #include namespace cml { /** Specializable class to detect storage selectors. */ -template struct is_storage_selector { +template struct is_storage_selector +{ static const bool value = false; }; /** Templated helper to determine the storage selector of @c T. @c T must * implement a selector_type typedef. */ -template struct storage_selector_of { - typedef typename T::selector_type type; +template struct storage_selector_of +{ + using type = typename T::selector_type; static_assert(is_storage_selector::value, "invalid storage selector"); }; /** Convenience alias for storage_selector_of. */ -template using storage_selector_of_t - = typename storage_selector_of::type; - +template +using storage_selector_of_t = typename storage_selector_of::type; /** Templated helper to determine the storage type of @c T. @c T must * implement a storage_type typedef. */ -template struct storage_type_of { - typedef typename T::storage_type type; +template struct storage_type_of +{ + using type = typename T::storage_type; }; /** Convenience alias for storage_type_of. */ -template using storage_type_of_t - = typename storage_type_of::type; - +template using storage_type_of_t = typename storage_type_of::type; /** Templated helper to determine the proxy type of @c T. @c T must * implement a proxy_type typedef. */ -template struct proxy_type_of { - typedef typename T::proxy_type type; +template struct proxy_type_of +{ + using type = typename T::proxy_type; }; /** Convenience alias for proxy_type_of. */ template using proxy_type_of_t = typename proxy_type_of::type; - /** Templated helper to rebind a storage type as vector storage. */ -template::value>::type* = nullptr> +template::value>::type* = nullptr> struct rebind_vector_storage { - typedef rebind_t type; + using type = rebind_t; }; /** Convenience alias for rebind_vector_storage. */ -template using rebind_vector_storage_t - = typename rebind_vector_storage::type; - +template +using rebind_vector_storage_t = typename rebind_vector_storage::type; /** Templated helper to rebind a storage type as matrix storage. */ -template::value>::type* = nullptr> +template::value>::type* = nullptr> struct rebind_matrix_storage { - typedef rebind_t type; + using type = rebind_t; }; /** Convenience alias for rebind_matrix_storage. */ -template using rebind_matrix_storage_t - = typename rebind_matrix_storage::type; - +template +using rebind_matrix_storage_t = typename rebind_matrix_storage::type; /** Templated helper to rebind a storage type as vector storage. */ -template::value>::type* = nullptr> +template::value>::type* = nullptr> struct rebind_quaternion_storage { - typedef rebind_t type; + using type = rebind_t; }; /** Convenience alias for rebind_quaternion_storage. */ -template using rebind_quaternion_storage_t - = typename rebind_quaternion_storage::type; - +template +using rebind_quaternion_storage_t = typename rebind_quaternion_storage::type; /** Specializable class used to disambiguate configurable storage types @c * Storage1 and @c Storage2 that have matching storage selectors. * * @note This should be specialized for user-defined storage types. */ -template struct storage_disambiguate { - typedef void type; +template struct storage_disambiguate +{ + using type = void; }; /** Convenience alias for storage_disambiguate. */ -template using storage_disambiguate_t - = typename storage_disambiguate::type; - -} // namespace cml - -#endif +template +using storage_disambiguate_t = + typename storage_disambiguate::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/types.h b/cml/types.h index 426d9ac..575ad2d 100644 --- a/cml/types.h +++ b/cml/types.h @@ -1,19 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_types_h -#define cml_types_h - #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/util.h b/cml/util.h index c48aec1..ae6f410 100644 --- a/cml/util.h +++ b/cml/util.h @@ -1,51 +1,61 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_util_h -#define cml_util_h - #include namespace cml { /** Convert horizontal field of view to vertical field of view. */ -template inline T xfov_to_yfov(T xfov, T aspect) { - return T(2*scalar_traits::atan(scalar_traits::tan(xfov/2) / aspect)); +template +inline T +xfov_to_yfov(T xfov, T aspect) +{ + return T(2 + * scalar_traits::atan(scalar_traits::tan(xfov / 2) / aspect)); } /** Convert vertical field of view to horizontal field of view. */ -template inline T yfov_to_xfov(T yfov, T aspect) { - return T(2*scalar_traits::atan(scalar_traits::tan(yfov/2) * aspect)); +template +inline T +yfov_to_xfov(T yfov, T aspect) +{ + return T(2 + * scalar_traits::atan(scalar_traits::tan(yfov / 2) * aspect)); } /** Convert horizontal zoom to vertical zoom. */ -template inline T xzoom_to_yzoom(T xzoom, T aspect) { +template +inline T +xzoom_to_yzoom(T xzoom, T aspect) +{ return xzoom * aspect; } /** Convert vertical zoom to horizontal zoom. */ -template inline T yzoom_to_xzoom(T yzoom, T aspect) { +template +inline T +yzoom_to_xzoom(T yzoom, T aspect) +{ return yzoom / aspect; } /** Convert zoom factor to field of view. */ -template inline T zoom_to_fov(T zoom) { - return T(2*scalar_traits::atan(T(1) / zoom)); +template +inline T +zoom_to_fov(T zoom) +{ + return T(2 * scalar_traits::atan(T(1) / zoom)); } /** Convert field of view to zoom factor. */ -template inline T fov_to_zoom(T fov) { - return T(1) / scalar_traits::tan(fov/2); +template +inline T +fov_to_zoom(T fov) +{ + return T(1) / scalar_traits::tan(fov / 2); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/util/matrix_print.h b/cml/util/matrix_print.h index b5fcd93..75f48e7 100644 --- a/cml/util/matrix_print.h +++ b/cml/util/matrix_print.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_util_matrix_print_h -#define cml_util_matrix_print_h - #include namespace cml { @@ -17,17 +12,11 @@ namespace cml { template class readable_matrix; /** Output a matrix to a std::ostream. */ -template std::ostream& operator<<( - std::ostream& os, const readable_matrix& v); - -} // namespace cml +template +std::ostream& operator<<(std::ostream& os, const readable_matrix& v); +} // namespace cml #define __CML_UTIL_MATRIX_PRINT_TPP #include #undef __CML_UTIL_MATRIX_PRINT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/util/matrix_print.tpp b/cml/util/matrix_print.tpp index c9579f2..b1f04cd 100644 --- a/cml/util/matrix_print.tpp +++ b/cml/util/matrix_print.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_UTIL_MATRIX_PRINT_TPP -#error "util/matrix_print.tpp not included correctly" +# error "util/matrix_print.tpp not included correctly" #endif #include @@ -13,20 +11,17 @@ namespace cml { -template inline std::ostream& +template +inline std::ostream& operator<<(std::ostream& os, const readable_matrix
& M) { for(int i = 0; i < M.rows(); ++i) { os << "["; - for(int j = 0; j < M.cols(); ++j) os << " " << M(i,j); + for(int j = 0; j < M.cols(); ++j) os << " " << M(i, j); os << " ]"; - if (i != M.rows()-1) os << std::endl; + if(i != M.rows() - 1) os << std::endl; } return os; } -} // namespace cml - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/util/quaternion_print.h b/cml/util/quaternion_print.h index 37fe65c..716f5ce 100644 --- a/cml/util/quaternion_print.h +++ b/cml/util/quaternion_print.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_util_quaternion_print_h -#define cml_util_quaternion_print_h - #include namespace cml { @@ -17,17 +12,12 @@ namespace cml { template class readable_quaternion; /** Output a quaternion to a std::ostream. */ -template std::ostream& operator<<( - std::ostream& os, const readable_quaternion& v); - -} // namespace cml +template +std::ostream& operator<<(std::ostream& os, + const readable_quaternion& v); +} // namespace cml #define __CML_UTIL_QUATERNION_PRINT_TPP #include #undef __CML_UTIL_QUATERNION_PRINT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/util/quaternion_print.tpp b/cml/util/quaternion_print.tpp index 2475b1b..c152bea 100644 --- a/cml/util/quaternion_print.tpp +++ b/cml/util/quaternion_print.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_UTIL_QUATERNION_PRINT_TPP -#error "util/quaternion_print.tpp not included correctly" +# error "util/quaternion_print.tpp not included correctly" #endif #include @@ -14,21 +12,15 @@ namespace cml { -template inline std::ostream& +template +inline std::ostream& operator<<(std::ostream& os, const readable_quaternion
& q) { - typedef order_type_trait_of_t
order_type; + using order_type = order_type_trait_of_t
; os << "[ " - << " " << q[order_type::W] - << " " << q[order_type::X] - << " " << q[order_type::Y] - << " " << q[order_type::Z] - << " ]"; + << " " << q[order_type::W] << " " << q[order_type::X] << " " + << q[order_type::Y] << " " << q[order_type::Z] << " ]"; return os; } -} // namespace cml - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/util/vector_hash.h b/cml/util/vector_hash.h index cd7d12d..1e348dc 100644 --- a/cml/util/vector_hash.h +++ b/cml/util/vector_hash.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_util_vector_hash_h -#define cml_util_vector_hash_h - #include #include #include @@ -16,20 +11,17 @@ /* Need specialization in std: */ namespace std { template -struct hash> +struct hash> { - typedef cml::vector vector_type; - inline std::size_t operator()(const vector_type& v) const { + using vector_type = cml::vector; + + inline std::size_t operator()(const vector_type& v) const + { std::size_t seed = 0; std::hash> hasher; - for(int i = 0; i < v.size(); ++ i) + for(int i = 0; i < v.size(); ++i) cml::detail::hash_combine(seed, hasher(v.get(i))); return seed; } }; -} - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace std diff --git a/cml/util/vector_print.h b/cml/util/vector_print.h index 58b83af..65bd159 100644 --- a/cml/util/vector_print.h +++ b/cml/util/vector_print.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_util_vector_print_h -#define cml_util_vector_print_h - #include namespace cml { @@ -17,17 +12,11 @@ namespace cml { template class readable_vector; /** Output a vector to a std::ostream. */ -template std::ostream& operator<<( - std::ostream& os, const readable_vector& v); - -} // namespace cml +template +std::ostream& operator<<(std::ostream& os, const readable_vector& v); +} // namespace cml #define __CML_UTIL_VECTOR_PRINT_TPP #include #undef __CML_UTIL_VECTOR_PRINT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/util/vector_print.tpp b/cml/util/vector_print.tpp index d5d2a75..90cea17 100644 --- a/cml/util/vector_print.tpp +++ b/cml/util/vector_print.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_UTIL_VECTOR_PRINT_TPP -#error "util/vector_print.tpp not included correctly" +# error "util/vector_print.tpp not included correctly" #endif #include @@ -13,16 +11,13 @@ namespace cml { -template inline std::ostream& +template +inline std::ostream& operator<<(std::ostream& os, const readable_vector
& v) { os << v[0]; - for (int i = 1; i < v.size(); ++i) os << " " << v[i]; + for(int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; } -} // namespace cml - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector.h b/cml/vector.h index 8dc7b26..b7bb320 100644 --- a/cml/vector.h +++ b/cml/vector.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_h -#define cml_vector_h - #include #include #include @@ -19,8 +14,3 @@ #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/binary_node.h b/cml/vector/binary_node.h index e737a76..69a85d7 100644 --- a/cml/vector/binary_node.h +++ b/cml/vector/binary_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_binary_node_h -#define cml_vector_binary_node_h - #include #include @@ -18,28 +13,27 @@ template class vector_binary_node; /** vector_binary_node<> traits. */ template -struct vector_traits< vector_binary_node > +struct vector_traits> { - typedef vector_binary_node vector_type; - typedef Sub1 left_arg_type; - typedef Sub2 right_arg_type; - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef vector_traits left_traits; - typedef vector_traits right_traits; - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; + using vector_type = vector_binary_node; + using left_arg_type = Sub1; + using right_arg_type = Sub2; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = vector_traits; + using right_traits = vector_traits; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; /* Determine the common storage type for the node, based on the storage * types of its subexpressions: */ - typedef vector_binary_storage_promote_t< - storage_type_of_t, - storage_type_of_t> storage_type; + using storage_type = vector_binary_storage_promote_t, + storage_type_of_t>; /* Traits and types for the storage: */ - typedef typename storage_type::size_tag size_tag; + using size_tag = typename storage_type::size_tag; /* Array size: */ static const int array_size = storage_type::array_size; @@ -48,33 +42,30 @@ struct vector_traits< vector_binary_node > /** Represents a binary vector operation in an expression tree. */ template class vector_binary_node -: public readable_vector< vector_binary_node > +: public readable_vector> { public: - - typedef vector_binary_node node_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::left_arg_type left_arg_type; - typedef typename traits_type::right_arg_type right_arg_type; - typedef typename traits_type::left_type left_type; - typedef typename traits_type::right_type right_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using node_type = vector_binary_node; + using readable_type = readable_vector; + using traits_type = vector_traits; + using left_arg_type = typename traits_type::left_arg_type; + using right_arg_type = typename traits_type::right_arg_type; + using left_type = typename traits_type::left_type; + using right_type = typename traits_type::right_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** Constant containing the array size. */ - static const int array_size = traits_type::array_size; + /** Constant containing the array size. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be + /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be * lvalue reference or rvalue reference types. * * @throws incompatible_vector_size_error at run-time if either Sub1 or @@ -82,79 +73,70 @@ class vector_binary_node * If both Sub1 and Sub2 are fixed-size expressions, then the sizes are * checked at compile time. */ - vector_binary_node(Sub1 left, Sub2 right); + vector_binary_node(Sub1 left, Sub2 right); - /** Move constructor. */ - vector_binary_node(node_type&& other); + /** Move constructor. */ + vector_binary_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - vector_binary_node(const node_type& other); + /** Copy constructor. */ + vector_binary_node(const node_type& other); #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the size of the vector expression. */ - int i_size() const; + /** Return the size of the vector expression. */ + int i_size() const; - /** Apply the operator to element @c i of the subexpressions and return + /** Apply the operator to element @c i of the subexpressions and return * the result. */ - immutable_value i_get(int i) const; + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the left subexpression. The expression is + /** The type used to store the left subexpression. The expression is * stored as a copy if Sub1 is an rvalue reference (temporary), or by * const reference if Sub1 is an lvalue reference. */ - typedef cml::if_t::value, - const left_type&, left_type> left_wrap_type; + using left_wrap_type = cml::if_t::value, const left_type&, + left_type>; - /** The type used to store the right subexpression. The expression is + /** The type used to store the right subexpression. The expression is * stored as a copy if Sub2 is an rvalue reference (temporary), or by * const reference if Sub2 is an lvalue reference. */ - typedef cml::if_t::value, - const right_type&, right_type> right_wrap_type; + using right_wrap_type = cml::if_t::value, const right_type&, + right_type>; protected: + /** The wrapped left subexpression. */ + left_wrap_type m_left; - /** The wrapped left subexpression. */ - left_wrap_type m_left; - - /** The wrapped right subexpression. */ - right_wrap_type m_right; + /** The wrapped right subexpression. */ + right_wrap_type m_right; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - vector_binary_node(const node_type&); + // Not copy constructible. + vector_binary_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_BINARY_NODE_TPP #include #undef __CML_VECTOR_BINARY_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/binary_node.tpp b/cml/vector/binary_node.tpp index 6f48660..952eb1d 100644 --- a/cml/vector/binary_node.tpp +++ b/cml/vector/binary_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_BINARY_NODE_TPP -#error "vector/binary_node.tpp not included correctly" +# error "vector/binary_node.tpp not included correctly" #endif #include @@ -15,8 +13,9 @@ namespace cml { /* vector_binary_node 'structors: */ template -vector_binary_node::vector_binary_node(Sub1 left, Sub2 right) -: m_left(std::move(left)), m_right(std::move(right)) +vector_binary_node::vector_binary_node(Sub1 left, Sub2 right) +: m_left(std::move(left)) +, m_right(std::move(right)) { cml::check_same_size(this->m_left, this->m_right); /* Note: this seems to be exception-safe since temporaries are stored by @@ -25,38 +24,36 @@ vector_binary_node::vector_binary_node(Sub1 left, Sub2 right) } template -vector_binary_node::vector_binary_node(node_type&& other) -: m_left(std::move(other.m_left)), m_right(std::move(other.m_right)) -{ -} +vector_binary_node::vector_binary_node(node_type&& other) +: m_left(std::move(other.m_left)) +, m_right(std::move(other.m_right)) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -vector_binary_node::vector_binary_node(const node_type& other) -: m_left(other.m_left), m_right(other.m_right) -{ -} +vector_binary_node::vector_binary_node(const node_type& other) +: m_left(other.m_left) +, m_right(other.m_right) +{} #endif - /* Internal methods: */ /* readable_vector interface: */ -template int -vector_binary_node::i_size() const +template +int +vector_binary_node::i_size() const { return this->m_left.size(); } -template auto -vector_binary_node::i_get(int i) const -> immutable_value +template +auto +vector_binary_node::i_get(int i) const -> immutable_value { return Op().apply(this->m_left.get(i), this->m_right.get(i)); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/binary_ops.h b/cml/vector/binary_ops.h index d374e00..b20d033 100644 --- a/cml/vector/binary_ops.h +++ b/cml/vector/binary_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_binary_ops_h -#define cml_vector_binary_ops_h - #include #include @@ -17,53 +12,47 @@ namespace cml { /** Helper function to generate a vector_binary_node from two vector types * (i.e. derived from readable_vector<>). */ -template* = nullptr, enable_if_vector_t* = nullptr> +template* = nullptr, + enable_if_vector_t* = nullptr> inline auto -make_vector_binary_node(Sub1&& sub1, Sub2&& sub2) --> vector_binary_node< -actual_operand_type_of_t, -actual_operand_type_of_t, -Op -> +make_vector_binary_node(Sub1&& sub1, + Sub2&& sub2) -> vector_binary_node, + actual_operand_type_of_t, Op> { - static_assert(std::is_same< - decltype(sub1), decltype(std::forward(sub1))>::value, + static_assert( + std::is_same(sub1))>::value, "internal error: unexpected expression type (sub1)"); - static_assert(std::is_same< - decltype(sub2), decltype(std::forward(sub2))>::value, + static_assert( + std::is_same(sub2))>::value, "internal error: unexpected expression type (sub2)"); /* Deduce the operand types of the subexpressions (&, const&, &&): */ - typedef actual_operand_type_of_t sub1_type; - typedef actual_operand_type_of_t sub2_type; - return vector_binary_node< - sub1_type, sub2_type, Op>((sub1_type) sub1, (sub2_type) sub2); + using sub1_type = actual_operand_type_of_t; + using sub2_type = actual_operand_type_of_t; + return vector_binary_node((sub1_type) sub1, + (sub2_type) sub2); } -template* = nullptr, enable_if_vector_t* = nullptr> -inline auto operator-(Sub1&& sub1, Sub2&& sub2) --> decltype(make_vector_binary_node>( +template* = nullptr, + enable_if_vector_t* = nullptr> +inline auto +operator-(Sub1&& sub1, Sub2&& sub2) + -> decltype(make_vector_binary_node>( std::forward(sub1), std::forward(sub2))) { - return make_vector_binary_node> - (std::forward(sub1), std::forward(sub2)); + return make_vector_binary_node>( + std::forward(sub1), std::forward(sub2)); } -template* = nullptr, enable_if_vector_t* = nullptr> -inline auto operator+(Sub1&& sub1, Sub2&& sub2) --> decltype(make_vector_binary_node>( +template* = nullptr, + enable_if_vector_t* = nullptr> +inline auto +operator+(Sub1&& sub1, Sub2&& sub2) + -> decltype(make_vector_binary_node>( std::forward(sub1), std::forward(sub2))) { - return make_vector_binary_node> - (std::forward(sub1), std::forward(sub2)); + return make_vector_binary_node>( + std::forward(sub1), std::forward(sub2)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/comparison.h b/cml/vector/comparison.h index 9b6e5d1..13be45b 100644 --- a/cml/vector/comparison.h +++ b/cml/vector/comparison.h @@ -1,57 +1,53 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_comparison_h -#define cml_vector_comparison_h - #include namespace cml { /** Returns true if @c left is lexicographically less than @c right. */ -template bool operator<( - const readable_vector& left, const readable_vector& right); +template +bool operator<(const readable_vector& left, + const readable_vector& right); /** Returns true if @c left is lexicographically less than or equal to @c * right. */ -template bool operator<=( - const readable_vector& left, const readable_vector& right); +template +bool operator<=(const readable_vector& left, + const readable_vector& right); /** Returns true if @c left is lexicographically greater than @c right. */ -template bool operator>( - const readable_vector& left, const readable_vector& right); +template +bool operator>(const readable_vector& left, + const readable_vector& right); /** Returns true if @c left is lexicographically greater than or equal to * @c right. */ -template bool operator>=( - const readable_vector& left, const readable_vector& right); +template +bool operator>=(const readable_vector& left, + const readable_vector& right); /** Returns true if the elements of @c left are all equal to the elements * of @c right. */ -template bool operator==( - const readable_vector& left, const readable_vector& right); +template +bool operator==(const readable_vector& left, + const readable_vector& right); /** Returns true if some element of @c left is not equal to the * corresponding element of @c right. */ -template bool operator!=( - const readable_vector& left, const readable_vector& right); +template +bool operator!=(const readable_vector& left, + const readable_vector& right); -} // namespace cml +} // namespace cml #define __CML_VECTOR_COMPARISON_TPP #include #undef __CML_VECTOR_COMPARISON_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/comparison.tpp b/cml/vector/comparison.tpp index d7dbc17..1a0e16e 100644 --- a/cml/vector/comparison.tpp +++ b/cml/vector/comparison.tpp @@ -1,83 +1,85 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_COMPARISON_TPP -#error "vector/comparison.tpp not included correctly" +# error "vector/comparison.tpp not included correctly" #endif #include namespace cml { -template inline bool operator<( - const readable_vector& left, const readable_vector& right - ) +template +inline bool +operator<(const readable_vector& left, const readable_vector& right) { int n = std::min(left.size(), right.size()); - for(int i = 0; i < n; i ++) { - /**/ if(left[i] < right[i]) return true; // Strictly less. - else if(right[i] < left[i]) return false; // Strictly greater. - else continue; // Possibly equal. + for(int i = 0; i < n; i++) { + /**/ if(left[i] < right[i]) + return true; // Strictly less. + else if(right[i] < left[i]) return false; // Strictly greater. + else continue; // Possibly equal. } /* Equal only if the same length: */ return left.size() < right.size(); } -template inline bool operator>( - const readable_vector& left, const readable_vector& right - ) +template +inline bool +operator>(const readable_vector& left, const readable_vector& right) { int n = std::min(left.size(), right.size()); - for(int i = 0; i < n; i ++) { - /**/ if(left[i] < right[i]) return false; // Strictly less. - else if(right[i] < left[i]) return true; // Strictly greater. - else continue; // Possibly equal. + for(int i = 0; i < n; i++) { + /**/ if(left[i] < right[i]) + return false; // Strictly less. + else if(right[i] < left[i]) return true; // Strictly greater. + else continue; // Possibly equal. } /* Equal only if the same length: */ return left.size() > right.size(); } -template inline bool operator==( - const readable_vector& left, const readable_vector& right - ) +template +inline bool +operator==(const readable_vector& left, + const readable_vector& right) { /* Possibly equal only if the same length: */ if(left.size() != right.size()) return false; - for(int i = 0; i < left.size(); i ++) { - /**/ if(left[i] < right[i]) return false; // Strictly less. - else if(right[i] < left[i]) return false; // Strictly greater. - else continue; // Possibly equal. + for(int i = 0; i < left.size(); i++) { + /**/ if(left[i] < right[i]) + return false; // Strictly less. + else if(right[i] < left[i]) return false; // Strictly greater. + else continue; // Possibly equal. } return true; } -template inline bool operator<=( - const readable_vector& left, const readable_vector& right - ) +template +inline bool +operator<=(const readable_vector& left, + const readable_vector& right) { return !(left > right); } -template inline bool operator>=( - const readable_vector& left, const readable_vector& right - ) +template +inline bool +operator>=(const readable_vector& left, + const readable_vector& right) { return !(left < right); } -template inline bool operator!=( - const readable_vector& left, const readable_vector& right - ) +template +inline bool +operator!=(const readable_vector& left, + const readable_vector& right) { return !(left == right); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/cross.h b/cml/vector/cross.h index 73b89e5..8e81ea9 100644 --- a/cml/vector/cross.h +++ b/cml/vector/cross.h @@ -1,18 +1,8 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_cross_h -#define cml_vector_cross_h - #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/cross_node.h b/cml/vector/cross_node.h index be3d4ec..1f28bd1 100644 --- a/cml/vector/cross_node.h +++ b/cml/vector/cross_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_cross_node_h -#define cml_vector_cross_node_h - #include #include @@ -18,30 +13,29 @@ template class vector_cross_node; /** vector_cross_node<> traits. */ template -struct vector_traits< vector_cross_node > +struct vector_traits> { - typedef vector_cross_node vector_type; - typedef Sub1 left_arg_type; - typedef Sub2 right_arg_type; - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef vector_traits left_traits; - typedef vector_traits right_traits; - - typedef value_type_promote_t element_type; - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; + using vector_type = vector_cross_node; + using left_arg_type = Sub1; + using right_arg_type = Sub2; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = vector_traits; + using right_traits = vector_traits; + + using element_type = value_type_promote_t; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; /* Determine the common storage type for the node, based on the storage * types of its subexpressions: */ - typedef vector_binary_storage_promote_t< - storage_type_of_t, - storage_type_of_t> storage_type; + using storage_type = vector_binary_storage_promote_t, + storage_type_of_t>; /* Traits and types for the storage: */ - typedef typename storage_type::size_tag size_tag; + using size_tag = typename storage_type::size_tag; /* Array size: */ static const int array_size = storage_type::array_size; @@ -49,34 +43,30 @@ struct vector_traits< vector_cross_node > /** Represents a cross product in an expression tree. */ template -class vector_cross_node -: public readable_vector< vector_cross_node > +class vector_cross_node : public readable_vector> { public: - - typedef vector_cross_node node_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::left_arg_type left_arg_type; - typedef typename traits_type::right_arg_type right_arg_type; - typedef typename traits_type::left_type left_type; - typedef typename traits_type::right_type right_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using node_type = vector_cross_node; + using readable_type = readable_vector; + using traits_type = vector_traits; + using left_arg_type = typename traits_type::left_arg_type; + using right_arg_type = typename traits_type::right_arg_type; + using left_type = typename traits_type::left_type; + using right_type = typename traits_type::right_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** Constant containing the array size. */ - static const int array_size = traits_type::array_size; + /** Constant containing the array size. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be + /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be * lvalue reference or rvalue reference types. * * @throws vector_size_error at run-time if either Sub1 or Sub2 is a @@ -84,79 +74,70 @@ class vector_cross_node * both Sub1 and Sub2 are fixed-size expressions, then the sizes are * checked at compile time. */ - vector_cross_node(Sub1 left, Sub2 right); + vector_cross_node(Sub1 left, Sub2 right); - /** Move constructor. */ - vector_cross_node(node_type&& other); + /** Move constructor. */ + vector_cross_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - vector_cross_node(const node_type& other); + /** Copy constructor. */ + vector_cross_node(const node_type& other); #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the size of the vector expression. */ - int i_size() const; + /** Return the size of the vector expression. */ + int i_size() const; - /** Apply the operator to element @c i of the subexpressions and return + /** Apply the operator to element @c i of the subexpressions and return * the result. */ - immutable_value i_get(int i) const; + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the left subexpression. The expression is + /** The type used to store the left subexpression. The expression is * stored as a copy if Sub1 is an rvalue reference (temporary), or by * const reference if Sub1 is an lvalue reference. */ - typedef cml::if_t::value, - const left_type&, left_type> left_wrap_type; + using left_wrap_type = cml::if_t::value, const left_type&, + left_type>; - /** The type used to store the right subexpression. The expression is + /** The type used to store the right subexpression. The expression is * stored as a copy if Sub2 is an rvalue reference (temporary), or by * const reference if Sub2 is an lvalue reference. */ - typedef cml::if_t::value, - const right_type&, right_type> right_wrap_type; + using right_wrap_type = cml::if_t::value, const right_type&, + right_type>; protected: + /** The wrapped left subexpression. */ + left_wrap_type m_left; - /** The wrapped left subexpression. */ - left_wrap_type m_left; - - /** The wrapped right subexpression. */ - right_wrap_type m_right; + /** The wrapped right subexpression. */ + right_wrap_type m_right; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - vector_cross_node(const node_type&); + // Not copy constructible. + vector_cross_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_CROSS_NODE_TPP #include #undef __CML_VECTOR_CROSS_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/cross_node.tpp b/cml/vector/cross_node.tpp index 06d6f29..c5494a8 100644 --- a/cml/vector/cross_node.tpp +++ b/cml/vector/cross_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_CROSS_NODE_TPP -#error "vector/cross_node.tpp not included correctly" +# error "vector/cross_node.tpp not included correctly" #endif #include @@ -15,8 +13,9 @@ namespace cml { /* vector_cross_node 'structors: */ template -vector_cross_node::vector_cross_node(Sub1 left, Sub2 right) -: m_left(std::move(left)), m_right(std::move(right)) +vector_cross_node::vector_cross_node(Sub1 left, Sub2 right) +: m_left(std::move(left)) +, m_right(std::move(right)) { cml::check_size(left, cml::int_c<3>()); cml::check_size(right, cml::int_c<3>()); @@ -26,40 +25,37 @@ vector_cross_node::vector_cross_node(Sub1 left, Sub2 right) } template -vector_cross_node::vector_cross_node(node_type&& other) -: m_left(std::move(other.m_left)), m_right(std::move(other.m_right)) -{ -} +vector_cross_node::vector_cross_node(node_type&& other) +: m_left(std::move(other.m_left)) +, m_right(std::move(other.m_right)) +{} template -vector_cross_node::vector_cross_node(const node_type& other) -: m_left(other.m_left), m_right(other.m_right) -{ -} - - +vector_cross_node::vector_cross_node(const node_type& other) +: m_left(other.m_left) +, m_right(other.m_right) +{} /* Internal methods: */ /* readable_vector interface: */ -template int -vector_cross_node::i_size() const +template +int +vector_cross_node::i_size() const { return 3; } -template auto -vector_cross_node::i_get(int i) const -> immutable_value +template +auto +vector_cross_node::i_get(int i) const -> immutable_value { - int i0 = (i+1)%3, i1 = (i+2)%3; + int i0 = (i + 1) % 3, i1 = (i + 2) % 3; return immutable_value( - this->m_left.get(i0)*this->m_right.get(i1) // 1,2; 2,0; 0,1 - - this->m_left.get(i1)*this->m_right.get(i0)) // 2,1; 0,2; 1,0 + this->m_left.get(i0) * this->m_right.get(i1) // 1,2; 2,0; 0,1 + - this->m_left.get(i1) * this->m_right.get(i0)) // 2,1; 0,2; 1,0 ; } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/cross_ops.h b/cml/vector/cross_ops.h index 7aa0d39..64725f2 100644 --- a/cml/vector/cross_ops.h +++ b/cml/vector/cross_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_cross_ops_h -#define cml_vector_cross_ops_h - #include namespace cml { @@ -20,24 +15,18 @@ namespace cml { * dynamically-sized and is not a 3D vector. The size is checked at * compile time for fixed-sized expressions. */ -template* = nullptr, enable_if_vector_t* = nullptr> +template* = nullptr, + enable_if_vector_t* = nullptr> inline auto -cross(Sub1&& sub1, Sub2&& sub2) --> vector_cross_node< - actual_operand_type_of_t, +cross(Sub1&& sub1, + Sub2&& sub2) -> vector_cross_node, actual_operand_type_of_t> { /* Deduce the operand types of the subexpressions (&, const&, &&): */ - typedef actual_operand_type_of_t sub1_type; - typedef actual_operand_type_of_t sub2_type; - return vector_cross_node< - sub1_type, sub2_type>((sub1_type) sub1, (sub2_type) sub2); + using sub1_type = actual_operand_type_of_t; + using sub2_type = actual_operand_type_of_t; + return vector_cross_node((sub1_type) sub1, + (sub2_type) sub2); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/detail/check_or_resize.h b/cml/vector/detail/check_or_resize.h index 711af52..216b711 100644 --- a/cml/vector/detail/check_or_resize.h +++ b/cml/vector/detail/check_or_resize.h @@ -1,27 +1,20 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - * - * @note This file must be included after cml/vector/writable_vector.h. - */ #pragma once -#ifndef cml_vector_detail_check_or_resize_h -#define cml_vector_detail_check_or_resize_h - #include #include #include -namespace cml { -namespace detail { +namespace cml::detail { /* check_or_resize for a read-only vector, left, that just forwards to * check_same_size. */ -template inline void +template +inline void check_or_resize(const readable_vector& left, const Other& right) { cml::check_same_size(left, right); @@ -30,9 +23,10 @@ check_or_resize(const readable_vector& left, const Other& right) /* check_or_resize for a resizable vector, left, that resizes the vector to * ensure it has the same size as right. */ -template inline auto +template +inline auto check_or_resize(writable_vector& left, const Other& right) --> decltype(left.actual().resize(0), void()) + -> decltype(left.actual().resize(0), void()) { left.actual().resize(cml::array_size_of(right)); } @@ -40,7 +34,8 @@ check_or_resize(writable_vector& left, const Other& right) /* check_or_resize for a read-only vector left and constant size N that * just forwards to check_size. */ -template inline void +template +inline void check_or_resize(const readable_vector& sub, int_c) { cml::check_size(sub, int_c()); @@ -49,7 +44,8 @@ check_or_resize(const readable_vector& sub, int_c) /* check_or_resize for a read-only vector left and run-time size N that * just forwards to check_size. */ -template inline void +template +inline void check_or_resize(const readable_vector& sub, int N) { cml::check_size(sub, N); @@ -58,9 +54,10 @@ check_or_resize(const readable_vector& sub, int N) /* check_or_resize for a resizable vector left and compile-time size N that * resizes the vector to N. */ -template inline auto +template +inline auto check_or_resize(writable_vector& sub, int_c) --> decltype(sub.actual().resize(0), void()) + -> decltype(sub.actual().resize(0), void()) { sub.actual().resize(N); } @@ -68,21 +65,21 @@ check_or_resize(writable_vector& sub, int_c) /* check_or_resize for a resizable vector left and run-time size N that * resizes the vector to N. */ -template inline auto +template +inline auto check_or_resize(writable_vector& sub, int N) --> decltype(sub.actual().resize(0), void()) + -> decltype(sub.actual().resize(0), void()) { sub.actual().resize(N); } - /* check_or_resize for a read-only vector, left, that just forwards to * check_same_size. */ -template inline void -check_or_resize( - const readable_vector& left, const readable_vector& right - ) +template +inline void +check_or_resize(const readable_vector& left, + const readable_vector& right) { cml::check_same_size(left, right); } @@ -90,11 +87,10 @@ check_or_resize( /* check_or_resize for a resizable vector, left, that resizes the vector to * ensure it has the same size as right. */ -template inline auto -check_or_resize( - writable_vector& left, const readable_vector& right - ) --> decltype(left.actual().resize(0), void()) +template +inline auto +check_or_resize(writable_vector& left, const readable_vector& right) + -> decltype(left.actual().resize(0), void()) { left.actual().resize(cml::array_size_of(right)); } @@ -102,10 +98,10 @@ check_or_resize( /* check_or_resize for a read-only vector that verifies the size is * other.size() + sizeof(eN): */ -template inline void +template +inline void check_or_resize(const readable_vector& sub, - const readable_vector& other, const Elements&... eN - ) + const readable_vector& other, const Elements&... eN) { cml::check_size(sub, combined_size_of(other, eN...)); } @@ -113,19 +109,12 @@ check_or_resize(const readable_vector& sub, /* check_or_resize for a resizable vector that resizes the vector to * other.size() + sizeof(eN): */ -template inline auto -check_or_resize(writable_vector& sub, - const readable_vector& other, const Elements&... eN - ) --> decltype(sub.actual().resize(0), void()) +template +inline auto +check_or_resize(writable_vector& sub, const readable_vector& other, + const Elements&... eN) -> decltype(sub.actual().resize(0), void()) { sub.actual().resize(combined_size_of(other, eN...)); } -} // namespace detail -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/vector/detail/combined_size_of.h b/cml/vector/detail/combined_size_of.h index 93ab2f3..e79bdf0 100644 --- a/cml/vector/detail/combined_size_of.h +++ b/cml/vector/detail/combined_size_of.h @@ -1,55 +1,41 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_detail_combined_size_of_h -#define cml_vector_detail_combined_size_of_h - #include -namespace cml { -namespace detail { +namespace cml::detail { -template inline -enable_if_fixed_size_t::value>> +template +inline enable_if_fixed_size_t::value>> combined_size_of(const readable_vector&) { return array_size_of_c::value; } -template inline -enable_if_fixed_size_t< - Sub, cml::int_c< - cml::plus_c::value,int(sizeof...(Elements))>::value - > - > +template +inline enable_if_fixed_size_t::value, int(sizeof...(Elements))>::value>> combined_size_of(const readable_vector&, const Elements&...) { return cml::int_c::value + int(sizeof...(Elements))>(); } -template inline -enable_if_dynamic_size_t +template +inline enable_if_dynamic_size_t combined_size_of(const readable_vector& sub) { return sub.size(); } -template inline -enable_if_dynamic_size_t +template +inline enable_if_dynamic_size_t combined_size_of(const readable_vector& sub, const Elements&...) { return sub.size() + int(sizeof...(Elements)); } -} // namespace detail -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/vector/detail/resize.h b/cml/vector/detail/resize.h index e0dedf6..93eb3de 100644 --- a/cml/vector/detail/resize.h +++ b/cml/vector/detail/resize.h @@ -1,34 +1,26 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_detail_resize_h -#define cml_vector_detail_resize_h - #include -namespace cml { -namespace detail { +namespace cml::detail { /** No-op for non-resizable vector. */ -template inline void resize(readable_vector&, int) {} +template +inline void +resize(readable_vector&, int) +{} /** Resize vectors that implement resize(). */ -template inline auto resize(writable_vector& sub, int size) --> decltype(sub.actual().resize(0), void()) +template +inline auto +resize(writable_vector& sub, int size) + -> decltype(sub.actual().resize(0), void()) { sub.actual().resize(size); } -} // namespace detail - -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} diff --git a/cml/vector/dot.h b/cml/vector/dot.h index 417d71f..4f901ad 100644 --- a/cml/vector/dot.h +++ b/cml/vector/dot.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_dot_h -#define cml_vector_dot_h - #include #include @@ -24,17 +19,12 @@ namespace cml { * both are fixed-size expressions, then the sizes are checked at compile * time. */ -template auto -dot(const readable_vector& left, const readable_vector& right) --> value_type_trait_promote_t; +template +auto dot(const readable_vector& left, const readable_vector& right) + -> value_type_trait_promote_t; -} // namespace cml +} // namespace cml #define __CML_VECTOR_DOT_TPP #include #undef __CML_VECTOR_DOT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/dot.tpp b/cml/vector/dot.tpp index 285f758..2d57ff1 100644 --- a/cml/vector/dot.tpp +++ b/cml/vector/dot.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_DOT_TPP -#error "vector/dot.tpp not included correctly" +# error "vector/dot.tpp not included correctly" #endif #include @@ -13,21 +11,19 @@ namespace cml { -template inline auto +template +inline auto dot(const readable_vector& left, const readable_vector& right) --> value_type_trait_promote_t + -> value_type_trait_promote_t { - typedef value_type_trait_promote_t result_type; + using result_type = value_type_trait_promote_t; cml::check_minimum_size(left, cml::int_c<1>()); cml::check_minimum_size(right, cml::int_c<1>()); cml::check_same_size(left, right); - result_type accum = result_type(left.get(0)*right.get(0)); - for(int i = 1; i < left.size(); ++ i) - accum += result_type(left.get(i)*right.get(i)); + result_type accum = result_type(left.get(0) * right.get(0)); + for(int i = 1; i < left.size(); ++i) + accum += result_type(left.get(i) * right.get(i)); return accum; } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/dynamic.h b/cml/vector/dynamic.h index b0046bc..fa2a633 100644 --- a/cml/vector/dynamic.h +++ b/cml/vector/dynamic.h @@ -1,17 +1,7 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_dynamic_h -#define cml_vector_dynamic_h - #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/dynamic_allocated.h b/cml/vector/dynamic_allocated.h index 1e528ad..cb184c3 100644 --- a/cml/vector/dynamic_allocated.h +++ b/cml/vector/dynamic_allocated.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_dynamic_allocated_h -#define cml_vector_dynamic_allocated_h - #include #include #include @@ -18,22 +13,21 @@ namespace cml { template -struct vector_traits< vector> > +struct vector_traits>> { /* Traits and types for the vector element: */ - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef typename element_traits::pointer pointer; - typedef typename element_traits::reference reference; - typedef typename element_traits::const_pointer const_pointer; - typedef typename element_traits::const_reference const_reference; - typedef typename element_traits::mutable_value mutable_value; - typedef typename element_traits::immutable_value immutable_value; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using pointer = typename element_traits::pointer; + using reference = typename element_traits::reference; + using const_pointer = typename element_traits::const_pointer; + using const_reference = typename element_traits::const_reference; + using mutable_value = typename element_traits::mutable_value; + using immutable_value = typename element_traits::immutable_value; /* The vector storage type: */ - typedef rebind_t< - allocated, vector_storage_tag> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = rebind_t, vector_storage_tag>; + using size_tag = typename storage_type::size_tag; static_assert(std::is_same::value, "invalid size tag"); @@ -45,257 +39,243 @@ struct vector_traits< vector> > /** Resizable vector. */ template class vector> -: public writable_vector< vector> > +: public writable_vector>> { protected: + /** The real allocator type. */ + using allocator_type = cml::rebind_alloc_t; - /** The real allocator type. */ - typedef cml::rebind_alloc_t allocator_type; - - /** Allocator traits. */ - typedef std::allocator_traits allocator_traits; + /** Allocator traits. */ + using allocator_traits = std::allocator_traits; - /** Require a stateless allocator. */ - static_assert(std::is_empty::value, - "cannot use a stateful allocator for dynamic<> vectors"); + /** Require a stateless allocator. */ + static_assert(std::is_empty::value, + "cannot use a stateful allocator for dynamic<> vectors"); public: - - typedef vector> vector_type; - typedef readable_vector readable_type; - typedef writable_vector writable_type; - typedef vector_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::pointer pointer; - typedef typename traits_type::reference reference; - typedef typename traits_type::const_pointer const_pointer; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using vector_type = vector>; + using readable_type = readable_vector; + using writable_type = writable_vector; + using traits_type = vector_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using pointer = typename traits_type::pointer; + using reference = typename traits_type::reference; + using const_pointer = typename traits_type::const_pointer; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /* Include methods from writable_type: */ - using writable_type::operator[]; + /* Include methods from writable_type: */ + using writable_type::operator[]; #ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - using writable_type::operator=; + using writable_type::operator=; #endif public: - - /** Constant containing the array size. */ - static const int array_size = traits_type::array_size; + /** Constant containing the array size. */ + static const int array_size = traits_type::array_size; public: - - /** Default constructor. + /** Default constructor. * * @note The vector has no elements. */ - vector(); + vector(); - /** Construct given a size. + /** Construct given a size. * * @throws std::invalid_argument if @c size < 0. */ - template::value>* = nullptr> - explicit vector(Int size); + template::value>* = nullptr> + explicit vector(Int size); - /** Copy constructor. */ - vector(const vector_type& other); + /** Copy constructor. */ + vector(const vector_type& other); - /** Move constructor. */ - vector(vector_type&& other); + /** Move constructor. */ + vector(vector_type&& other); - /** Construct from a readable_vector. */ - template vector(const readable_vector& sub); + /** Construct from a readable_vector. */ + template vector(const readable_vector& sub); - /** Construct from at least 1 value. The vector is resized to + /** Construct from at least 1 value. The vector is resized to * accomodate the number of elements passed. * * @note This overload is enabled only if all of the arguments are * convertible to value_type. */ - template* = nullptr> - vector(const E0& e0, const Elements&... eN) - // XXX Should be in vector/dynamic_allocated.tpp, but VC++12 has - // brain-dead out-of-line template argument matching... - : m_data(0), m_size(0) - { - this->assign_elements(e0, eN...); - } - - /** Construct from a readable_vector and at least one + template* = nullptr> + vector(const E0& e0, const Elements&... eN) + // XXX Should be in vector/dynamic_allocated.tpp, but VC++12 has + // brain-dead out-of-line template argument matching... + : m_data(0) + , m_size(0) + { + this->assign_elements(e0, eN...); + } + + /** Construct from a readable_vector and at least one * additional element. The vector is resized to accomodate the total * number of elements passed. * * @note This overload is enabled only if the value_type of @c sub and * all of the scalar arguments are convertible to value_type. */ - template, E0, Elements...>* = nullptr> - vector( - const readable_vector& sub, const E0& e0, const Elements&... eN - ) - // XXX Should be in vector/fixed_compiled.tpp, but VC++12 has - // brain-dead out-of-line template argument matching... - : m_data(0), m_size(0) - { - this->assign(sub, e0, eN...); - } - - /** Construct from an array type. */ - template* = nullptr> - vector(const Array& array); - - /** Construct from a pointer to an array. */ - template* = nullptr> - vector(const Pointer& array, int size); - - /** Construct from a pointer to an array. */ - template* = nullptr> - vector(int size, const Pointer& array); - - /** Construct from std::initializer_list. */ - template vector(std::initializer_list l); - - /** Destructor. */ - ~vector(); + template, E0, + Elements...>* = nullptr> + vector(const readable_vector& sub, const E0& e0, const Elements&... eN) + // XXX Should be in vector/fixed_compiled.tpp, but VC++12 has + // brain-dead out-of-line template argument matching... + : m_data(0) + , m_size(0) + { + this->assign(sub, e0, eN...); + } + /** Construct from an array type. */ + template* = nullptr> + vector(const Array& array); - public: + /** Construct from a pointer to an array. */ + template* = nullptr> + vector(const Pointer& array, int size); + + /** Construct from a pointer to an array. */ + template* = nullptr> + vector(int size, const Pointer& array); + + /** Construct from std::initializer_list. */ + template vector(std::initializer_list l); + + /** Destructor. */ + ~vector(); - /** Return access to the vector data as a raw pointer. */ - pointer data(); - /** Return const access to the vector data as a raw pointer. */ - const_pointer data() const; + public: + /** Return access to the vector data as a raw pointer. */ + pointer data(); + + /** Return const access to the vector data as a raw pointer. */ + const_pointer data() const; - /** Read-only iterator. */ - const_pointer begin() const; + /** Read-only iterator. */ + const_pointer begin() const; - /** Read-only iterator. */ - const_pointer end() const; + /** Read-only iterator. */ + const_pointer end() const; - /** Resize the vector to the specified size. + /** Resize the vector to the specified size. * * @note This will reallocate the array and copy existing elements, if * any. * * @throws std::invalid_argument if @c n is negative. */ - void resize(int n); + void resize(int n); - /** Resize the vector to the specified size without copying the old + /** Resize the vector to the specified size without copying the old * elements. * * @throws std::invalid_argument if @c n is negative. */ - void resize_fast(int n); + void resize_fast(int n); public: + /** Copy assignment. */ + vector_type& operator=(const vector_type& other); - /** Copy assignment. */ - vector_type& operator=(const vector_type& other); - - /** Move assignment. */ - vector_type& operator=(vector_type&& other); + /** Move assignment. */ + vector_type& operator=(vector_type&& other); #ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline vector_type& operator=(const readable_vector& other) { - return this->assign(other); - } - - template* = nullptr> - inline vector_type& operator=(const Array& array) { - return this->assign(array); - } - - template - inline vector_type& operator=(std::initializer_list l) { - return this->assign(l); - } + template + inline vector_type& operator=(const readable_vector& other) + { + return this->assign(other); + } + + template* = nullptr> + inline vector_type& operator=(const Array& array) + { + return this->assign(array); + } + + template + inline vector_type& operator=(std::initializer_list l) + { + return this->assign(l); + } #endif protected: - - /** No-op for trivially destructible elements + /** No-op for trivially destructible elements * (is_trivially_destructible). */ - void destruct(pointer, int, std::true_type); + void destruct(pointer, int, std::true_type); - /** Invoke non-trivial destructors for @c n elements starting at @c + /** Invoke non-trivial destructors for @c n elements starting at @c * data. */ - void destruct(pointer data, int n, std::false_type); + void destruct(pointer data, int n, std::false_type); protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the length of the vector. */ - int i_size() const; + /** Return the length of the vector. */ + int i_size() const; - /** Return vector const element @c i. */ - immutable_value i_get(int i) const; + /** Return vector const element @c i. */ + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: + /** @name writable_vector Interface */ + /*@{*/ - /** @name writable_vector Interface */ - /*@{*/ + friend writable_type; - friend writable_type; + /** Return vector element @c i. */ + mutable_value i_get(int i); - /** Return vector element @c i. */ - mutable_value i_get(int i); - - /** Set element @c i. */ - template vector_type& i_put(int i, const Other& v) __CML_REF; + /** Set element @c i. */ + template vector_type& i_put(int i, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i on a temporary. */ - template vector_type&& i_put(int i, const Other& v) &&; + /** Set element @c i on a temporary. */ + template vector_type&& i_put(int i, const Other& v) &&; #endif - /*@}*/ + /*@}*/ protected: + /** Dynamic storage. */ + pointer m_data; - /** Dynamic storage. */ - pointer m_data; - - /** Size of the vector. */ - int m_size; + /** Size of the vector. */ + int m_size; }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_DYNAMIC_ALLOCATED_TPP #include #undef __CML_VECTOR_DYNAMIC_ALLOCATED_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/dynamic_allocated.tpp b/cml/vector/dynamic_allocated.tpp index f140ec0..3beb6f0 100644 --- a/cml/vector/dynamic_allocated.tpp +++ b/cml/vector/dynamic_allocated.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_DYNAMIC_ALLOCATED_TPP -#error "vector/dynamic_allocated.tpp not included correctly" +# error "vector/dynamic_allocated.tpp not included correctly" #endif #include @@ -16,35 +14,40 @@ namespace cml { template vector>::vector() -: m_data(0), m_size(0) -{ -} +: m_data(0) +, m_size(0) +{} template template::value>*> vector>::vector(Int size) -: m_data(0), m_size(0) +: m_data(0) +, m_size(0) { this->resize_fast(int(size)); } template vector>::vector(const vector_type& other) -: m_data(0), m_size(0) +: m_data(0) +, m_size(0) { this->assign(other); } template vector>::vector(vector_type&& other) -: m_data(0), m_size(0) +: m_data(0) +, m_size(0) { this->operator=(std::move(other)); } -template template +template +template vector>::vector(const readable_vector& sub) -: m_data(0), m_size(0) +: m_data(0) +, m_size(0) { this->assign(sub); } @@ -52,7 +55,8 @@ vector>::vector(const readable_vector& sub) template template*> vector>::vector(const Array& array) -: m_data(0), m_size(0) +: m_data(0) +, m_size(0) { this->assign(array); } @@ -60,7 +64,8 @@ vector>::vector(const Array& array) template template*> vector>::vector(const Pointer& array, int size) -: m_data(0), m_size(0) +: m_data(0) +, m_size(0) { this->resize_fast(size); this->assign(array); @@ -69,23 +74,25 @@ vector>::vector(const Pointer& array, int size) template template*> vector>::vector(int size, const Pointer& array) -: m_data(0), m_size(0) +: m_data(0) +, m_size(0) { this->resize_fast(size); this->assign(array); } -template template +template +template vector>::vector(std::initializer_list l) -: m_data(0), m_size(0) +: m_data(0) +, m_size(0) { this->assign(l); } -template -vector>::~vector() +template vector>::~vector() { - typedef typename allocator_traits::size_type size_type; + using size_type = typename allocator_traits::size_type; int n = this->m_size; this->destruct(this->m_data, n, typename std::is_trivially_destructible::type()); @@ -94,35 +101,38 @@ vector>::~vector() allocator_traits::deallocate(allocator, this->m_data, size_type(n)); } - - /* Public methods: */ -template auto +template +auto vector>::data() -> pointer { return this->m_data; } -template auto +template +auto vector>::data() const -> const_pointer { return this->m_data; } -template auto +template +auto vector>::begin() const -> const_pointer { return this->m_data; } -template auto +template +auto vector>::end() const -> const_pointer { return this->m_data + this->m_size; } -template void +template +void vector>::resize(int n) { cml_require(n >= 0, std::invalid_argument, "size < 0"); @@ -138,7 +148,6 @@ vector>::resize(int n) int size = this->m_size; pointer copy = allocator_traits::allocate(allocator, n); try { - /* Destruct elements if necessary: */ this->destruct(data, size, typename std::is_trivially_destructible::type()); @@ -146,15 +155,15 @@ vector>::resize(int n) /* Copy elements to the new array if necessary: */ if(data) { int to = std::min(size, n); - for(pointer src = data, dst = copy; src < data + to; ++ src, ++ dst) { - allocator_traits::construct(allocator, dst, *src); + for(pointer src = data, dst = copy; src < data + to; ++src, ++dst) { + allocator_traits::construct(allocator, dst, *src); } /* Deallocate the old array: */ allocator_traits::deallocate(allocator, data, size); } } catch(...) { - allocator_traits::deallocate(allocator,copy,n); + allocator_traits::deallocate(allocator, copy, n); throw; } @@ -163,7 +172,8 @@ vector>::resize(int n) this->m_size = n; } -template void +template +void vector>::resize_fast(int n) { cml_require(n >= 0, std::invalid_argument, "size < 0"); @@ -179,15 +189,14 @@ vector>::resize_fast(int n) int size = this->m_size; pointer copy = allocator_traits::allocate(allocator, n); try { - /* Destruct elements if necessary: */ this->destruct(data, size, typename std::is_trivially_destructible::type()); /* Deallocate the old array: */ - allocator_traits::deallocate(allocator,data,size); + allocator_traits::deallocate(allocator, data, size); } catch(...) { - allocator_traits::deallocate(allocator,copy,n); + allocator_traits::deallocate(allocator, copy, n); throw; } @@ -196,14 +205,15 @@ vector>::resize_fast(int n) this->m_size = n; } - -template auto +template +auto vector>::operator=(const vector_type& other) -> vector_type& { return this->assign(other); } -template auto +template +auto vector>::operator=(vector_type&& other) -> vector_type& { /* Ensure deletion of the current array, if any: */ @@ -214,17 +224,17 @@ vector>::operator=(vector_type&& other) -> vector_type& return *this; } - - /* Internal methods: */ -template void +template +void vector>::destruct(pointer, int, std::true_type) { /* Nothing to do. */ } -template void +template +void vector>::destruct(pointer data, int n, std::false_type) { /* Short-circuit null: */ @@ -233,44 +243,49 @@ vector>::destruct(pointer data, int n, std::false_type) /* Destruct each element: */ else { auto allocator = allocator_type(); - for(pointer e = data; e < data + n; ++ e) - allocator_traits::destroy(allocator,e); + for(pointer e = data; e < data + n; ++e) + allocator_traits::destroy(allocator, e); } } - /* readable_vector interface: */ -template int +template +int vector>::i_size() const { return this->m_size; } -template auto +template +auto vector>::i_get(int i) const -> immutable_value { return this->m_data[i]; } - /* writable_vector interface: */ -template auto +template +auto vector>::i_get(int i) -> mutable_value { return this->m_data[i]; } -template template auto -vector>::i_put(int i, const Other& v) __CML_REF -> vector_type& +template +template +auto +vector>::i_put(int i, const Other& v) __CML_REF->vector_type& { this->m_data[i] = value_type(v); return *this; } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template auto +template +template +auto vector>::i_put(int i, const Other& v) && -> vector_type&& { this->m_data[i] = value_type(v); @@ -278,7 +293,4 @@ vector>::i_put(int i, const Other& v) && -> vector_type&& } #endif -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/dynamic_const_external.h b/cml/vector/dynamic_const_external.h index a5692ec..c4a4833 100644 --- a/cml/vector/dynamic_const_external.h +++ b/cml/vector/dynamic_const_external.h @@ -1,33 +1,27 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_dynamic_const_external_h -#define cml_vector_dynamic_const_external_h - #include #include #include namespace cml { -template -struct vector_traits< vector> > +template struct vector_traits>> { /* Traits and types for the vector element: */ - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef typename element_traits::const_pointer const_pointer; - typedef typename element_traits::const_reference const_reference; - typedef typename element_traits::immutable_value immutable_value; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using const_pointer = typename element_traits::const_pointer; + using const_reference = typename element_traits::const_reference; + using immutable_value = typename element_traits::immutable_value; /* The vector storage type: */ - typedef rebind_t, vector_storage_tag> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = rebind_t, vector_storage_tag>; + using size_tag = typename storage_type::size_tag; static_assert(std::is_same::value, "invalid size tag"); @@ -39,94 +33,83 @@ struct vector_traits< vector> > /** Runtime-length wrapped array pointer as a vector. */ template class vector> -: public readable_vector< vector> > +: public readable_vector>> { public: - - typedef vector> vector_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::const_pointer const_pointer; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using vector_type = vector>; + using readable_type = readable_vector; + using traits_type = vector_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using const_pointer = typename traits_type::const_pointer; + using const_reference = typename traits_type::const_reference; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** Constant containing the array size. */ - static const int array_size = -1; + /** Constant containing the array size. */ + static const int array_size = -1; public: - - /** Default construct with a null pointer and 0 size. + /** Default construct with a null pointer and 0 size. * * @warning The default constructor is enabled only if the compiler * supports rvalue references from *this. */ - vector(); + vector(); - /** Construct from the wrapped pointer and size. */ - vector(const_pointer data, int size); + /** Construct from the wrapped pointer and size. */ + vector(const_pointer data, int size); - /** Construct from the wrapped pointer and size. */ - vector(int size, const_pointer data); + /** Construct from the wrapped pointer and size. */ + vector(int size, const_pointer data); - /** Move constructor. */ - vector(vector_type&& other); + /** Move constructor. */ + vector(vector_type&& other); public: + /** Return const access to the vector data as a raw pointer. */ + const_pointer data() const; - /** Return const access to the vector data as a raw pointer. */ - const_pointer data() const; + /** Read-only iterator. */ + const_pointer begin() const; - /** Read-only iterator. */ - const_pointer begin() const; + /** Read-only iterator. */ + const_pointer end() const; - /** Read-only iterator. */ - const_pointer end() const; - - /** Reset the vector to have no elements and no external pointer. */ - void reset(); + /** Reset the vector to have no elements and no external pointer. */ + void reset(); protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the length of the vector. */ - int i_size() const; + /** Return the length of the vector. */ + int i_size() const; - /** Return vector const element @c i. */ - immutable_value i_get(int i) const; + /** Return vector const element @c i. */ + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: + /** Wrapped pointer. */ + const_pointer m_data; - /** Wrapped pointer. */ - const_pointer m_data; - - /** Number of elements. */ - int m_size; + /** Number of elements. */ + int m_size; }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_DYNAMIC_CONST_EXTERNAL_TPP #include #undef __CML_VECTOR_DYNAMIC_CONST_EXTERNAL_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/dynamic_const_external.tpp b/cml/vector/dynamic_const_external.tpp index ee1d17c..71dd778 100644 --- a/cml/vector/dynamic_const_external.tpp +++ b/cml/vector/dynamic_const_external.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_DYNAMIC_CONST_EXTERNAL_TPP -#error "vector/dynamic_const_external.tpp not included correctly" +# error "vector/dynamic_const_external.tpp not included correctly" #endif #include @@ -17,27 +15,28 @@ namespace cml { #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template vector>::vector() -: m_data(0), m_size(0) -{ -} +: m_data(0) +, m_size(0) +{} #endif template vector>::vector(const_pointer data, int size) -: m_data(data), m_size(size) +: m_data(data) +, m_size(size) { cml_require(size >= 0, std::invalid_argument, "size < 0"); } template vector>::vector(int size, const_pointer data) -: m_data(data), m_size(size) +: m_data(data) +, m_size(size) { cml_require(size >= 0, std::invalid_argument, "size < 0"); } -template -vector>::vector(vector_type&& other) +template vector>::vector(vector_type&& other) { this->m_data = other.m_data; this->m_size = other.m_size; @@ -45,54 +44,53 @@ vector>::vector(vector_type&& other) other.m_size = 0; } - - /* Public methods: */ -template auto +template +auto vector>::data() const -> const_pointer { return this->m_data; } -template auto +template +auto vector>::begin() const -> const_pointer { return this->m_data; } -template auto +template +auto vector>::end() const -> const_pointer { return this->m_data + this->m_size; } -template void +template +void vector>::reset() { this->m_size = 0; this->m_data = nullptr; } - - /* Internal methods: */ /* readable_vector interface: */ -template int +template +int vector>::i_size() const { return this->m_size; } -template auto +template +auto vector>::i_get(int i) const -> immutable_value { return this->m_data[i]; } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/dynamic_external.h b/cml/vector/dynamic_external.h index 5bd2000..7952c1f 100644 --- a/cml/vector/dynamic_external.h +++ b/cml/vector/dynamic_external.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_dynamic_external_h -#define cml_vector_dynamic_external_h - #include #include #include @@ -20,22 +15,21 @@ namespace cml { -template -struct vector_traits< vector> > +template struct vector_traits>> { /* Traits and types for the vector element: */ - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef typename element_traits::pointer pointer; - typedef typename element_traits::reference reference; - typedef typename element_traits::const_pointer const_pointer; - typedef typename element_traits::const_reference const_reference; - typedef typename element_traits::mutable_value mutable_value; - typedef typename element_traits::immutable_value immutable_value; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using pointer = typename element_traits::pointer; + using reference = typename element_traits::reference; + using const_pointer = typename element_traits::const_pointer; + using const_reference = typename element_traits::const_reference; + using mutable_value = typename element_traits::mutable_value; + using immutable_value = typename element_traits::immutable_value; /* The vector storage type: */ - typedef rebind_t, vector_storage_tag> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = rebind_t, vector_storage_tag>; + using size_tag = typename storage_type::size_tag; static_assert(std::is_same::value, "invalid size tag"); @@ -47,170 +41,159 @@ struct vector_traits< vector> > /** Runtime-length wrapped array pointer as a vector. */ template class vector> -: public writable_vector< vector> > +: public writable_vector>> { public: - - typedef vector> vector_type; - typedef readable_vector readable_type; - typedef writable_vector writable_type; - typedef vector_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::pointer pointer; - typedef typename traits_type::reference reference; - typedef typename traits_type::const_pointer const_pointer; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using vector_type = vector>; + using readable_type = readable_vector; + using writable_type = writable_vector; + using traits_type = vector_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using pointer = typename traits_type::pointer; + using reference = typename traits_type::reference; + using const_pointer = typename traits_type::const_pointer; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /* Include methods from writable_type: */ - using writable_type::operator[]; + /* Include methods from writable_type: */ + using writable_type::operator[]; #ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - using writable_type::operator=; + using writable_type::operator=; #endif public: - - /** Constant containing the array size. */ - static const int array_size = -1; + /** Constant containing the array size. */ + static const int array_size = -1; public: - - /** Default construct with a null pointer and 0 size. + /** Default construct with a null pointer and 0 size. * * @warning The default constructor is enabled only if the compiler * supports rvalue references from *this. */ - vector(); + vector(); - /** Construct from the wrapped pointer and size. + /** Construct from the wrapped pointer and size. * * @note This is for CML1 compatibility. */ - vector(pointer data, int size); + vector(pointer data, int size); - /** Construct from the wrapped pointer and size. */ - vector(int size, pointer data); + /** Construct from the wrapped pointer and size. */ + vector(int size, pointer data); - /** Copy constructor. + /** Copy constructor. * * @warning This copy has the semantics of a raw pointer, and can lead * to memory leaks if not used correctly. */ - vector(const vector_type& other); + vector(const vector_type& other); - /** Move constructor. */ - vector(vector_type&& other); + /** Move constructor. */ + vector(vector_type&& other); public: + /** Return access to the vector data as a raw pointer. */ + pointer data(); - /** Return access to the vector data as a raw pointer. */ - pointer data(); - - /** Return const access to the vector data as a raw pointer. */ - const_pointer data() const; + /** Return const access to the vector data as a raw pointer. */ + const_pointer data() const; - /** Read-only iterator. */ - const_pointer begin() const; + /** Read-only iterator. */ + const_pointer begin() const; - /** Read-only iterator. */ - const_pointer end() const; + /** Read-only iterator. */ + const_pointer end() const; - /** Reset the vector to have no elements and no external pointer. */ - void reset(); + /** Reset the vector to have no elements and no external pointer. */ + void reset(); public: - - /** Copy assignment. + /** Copy assignment. * * @note This copies element-by-element from @c other. */ - vector_type& operator=(const vector_type& other); + vector_type& operator=(const vector_type& other); - /** Move assignment. */ - vector_type& operator=(vector_type&& other); + /** Move assignment. */ + vector_type& operator=(vector_type&& other); #ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline vector_type& operator=(const readable_vector& other) { - return this->assign(other); - } - - template* = nullptr> - inline vector_type& operator=(const Array& array) { - return this->assign(array); - } - - template - inline vector_type& operator=(std::initializer_list l) { - return this->assign(l); - } + template + inline vector_type& operator=(const readable_vector& other) + { + return this->assign(other); + } + + template* = nullptr> + inline vector_type& operator=(const Array& array) + { + return this->assign(array); + } + + template + inline vector_type& operator=(std::initializer_list l) + { + return this->assign(l); + } #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the length of the vector. */ - int i_size() const; + /** Return the length of the vector. */ + int i_size() const; - /** Return vector const element @c i. */ - immutable_value i_get(int i) const; + /** Return vector const element @c i. */ + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: + /** @name writable_vector Interface */ + /*@{*/ - /** @name writable_vector Interface */ - /*@{*/ + friend writable_type; - friend writable_type; + /** Return vector element @c i. */ + mutable_value i_get(int i); - /** Return vector element @c i. */ - mutable_value i_get(int i); - - /** Set element @c i. */ - template vector_type& i_put(int i, const Other& v) __CML_REF; + /** Set element @c i. */ + template vector_type& i_put(int i, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i on a temporary. */ - template vector_type&& i_put(int i, const Other& v) &&; + /** Set element @c i on a temporary. */ + template vector_type&& i_put(int i, const Other& v) &&; #endif - /*@}*/ + /*@}*/ protected: + /** Wrapped pointer. */ + pointer m_data; - /** Wrapped pointer. */ - pointer m_data; - - /** Number of elements. */ - int m_size; + /** Number of elements. */ + int m_size; }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_DYNAMIC_EXTERNAL_TPP #include #undef __CML_VECTOR_DYNAMIC_EXTERNAL_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/dynamic_external.tpp b/cml/vector/dynamic_external.tpp index 2a8e694..c6d1a4e 100644 --- a/cml/vector/dynamic_external.tpp +++ b/cml/vector/dynamic_external.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_DYNAMIC_EXTERNAL_TPP -#error "vector/dynamic_external.tpp not included correctly" +# error "vector/dynamic_external.tpp not included correctly" #endif #include @@ -16,7 +14,8 @@ namespace cml { template vector>::vector() -: m_data(0), m_size(0) +: m_data(0) +, m_size(0) { #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS static_assert(false, "external vector default constructor not supported"); @@ -25,27 +24,27 @@ vector>::vector() template vector>::vector(pointer data, int size) -: m_data(data), m_size(size) +: m_data(data) +, m_size(size) { cml_require(size >= 0, std::invalid_argument, "size < 0"); } template vector>::vector(int size, pointer data) -: m_data(data), m_size(size) +: m_data(data) +, m_size(size) { cml_require(size >= 0, std::invalid_argument, "size < 0"); } -template -vector>::vector(const vector_type& other) +template vector>::vector(const vector_type& other) { this->m_data = other.m_data; this->m_size = other.m_size; } -template -vector>::vector(vector_type&& other) +template vector>::vector(vector_type&& other) { this->m_data = other.m_data; this->m_size = other.m_size; @@ -53,49 +52,53 @@ vector>::vector(vector_type&& other) other.m_size = 0; } - - /* Public methods: */ -template auto +template +auto vector>::data() -> pointer { return this->m_data; } -template auto +template +auto vector>::data() const -> const_pointer { return this->m_data; } -template auto +template +auto vector>::begin() const -> const_pointer { return this->m_data; } -template auto +template +auto vector>::end() const -> const_pointer { return this->m_data + this->m_size; } -template void +template +void vector>::reset() { this->m_size = 0; this->m_data = nullptr; } - -template auto +template +auto vector>::operator=(const vector_type& other) -> vector_type& { return this->assign(other); } -template auto +template +auto vector>::operator=(vector_type&& other) -> vector_type& { this->m_data = other.m_data; @@ -105,42 +108,46 @@ vector>::operator=(vector_type&& other) -> vector_type& return *this; } - - /* Internal methods: */ /* readable_vector interface: */ -template int +template +int vector>::i_size() const { return this->m_size; } -template auto +template +auto vector>::i_get(int i) const -> immutable_value { return this->m_data[i]; } - /* writable_vector interface: */ -template auto +template +auto vector>::i_get(int i) -> mutable_value { return this->m_data[i]; } -template template auto -vector>::i_put(int i, const Other& v) __CML_REF -> vector_type& +template +template +auto +vector>::i_put(int i, const Other& v) __CML_REF->vector_type& { this->m_data[i] = value_type(v); return *this; } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template auto +template +template +auto vector>::i_put(int i, const Other& v) && -> vector_type&& { this->m_data[i] = value_type(v); @@ -148,7 +155,4 @@ vector>::i_put(int i, const Other& v) && -> vector_type&& } #endif -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/external.h b/cml/vector/external.h index a66acde..56b4020 100644 --- a/cml/vector/external.h +++ b/cml/vector/external.h @@ -1,18 +1,8 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_external_h -#define cml_vector_external_h - #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/fixed.h b/cml/vector/fixed.h index 76e1cec..192d9af 100644 --- a/cml/vector/fixed.h +++ b/cml/vector/fixed.h @@ -1,17 +1,7 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_fixed_h -#define cml_vector_fixed_h - #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/fixed_compiled.h b/cml/vector/fixed_compiled.h index f690da3..d8efd4e 100644 --- a/cml/vector/fixed_compiled.h +++ b/cml/vector/fixed_compiled.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_fixed_compiled_h -#define cml_vector_fixed_compiled_h - #include #include #include @@ -16,21 +11,21 @@ namespace cml { template -struct vector_traits< vector> > +struct vector_traits>> { /* Traits and types for the vector element: */ - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef typename element_traits::pointer pointer; - typedef typename element_traits::reference reference; - typedef typename element_traits::const_pointer const_pointer; - typedef typename element_traits::const_reference const_reference; - typedef typename element_traits::mutable_value mutable_value; - typedef typename element_traits::immutable_value immutable_value; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using pointer = typename element_traits::pointer; + using reference = typename element_traits::reference; + using const_pointer = typename element_traits::const_pointer; + using const_reference = typename element_traits::const_reference; + using mutable_value = typename element_traits::mutable_value; + using immutable_value = typename element_traits::immutable_value; /* The vector storage type: */ - typedef rebind_t, vector_storage_tag> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = rebind_t, vector_storage_tag>; + using size_tag = typename storage_type::size_tag; static_assert(std::is_same::value, "invalid size tag"); @@ -42,195 +37,187 @@ struct vector_traits< vector> > /** Fixed-length vector. */ template class vector> -: public writable_vector< vector> > +: public writable_vector>> { public: - - typedef vector> vector_type; - typedef readable_vector readable_type; - typedef writable_vector writable_type; - typedef vector_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::pointer pointer; - typedef typename traits_type::reference reference; - typedef typename traits_type::const_pointer const_pointer; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using vector_type = vector>; + using readable_type = readable_vector; + using writable_type = writable_vector; + using traits_type = vector_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using pointer = typename traits_type::pointer; + using reference = typename traits_type::reference; + using const_pointer = typename traits_type::const_pointer; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /* Include methods from writable_type: */ - using writable_type::operator[]; + /* Include methods from writable_type: */ + using writable_type::operator[]; #ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - using writable_type::operator=; + using writable_type::operator=; #endif public: + /** Constant containing the array size. */ + static const int array_size = traits_type::array_size; - /** Constant containing the array size. */ - static const int array_size = traits_type::array_size; - - /** The dimension (same as array_size). */ - static const int dimension = array_size; + /** The dimension (same as array_size). */ + static const int dimension = array_size; public: - - /** Compiler-default constructor. + /** Compiler-default constructor. * * @note The vector elements are uninitialized. */ - vector() = default; + vector() = default; - /** Compiler-default destructor. */ - ~vector() = default; + /** Compiler-default destructor. */ + ~vector() = default; - /** Compiler-default copy constructor. */ - vector(const vector_type& other) = default; + /** Compiler-default copy constructor. */ + vector(const vector_type& other) = default; #ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR - /** Compiler-default move constructor. */ - vector(vector_type&& other) = default; + /** Compiler-default move constructor. */ + vector(vector_type&& other) = default; #endif - /** Construct from a readable_vector. */ - template vector(const readable_vector& sub); + /** Construct from a readable_vector. */ + template vector(const readable_vector& sub); - /** Construct from at least 1 value. + /** Construct from at least 1 value. * * @note This overload is enabled only if all of the arguments are * convertible to value_type. */ - template* = nullptr> - vector(const E0& e0, const Elements&... eN) - // XXX Should be in vector/fixed_compiled.tpp, but VC++12 has - // brain-dead out-of-line template argument matching... - { - this->assign_elements(e0, eN...); - } - - /** Construct from a readable_vector and at least one + template* = nullptr> + vector(const E0& e0, const Elements&... eN) + // XXX Should be in vector/fixed_compiled.tpp, but VC++12 has + // brain-dead out-of-line template argument matching... + { + this->assign_elements(e0, eN...); + } + + /** Construct from a readable_vector and at least one * additional element. * * @note This overload is enabled only if the value_type of @c sub and * all of the scalar arguments are convertible to value_type. */ - template, E0, Elements...>* = nullptr> - vector( - const readable_vector& sub, const E0& e0, const Elements&... eN - ) - // XXX Should be in vector/fixed_compiled.tpp, but VC++12 has - // brain-dead out-of-line template argument matching... - { - this->assign(sub, e0, eN...); - } - - /** Construct from an array type. */ - template* = nullptr> - vector(const Array& array); - - /** Construct from a pointer to an array. */ - template* = nullptr> - vector(const Pointer& array); - - /** Construct from std::initializer_list. */ - template vector(std::initializer_list l); + template, E0, + Elements...>* = nullptr> + vector(const readable_vector& sub, const E0& e0, const Elements&... eN) + // XXX Should be in vector/fixed_compiled.tpp, but VC++12 has + // brain-dead out-of-line template argument matching... + { + this->assign(sub, e0, eN...); + } + /** Construct from an array type. */ + template* = nullptr> + vector(const Array& array); - public: + /** Construct from a pointer to an array. */ + template* = nullptr> + vector(const Pointer& array); - /** Return access to the vector data as a raw pointer. */ - pointer data(); + /** Construct from std::initializer_list. */ + template vector(std::initializer_list l); - /** Return const access to the vector data as a raw pointer. */ - const_pointer data() const; - /** Read-only iterator. */ - const_pointer begin() const; + public: + /** Return access to the vector data as a raw pointer. */ + pointer data(); - /** Read-only iterator. */ - const_pointer end() const; + /** Return const access to the vector data as a raw pointer. */ + const_pointer data() const; + /** Read-only iterator. */ + const_pointer begin() const; - public: + /** Read-only iterator. */ + const_pointer end() const; - /** Copy assignment. */ - vector_type& operator=(const vector_type& other); - /** Move assignment. */ - vector_type& operator=(vector_type&& other); + public: + /** Copy assignment. */ + vector_type& operator=(const vector_type& other); + + /** Move assignment. */ + vector_type& operator=(vector_type&& other); #ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline vector_type& operator=(const readable_vector& other) { - return this->assign(other); - } - - template* = nullptr> - inline vector_type& operator=(const Array& array) { - return this->assign(array); - } - - template - inline vector_type& operator=(std::initializer_list l) { - return this->assign(l); - } + template + inline vector_type& operator=(const readable_vector& other) + { + return this->assign(other); + } + + template* = nullptr> + inline vector_type& operator=(const Array& array) + { + return this->assign(array); + } + + template + inline vector_type& operator=(std::initializer_list l) + { + return this->assign(l); + } #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ + friend readable_type; - friend readable_type; + /** Return the length of the vector. */ + int i_size() const; - /** Return the length of the vector. */ - int i_size() const; + /** Return vector const element @c i. */ + immutable_value i_get(int i) const; - /** Return vector const element @c i. */ - immutable_value i_get(int i) const; - - /*@}*/ + /*@}*/ protected: + /** @name writable_vector Interface */ + /*@{*/ - /** @name writable_vector Interface */ - /*@{*/ - - friend writable_type; + friend writable_type; - /** Return vector element @c i. */ - mutable_value i_get(int i); + /** Return vector element @c i. */ + mutable_value i_get(int i); - /** Set element @c i. */ - template vector_type& i_put(int i, const Other& v) __CML_REF; + /** Set element @c i. */ + template vector_type& i_put(int i, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i on a temporary. */ - template vector_type&& i_put(int i, const Other& v) &&; + /** Set element @c i on a temporary. */ + template vector_type&& i_put(int i, const Other& v) &&; #endif - /*@}*/ + /*@}*/ protected: - - /** Fixed-length array. */ - value_type m_data[Size]; + /** Fixed-length array. */ + value_type m_data[Size]; }; -} // namespace cml +} // namespace cml #ifdef CML_HAS_STRUCTURED_BINDINGS template @@ -249,8 +236,3 @@ struct std::tuple_element>> #define __CML_VECTOR_FIXED_COMPILED_TPP #include #undef __CML_VECTOR_FIXED_COMPILED_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/fixed_compiled.tpp b/cml/vector/fixed_compiled.tpp index b1bc062..04c6f8d 100644 --- a/cml/vector/fixed_compiled.tpp +++ b/cml/vector/fixed_compiled.tpp @@ -1,18 +1,17 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_FIXED_COMPILED_TPP -#error "vector/fixed_compiled.tpp not included correctly" +# error "vector/fixed_compiled.tpp not included correctly" #endif namespace cml { /* fixed 'structors: */ -template template +template +template vector>::vector(const readable_vector& sub) { this->assign(sub); @@ -32,91 +31,98 @@ vector>::vector(const Pointer& array) this->assign(array); } -template template +template +template vector>::vector(std::initializer_list l) { this->assign(l); } - - /* Public methods: */ -template auto +template +auto vector>::data() -> pointer { return &this->m_data[0]; } -template auto +template +auto vector>::data() const -> const_pointer { return &this->m_data[0]; } -template auto +template +auto vector>::begin() const -> const_pointer { return &this->m_data[0]; } -template auto +template +auto vector>::end() const -> const_pointer { return (&this->m_data[0]) + S; } -template auto -vector>::operator=(const vector_type& other) --> vector_type& +template +auto +vector>::operator=(const vector_type& other) -> vector_type& { return this->assign(other); } -template auto -vector>::operator=(vector_type&& other) --> vector_type& +template +auto +vector>::operator=(vector_type&& other) -> vector_type& { - for(int i = 0; i < S; ++ i) this->m_data[i] = std::move(other.m_data[i]); + for(int i = 0; i < S; ++i) this->m_data[i] = std::move(other.m_data[i]); return *this; } - - /* Internal methods: */ /* readable_vector interface: */ -template int +template +int vector>::i_size() const { return S; } -template auto +template +auto vector>::i_get(int i) const -> immutable_value { return this->m_data[i]; } - /* writable_vector interface: */ -template auto +template +auto vector>::i_get(int i) -> mutable_value { return this->m_data[i]; } -template template auto -vector>::i_put(int i, const Other& v) __CML_REF -> vector_type& +template +template +auto +vector>::i_put(int i, const Other& v) __CML_REF->vector_type& { this->m_data[i] = value_type(v); return *this; } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template auto +template +template +auto vector>::i_put(int i, const Other& v) && -> vector_type&& { this->m_data[i] = value_type(v); @@ -124,7 +130,4 @@ vector>::i_put(int i, const Other& v) && -> vector_type&& } #endif -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/fixed_const_external.h b/cml/vector/fixed_const_external.h index 1508b9b..d0f6e52 100644 --- a/cml/vector/fixed_const_external.h +++ b/cml/vector/fixed_const_external.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_fixed_const_external_h -#define cml_vector_fixed_const_external_h - #include #include #include @@ -16,18 +11,18 @@ namespace cml { template -struct vector_traits< vector> > +struct vector_traits>> { /* Traits and types for the vector element: */ - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef typename element_traits::const_pointer const_pointer; - typedef typename element_traits::const_reference const_reference; - typedef typename element_traits::immutable_value immutable_value; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using const_pointer = typename element_traits::const_pointer; + using const_reference = typename element_traits::const_reference; + using immutable_value = typename element_traits::immutable_value; /* The vector storage type: */ - typedef rebind_t, vector_storage_tag> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = rebind_t, vector_storage_tag>; + using size_tag = typename storage_type::size_tag; static_assert(std::is_same::value, "invalid size tag"); @@ -39,88 +34,77 @@ struct vector_traits< vector> > /** Fixed-length wrapped array pointer as a vector. */ template class vector> -: public readable_vector< vector> > +: public readable_vector>> { public: - - typedef vector> vector_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::const_pointer const_pointer; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using vector_type = vector>; + using readable_type = readable_vector; + using traits_type = vector_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using const_pointer = typename traits_type::const_pointer; + using const_reference = typename traits_type::const_reference; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: + /** Constant containing the array size. */ + static const int array_size = traits_type::array_size; - /** Constant containing the array size. */ - static const int array_size = traits_type::array_size; - - /** The dimension (same as array_size). */ - static const int dimension = array_size; + /** The dimension (same as array_size). */ + static const int dimension = array_size; public: - - /** Default construct with a null pointer. + /** Default construct with a null pointer. * * @warning The default constructor is enabled only if the compiler * supports rvalue references from *this. */ - vector(); + vector(); - /** Construct from the wrapped pointer. */ - explicit vector(const_pointer data); + /** Construct from the wrapped pointer. */ + explicit vector(const_pointer data); - /** Move constructor. */ - vector(vector_type&& other); + /** Move constructor. */ + vector(vector_type&& other); public: + /** Return const access to the vector data as a raw pointer. */ + const_pointer data() const; - /** Return const access to the vector data as a raw pointer. */ - const_pointer data() const; - - /** Read-only iterator. */ - const_pointer begin() const; + /** Read-only iterator. */ + const_pointer begin() const; - /** Read-only iterator. */ - const_pointer end() const; + /** Read-only iterator. */ + const_pointer end() const; protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ + friend readable_type; - friend readable_type; + /** Return the length of the vector. */ + int i_size() const; - /** Return the length of the vector. */ - int i_size() const; + /** Return vector const element @c i. */ + immutable_value i_get(int i) const; - /** Return vector const element @c i. */ - immutable_value i_get(int i) const; - - /*@}*/ + /*@}*/ protected: - - /** Wrapped pointer. */ - const_pointer m_data; + /** Wrapped pointer. */ + const_pointer m_data; }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_FIXED_CONST_EXTERNAL_TPP #include #undef __CML_VECTOR_FIXED_CONST_EXTERNAL_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/fixed_const_external.tpp b/cml/vector/fixed_const_external.tpp index eaa63b3..89ab611 100644 --- a/cml/vector/fixed_const_external.tpp +++ b/cml/vector/fixed_const_external.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_FIXED_CONST_EXTERNAL_TPP -#error "vector/fixed_const_external.tpp not included correctly" +# error "vector/fixed_const_external.tpp not included correctly" #endif namespace cml { @@ -16,15 +14,13 @@ namespace cml { template vector>::vector() : m_data(0) -{ -} +{} #endif template vector>::vector(const_pointer data) : m_data(data) -{ -} +{} template vector>::vector(vector_type&& other) @@ -33,47 +29,45 @@ vector>::vector(vector_type&& other) other.m_data = nullptr; } - - /* Public methods: */ -template auto +template +auto vector>::data() const -> const_pointer { return this->m_data; } -template auto +template +auto vector>::begin() const -> const_pointer { return this->m_data; } -template auto +template +auto vector>::end() const -> const_pointer { return this->m_data + S; } - - /* Internal methods: */ /* readable_vector interface: */ -template int +template +int vector>::i_size() const { return S; } -template auto +template +auto vector>::i_get(int i) const -> immutable_value { return this->m_data[i]; } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/fixed_external.h b/cml/vector/fixed_external.h index 03b90c9..0dec1e0 100644 --- a/cml/vector/fixed_external.h +++ b/cml/vector/fixed_external.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_fixed_external_h -#define cml_vector_fixed_external_h - #include #include #include @@ -21,21 +16,21 @@ namespace cml { template -struct vector_traits< vector> > +struct vector_traits>> { /* Traits and types for the vector element: */ - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef typename element_traits::pointer pointer; - typedef typename element_traits::reference reference; - typedef typename element_traits::const_pointer const_pointer; - typedef typename element_traits::const_reference const_reference; - typedef typename element_traits::mutable_value mutable_value; - typedef typename element_traits::immutable_value immutable_value; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using pointer = typename element_traits::pointer; + using reference = typename element_traits::reference; + using const_pointer = typename element_traits::const_pointer; + using const_reference = typename element_traits::const_reference; + using mutable_value = typename element_traits::mutable_value; + using immutable_value = typename element_traits::immutable_value; /* The vector storage type: */ - typedef rebind_t, vector_storage_tag> storage_type; - typedef typename storage_type::size_tag size_tag; + using storage_type = rebind_t, vector_storage_tag>; + using size_tag = typename storage_type::size_tag; static_assert(std::is_same::value, "invalid size tag"); @@ -47,152 +42,146 @@ struct vector_traits< vector> > /** Fixed-length wrapped array pointer as a vector. */ template class vector> -: public writable_vector< vector> > +: public writable_vector>> { public: - - typedef vector> vector_type; - typedef readable_vector readable_type; - typedef writable_vector writable_type; - typedef vector_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::pointer pointer; - typedef typename traits_type::reference reference; - typedef typename traits_type::const_pointer const_pointer; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using vector_type = vector>; + using readable_type = readable_vector; + using writable_type = writable_vector; + using traits_type = vector_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using pointer = typename traits_type::pointer; + using reference = typename traits_type::reference; + using const_pointer = typename traits_type::const_pointer; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /* Include methods from writable_type: */ - using writable_type::operator[]; + /* Include methods from writable_type: */ + using writable_type::operator[]; #ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - using writable_type::operator=; + using writable_type::operator=; #endif public: + /** Constant containing the array size. */ + static const int array_size = traits_type::array_size; - /** Constant containing the array size. */ - static const int array_size = traits_type::array_size; - - /** The dimension (same as array_size). */ - static const int dimension = array_size; + /** The dimension (same as array_size). */ + static const int dimension = array_size; public: + /** Default construct with a null pointer. */ + vector(); - /** Default construct with a null pointer. */ - vector(); - - /** Construct from the wrapped pointer. */ - explicit vector(pointer data); + /** Construct from the wrapped pointer. */ + explicit vector(pointer data); - /** Copy constructor. + /** Copy constructor. * * @warning This copy has the semantics of a raw pointer, and can lead * to memory leaks if not used correctly. */ - vector(const vector_type& other); + vector(const vector_type& other); - /** Move constructor. */ - vector(vector_type&& other); + /** Move constructor. */ + vector(vector_type&& other); public: + /** Return access to the vector data as a raw pointer. */ + pointer data(); - /** Return access to the vector data as a raw pointer. */ - pointer data(); - - /** Return const access to the vector data as a raw pointer. */ - const_pointer data() const; + /** Return const access to the vector data as a raw pointer. */ + const_pointer data() const; - /** Read-only iterator. */ - const_pointer begin() const; + /** Read-only iterator. */ + const_pointer begin() const; - /** Read-only iterator. */ - const_pointer end() const; + /** Read-only iterator. */ + const_pointer end() const; public: - - /** Copy assignment. + /** Copy assignment. * * @warning This assignment has the semantics of a raw pointer, and can * lead to memory leaks if not used correctly. */ - vector_type& operator=(const vector_type& other); + vector_type& operator=(const vector_type& other); - /** Move assignment. */ - vector_type& operator=(vector_type&& other); + /** Move assignment. */ + vector_type& operator=(vector_type&& other); #ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline vector_type& operator=(const readable_vector& other) { - return this->assign(other); - } - - template* = nullptr> - inline vector_type& operator=(const Array& array) { - return this->assign(array); - } - - template - inline vector_type& operator=(std::initializer_list l) { - return this->assign(l); - } + template + inline vector_type& operator=(const readable_vector& other) + { + return this->assign(other); + } + + template* = nullptr> + inline vector_type& operator=(const Array& array) + { + return this->assign(array); + } + + template + inline vector_type& operator=(std::initializer_list l) + { + return this->assign(l); + } #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the length of the vector. */ - int i_size() const; + /** Return the length of the vector. */ + int i_size() const; - /** Return vector const element @c i. */ - immutable_value i_get(int i) const; + /** Return vector const element @c i. */ + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: + /** @name writable_vector Interface */ + /*@{*/ - /** @name writable_vector Interface */ - /*@{*/ + friend writable_type; - friend writable_type; + /** Return vector element @c i. */ + mutable_value i_get(int i); - /** Return vector element @c i. */ - mutable_value i_get(int i); - - /** Set element @c i. */ - template vector_type& i_put(int i, const Other& v) __CML_REF; + /** Set element @c i. */ + template vector_type& i_put(int i, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i on a temporary. */ - template vector_type&& i_put(int i, const Other& v) &&; + /** Set element @c i on a temporary. */ + template vector_type&& i_put(int i, const Other& v) &&; #endif - /*@}*/ + /*@}*/ protected: - - /** Wrapped pointer. */ - pointer m_data; + /** Wrapped pointer. */ + pointer m_data; }; -} // namespace cml +} // namespace cml #ifdef CML_HAS_STRUCTURED_BINDINGS template @@ -211,8 +200,3 @@ struct std::tuple_element>> #define __CML_VECTOR_FIXED_EXTERNAL_TPP #include #undef __CML_VECTOR_FIXED_EXTERNAL_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/fixed_external.tpp b/cml/vector/fixed_external.tpp index c15326e..8a3a351 100644 --- a/cml/vector/fixed_external.tpp +++ b/cml/vector/fixed_external.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_FIXED_EXTERNAL_TPP -#error "vector/fixed_external.tpp not included correctly" +# error "vector/fixed_external.tpp not included correctly" #endif namespace cml { @@ -15,14 +13,12 @@ namespace cml { template vector>::vector() : m_data(0) -{ -} +{} template vector>::vector(pointer data) : m_data(data) -{ -} +{} template vector>::vector(const vector_type& other) @@ -30,49 +26,51 @@ vector>::vector(const vector_type& other) this->m_data = other.m_data; } -template -vector>::vector(vector_type&& other) +template vector>::vector(vector_type&& other) { this->m_data = other.m_data; other.m_data = nullptr; } - - /* Public methods: */ -template auto +template +auto vector>::data() -> pointer { return this->m_data; } -template auto +template +auto vector>::data() const -> const_pointer { return this->m_data; } -template auto +template +auto vector>::begin() const -> const_pointer { return this->m_data; } -template auto +template +auto vector>::end() const -> const_pointer { return this->m_data + S; } - -template auto +template +auto vector>::operator=(const vector_type& other) -> vector_type& { return this->assign(other); } -template auto +template +auto vector>::operator=(vector_type&& other) -> vector_type& { this->m_data = other.m_data; @@ -80,42 +78,46 @@ vector>::operator=(vector_type&& other) -> vector_type& return *this; } - - /* Internal methods: */ /* readable_vector interface: */ -template int +template +int vector>::i_size() const { return S; } -template auto +template +auto vector>::i_get(int i) const -> immutable_value { return this->m_data[i]; } - /* writable_vector interface: */ -template auto +template +auto vector>::i_get(int i) -> mutable_value { return this->m_data[i]; } -template template auto -vector>::i_put(int i, const Other& v) __CML_REF -> vector_type& +template +template +auto +vector>::i_put(int i, const Other& v) __CML_REF->vector_type& { this->m_data[i] = value_type(v); return *this; } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template auto +template +template +auto vector>::i_put(int i, const Other& v) && -> vector_type&& { this->m_data[i] = value_type(v); @@ -123,7 +125,4 @@ vector>::i_put(int i, const Other& v) && -> vector_type&& } #endif -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/functions.h b/cml/vector/functions.h index bfd8227..bf58958 100644 --- a/cml/vector/functions.h +++ b/cml/vector/functions.h @@ -1,41 +1,30 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_functions_h -#define cml_vector_functions_h - #include #include namespace cml { /** Return the squared length of @c v. */ -template auto -length_squared(const readable_vector& v) --> value_type_trait_of_t; +template +auto length_squared(const readable_vector& v) + -> value_type_trait_of_t; /** Return the length of @c v. */ -template auto -length(const readable_vector& v) --> value_type_trait_of_t; +template +auto length(const readable_vector& v) + -> value_type_trait_of_t; /** Return a normalized copy of @c v. */ -template auto -normalize(const readable_vector& v) --> temporary_of_t; +template +auto normalize(const readable_vector& v) -> temporary_of_t; -} // namespace cml +} // namespace cml #define __CML_VECTOR_FUNCTIONS_TPP #include #undef __CML_VECTOR_FUNCTIONS_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/functions.tpp b/cml/vector/functions.tpp index 83ba55f..ec7d7d2 100644 --- a/cml/vector/functions.tpp +++ b/cml/vector/functions.tpp @@ -1,36 +1,34 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_FUNCTIONS_TPP -#error "vector/functions.tpp not included correctly" +# error "vector/functions.tpp not included correctly" #endif #include namespace cml { -template inline auto +template +inline auto length_squared(const readable_vector
& v) -> value_type_trait_of_t
{ return v.length_squared(); } -template inline auto +template +inline auto length(const readable_vector
& v) -> value_type_trait_of_t
{ return v.length(); } -template inline auto +template +inline auto normalize(const readable_vector
& v) -> temporary_of_t
{ return v.normalize(); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/fwd.h b/cml/vector/fwd.h index 65d509f..89aa33e 100644 --- a/cml/vector/fwd.h +++ b/cml/vector/fwd.h @@ -1,22 +1,12 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_fwd_h -#define cml_vector_fwd_h - namespace cml { template class readable_vector; template class writable_vector; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/hadamard_product.h b/cml/vector/hadamard_product.h index c2a7a48..c5e744c 100644 --- a/cml/vector/hadamard_product.h +++ b/cml/vector/hadamard_product.h @@ -1,32 +1,23 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_hadamard_product_h -#define cml_vector_hadamard_product_h - #include namespace cml { /** Elementwise (Hadamard) product of two vectors. */ -template* = nullptr, enable_if_vector_t* = nullptr> -inline auto hadamard(Sub1&& sub1, Sub2&& sub2) --> decltype(make_vector_binary_node>( +template* = nullptr, + enable_if_vector_t* = nullptr> +inline auto +hadamard(Sub1&& sub1, Sub2&& sub2) + -> decltype(make_vector_binary_node>( std::forward(sub1), std::forward(sub2))) { - return make_vector_binary_node> - (std::forward(sub1), std::forward(sub2)); + return make_vector_binary_node>( + std::forward(sub1), std::forward(sub2)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/ops.h b/cml/vector/ops.h index 5e9e1be..3e78efd 100644 --- a/cml/vector/ops.h +++ b/cml/vector/ops.h @@ -1,19 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_ops_h -#define cml_vector_ops_h - #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/outer_product.h b/cml/vector/outer_product.h index 3aa6b54..04ed2f1 100644 --- a/cml/vector/outer_product.h +++ b/cml/vector/outer_product.h @@ -1,18 +1,8 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_outer_product_h -#define cml_vector_outer_product_h - #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/outer_product_node.h b/cml/vector/outer_product_node.h index 990ab42..88b49a0 100644 --- a/cml/vector/outer_product_node.h +++ b/cml/vector/outer_product_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_outer_product_node_h -#define cml_vector_outer_product_node_h - #include #include #include @@ -19,32 +14,31 @@ template class outer_product_node; /** outer_product_node<> traits. */ template -struct matrix_traits< outer_product_node > +struct matrix_traits> { - typedef outer_product_node matrix_type; - typedef Sub1 left_arg_type; - typedef Sub2 right_arg_type; - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef vector_traits left_traits; - typedef vector_traits right_traits; + using matrix_type = outer_product_node; + using left_arg_type = Sub1; + using right_arg_type = Sub2; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = vector_traits; + using right_traits = vector_traits; /* Deduce the element type: */ - typedef scalar_traits< - value_type_promote_t> element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; + using element_traits = scalar_traits>; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; /* Determine the common storage type for the node, based on the storage * types of its subexpressions: */ - typedef storage_type_of_t left_storage_type; - typedef storage_type_of_t right_storage_type; - typedef matrix_outer_product_storage_promote_t< - left_storage_type, right_storage_type> storage_type; + using left_storage_type = storage_type_of_t; + using right_storage_type = storage_type_of_t; + using storage_type = matrix_outer_product_storage_promote_t; /* Traits and types for the storage: */ - typedef typename storage_type::size_tag size_tag; + using size_tag = typename storage_type::size_tag; /* Array rows: */ static const int array_rows = storage_type::array_rows; @@ -53,10 +47,10 @@ struct matrix_traits< outer_product_node > static const int array_cols = storage_type::array_cols; /* Unspecified basis: */ - typedef any_basis basis_tag; + using basis_tag = any_basis; /* Unspecified layout: */ - typedef any_major layout_tag; + using layout_tag = any_major; /** Constant containing the matrix basis enumeration value. */ static const basis_kind matrix_basis = basis_tag::value; @@ -68,44 +62,41 @@ struct matrix_traits< outer_product_node > /** Represents a vector outer product in an expression tree. */ template class outer_product_node -: public readable_matrix< outer_product_node > +: public readable_matrix> { public: - - typedef outer_product_node node_type; - typedef readable_matrix readable_type; - typedef matrix_traits traits_type; - typedef typename traits_type::left_arg_type left_arg_type; - typedef typename traits_type::right_arg_type right_arg_type; - typedef typename traits_type::left_type left_type; - typedef typename traits_type::right_type right_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; - typedef typename traits_type::basis_tag basis_tag; - typedef typename traits_type::layout_tag layout_tag; + using node_type = outer_product_node; + using readable_type = readable_matrix; + using traits_type = matrix_traits; + using left_arg_type = typename traits_type::left_arg_type; + using right_arg_type = typename traits_type::right_arg_type; + using left_type = typename traits_type::left_type; + using right_type = typename traits_type::right_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; + using basis_tag = typename traits_type::basis_tag; + using layout_tag = typename traits_type::layout_tag; public: + /** Constant containing the number of rows. */ + static const int array_rows = traits_type::array_rows; - /** Constant containing the number of rows. */ - static const int array_rows = traits_type::array_rows; + /** Constant containing the number of columns. */ + static const int array_cols = traits_type::array_cols; - /** Constant containing the number of columns. */ - static const int array_cols = traits_type::array_cols; - - /** Constant containing the array layout enumeration value. */ - static const layout_kind array_layout = traits_type::array_layout; + /** Constant containing the array layout enumeration value. */ + static const layout_kind array_layout = traits_type::array_layout; - /** Constant containing the matrix basis enumeration value. */ - static const basis_kind matrix_basis = traits_type::matrix_basis; + /** Constant containing the matrix basis enumeration value. */ + static const basis_kind matrix_basis = traits_type::matrix_basis; public: - - /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be + /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be * lvalue reference or rvalue reference types. * * @throws incompatible_matrix_sizes at run-time if either Sub1 or Sub2 @@ -113,81 +104,72 @@ class outer_product_node * both Sub1 and Sub2 are fixed-size expressions, then the sizes are * checked at compile time. */ - outer_product_node(Sub1 left, Sub2 right); + outer_product_node(Sub1 left, Sub2 right); - /** Move constructor. */ - outer_product_node(node_type&& other); + /** Move constructor. */ + outer_product_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - outer_product_node(const node_type& other); + /** Copy constructor. */ + outer_product_node(const node_type& other); #endif protected: + /** @name readable_matrix Interface */ + /*@{*/ - /** @name readable_matrix Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the row size of the matrix expression. */ - int i_rows() const; + /** Return the row size of the matrix expression. */ + int i_rows() const; - /** Return the column size of the matrix expression. */ - int i_cols() const; + /** Return the column size of the matrix expression. */ + int i_cols() const; - /** Apply the operator to element @c (i,j) of the subexpressions and + /** Apply the operator to element @c (i,j) of the subexpressions and * return the result. */ - immutable_value i_get(int i, int j) const; + immutable_value i_get(int i, int j) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the left subexpression. The expression is + /** The type used to store the left subexpression. The expression is * stored as a copy if Sub1 is an rvalue reference (temporary), or by * const reference if Sub1 is an lvalue reference. */ - typedef cml::if_t::value, - const left_type&, left_type> left_wrap_type; + using left_wrap_type = cml::if_t::value, const left_type&, + left_type>; - /** The type used to store the right subexpression. The expression is + /** The type used to store the right subexpression. The expression is * stored as a copy if Sub2 is an rvalue reference (temporary), or by * const reference if Sub2 is an lvalue reference. */ - typedef cml::if_t::value, - const right_type&, right_type> right_wrap_type; + using right_wrap_type = cml::if_t::value, const right_type&, + right_type>; protected: + /** The wrapped left subexpression. */ + left_wrap_type m_left; - /** The wrapped left subexpression. */ - left_wrap_type m_left; - - /** The wrapped right subexpression. */ - right_wrap_type m_right; + /** The wrapped right subexpression. */ + right_wrap_type m_right; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - outer_product_node(const node_type&); + // Not copy constructible. + outer_product_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_OUTER_PRODUCT_NODE_TPP #include #undef __CML_VECTOR_OUTER_PRODUCT_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/outer_product_node.tpp b/cml/vector/outer_product_node.tpp index 34f6d95..5efe53b 100644 --- a/cml/vector/outer_product_node.tpp +++ b/cml/vector/outer_product_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_OUTER_PRODUCT_NODE_TPP -#error "vector/outer_product_node.tpp not included correctly" +# error "vector/outer_product_node.tpp not included correctly" #endif namespace cml { @@ -13,50 +11,49 @@ namespace cml { /* outer_product_node 'structors: */ template -outer_product_node::outer_product_node(Sub1 left, Sub2 right) -: m_left(std::move(left)), m_right(std::move(right)) -{ -} +outer_product_node::outer_product_node(Sub1 left, Sub2 right) +: m_left(std::move(left)) +, m_right(std::move(right)) +{} template -outer_product_node::outer_product_node(node_type&& other) -: m_left(std::move(other.m_left)), m_right(std::move(other.m_right)) -{ -} +outer_product_node::outer_product_node(node_type&& other) +: m_left(std::move(other.m_left)) +, m_right(std::move(other.m_right)) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -outer_product_node::outer_product_node(const node_type& other) -: m_left(other.m_left), m_right(other.m_right) -{ -} +outer_product_node::outer_product_node(const node_type& other) +: m_left(other.m_left) +, m_right(other.m_right) +{} #endif - /* Internal methods: */ /* readable_matrix interface: */ -template int -outer_product_node::i_rows() const +template +int +outer_product_node::i_rows() const { return this->m_left.size(); } -template int -outer_product_node::i_cols() const +template +int +outer_product_node::i_cols() const { return this->m_right.size(); } -template auto -outer_product_node::i_get(int i, int j) const -> immutable_value +template +auto +outer_product_node::i_get(int i, int j) const -> immutable_value { - return immutable_value(this->m_left.get(i)*this->m_right.get(j)); + return immutable_value(this->m_left.get(i) * this->m_right.get(j)); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/outer_product_ops.h b/cml/vector/outer_product_ops.h index 12af0a9..1a61fc0 100644 --- a/cml/vector/outer_product_ops.h +++ b/cml/vector/outer_product_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_outer_product_ops_h -#define cml_vector_outer_product_ops_h - #include namespace cml { @@ -16,30 +11,25 @@ namespace cml { /** Compute the outer product of vectors @c sub1 and @c sub2 as a matrix * expression node. */ -template* = nullptr, enable_if_vector_t* = nullptr> -inline auto outer(Sub1&& sub1, Sub2&& sub2) --> outer_product_node< -actual_operand_type_of_t, -actual_operand_type_of_t> +template* = nullptr, + enable_if_vector_t* = nullptr> +inline auto +outer(Sub1&& sub1, + Sub2&& sub2) -> outer_product_node, + actual_operand_type_of_t> { - static_assert(std::is_same< - decltype(sub1), decltype(std::forward(sub1))>::value, + static_assert( + std::is_same(sub1))>::value, "internal error: unexpected expression type (sub1)"); - static_assert(std::is_same< - decltype(sub2), decltype(std::forward(sub2))>::value, + static_assert( + std::is_same(sub2))>::value, "internal error: unexpected expression type (sub2)"); /* Deduce the operand types of the subexpressions (&, const&, &&): */ - typedef actual_operand_type_of_t sub1_type; - typedef actual_operand_type_of_t sub2_type; - return outer_product_node< - sub1_type, sub2_type>((sub1_type) sub1, (sub2_type) sub2); + using sub1_type = actual_operand_type_of_t; + using sub2_type = actual_operand_type_of_t; + return outer_product_node((sub1_type) sub1, + (sub2_type) sub2); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/perp_dot.h b/cml/vector/perp_dot.h index 15fc29e..18ed97c 100644 --- a/cml/vector/perp_dot.h +++ b/cml/vector/perp_dot.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_perp_dot_h -#define cml_vector_perp_dot_h - #include #include @@ -18,7 +13,7 @@ namespace cml { * cml::perp_dot. */ template - using perp_dot_promote_t = value_type_trait_promote_t; +using perp_dot_promote_t = value_type_trait_promote_t; /** Compute the "cross-product" of two 2D vectors, and return the scalar * result. @@ -30,17 +25,12 @@ template * dynamically-sized and is not a 2D vector. The size is checked at * compile time for fixed-sized expressions. */ -template auto perp_dot( - const readable_vector& left, const readable_vector& right) - -> perp_dot_promote_t; +template +auto perp_dot(const readable_vector& left, + const readable_vector& right) -> perp_dot_promote_t; -} // namespace cml +} // namespace cml #define __CML_VECTOR_PERP_DOT_TPP #include #undef __CML_VECTOR_PERP_DOT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/perp_dot.tpp b/cml/vector/perp_dot.tpp index 1eb6fc4..84a95a6 100644 --- a/cml/vector/perp_dot.tpp +++ b/cml/vector/perp_dot.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_PERP_DOT_TPP -#error "vector/perp_dot.tpp not included correctly" +# error "vector/perp_dot.tpp not included correctly" #endif #include @@ -13,17 +11,15 @@ namespace cml { -template inline auto perp_dot( - const readable_vector& left, const readable_vector& right - ) -> perp_dot_promote_t +template +inline auto +perp_dot(const readable_vector& left, const readable_vector& right) + -> perp_dot_promote_t { - typedef perp_dot_promote_t result_type; + using result_type = perp_dot_promote_t; cml::check_size(left, cml::int_c<2>()); cml::check_size(right, cml::int_c<2>()); - return result_type(left[0]*right[1] - left[1]*right[0]); + return result_type(left[0] * right[1] - left[1] * right[0]); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/products.h b/cml/vector/products.h index c72b0f2..7abdae0 100644 --- a/cml/vector/products.h +++ b/cml/vector/products.h @@ -1,21 +1,11 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_products_h -#define cml_vector_products_h - #include #include #include #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/promotion.h b/cml/vector/promotion.h index 9963f40..09aefdf 100644 --- a/cml/vector/promotion.h +++ b/cml/vector/promotion.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_promotion_h -#define cml_vector_promotion_h - #include #include #include @@ -24,33 +19,31 @@ namespace cml { * * @note This can be specialized to accomodate user-defined storage types. */ -template -struct vector_binary_storage_promote +template struct vector_binary_storage_promote { static_assert( - is_vector_storage::value && - is_vector_storage::value, + is_vector_storage::value && is_vector_storage::value, "expected vector storage types for binary promotion"); /* Determine the common unbound storage type: */ - typedef storage_promote_t unbound_type; + using unbound_type = storage_promote_t; /* Determine the new vector size: */ - static const int array_size - = Storage1::array_size > Storage2::array_size - ? Storage1::array_size : Storage2::array_size; + static const int array_size = Storage1::array_size > Storage2::array_size + ? Storage1::array_size + : Storage2::array_size; /* Resize: */ - typedef resize_storage_t resized_type; + using resized_type = resize_storage_t; /* Rebind to a vector storage type: */ - typedef rebind_vector_storage_t type; + using type = rebind_vector_storage_t; }; /** Convenience alias for vector_binary_storage_promote. */ template - using vector_binary_storage_promote_t = - typename vector_binary_storage_promote::type; +using vector_binary_storage_promote_t = + typename vector_binary_storage_promote::type; /** Helper to deduce a reasonable vector type from two vector subexpression @@ -58,37 +51,32 @@ template */ template struct vector_promote; -template struct vector_promote< - Sub1, Sub2, typename std::enable_if< - is_vector::value && is_vector::value>::type> +template +struct vector_promote::value + && is_vector::value>::type> { - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef vector_traits left_traits; - typedef vector_traits right_traits; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = vector_traits; + using right_traits = vector_traits; /* Deduce the new vector element type: */ - typedef value_type_promote_t value_type; + using value_type = value_type_promote_t; /* Determine the new storage type: */ - typedef vector_binary_storage_promote_t< - storage_type_of_t, - storage_type_of_t> storage_type; + using storage_type = vector_binary_storage_promote_t, + storage_type_of_t>; /* Use the proxy type for the temporary: */ - typedef proxy_type_of_t proxy_type; + using proxy_type = proxy_type_of_t; /* Build the vector type: */ - typedef vector type; + using type = vector; }; /** Convenience alias for vector_promote<>. */ template - using vector_promote_t = typename vector_promote::type; - -} // namespace cml - -#endif +using vector_promote_t = typename vector_promote::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/readable_vector.h b/cml/vector/readable_vector.h index f865d63..45b4a75 100644 --- a/cml/vector/readable_vector.h +++ b/cml/vector/readable_vector.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_readable_vector_h -#define cml_vector_readable_vector_h - #include #include #include @@ -31,110 +26,103 @@ template class subvector_node; * by vector_traits. Note that immutable_value is not * necessarily a reference or const type. */ -template -class readable_vector +template class readable_vector { public: - - typedef DerivedT vector_type; - typedef vector_traits traits_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::size_tag size_tag; + using vector_type = DerivedT; + using traits_type = vector_traits; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using size_tag = typename traits_type::size_tag; public: + /** @name CML1 Types */ + /*@{*/ - /** @name CML1 Types */ - /*@{*/ + using subvector_type = subvector_of_t; + using supervector_type = supervector_of_t; - typedef subvector_of_t subvector_type; - typedef supervector_of_t supervector_type; - - /*@}*/ + /*@}*/ public: + /** Return a const reference to the vector cast as DerivedT. */ + const DerivedT& actual() const; - /** Return a const reference to the vector cast as DerivedT. */ - const DerivedT& actual() const; - - /** Return the number of vector elements. */ - int size() const; + /** Return the number of vector elements. */ + int size() const; - /** Return const element @c i. */ - immutable_value get(int i) const; + /** Return const element @c i. */ + immutable_value get(int i) const; #ifdef CML_HAS_STRUCTURED_BINDINGS - /** Return const element @c i. */ - template>* = nullptr> - immutable_value get() const; + /** Return const element @c i. */ + template>* = nullptr> + immutable_value get() const; #endif - /** Return const element @c i. */ - immutable_value operator[](int i) const; + /** Return const element @c i. */ + immutable_value operator[](int i) const; public: + /** Return the squared length of the vector. */ + value_type length_squared() const; - /** Return the squared length of the vector. */ - value_type length_squared() const; - - /** Return the length of the vector. */ - value_type length() const; + /** Return the length of the vector. */ + value_type length() const; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Return the normalized vector as an expression node. */ - vector_scalar_node> normalize() const &; + /** Return the normalized vector as an expression node. */ + vector_scalar_node> + normalize() const&; - /** Return the normalized vector as an expression node, moving the + /** Return the normalized vector as an expression node, moving the * source into the node. */ - vector_scalar_node> normalize() const &&; + vector_scalar_node> + normalize() const&&; #else - /** Return the normalized vector as an expression node. */ - vector_scalar_node> normalize() const; + /** Return the normalized vector as an expression node. */ + vector_scalar_node> + normalize() const; #endif #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Return subvector @c i as an expression node. */ - subvector_node subvector(int i) const &; + /** Return subvector @c i as an expression node. */ + subvector_node subvector(int i) const&; - /** Return subvector @c i as an expression node, moving the source + /** Return subvector @c i as an expression node, moving the source * into the node. */ - subvector_node subvector(int i) const &&; + subvector_node subvector(int i) const&&; #else - /** Return subvector @c i as an expression node. */ - subvector_node subvector(int i) const; + /** Return subvector @c i as an expression node. */ + subvector_node subvector(int i) const; #endif protected: + // Use the compiler-generated default constructor: + readable_vector() = default; - // Use the compiler-generated default constructor: - readable_vector() = default; - - // Use the compiler-generated copy constructor: - readable_vector(const readable_vector&) = default; + // Use the compiler-generated copy constructor: + readable_vector(const readable_vector&) = default; #ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR - // Use the compiler-generated move constructor: - readable_vector(readable_vector&&) = default; + // Use the compiler-generated move constructor: + readable_vector(readable_vector&&) = default; #endif }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_READABLE_VECTOR_TPP #include #undef __CML_VECTOR_READABLE_VECTOR_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/readable_vector.tpp b/cml/vector/readable_vector.tpp index 2c99437..c93ba80 100644 --- a/cml/vector/readable_vector.tpp +++ b/cml/vector/readable_vector.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_READABLE_VECTOR_TPP -#error "vector/readable_vector.tpp not included correctly" +# error "vector/readable_vector.tpp not included correctly" #endif #include @@ -18,19 +16,22 @@ namespace cml { /* Public methods: */ -template const DT& +template +const DT& readable_vector
::actual() const { return (const DT&) *this; } -template int +template +int readable_vector
::size() const { return this->actual().i_size(); } -template auto +template +auto readable_vector
::get(int i) const -> immutable_value { return this->actual().i_get(i); @@ -38,86 +39,90 @@ readable_vector
::get(int i) const -> immutable_value #ifdef CML_HAS_STRUCTURED_BINDINGS template -template>*> auto -readable_vector
::get() const --> immutable_value +template>*> +auto +readable_vector
::get() const -> immutable_value { return this->actual().i_get(I); } #endif -template auto +template +auto readable_vector
::operator[](int i) const -> immutable_value { return this->get(i); } - -template auto +template +auto readable_vector
::length_squared() const -> value_type { cml::check_minimum_size(*this, cml::int_c<1>()); auto accum = cml::sqr(this->get(0)); - for(int i = 1; i < this->size(); ++ i) accum += cml::sqr(this->get(i)); + for(int i = 1; i < this->size(); ++i) accum += cml::sqr(this->get(i)); return accum; } -template auto +template +auto readable_vector
::length() const -> value_type { return element_traits::sqrt(this->length_squared()); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template auto -readable_vector
::normalize() const & -> vector_scalar_node< - const DT&, value_type, op::binary_divide> +template +auto +readable_vector
::normalize() const& -> vector_scalar_node> { - return vector_scalar_node< - const DT&, value_type, op::binary_divide> - ((const DT&) *this, this->length()); + return vector_scalar_node>((const DT&) *this, + this->length()); } -template auto -readable_vector
::normalize() const && -> vector_scalar_node< - DT&&, value_type, op::binary_divide> +template +auto +readable_vector
::normalize() const&& -> vector_scalar_node> { - return vector_scalar_node< - DT&&, value_type, op::binary_divide> - ((DT&&) *this, this->length()); + return vector_scalar_node>((DT&&) *this, this->length()); } #else -template auto -readable_vector
::normalize() const -> vector_scalar_node< - DT, value_type, op::binary_divide> +template +auto +readable_vector
::normalize() const -> vector_scalar_node> { - return vector_scalar_node< - DT, value_type, op::binary_divide> - ((const DT&) *this, this->length()); + return vector_scalar_node>((const DT&) *this, + this->length()); } #endif #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template auto -readable_vector
::subvector(int i) const & -> subvector_node +template +auto +readable_vector
::subvector(int i) const& -> subvector_node { return subvector_node((const DT&) *this, i); } -template auto -readable_vector
::subvector(int i) const && -> subvector_node +template +auto +readable_vector
::subvector(int i) const&& -> subvector_node { return subvector_node((DT&&) *this, i); } #else -template auto +template +auto readable_vector
::subvector(int i) const -> subvector_node
{ return subvector_node
((const DT&) *this, i); } #endif -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/scalar_node.h b/cml/vector/scalar_node.h index c9e2450..2599b25 100644 --- a/cml/vector/scalar_node.h +++ b/cml/vector/scalar_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_scalar_node_h -#define cml_vector_scalar_node_h - #include namespace cml { @@ -17,20 +12,20 @@ template class vector_scalar_node; /** vector_scalar_node<> traits. */ template -struct vector_traits< vector_scalar_node > +struct vector_traits> { /* Figure out the basic types of Sub and Scalar: */ - typedef vector_scalar_node vector_type; - typedef Sub left_arg_type; - typedef Scalar right_arg_type; - typedef cml::unqualified_type_t left_type; - typedef cml::unqualified_type_t right_type; - typedef vector_traits left_traits; - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; - typedef typename left_traits::storage_type storage_type; - typedef typename left_traits::size_tag size_tag; + using vector_type = vector_scalar_node; + using left_arg_type = Sub; + using right_arg_type = Scalar; + using left_type = cml::unqualified_type_t; + using right_type = cml::unqualified_type_t; + using left_traits = vector_traits; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; + using storage_type = typename left_traits::storage_type; + using size_tag = typename left_traits::size_tag; /* Propagate the array size from the subexpression: */ static const int array_size = left_traits::array_size; @@ -41,101 +36,89 @@ struct vector_traits< vector_scalar_node > */ template class vector_scalar_node -: public readable_vector< vector_scalar_node > +: public readable_vector> { public: - - typedef vector_scalar_node node_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::left_arg_type left_arg_type; - typedef typename traits_type::right_arg_type right_arg_type; - typedef typename traits_type::left_type left_type; - typedef typename traits_type::right_type right_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using node_type = vector_scalar_node; + using readable_type = readable_vector; + using traits_type = vector_traits; + using left_arg_type = typename traits_type::left_arg_type; + using right_arg_type = typename traits_type::right_arg_type; + using left_type = typename traits_type::left_type; + using right_type = typename traits_type::right_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** The array size constant is the same as the subexpression. */ - static const int array_size = traits_type::array_size; + /** The array size constant is the same as the subexpression. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped sub-expression and the scalar to apply. + /** Construct from the wrapped sub-expression and the scalar to apply. * @c left must be an lvalue reference or rvalue reference. */ - vector_scalar_node(Sub left, const right_type& right); + vector_scalar_node(Sub left, const right_type& right); - /** Move constructor. */ - vector_scalar_node(node_type&& other); + /** Move constructor. */ + vector_scalar_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - vector_scalar_node(const node_type& other); + /** Copy constructor. */ + vector_scalar_node(const node_type& other); #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the size of the vector expression. */ - int i_size() const; + /** Return the size of the vector expression. */ + int i_size() const; - /** Apply the scalar operator to element @c i of the subexpression and + /** Apply the scalar operator to element @c i of the subexpression and * return the result. */ - immutable_value i_get(int i) const; + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the left subexpression. The expression is + /** The type used to store the left subexpression. The expression is * stored as a copy if Sub is an rvalue reference (temporary), or by * const reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const left_type&, left_type> left_wrap_type; + using left_wrap_type = cml::if_t::value, const left_type&, + left_type>; protected: + /** The vector operand. */ + left_wrap_type m_left; - /** The vector operand. */ - left_wrap_type m_left; - - /** The scalar operand. */ - right_type m_right; + /** The scalar operand. */ + right_type m_right; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - vector_scalar_node(const node_type&); + // Not copy constructible. + vector_scalar_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_SCALAR_NODE_TPP #include #undef __CML_VECTOR_SCALAR_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/scalar_node.tpp b/cml/vector/scalar_node.tpp index c94937b..ca718ff 100644 --- a/cml/vector/scalar_node.tpp +++ b/cml/vector/scalar_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_SCALAR_NODE_TPP -#error "vector/scalar_node.tpp not included correctly" +# error "vector/scalar_node.tpp not included correctly" #endif namespace cml { @@ -13,25 +11,24 @@ namespace cml { /* vector_scalar_node 'structors: */ template -vector_scalar_node::vector_scalar_node( - Sub left, const right_type& right - ) -: m_left(std::move(left)), m_right(right) -{ -} +vector_scalar_node::vector_scalar_node(Sub left, + const right_type& right) +: m_left(std::move(left)) +, m_right(right) +{} template -vector_scalar_node::vector_scalar_node(node_type&& other) -: m_left(std::move(other.m_left)), m_right(std::move(other.m_right)) -{ -} +vector_scalar_node::vector_scalar_node(node_type&& other) +: m_left(std::move(other.m_left)) +, m_right(std::move(other.m_right)) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -vector_scalar_node::vector_scalar_node(const node_type& other) -: m_left(other.m_left), m_right(other.m_right) -{ -} +vector_scalar_node::vector_scalar_node(const node_type& other) +: m_left(other.m_left) +, m_right(other.m_right) +{} #endif @@ -39,19 +36,18 @@ vector_scalar_node::vector_scalar_node(const node_type& other) /* readable_vector interface: */ -template int -vector_scalar_node::i_size() const +template +int +vector_scalar_node::i_size() const { return this->m_left.size(); } -template auto -vector_scalar_node::i_get(int i) const -> immutable_value +template +auto +vector_scalar_node::i_get(int i) const -> immutable_value { return Op().apply(this->m_left.get(i), this->m_right); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/scalar_ops.h b/cml/vector/scalar_ops.h index d2aec3a..9e565ef 100644 --- a/cml/vector/scalar_ops.h +++ b/cml/vector/scalar_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_scalar_ops_h -#define cml_vector_scalar_ops_h - #include #include #include @@ -18,72 +13,61 @@ namespace cml { /** Helper function to generate a vector_scalar_node from a vector type * (i.e. derived from readable_vector<>) and a scalar type. */ -template* = nullptr, - enable_if_arithmetic_t>* = nullptr -> inline auto -make_vector_scalar_node(Sub&& sub, Scalar&& v) --> vector_scalar_node< -actual_operand_type_of_t, -actual_operand_type_of_t, -Op -> +template* = nullptr, + enable_if_arithmetic_t>* = nullptr> +inline auto +make_vector_scalar_node(Sub&& sub, + Scalar&& v) -> vector_scalar_node, + actual_operand_type_of_t, Op> { - static_assert(std::is_same< - decltype(sub), decltype(std::forward(sub))>::value, + static_assert( + std::is_same(sub))>::value, "internal error: unexpected expression type (sub)"); - static_assert(std::is_same< - decltype(v), decltype(std::forward(v))>::value, + static_assert( + std::is_same(v))>::value, "internal error: unexpected expression type (v)"); /* Deduce the operand types of the scalar and the subexpression (&, * const&, &&): */ - typedef actual_operand_type_of_t sub_type; - typedef actual_operand_type_of_t scalar_type; - return vector_scalar_node( - (sub_type) sub, (scalar_type) v); + using sub_type = actual_operand_type_of_t; + using scalar_type = actual_operand_type_of_t; + return vector_scalar_node((sub_type) sub, + (scalar_type) v); } -template* = nullptr, - enable_if_arithmetic_t>* = nullptr -> -inline auto operator*(Sub&& sub, Scalar&& v) --> decltype(make_vector_scalar_node>( +template* = nullptr, + enable_if_arithmetic_t>* = nullptr> +inline auto +operator*(Sub&& sub, Scalar&& v) + -> decltype(make_vector_scalar_node>( std::forward(sub), std::forward(v))) { - return make_vector_scalar_node>( + return make_vector_scalar_node>( std::forward(sub), std::forward(v)); } template>* = nullptr, - enable_if_vector_t* = nullptr -> -inline auto operator*(Scalar&& v, Sub&& sub) --> decltype(make_vector_scalar_node>( + enable_if_vector_t* = nullptr> +inline auto +operator*(Scalar&& v, Sub&& sub) + -> decltype(make_vector_scalar_node>( std::forward(sub), std::forward(v))) { - return make_vector_scalar_node>( + return make_vector_scalar_node>( std::forward(sub), std::forward(v)); } -template* = nullptr, - enable_if_arithmetic_t>* = nullptr -> -inline auto operator/(Sub&& sub, Scalar&& v) --> decltype(make_vector_scalar_node>( +template* = nullptr, + enable_if_arithmetic_t>* = nullptr> +inline auto +operator/(Sub&& sub, Scalar&& v) + -> decltype(make_vector_scalar_node>( std::forward(sub), std::forward(v))) { - return make_vector_scalar_node>( + return make_vector_scalar_node>( std::forward(sub), std::forward(v)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/size_checking.h b/cml/vector/size_checking.h index 5ac72df..2917897 100644 --- a/cml/vector/size_checking.h +++ b/cml/vector/size_checking.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_size_checking_h -#define cml_vector_size_checking_h - #include #include #include @@ -19,33 +14,41 @@ namespace cml { /** Exception thrown when run-time size checking is enabled, and the * operands of a vector expression have incompatible sizes. */ -struct incompatible_vector_size_error : std::runtime_error { +struct incompatible_vector_size_error : std::runtime_error +{ incompatible_vector_size_error() - : std::runtime_error("incompatible vector expression sizes") {} + : std::runtime_error("incompatible vector expression sizes") + {} }; /** Exception thrown when run-time size checking is enabled, and the * operand of a vector expression does not meet a minimum size. */ -struct minimum_vector_size_error : std::runtime_error { +struct minimum_vector_size_error : std::runtime_error +{ minimum_vector_size_error() - : std::runtime_error("vector expression too short") {} + : std::runtime_error("vector expression too short") + {} }; /** Exception thrown when run-time size checking is enabled, and the * operand of a vector expression does not have the required size. */ -struct vector_size_error : std::runtime_error { +struct vector_size_error : std::runtime_error +{ vector_size_error() - : std::runtime_error("incorrect vector expression size") {} + : std::runtime_error("incorrect vector expression size") + {} }; /** Exception thrown when run-time size checking is enabled, and the * size of a vector expression operand is outside the required range. */ -struct vector_size_range_error : std::runtime_error { +struct vector_size_range_error : std::runtime_error +{ vector_size_range_error() - : std::runtime_error("vector expression size out of range") {} + : std::runtime_error("vector expression size out of range") + {} }; @@ -66,8 +69,9 @@ struct vector_size_range_error : std::runtime_error { * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_VECTOR_SIZE_CHECKS at compile time. */ -template void check_same_size( - const readable_vector& left, const readable_vector& right); +template +void check_same_size(const readable_vector& left, + const readable_vector& right); /** Front-end for both compile-time and run-time vector binary expression * length checking against a fixed-length array. The first expression must @@ -88,8 +92,8 @@ template void check_same_size( * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_VECTOR_SIZE_CHECKS at compile time. */ -template void -check_same_size(const readable_vector& left, const Sub2& right, +template +void check_same_size(const readable_vector& left, const Sub2& right, enable_if_array_t* = 0); /** Front-end for run-time vector binary expression length checking. The @@ -109,7 +113,7 @@ check_same_size(const readable_vector& left, const Sub2& right, */ template auto check_same_size(const readable_vector& left, const Sub2& right) --> decltype(right.size(), void()); + -> decltype(right.size(), void()); /** Front-end for minimum vector expression length checking against a @@ -154,8 +158,7 @@ void check_minimum_size(const readable_vector& left, cml::int_c); * @note Run-time checking can be disabled by defining * CML_NO_RUNTIME_VECTOR_SIZE_CHECKS at compile time. */ -template -void check_size(const readable_vector& left, int N); +template void check_size(const readable_vector& left, int N); /** Front-end for compile-time and run-time vector expression length * checking against an integer constant via int_c. The expression must @@ -205,16 +208,11 @@ void check_size_range(const readable_vector& left, int Low, int High); * CML_NO_RUNTIME_VECTOR_SIZE_CHECKS at compile time. */ template -void check_size_range( - const readable_vector& left, cml::int_c, cml::int_c); +void check_size_range(const readable_vector& left, cml::int_c, + cml::int_c); -} // namespace cml +} // namespace cml #define __CML_VECTOR_SIZE_CHECKING_TPP #include #undef __CML_VECTOR_SIZE_CHECKING_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/size_checking.tpp b/cml/vector/size_checking.tpp index 23235f3..4f5f256 100644 --- a/cml/vector/size_checking.tpp +++ b/cml/vector/size_checking.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_SIZE_CHECKING_TPP -#error "vector/size_checking.tpp not included correctly" +# error "vector/size_checking.tpp not included correctly" #endif #include @@ -16,11 +14,14 @@ namespace cml { namespace detail { /* No-op binary vector expression size checking: */ -template inline void -check_same_size(const readable_vector&, const Sub2&, any_size_tag) {} +template +inline void +check_same_size(const readable_vector&, const Sub2&, any_size_tag) +{} /* Compile-time binary vector expression size checking: */ -template inline void +template +inline void check_same_size(const readable_vector&, const Sub2&, fixed_size_tag) { static_assert(array_size_of_c::value == array_size_of_c::value, @@ -28,39 +29,38 @@ check_same_size(const readable_vector&, const Sub2&, fixed_size_tag) } /* Run-time binary vector expression size checking: */ -template inline void -check_same_size( - const readable_vector& left, const Sub2& right, dynamic_size_tag - ) +template +inline void +check_same_size(const readable_vector& left, const Sub2& right, + dynamic_size_tag) { #ifndef CML_NO_RUNTIME_VECTOR_SIZE_CHECKS cml_require(array_size_of(left) == array_size_of(right), - incompatible_vector_size_error, /**/); + incompatible_vector_size_error, + /**/); #endif } - - /* No-op minimum vector size checking. */ -template inline void -check_minimum_size( - const readable_vector&, int, enable_if_any_size_t* = nullptr - ) -{ -} +template +inline void +check_minimum_size(const readable_vector&, int, + enable_if_any_size_t* = nullptr) +{} /* Compile-time minimum size checking against a constant. */ -template inline void -check_minimum_size(const readable_vector&, - cml::int_c, enable_if_fixed_size_t* = nullptr - ) +template +inline void +check_minimum_size(const readable_vector&, cml::int_c, + enable_if_fixed_size_t* = nullptr) { - static_assert( - array_size_of_c::value >= N, "vector expression too short"); + static_assert(array_size_of_c::value >= N, + "vector expression too short"); } /* Run-time minimum vector size checking. */ -template inline void +template +inline void check_minimum_size(const readable_vector& sub, int N) { #ifndef CML_NO_RUNTIME_VECTOR_SIZE_CHECKS @@ -68,28 +68,26 @@ check_minimum_size(const readable_vector& sub, int N) #endif } - - /* No-op vector size checking. */ -template inline void -check_size( - const readable_vector&, int, enable_if_any_size_t* = nullptr - ) -{ -} +template +inline void +check_size(const readable_vector&, int, + enable_if_any_size_t* = nullptr) +{} /* Compile-time size checking against a constant. */ -template inline void -check_size(const readable_vector&, - cml::int_c, enable_if_fixed_size_t* = nullptr - ) +template +inline void +check_size(const readable_vector&, cml::int_c, + enable_if_fixed_size_t* = nullptr) { - static_assert( - array_size_of_c::value == N, "incorrect vector expression size"); + static_assert(array_size_of_c::value == N, + "incorrect vector expression size"); } /* Run-time vector size checking. */ -template inline void +template +inline void check_size(const readable_vector& sub, int N) { #ifndef CML_NO_RUNTIME_VECTOR_SIZE_CHECKS @@ -97,22 +95,18 @@ check_size(const readable_vector& sub, int N) #endif } - - /* No-op vector size range checking. */ -template inline void -check_size_range( - const readable_vector&, int, int, enable_if_any_size_t* = nullptr - ) -{ -} +template +inline void +check_size_range(const readable_vector&, int, int, + enable_if_any_size_t* = nullptr) +{} /* Compile-time size range checking against constants. */ -template inline void -check_size_range(const readable_vector&, - cml::int_c, cml::int_c, - enable_if_fixed_size_t* = nullptr - ) +template +inline void +check_size_range(const readable_vector&, cml::int_c, cml::int_c, + enable_if_fixed_size_t* = nullptr) { static_assert( array_size_of_c::value >= Low && array_size_of_c::value <= High, @@ -120,100 +114,99 @@ check_size_range(const readable_vector&, } /* Run-time vector size checking. */ -template inline void +template +inline void check_size_range(const readable_vector& sub, int Low, int High) { #ifndef CML_NO_RUNTIME_VECTOR_SIZE_CHECKS - cml_require( - array_size_of(sub) >= Low && array_size_of(sub) <= High, - vector_size_range_error, /**/); + cml_require(array_size_of(sub) >= Low && array_size_of(sub) <= High, + vector_size_range_error, + /**/); #endif } -} // namespace detail - +} // namespace detail /* check_same_size: */ -template inline void -check_same_size( - const readable_vector& left, const readable_vector& right - ) +template +inline void +check_same_size(const readable_vector& left, + const readable_vector& right) { - typedef size_tag_of_t tag1; - typedef size_tag_of_t tag2; - detail::check_same_size( - left, right.actual(), size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = size_tag_of_t; + detail::check_same_size(left, right.actual(), + size_check_promote_t()); } -template inline void -check_same_size( - const readable_vector& left, const Sub2& right, - enable_if_array_t* - ) +template +inline void +check_same_size(const readable_vector& left, const Sub2& right, + enable_if_array_t*) { - typedef size_tag_of_t tag1; - typedef tag1 tag2; // dynamic/dynamic or fixed/fixed. - detail::check_same_size(left, right, size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = tag1; // dynamic/dynamic or fixed/fixed. + detail::check_same_size(left, right, size_check_promote_t()); } -template auto +template +auto check_same_size(const readable_vector& left, const Sub2& right) --> decltype(right.size(), void()) + -> decltype(right.size(), void()) { - typedef size_tag_of_t tag1; - typedef dynamic_size_tag tag2; // dynamic/dynamic or fixed/dynamic. - detail::check_same_size(left, right, size_check_promote_t()); + using tag1 = size_tag_of_t; + using tag2 = dynamic_size_tag; // dynamic/dynamic or fixed/dynamic. + detail::check_same_size(left, right, size_check_promote_t()); } - /* check_minimum_size: */ -template inline void +template +inline void check_minimum_size(const readable_vector& left, int N) { detail::check_minimum_size(left, N); } -template inline void +template +inline void check_minimum_size(const readable_vector& left, cml::int_c) { detail::check_minimum_size(left, cml::int_c()); } - /* check_size: */ -template inline void +template +inline void check_size(const readable_vector& left, int N) { detail::check_size(left, N); } -template inline void +template +inline void check_size(const readable_vector& left, cml::int_c) { detail::check_size(left, cml::int_c()); } - /* check_size_range: */ -template inline void +template +inline void check_size_range(const readable_vector& left, int Low, int High) { detail::check_size_range(left, Low, High); } -template inline void -check_size_range( - const readable_vector& left, cml::int_c, cml::int_c - ) +template +inline void +check_size_range(const readable_vector& left, cml::int_c, + cml::int_c) { detail::check_size_range(left, cml::int_c(), cml::int_c()); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/subvector.h b/cml/vector/subvector.h index 76d9cf6..a2f2ba3 100644 --- a/cml/vector/subvector.h +++ b/cml/vector/subvector.h @@ -1,18 +1,8 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_subvector_h -#define cml_vector_subvector_h - #include #include - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/subvector_node.h b/cml/vector/subvector_node.h index 339df28..78847db 100644 --- a/cml/vector/subvector_node.h +++ b/cml/vector/subvector_node.h @@ -1,13 +1,8 @@ -/* -*- C++ -*- ------------------------------------------------------------ @@COPYRIGHT@@ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_subvector_node_h -#define cml_vector_subvector_node_h - #include #include @@ -16,34 +11,33 @@ namespace cml { template class subvector_node; /** subvector_node<> traits. */ -template -struct vector_traits< subvector_node > +template struct vector_traits> { /* Figure out the basic type of Sub: */ - typedef subvector_node vector_type; - typedef Sub sub_arg_type; - typedef cml::unqualified_type_t sub_type; - typedef vector_traits sub_traits; - typedef typename sub_traits::element_traits element_traits; - typedef typename sub_traits::value_type value_type; - typedef typename sub_traits::immutable_value immutable_value; + using vector_type = subvector_node; + using sub_arg_type = Sub; + using sub_type = cml::unqualified_type_t; + using sub_traits = vector_traits; + using element_traits = typename sub_traits::element_traits; + using value_type = typename sub_traits::value_type; + using immutable_value = typename sub_traits::immutable_value; /* Compute the new storage size: */ + private: static const int old_array_size = sub_traits::array_size; static const int new_array_size = old_array_size - 1; static const int N = new_array_size > 0 ? new_array_size : -1; - public: + public: /* Resize the storage type of the subexpression: */ - typedef resize_storage_t< - storage_type_of_t, N> resized_type; + using resized_type = resize_storage_t, N>; /* Rebind to vector storage: */ - typedef rebind_t storage_type; + using storage_type = rebind_t; /* Traits and types for the new storage: */ - typedef typename storage_type::size_tag size_tag; + using size_tag = typename storage_type::size_tag; /* Array size: */ static const int array_size = storage_type::array_size; @@ -53,95 +47,83 @@ struct vector_traits< subvector_node > * the length of the wrapped subexpression. */ template -class subvector_node -: public readable_vector< subvector_node > +class subvector_node : public readable_vector> { public: - - typedef subvector_node node_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::sub_arg_type sub_arg_type; - typedef typename traits_type::sub_type sub_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using node_type = subvector_node; + using readable_type = readable_vector; + using traits_type = vector_traits; + using sub_arg_type = typename traits_type::sub_arg_type; + using sub_type = typename traits_type::sub_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** The array size constant depends upon the subexpression size. */ - static const int array_size = traits_type::array_size; + /** The array size constant depends upon the subexpression size. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped sub-expression and the element to drop. + /** Construct from the wrapped sub-expression and the element to drop. * @c sub must be an lvalue reference or rvalue reference. */ - subvector_node(Sub sub, int skip); + subvector_node(Sub sub, int skip); - /** Move constructor. */ - subvector_node(node_type&& other); + /** Move constructor. */ + subvector_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - subvector_node(const node_type& other); + /** Copy constructor. */ + subvector_node(const node_type& other); #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the size of the vector expression. */ - int i_size() const; + /** Return the size of the vector expression. */ + int i_size() const; - /** Apply the operator to element @c i and return the result. */ - immutable_value i_get(int i) const; + /** Apply the operator to element @c i and return the result. */ + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the subexpression. The expression is stored + /** The type used to store the subexpression. The expression is stored * as a copy if Sub is an rvalue reference (temporary), or by const * reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const sub_type&, sub_type> wrap_type; + using wrap_type = cml::if_t::value, const sub_type&, + sub_type>; - /** The wrapped subexpression. */ - wrap_type m_sub; + /** The wrapped subexpression. */ + wrap_type m_sub; - /** The element to skip. */ - int m_skip; + /** The element to skip. */ + int m_skip; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - subvector_node(const node_type&); + // Not copy constructible. + subvector_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_SUBVECTOR_NODE_TPP #include #undef __CML_VECTOR_SUBVECTOR_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/subvector_node.tpp b/cml/vector/subvector_node.tpp index 7ff9534..740a28e 100644 --- a/cml/vector/subvector_node.tpp +++ b/cml/vector/subvector_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_SUBVECTOR_NODE_TPP -#error "vector/subvector_node.tpp not included correctly" +# error "vector/subvector_node.tpp not included correctly" #endif namespace cml { @@ -14,43 +12,41 @@ namespace cml { template subvector_node::subvector_node(Sub sub, int skip) -: m_sub(std::move(sub)), m_skip(skip) -{ -} +: m_sub(std::move(sub)) +, m_skip(skip) +{} template subvector_node::subvector_node(node_type&& other) -: m_sub(std::move(other.m_sub)), m_skip(other.m_skip) -{ -} +: m_sub(std::move(other.m_sub)) +, m_skip(other.m_skip) +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template subvector_node::subvector_node(const node_type& other) -: m_sub(other.m_sub), m_skip(other.m_skip) -{ -} +: m_sub(other.m_sub) +, m_skip(other.m_skip) +{} #endif - /* Internal methods: */ /* readable_vector interface: */ -template int +template +int subvector_node::i_size() const { return this->m_sub.size() - 1; } -template auto +template +auto subvector_node::i_get(int i) const -> immutable_value { - return this->m_sub.get((i < this->m_skip) ? i : (i+1)); + return this->m_sub.get((i < this->m_skip) ? i : (i + 1)); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/subvector_ops.h b/cml/vector/subvector_ops.h index 916e57c..3e92637 100644 --- a/cml/vector/subvector_ops.h +++ b/cml/vector/subvector_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_subvector_ops_h -#define cml_vector_subvector_ops_h - #include namespace cml { @@ -16,23 +11,19 @@ namespace cml { /** Return an expression node for the subvector @c i of @c sub. @c sub is * stored by const reference in the node. */ -template auto subvector(const readable_vector& sub, int i) --> subvector_node; +template +auto subvector(const readable_vector& sub, int i) + -> subvector_node; /** Return an expression node for subvector @c i of the temporary * subexpression @c sub. @c sub is stored by value in the node (via * std::move). */ -template auto subvector(readable_vector&& sub) --> subvector_node; +template +auto subvector(readable_vector&& sub) -> subvector_node; -} // namespace cml +} // namespace cml #define __CML_VECTOR_SUBVECTOR_OPS_TPP #include #undef __CML_VECTOR_SUBVECTOR_OPS_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/subvector_ops.tpp b/cml/vector/subvector_ops.tpp index 61dfe61..65aee65 100644 --- a/cml/vector/subvector_ops.tpp +++ b/cml/vector/subvector_ops.tpp @@ -1,30 +1,25 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_SUBVECTOR_OPS_TPP -#error "vector/subvector_ops.tpp not included correctly" +# error "vector/subvector_ops.tpp not included correctly" #endif namespace cml { -template inline auto -subvector(const readable_vector& sub, int i) --> subvector_node +template +inline auto +subvector(const readable_vector& sub, int i) -> subvector_node { return subvector_node(sub.actual(), i); } -template inline auto -subvector(readable_vector&& sub, int i) --> subvector_node +template +inline auto +subvector(readable_vector&& sub, int i) -> subvector_node { return subvector_node((Sub&&) sub, i); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/temporary.h b/cml/vector/temporary.h index 6d2b049..fd9a05a 100644 --- a/cml/vector/temporary.h +++ b/cml/vector/temporary.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_temporary_h -#define cml_vector_temporary_h - #include #include #include @@ -19,93 +14,88 @@ namespace cml { /** Deduce a temporary for a vector expression. */ template -struct temporary_of< Vector, cml::enable_if_vector_t > +struct temporary_of> { - typedef cml::unqualified_type_t vector_type; + using vector_type = cml::unqualified_type_t; /* Propagate the element type of the original vector: */ - typedef vector_traits traits_type; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::storage_type storage_type; + using traits_type = vector_traits; + using value_type = typename traits_type::value_type; + using storage_type = typename traits_type::storage_type; /* Need the proxy for the storage type: */ - typedef proxy_type_of_t proxy_type; + using proxy_type = proxy_type_of_t; /* Build the temporary: */ - typedef vector type; + using type = vector; }; - /** Deduce a subvector temporary type for a vector expression. */ -template::array_size == vector_traits::array_size - >::type* = nullptr> +template::array_size + == vector_traits::array_size>::type* = nullptr> struct subvector_of { - typedef cml::unqualified_type_t vector_type; + using vector_type = cml::unqualified_type_t; /* Propagate the element type of the original vector: */ - typedef vector_traits traits_type; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::size_tag size_tag; + using traits_type = vector_traits; + using storage_type = typename traits_type::storage_type; + using value_type = typename traits_type::value_type; + using size_tag = typename traits_type::size_tag; /* Compute the new storage size: */ + private: static const int old_array_size = traits_type::array_size; static const int new_array_size = old_array_size - 1; static const int N = new_array_size > 0 ? new_array_size : -1; - public: + public: /* Determine the new storage type: */ - typedef resize_storage_t resized_type; - typedef rebind_t rebound_type; - typedef proxy_type_of_t proxy_type; + using resized_type = resize_storage_t; + using rebound_type = rebind_t; + using proxy_type = proxy_type_of_t; /* Build the subvector from the new storage type: */ - typedef vector type; + using type = vector; }; /** Convenience alias for subvector_of. */ template using subvector_of_t = typename subvector_of::type; - /** Deduce a supervector temporary type for a vector expression. */ -template::array_size == vector_traits::array_size - >::type* = nullptr> +template::array_size + == vector_traits::array_size>::type* = nullptr> struct supervector_of { - typedef cml::unqualified_type_t vector_type; + using vector_type = cml::unqualified_type_t; /* Propagate the element type of the original vector: */ - typedef vector_traits traits_type; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::size_tag size_tag; + using traits_type = vector_traits; + using storage_type = typename traits_type::storage_type; + using value_type = typename traits_type::value_type; + using size_tag = typename traits_type::size_tag; /* Compute the new storage size: */ + private: static const int old_array_size = traits_type::array_size; static const int new_array_size = old_array_size + 1; static const int N = new_array_size > 0 ? new_array_size : -1; - public: + public: /* Determine the new storage type: */ - typedef resize_storage_t resized_type; - typedef rebind_t rebound_type; - typedef proxy_type_of_t proxy_type; + using resized_type = resize_storage_t; + using rebound_type = rebind_t; + using proxy_type = proxy_type_of_t; /* Build the supervector from the new storage type: */ - typedef vector type; + using type = vector; }; /** Convenience alias for supervector_of. */ template using supervector_of_t = typename supervector_of::type; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/traits.h b/cml/vector/traits.h index 1fab953..e2a859d 100644 --- a/cml/vector/traits.h +++ b/cml/vector/traits.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_traits_h -#define cml_vector_traits_h - #include #include @@ -23,14 +18,9 @@ namespace cml { template struct vector_traits; /** traits_of for vector types. */ -template -struct traits_of> { - typedef vector_traits type; +template struct traits_of> +{ + using type = vector_traits; }; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/triple_product.h b/cml/vector/triple_product.h index c14ec41..7e1f719 100644 --- a/cml/vector/triple_product.h +++ b/cml/vector/triple_product.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_triple_product_h -#define cml_vector_triple_product_h - #include #include @@ -18,7 +13,7 @@ namespace cml { * cml::triple_product. */ template - using triple_product_promote_t = value_type_trait_promote_t; +using triple_product_promote_t = value_type_trait_promote_t; /** Compute the scalar triple product ("box product") of 3 3D vectors, and * return the scalar result. @@ -30,17 +25,13 @@ template * and is not a 3D vector. The size is checked at compile time for * fixed-sized expressions. */ -template auto triple_product( - const readable_vector& a, const readable_vector& b, - const readable_vector& c) -> triple_product_promote_t; +template +auto triple_product(const readable_vector& a, + const readable_vector& b, const readable_vector& c) + -> triple_product_promote_t; -} // namespace cml +} // namespace cml #define __CML_VECTOR_TRIPLE_PRODUCT_TPP #include #undef __CML_VECTOR_TRIPLE_PRODUCT_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/triple_product.tpp b/cml/vector/triple_product.tpp index 4eaf310..ae711d6 100644 --- a/cml/vector/triple_product.tpp +++ b/cml/vector/triple_product.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_TRIPLE_PRODUCT_TPP -#error "vector/triple_product.tpp not included correctly" +# error "vector/triple_product.tpp not included correctly" #endif #include @@ -13,18 +11,15 @@ namespace cml { -template inline auto -triple_product(const readable_vector& a, - const readable_vector& b, const readable_vector& c - ) -> triple_product_promote_t +template +inline auto +triple_product(const readable_vector& a, const readable_vector& b, + const readable_vector& c) -> triple_product_promote_t { cml::check_size(a, cml::int_c<3>()); cml::check_size(b, cml::int_c<3>()); cml::check_size(c, cml::int_c<3>()); - return cml::dot(a, cross(b,c)); + return cml::dot(a, cross(b, c)); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/type_util.h b/cml/vector/type_util.h index 71e6b53..325fa62 100644 --- a/cml/vector/type_util.h +++ b/cml/vector/type_util.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_type_util_h -#define cml_vector_type_util_h - #include #include @@ -19,23 +14,21 @@ namespace cml { * otherwise. The static bool @c value is set to true or false to match @c * type. */ -template struct is_vector { +template struct is_vector +{ private: - /* Strip const, volatile, and reference from T to get the type to test: */ - typedef cml::unqualified_type_t naked_type; + using naked_type = cml::unqualified_type_t; /* Deduce the derived type (fails if T is not statically polymorphic): */ - typedef actual_type_of_t derived_type; + using derived_type = actual_type_of_t; public: - /* std::true_type if T is derived from readable_vector<>, std::false_type * otherwise: */ - typedef std::is_base_of< - readable_vector, naked_type> type; + using type = std::is_base_of, naked_type>; /* True or false, depending upon 'type': */ static const bool value = type::value; @@ -44,16 +37,12 @@ template struct is_vector { /** Wrapper for enable_if to detect vector types (derived from * readable_vector). */ -template struct enable_if_vector -: std::enable_if::value> {}; +template +struct enable_if_vector : std::enable_if::value> +{}; /** Convenience alias for enable_if_vector. */ -template using enable_if_vector_t - = typename enable_if_vector::type; - -} // namespace cml - -#endif +template +using enable_if_vector_t = typename enable_if_vector::type; -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/types.h b/cml/vector/types.h index ef2aa5b..ac0b274 100644 --- a/cml/vector/types.h +++ b/cml/vector/types.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_types_h -#define cml_vector_types_h - #include #include @@ -17,50 +12,45 @@ namespace cml { /** @defgroup vector_types Predefined Vector Types */ /*@{*/ -typedef vector> vector2i; -typedef vector> vector3i; -typedef vector> vector4i; -typedef vector> vectori; -typedef vector> external2i; -typedef vector> external3i; -typedef vector> external4i; -typedef vector> externalni; -typedef vector> external2ci; -typedef vector> external3ci; -typedef vector> external4ci; -typedef vector> externalnci; - -typedef vector> vector2f; -typedef vector> vector3f; -typedef vector> vector4f; -typedef vector> vectorf; -typedef vector> external2f; -typedef vector> external3f; -typedef vector> external4f; -typedef vector> externalnf; -typedef vector> external2cf; -typedef vector> external3cf; -typedef vector> external4cf; -typedef vector> externalncf; - -typedef vector> vector2d; -typedef vector> vector3d; -typedef vector> vector4d; -typedef vector> vectord; -typedef vector> external2d; -typedef vector> external3d; -typedef vector> external4d; -typedef vector> externalnd; -typedef vector> external2cd; -typedef vector> external3cd; -typedef vector> external4cd; -typedef vector> externalncd; +using vector2i = vector>; +using vector3i = vector>; +using vector4i = vector>; +using vectori = vector>; +using external2i = vector>; +using external3i = vector>; +using external4i = vector>; +using externalni = vector>; +using external2ci = vector>; +using external3ci = vector>; +using external4ci = vector>; +using externalnci = vector>; + +using vector2f = vector>; +using vector3f = vector>; +using vector4f = vector>; +using vectorf = vector>; +using external2f = vector>; +using external3f = vector>; +using external4f = vector>; +using externalnf = vector>; +using external2cf = vector>; +using external3cf = vector>; +using external4cf = vector>; +using externalncf = vector>; + +using vector2d = vector>; +using vector3d = vector>; +using vector4d = vector>; +using vectord = vector>; +using external2d = vector>; +using external3d = vector>; +using external4d = vector>; +using externalnd = vector>; +using external2cd = vector>; +using external3cd = vector>; +using external4cd = vector>; +using externalncd = vector>; /*@}*/ -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/unary_node.h b/cml/vector/unary_node.h index 8c8950d..79f0aa0 100644 --- a/cml/vector/unary_node.h +++ b/cml/vector/unary_node.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_unary_node_h -#define cml_vector_unary_node_h - #include namespace cml { @@ -16,18 +11,17 @@ namespace cml { template class vector_unary_node; /** vector_unary_node<> traits. */ -template -struct vector_traits< vector_unary_node > +template struct vector_traits> { - typedef vector_unary_node vector_type; - typedef Sub sub_arg_type; - typedef cml::unqualified_type_t sub_type; - typedef vector_traits sub_traits; - typedef scalar_traits element_traits; - typedef typename element_traits::value_type value_type; - typedef value_type immutable_value; - typedef typename sub_traits::storage_type storage_type; - typedef typename sub_traits::size_tag size_tag; + using vector_type = vector_unary_node; + using sub_arg_type = Sub; + using sub_type = cml::unqualified_type_t; + using sub_traits = vector_traits; + using element_traits = scalar_traits; + using value_type = typename element_traits::value_type; + using immutable_value = value_type; + using storage_type = typename sub_traits::storage_type; + using size_tag = typename sub_traits::size_tag; /* Propagate the array size from the subexpression: */ static const int array_size = sub_traits::array_size; @@ -35,92 +29,80 @@ struct vector_traits< vector_unary_node > /** Represents a unary vector operation in an expression tree. */ template -class vector_unary_node -: public readable_vector< vector_unary_node > +class vector_unary_node : public readable_vector> { public: - - typedef vector_unary_node node_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::sub_arg_type sub_arg_type; - typedef typename traits_type::sub_type sub_type; - typedef typename traits_type::element_traits element_traits; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::immutable_value immutable_value; - typedef typename traits_type::storage_type storage_type; - typedef typename traits_type::size_tag size_tag; + using node_type = vector_unary_node; + using readable_type = readable_vector; + using traits_type = vector_traits; + using sub_arg_type = typename traits_type::sub_arg_type; + using sub_type = typename traits_type::sub_type; + using element_traits = typename traits_type::element_traits; + using value_type = typename traits_type::value_type; + using immutable_value = typename traits_type::immutable_value; + using storage_type = typename traits_type::storage_type; + using size_tag = typename traits_type::size_tag; public: - - /** The array size constant is the same as the subexpression. */ - static const int array_size = traits_type::array_size; + /** The array size constant is the same as the subexpression. */ + static const int array_size = traits_type::array_size; public: - - /** Construct from the wrapped sub-expression. @c sub must be an + /** Construct from the wrapped sub-expression. @c sub must be an * lvalue reference or rvalue reference. */ - explicit vector_unary_node(Sub sub); + explicit vector_unary_node(Sub sub); - /** Move constructor. */ - vector_unary_node(node_type&& other); + /** Move constructor. */ + vector_unary_node(node_type&& other); #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Copy constructor. */ - vector_unary_node(const node_type& other); + /** Copy constructor. */ + vector_unary_node(const node_type& other); #endif protected: + /** @name readable_vector Interface */ + /*@{*/ - /** @name readable_vector Interface */ - /*@{*/ - - friend readable_type; + friend readable_type; - /** Return the size of the vector expression. */ - int i_size() const; + /** Return the size of the vector expression. */ + int i_size() const; - /** Apply the operator to element @c i and return the result. */ - immutable_value i_get(int i) const; + /** Apply the operator to element @c i and return the result. */ + immutable_value i_get(int i) const; - /*@}*/ + /*@}*/ protected: - - /** The type used to store the subexpression. The expression is stored + /** The type used to store the subexpression. The expression is stored * as a copy if Sub is an rvalue reference (temporary), or by const * reference if Sub is an lvalue reference. */ - typedef cml::if_t::value, - const sub_type&, sub_type> sub_wrap_type; + using sub_wrap_type = cml::if_t::value, const sub_type&, + sub_type>; - /** The wrapped subexpression. */ - sub_wrap_type m_sub; + /** The wrapped subexpression. */ + sub_wrap_type m_sub; private: - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - vector_unary_node(const node_type&); + // Not copy constructible. + vector_unary_node(const node_type&); #endif - // Not assignable. - node_type& operator=(const node_type&); + // Not assignable. + node_type& operator=(const node_type&); }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_UNARY_NODE_TPP #include #undef __CML_VECTOR_UNARY_NODE_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/unary_node.tpp b/cml/vector/unary_node.tpp index 1253912..f4ae780 100644 --- a/cml/vector/unary_node.tpp +++ b/cml/vector/unary_node.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_UNARY_NODE_TPP -#error "vector/unary_node.tpp not included correctly" +# error "vector/unary_node.tpp not included correctly" #endif namespace cml { @@ -13,44 +11,39 @@ namespace cml { /* vector_unary_node 'structors: */ template -vector_unary_node::vector_unary_node(Sub sub) +vector_unary_node::vector_unary_node(Sub sub) : m_sub(std::move(sub)) -{ -} +{} template -vector_unary_node::vector_unary_node(node_type&& other) +vector_unary_node::vector_unary_node(node_type&& other) : m_sub(std::move(other.m_sub)) -{ -} +{} #ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -vector_unary_node::vector_unary_node(const node_type& other) +vector_unary_node::vector_unary_node(const node_type& other) : m_sub(other.m_sub) -{ -} +{} #endif - /* Internal methods: */ /* readable_vector interface: */ -template int -vector_unary_node::i_size() const +template +int +vector_unary_node::i_size() const { return this->m_sub.size(); } -template auto -vector_unary_node::i_get(int i) const -> immutable_value +template +auto +vector_unary_node::i_get(int i) const -> immutable_value { return Op().apply(this->m_sub.get(i)); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/vector/unary_ops.h b/cml/vector/unary_ops.h index 204571d..b6bc5ea 100644 --- a/cml/vector/unary_ops.h +++ b/cml/vector/unary_ops.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_unary_ops_h -#define cml_vector_unary_ops_h - #include #include @@ -18,35 +13,33 @@ namespace cml { * (i.e. derived from readable_vector<>). */ template* = nullptr> -inline auto make_vector_unary_node(Sub&& sub) --> vector_unary_node, Op> +inline auto +make_vector_unary_node(Sub&& sub) + -> vector_unary_node, Op> { - static_assert(std::is_same< - decltype(sub), decltype(std::forward(sub))>::value, + static_assert( + std::is_same(sub))>::value, "internal error: unexpected expression type"); /* Deduce the operand type of the subexpression (&, const&, &&): */ - typedef actual_operand_type_of_t sub_type; + using sub_type = actual_operand_type_of_t; return vector_unary_node((sub_type) sub); } template* = nullptr> -inline auto operator-(Sub&& sub) --> decltype(make_vector_unary_node>(std::forward(sub))) +inline auto +operator-(Sub&& sub) -> decltype(make_vector_unary_node>( + std::forward(sub))) { return make_vector_unary_node>(std::forward(sub)); } template* = nullptr> -inline auto operator+(Sub&& sub) --> decltype(make_vector_unary_node>(std::forward(sub))) +inline auto +operator+(Sub&& sub) + -> decltype(make_vector_unary_node>(std::forward(sub))) { return make_vector_unary_node>(std::forward(sub)); } -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/vector.h b/cml/vector/vector.h index 6b5ab0f..4309a13 100644 --- a/cml/vector/vector.h +++ b/cml/vector/vector.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_vector_h -#define cml_vector_vector_h - namespace cml { /** Specializable class for building vector types. @@ -25,9 +20,4 @@ namespace cml { */ template class vector; -} // namespace cml - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml diff --git a/cml/vector/writable_vector.h b/cml/vector/writable_vector.h index e93df9f..aedf2b4 100644 --- a/cml/vector/writable_vector.h +++ b/cml/vector/writable_vector.h @@ -1,14 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_vector_writable_vector_h -#define cml_vector_writable_vector_h - #include #include #include @@ -40,150 +35,145 @@ namespace cml { * Note that mutable_value need not be a reference type. */ template -class writable_vector -: public readable_vector +class writable_vector : public readable_vector { public: - - typedef DerivedT vector_type; - typedef readable_vector readable_type; - typedef vector_traits traits_type; - typedef typename traits_type::value_type value_type; - typedef typename traits_type::const_reference const_reference; - typedef typename traits_type::mutable_value mutable_value; + using vector_type = DerivedT; + using readable_type = readable_vector; + using traits_type = vector_traits; + using value_type = typename traits_type::value_type; + using const_reference = typename traits_type::const_reference; + using mutable_value = typename traits_type::mutable_value; public: - - /* Disambiguate readable_vector<> methods: */ - using readable_type::actual; - using readable_type::get; - using readable_type::normalize; - using readable_type::operator[]; + /* Disambiguate readable_vector<> methods: */ + using readable_type::actual; + using readable_type::get; + using readable_type::normalize; + using readable_type::operator[]; public: + /** Return a mutable reference to the vector cast as DerivedT. */ + DerivedT& actual(); - /** Return a mutable reference to the vector cast as DerivedT. */ - DerivedT& actual(); - - /** Set element @c i. */ - template DerivedT& put(int i, const Other& v) __CML_REF; + /** Set element @c i. */ + template DerivedT& put(int i, const Other& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i on a temporary. */ - template DerivedT&& put(int i, const Other& v) &&; + /** Set element @c i on a temporary. */ + template DerivedT&& put(int i, const Other& v) &&; #endif - /** Return mutable element @c i. */ - mutable_value get(int i); + /** Return mutable element @c i. */ + mutable_value get(int i); #ifdef CML_HAS_STRUCTURED_BINDINGS - /** Return const element @c i. */ - template>* = nullptr> - mutable_value get(); + /** Return const element @c i. */ + template>* = nullptr> + mutable_value get(); #endif - /** Return a mutable reference to element @c i. */ - mutable_value operator[](int i); + /** Return a mutable reference to element @c i. */ + mutable_value operator[](int i); public: - - /** Divide the vector elements by the length of the vector. */ - DerivedT& normalize() __CML_REF; + /** Divide the vector elements by the length of the vector. */ + DerivedT& normalize() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Divide the vector elements of a temporary by the length of the + /** Divide the vector elements of a temporary by the length of the * vector. */ - DerivedT&& normalize() &&; + DerivedT&& normalize() &&; #endif - /** Zero the vector elements. */ - DerivedT& zero() __CML_REF; + /** Zero the vector elements. */ + DerivedT& zero() __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Zero the vector elements of a temporary. */ - DerivedT&& zero() &&; + /** Zero the vector elements of a temporary. */ + DerivedT&& zero() &&; #endif - /** Set element @c i to value_type(1), and the other elements to 0. */ - DerivedT& cardinal(int i) __CML_REF; + /** Set element @c i to value_type(1), and the other elements to 0. */ + DerivedT& cardinal(int i) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set element @c i of a temporary to value_type(1), and the other + /** Set element @c i of a temporary to value_type(1), and the other * elements to 0. */ - DerivedT&& cardinal(int i) &&; + DerivedT&& cardinal(int i) &&; #endif - /** Set the vector to the pairwise minimum elements with @c other. + /** Set the vector to the pairwise minimum elements with @c other. * * @throws incompatible_vector_size_error at run-time if either vector is * dynamically-sized, and @c other.size() != this->size(). If both are * fixed-size expressions, then the size is checked at compile time. */ - template DerivedT& - minimize(const readable_vector& other) __CML_REF; + template + DerivedT& minimize(const readable_vector& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set the temporary vector to the pairwise minimum elements with @c + /** Set the temporary vector to the pairwise minimum elements with @c * other. * * @throws incompatible_vector_size_error at run-time if either vector is * dynamically-sized, and @c other.size() != this->size(). If both are * fixed-size expressions, then the size is checked at compile time. */ - template DerivedT&& - minimize(const readable_vector& other) &&; + template + DerivedT&& minimize(const readable_vector& other) &&; #endif - /** Set the vector to the pairwise minimum elements with @c other. + /** Set the vector to the pairwise minimum elements with @c other. * * @throws incompatible_vector_size_error at run-time if either vector is * dynamically-sized, and @c other.size() != this->size(). If both are * fixed-size expressions, then the size is checked at compile time. */ - template DerivedT& - maximize(const readable_vector& other) __CML_REF; + template + DerivedT& maximize(const readable_vector& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set the vector to the pairwise minimum elements with @c other. + /** Set the vector to the pairwise minimum elements with @c other. * * @throws incompatible_vector_size_error at run-time if either vector is * dynamically-sized, and @c other.size() != this->size(). If both are * fixed-size expressions, then the size is checked at compile time. */ - template DerivedT&& - maximize(const readable_vector& other) &&; + template + DerivedT&& maximize(const readable_vector& other) &&; #endif - /** Set elements to random values in the range @c[low,high]. + /** Set elements to random values in the range @c[low,high]. * * @note Use std::srand() to seed the random number generator. */ - DerivedT& random(const_reference low, const_reference high) __CML_REF; + DerivedT& random(const_reference low, const_reference high) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set elements of a temporary to random values in the range + /** Set elements of a temporary to random values in the range * @c[low,high]. */ - DerivedT&& random(const_reference low, const_reference high) &&; + DerivedT&& random(const_reference low, const_reference high) &&; #endif - /** Set all elements to a specific value. */ - DerivedT& fill(const_reference v) __CML_REF; + /** Set all elements to a specific value. */ + DerivedT& fill(const_reference v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set all elements of a temporary to a specific value. */ - DerivedT&& fill(const_reference v) &&; + /** Set all elements of a temporary to a specific value. */ + DerivedT&& fill(const_reference v) &&; #endif public: - - /** Assign from a variable list of at least one value. If the vector is + /** Assign from a variable list of at least one value. If the vector is * resizable, it is resized to exactly accomodate the elements of @c * eN. If the vector is fixed-size, it must have the same length as @c * eN. @@ -191,12 +181,12 @@ class writable_vector * @note This overload is enabled only if all of the arguments are * convertible to value_type. */ - template auto - set(const E0& e0, const Elements&... eN) __CML_REF -> enable_if_t< - are_convertible::value, DerivedT&>; + template + auto set(const E0& e0, const Elements&... eN) __CML_REF->enable_if_t< + are_convertible::value, DerivedT&>; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Assign a temporary from a variable list of at least one value. If + /** Assign a temporary from a variable list of at least one value. If * the vector is resizable, it is resized to exactly accomodate the * elements of @c eN. If the vector is fixed-size, it must have the * same length as @c eN. @@ -204,151 +194,149 @@ class writable_vector * @note This overload is enabled only if all of the arguments are * convertible to value_type. */ - template auto - set(const E0& e0, const Elements&... eN) && -> enable_if_t< - are_convertible::value, DerivedT&&>; + template + auto set(const E0& e0, const Elements&... eN) && -> enable_if_t< + are_convertible::value, DerivedT&&>; #endif - /** Copy assignment. */ - DerivedT& operator=(const writable_vector& other) __CML_REF; + /** Copy assignment. */ + DerivedT& operator=(const writable_vector& other) __CML_REF; - /** Assign from a readable_vector. + /** Assign from a readable_vector. * * @throws incompatible_vector_size_error at run-time if the vector is not * resizable, and if @c other.size() != this->size(). If both are * fixed-size, then the size is checked at compile time. */ - template DerivedT& - operator=(const readable_vector& other) __CML_REF; + template + DerivedT& operator=(const readable_vector& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Assign a temporary from a readable_vector. + /** Assign a temporary from a readable_vector. * * @throws incompatible_vector_size_error at run-time if the vector is not * resizable, and if @c other.size() != this->size(). If both are * fixed-size, then the size is checked at compile time. */ - template DerivedT&& - operator=(const readable_vector& other) &&; + template + DerivedT&& operator=(const readable_vector& other) &&; #endif - /** Assign from a fixed-length array type. + /** Assign from a fixed-length array type. * * @throws incompatible_vector_size_error at run-time if the vector is not * resizable, and if @c array_size_of_c::value != * this->size(). If both are fixed-size, then the size is checked at * compile time. */ - template* = nullptr> - DerivedT& operator=(const Array& array) __CML_REF; + template* = nullptr> + DerivedT& operator=(const Array& array) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Assign a temporary from a fixed-length array type. + /** Assign a temporary from a fixed-length array type. * * @throws incompatible_vector_size_error at run-time if the vector is not * resizable, and if @c array_size_of_c::value != * this->size(). If both are fixed-size, then the size is checked at * compile time. */ - template* = nullptr> - DerivedT&& operator=(const Array& array) &&; + template* = nullptr> + DerivedT&& operator=(const Array& array) &&; #endif - /** Assign from initializer list. + /** Assign from initializer list. * * @throws incompatible_vector_size_error if the vector is not resizable, * and if @c l.size() != this->size(). */ - template - DerivedT& operator=(std::initializer_list l) __CML_REF; + template + DerivedT& operator=(std::initializer_list l) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Assign a temporary from initializer list. + /** Assign a temporary from initializer list. * * @throws incompatible_vector_size_error if the vector is not resizable, * and if @c l.size() != this->size(). */ - template - DerivedT&& operator=(std::initializer_list l) &&; + template DerivedT&& operator=(std::initializer_list l) &&; #endif - /** Modify the vector by addition of another vector. + /** Modify the vector by addition of another vector. * * @throws incompatible_vector_size_error at run-time if the vector is * dynamically-sized, and if @c other.size() != this->size(). If both * are fixed-size expressions, then the size is checked at compile * time. */ - template DerivedT& - operator+=(const readable_vector& other) __CML_REF; + template + DerivedT& operator+=(const readable_vector& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Modify a temporary vector by addition of another vector. + /** Modify a temporary vector by addition of another vector. * * @throws incompatible_vector_size_error at run-time if the vector is * dynamically-sized, and if @c other.size() != this->size(). If both * are fixed-size expressions, then the size is checked at compile * time. */ - template DerivedT&& - operator+=(const readable_vector& other) &&; + template + DerivedT&& operator+=(const readable_vector& other) &&; #endif - /** Modify the vector by subtraction of another vector. + /** Modify the vector by subtraction of another vector. * * @throws incompatible_vector_size_error at run-time if the vector is * dynamically-sized, and if @c other.size() != this->size(). If both * are fixed-size expressions, then the size is checked at compile * time. */ - template DerivedT& - operator-=(const readable_vector& other) __CML_REF; + template + DerivedT& operator-=(const readable_vector& other) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Modify a temporary vector by subtraction of another vector. + /** Modify a temporary vector by subtraction of another vector. * * @throws incompatible_vector_size_error at run-time if the vector is * dynamically-sized, and if @c other.size() != this->size(). If both * are fixed-size expressions, then the size is checked at compile * time. */ - template DerivedT&& - operator-=(const readable_vector& other) &&; + template + DerivedT&& operator-=(const readable_vector& other) &&; #endif - /** Multiply the vector by a scalar convertible to its value_type. */ - template* = nullptr> - DerivedT& operator*=(const ScalarT& v) __CML_REF; + /** Multiply the vector by a scalar convertible to its value_type. */ + template* = nullptr> + DerivedT& operator*=(const ScalarT& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Multiply the temporary vector by a scalar convertible to its + /** Multiply the temporary vector by a scalar convertible to its * value_type. */ - template* = nullptr> - DerivedT&& operator*=(const ScalarT& v) &&; + template* = nullptr> + DerivedT&& operator*=(const ScalarT& v) &&; #endif - /** Divide the vector by a scalar convertible to its value_type. */ - template* = nullptr> - DerivedT& operator/=(const ScalarT& v) __CML_REF; + /** Divide the vector by a scalar convertible to its value_type. */ + template* = nullptr> + DerivedT& operator/=(const ScalarT& v) __CML_REF; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Divide the vector temporary by a scalar convertible to its + /** Divide the vector temporary by a scalar convertible to its * value_type. */ - template* = nullptr> - DerivedT&& operator/=(const ScalarT& v) &&; + template* = nullptr> + DerivedT&& operator/=(const ScalarT& v) &&; #endif protected: - - /** Assign from a readable_vector. + /** Assign from a readable_vector. * * @note This depends upon implicit conversion of the source vector * elements to the vector value_type. @@ -357,20 +345,20 @@ class writable_vector * resizable, and if @c other.size() != this->size(). If both are * fixed-size expressions, then the size is checked at compile time. */ - template - DerivedT& assign(const readable_vector& other); + template + DerivedT& assign(const readable_vector& other); - /** Construct from a fixed-length array of values. If the vector is + /** Construct from a fixed-length array of values. If the vector is * resizable, it is resized to exactly accomodate the array. If the * vector is fixed-size, it must have the same length as @c array. * * @note This depends upon implicit conversions of the elements to the * vector value_type. */ - template* = nullptr> - DerivedT& assign(const Array& array); + template* = nullptr> + DerivedT& assign(const Array& array); - /** Assign from a pointer to an array. + /** Assign from a pointer to an array. * * @note This depends upon implicit conversion of the array elements to * the vector value_type. @@ -378,27 +366,26 @@ class writable_vector * @note The number of elements read from @c array depends upon the * current size of the vector. */ - template* = nullptr> - DerivedT& assign(const Pointer& array); + template* = nullptr> + DerivedT& assign(const Pointer& array); - /** Construct from an initializer_list. If the vector is resizable, it + /** Construct from an initializer_list. If the vector is resizable, it * is resized to exactly accomodate the elements of @c l. If the vector * is fixed-size, it must have the same length as @c array. * * @note This depends upon implicit conversions of the elements to the * vector value_type. */ - template - DerivedT& assign(const std::initializer_list& l); + template DerivedT& assign(const std::initializer_list& l); - /** Assign from a subvector and 1 or more additional elements to + /** Assign from a subvector and 1 or more additional elements to * append. */ - template - DerivedT& assign( - const readable_vector& other, const Elements&... eN); + template + DerivedT& assign(const readable_vector& other, + const Elements&... eN); - /** Construct from a variable list of values. If the vector is + /** Construct from a variable list of values. If the vector is * resizable, it is resized to exactly accomodate the elements of @c * eN. If the vector is fixed-size, it must have the same length as @c * eN. @@ -406,31 +393,24 @@ class writable_vector * @note This depends upon implicit conversions of the elements to the * vector value_type. */ - template - DerivedT& assign_elements(const Elements&... eN); + template DerivedT& assign_elements(const Elements&... eN); protected: + // Use the compiler-generated default constructor: + writable_vector() = default; - // Use the compiler-generated default constructor: - writable_vector() = default; - - // Use the compiler-generated copy constructor: - writable_vector(const writable_vector&) = default; + // Use the compiler-generated copy constructor: + writable_vector(const writable_vector&) = default; #ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR - // Use the compiler-generated move constructor: - writable_vector(writable_vector&&) = default; + // Use the compiler-generated move constructor: + writable_vector(writable_vector&&) = default; #endif }; -} // namespace cml +} // namespace cml #define __CML_VECTOR_WRITABLE_VECTOR_TPP #include #undef __CML_VECTOR_WRITABLE_VECTOR_TPP - -#endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/cml/vector/writable_vector.tpp b/cml/vector/writable_vector.tpp index f648011..32c830c 100644 --- a/cml/vector/writable_vector.tpp +++ b/cml/vector/writable_vector.tpp @@ -1,11 +1,9 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #ifndef __CML_VECTOR_WRITABLE_VECTOR_TPP -#error "vector/writable_vector.tpp not included correctly" +# error "vector/writable_vector.tpp not included correctly" #endif #include @@ -16,56 +14,55 @@ namespace cml { namespace detail { /* Terminate the assignment recursion at the final element. */ -template inline void +template +inline void assign_elements(writable_vector& sub, cml::int_c, const E0& e0) { - sub.put(I,e0); + sub.put(I, e0); } /* Set element I of sub to e0, then assign the remainder of the elements * starting from I+1. */ -template inline void -assign_elements( - writable_vector& sub, cml::int_c, const E0& e0, const Es&... eN - ) +template +inline void +assign_elements(writable_vector& sub, cml::int_c, const E0& e0, + const Es&... eN) { - sub.put(I,e0); - assign_elements(sub, cml::int_c(), eN...); + sub.put(I, e0); + assign_elements(sub, cml::int_c(), eN...); } - - /* Set sub(i) to e0: */ -template inline void +template +inline void assign_elements(writable_vector& sub, int i, const E0& e0) { sub.put(i, e0); } /* Assign the elements of sub from eN starting from index i. */ -template inline void -assign_elements( - writable_vector& sub, int i, const E0& e0, const Es&... eN - ) +template +inline void +assign_elements(writable_vector& sub, int i, const E0& e0, const Es&... eN) { sub.put(i, e0); - assign_elements(sub, i+1, eN...); + assign_elements(sub, i + 1, eN...); } -} // namespace detail - - +} // namespace detail /* Public methods: */ -template DT& +template +DT& writable_vector
::actual() { return (DT&) *this; } -template auto +template +auto writable_vector
::get(int i) -> mutable_value { return this->actual().i_get(i); @@ -73,136 +70,156 @@ writable_vector
::get(int i) -> mutable_value #ifdef CML_HAS_STRUCTURED_BINDINGS template -template>*> auto +template>*> +auto writable_vector
::get() -> mutable_value { return this->actual().i_get(I); } #endif -template auto +template +auto writable_vector
::operator[](int i) -> mutable_value { return this->get(i); } -template template DT& +template +template +DT& writable_vector
::put(int i, const Other& v) __CML_REF { - return this->actual().i_put(i,v); + return this->actual().i_put(i, v); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_vector
::put(int i, const Other& v) && { - this->put(i,v); // Forward to put(...) & + this->put(i, v); // Forward to put(...) & return (DT&&) *this; } #endif -template DT& +template +DT& writable_vector
::normalize() __CML_REF { return this->operator/=(this->length()); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_vector
::normalize() && { - this->normalize(); // Forward to normalize & + this->normalize(); // Forward to normalize & return (DT&&) *this; } #endif -template DT& +template +DT& writable_vector
::zero() __CML_REF { - for(int i = 0; i < this->size(); ++ i) this->put(i,0); + for(int i = 0; i < this->size(); ++i) this->put(i, 0); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_vector
::zero() && { - this->zero(); // Forward to zero & + this->zero(); // Forward to zero & return (DT&&) *this; } #endif -template DT& +template +DT& writable_vector
::cardinal(int i) __CML_REF { - return this->zero().put(i,1); + return this->zero().put(i, 1); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_vector
::cardinal(int i) && { - this->cardinal(i); // Forward to cardinal & + this->cardinal(i); // Forward to cardinal & return (DT&&) *this; } #endif -template template DT& +template +template +DT& writable_vector
::minimize(const readable_vector& other) __CML_REF { cml::check_same_size(*this, other); - for(int i = 0; i < this->size(); ++ i) { + for(int i = 0; i < this->size(); ++i) { this->put(i, std::min(this->get(i), value_type(other.get(i)))); } return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_vector
::minimize(const readable_vector& other) && { - this->minimize(other); // Forward to minimize & + this->minimize(other); // Forward to minimize & return (DT&&) *this; } #endif -template template DT& +template +template +DT& writable_vector
::maximize(const readable_vector& other) __CML_REF { cml::check_same_size(*this, other); - for(int i = 0; i < this->size(); ++ i) { + for(int i = 0; i < this->size(); ++i) { this->put(i, std::max(this->get(i), value_type(other.get(i)))); } return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_vector
::maximize(const readable_vector& other) && { - this->maximize(other); // Forward to maximize & + this->maximize(other); // Forward to maximize & return (DT&&) *this; } #endif -template DT& -writable_vector
::random( - const_reference low, const_reference high - ) __CML_REF +template +DT& +writable_vector
::random(const_reference low, const_reference high) __CML_REF { - typedef if_t::value - , std::uniform_int_distribution - , std::uniform_real_distribution> distribution_type; + using distribution_type = if_t::value, + std::uniform_int_distribution, + std::uniform_real_distribution>; std::default_random_engine gen(std::rand()); distribution_type d(low, high); - for(int i = 0; i < this->size(); ++ i) this->put(i, d(gen)); + for(int i = 0; i < this->size(); ++i) this->put(i, d(gen)); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_vector
::random(const_reference low, const_reference high) && { this->random(low, high); @@ -210,15 +227,17 @@ writable_vector
::random(const_reference low, const_reference high) && } #endif -template DT& +template +DT& writable_vector
::fill(const_reference v) __CML_REF { - for(int i = 0; i < this->size(); ++ i) this->put(i, v); + for(int i = 0; i < this->size(); ++i) this->put(i, v); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& +template +DT&& writable_vector
::fill(const_reference v) && { this->fill(v); @@ -226,37 +245,46 @@ writable_vector
::fill(const_reference v) && } #endif -template template auto +template +template +auto writable_vector
::set(const E0& e0, const Es&... eN) __CML_REF --> enable_if_t::value, DT&> + ->enable_if_t::value, DT&> { return this->assign_elements(e0, eN...); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template auto -writable_vector
::set(const E0& e0, const Es&... eN) && --> enable_if_t::value, DT&&> +template +template +auto +writable_vector
::set(const E0& e0, const Es&... eN) && -> enable_if_t< + are_convertible::value, DT&&> { this->assign_elements(e0, eN...); return (DT&&) *this; } #endif -template DT& +template +DT& writable_vector
::operator=(const writable_vector& other) __CML_REF { return this->assign(other); } -template template DT& +template +template +DT& writable_vector
::operator=(const readable_vector& other) __CML_REF { return this->assign(other); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_vector
::operator=(const readable_vector& other) && { this->operator=(other); @@ -265,7 +293,8 @@ writable_vector
::operator=(const readable_vector& other) && #endif template -template*> DT& +template*> +DT& writable_vector
::operator=(const Array& array) __CML_REF { return this->assign(array); @@ -273,7 +302,8 @@ writable_vector
::operator=(const Array& array) __CML_REF #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template*> DT&& +template*> +DT&& writable_vector
::operator=(const Array& array) && { this->operator=(array); @@ -281,32 +311,40 @@ writable_vector
::operator=(const Array& array) && } #endif -template template DT& +template +template +DT& writable_vector
::operator=(std::initializer_list l) __CML_REF { return this->assign(l); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_vector
::operator=(std::initializer_list l) && { return this->assign(l); } #endif -template template DT& +template +template +DT& writable_vector
::operator+=(const readable_vector& other) __CML_REF { - typedef binary_plus_t op_type; + using op_type = binary_plus_t; detail::check_or_resize(*this, other); - for(int i = 0; i < this->size(); ++ i) + for(int i = 0; i < this->size(); ++i) this->put(i, op_type().apply(this->get(i), other.get(i))); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_vector
::operator+=(const readable_vector& other) && { this->operator+=(other); @@ -314,18 +352,22 @@ writable_vector
::operator+=(const readable_vector& other) && } #endif -template template DT& +template +template +DT& writable_vector
::operator-=(const readable_vector& other) __CML_REF { - typedef binary_minus_t op_type; + using op_type = binary_minus_t; detail::check_or_resize(*this, other); - for(int i = 0; i < this->size(); ++ i) + for(int i = 0; i < this->size(); ++i) this->put(i, op_type().apply(this->get(i), other.get(i))); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template template DT&& +template +template +DT&& writable_vector
::operator-=(const readable_vector& other) && { this->operator-=(other); @@ -334,21 +376,21 @@ writable_vector
::operator-=(const readable_vector& other) && #endif template -template::value_type, ScalarT>*> +template::value_type, ScalarT>*> DT& writable_vector
::operator*=(const ScalarT& v) __CML_REF { - typedef binary_multiply_t op_type; - for(int i = 0; i < this->size(); ++ i) + using op_type = binary_multiply_t; + for(int i = 0; i < this->size(); ++i) this->put(i, op_type().apply(this->get(i), v)); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template::value_type, ScalarT>*> +template::value_type, ScalarT>*> DT&& writable_vector
::operator*=(const ScalarT& v) && { @@ -358,21 +400,21 @@ writable_vector
::operator*=(const ScalarT& v) && #endif template -template::value_type, ScalarT>*> +template::value_type, ScalarT>*> DT& writable_vector
::operator/=(const ScalarT& v) __CML_REF { - typedef binary_divide_t op_type; - for(int i = 0; i < this->size(); ++ i) + using op_type = binary_divide_t; + for(int i = 0; i < this->size(); ++i) this->put(i, op_type().apply(this->get(i), v)); return this->actual(); } #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template -template::value_type, ScalarT>*> +template::value_type, ScalarT>*> DT&& writable_vector
::operator/=(const ScalarT& v) && { @@ -382,55 +424,65 @@ writable_vector
::operator/=(const ScalarT& v) && #endif - /* Internal methods: */ -template template DT& +template +template +DT& writable_vector
::assign(const readable_vector& other) { detail::check_or_resize(*this, other); - for(int i = 0; i < this->size(); ++ i) this->put(i, other.get(i)); + for(int i = 0; i < this->size(); ++i) this->put(i, other.get(i)); return this->actual(); } template -template*> DT& +template*> +DT& writable_vector
::assign(const Array& array) { static const int N = array_size_of_c::value; detail::check_or_resize(*this, N); - for(int i = 0; i < N; ++ i) this->put(i, array[i]); + for(int i = 0; i < N; ++i) this->put(i, array[i]); return this->actual(); } template -template*> DT& +template*> +DT& writable_vector
::assign(const Pointer& array) { - for(int i = 0; i < this->size(); ++ i) this->put(i, array[i]); + for(int i = 0; i < this->size(); ++i) this->put(i, array[i]); return this->actual(); } -template template DT& +template +template +DT& writable_vector
::assign(const std::initializer_list& l) { detail::check_or_resize(*this, l); - int i = 0; for(Other v : l) { this->put(i ++, v); } + int i = 0; + for(Other v : l) { + this->put(i++, v); + } return this->actual(); } -template template DT& -writable_vector
::assign( - const readable_vector& other, const Es&... eN - ) +template +template +DT& +writable_vector
::assign(const readable_vector& other, const Es&... eN) { detail::check_or_resize(*this, other, eN...); - for(int i = 0; i < other.size(); ++ i) this->put(i, other.get(i)); + for(int i = 0; i < other.size(); ++i) this->put(i, other.get(i)); detail::assign_elements(*this, other.size(), eN...); return this->actual(); } -template template DT& +template +template +DT& writable_vector
::assign_elements(const Es&... eN) { static const int N = int(sizeof...(eN)); @@ -439,7 +491,4 @@ writable_vector
::assign_elements(const Es&... eN) return this->actual(); } -} // namespace cml - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 +} // namespace cml \ No newline at end of file diff --git a/cml/version.h b/cml/version.h index bafa8a5..1acebab 100644 --- a/cml/version.h +++ b/cml/version.h @@ -1,18 +1,11 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once -#ifndef cml_version_h -#define cml_version_h - /* Current CML version: */ -#define CML_VERSION 200202U +#define CML_VERSION 200202U /* Current CML version as a string: */ -#define CML_VERSION_STRING "2.2.2" - -#endif \ No newline at end of file +#define CML_VERSION_STRING "2.2.2" From d75ece4a6589e831d5f69abb70d0ecfc17a5d96e Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 17:44:27 -0500 Subject: [PATCH 07/38] Cleanup tests and make them link statically on Windows by default - Applied clang-format (replacing tabs with spaces), removed extraneous header and footer comments, and made all files have Unix line endings. --- CMakeLists.txt | 73 +- tests/CMakeLists.txt | 72 +- tests/common/CMakeLists.txt | 7 +- tests/common/rv_from_this1.cpp | 26 +- tests/common/temporary_of1.cpp | 10 +- tests/common/type_map1.cpp | 33 +- tests/common/type_table1.cpp | 73 +- tests/common/type_util1.cpp | 82 +- tests/main/CMakeLists.txt | 12 +- tests/main/catch.hpp | 3538 ++++++++--------- tests/main/catch_main.cpp | 8 +- tests/main/catch_runner.h | 12 +- tests/mathlib/CMakeLists.txt | 13 +- tests/mathlib/coordinate_conversion1.cpp | 31 +- tests/mathlib/frustum1.cpp | 55 +- tests/mathlib/matrix_basis1.cpp | 52 +- tests/mathlib/matrix_generators1.cpp | 140 +- tests/mathlib/matrix_invert1.cpp | 74 +- tests/mathlib/matrix_projection1.cpp | 26 +- tests/mathlib/matrix_rotation1.cpp | 121 +- tests/mathlib/matrix_scale1.cpp | 62 +- tests/mathlib/matrix_transform1.cpp | 50 +- tests/mathlib/matrix_translation1.cpp | 251 +- tests/mathlib/quaternion_basis1.cpp | 7 +- tests/mathlib/quaternion_rotation1.cpp | 94 +- tests/mathlib/random_unit1.cpp | 13 +- tests/mathlib/vector_angle1.cpp | 33 +- tests/mathlib/vector_misc1.cpp | 7 +- tests/mathlib/vector_rotation1.cpp | 21 +- tests/mathlib/vector_transform1.cpp | 114 +- tests/matrix/CMakeLists.txt | 7 +- tests/matrix/basis1.cpp | 133 +- tests/matrix/determinant1.cpp | 141 +- tests/matrix/dynamic_allocated_matrix1.cpp | 326 +- tests/matrix/dynamic_external_matrix1.cpp | 251 +- tests/matrix/fixed_compiled_matrix1.cpp | 388 +- tests/matrix/fixed_external_matrix1.cpp | 217 +- tests/matrix/lu1.cpp | 590 +-- tests/matrix/matrix_binary_node1.cpp | 830 ++-- tests/matrix/matrix_comparison1.cpp | 31 +- tests/matrix/matrix_functions1.cpp | 79 +- tests/matrix/matrix_hadamard_product1.cpp | 248 +- tests/matrix/matrix_inverse1.cpp | 324 +- tests/matrix/matrix_matrix_product1.cpp | 769 ++-- tests/matrix/matrix_promotion1.cpp | 88 +- tests/matrix/matrix_scalar_node1.cpp | 501 +-- tests/matrix/matrix_transpose1.cpp | 255 +- tests/matrix/matrix_unary_node1.cpp | 306 +- tests/matrix/matrix_vector_product1.cpp | 99 +- tests/matrix/rowcol1.cpp | 137 +- tests/quaternion/CMakeLists.txt | 11 +- tests/quaternion/conjugate1.cpp | 82 +- .../quaternion/fixed_compiled_quaternion1.cpp | 46 +- tests/quaternion/imaginary1.cpp | 14 +- tests/quaternion/inverse1.cpp | 82 +- tests/quaternion/quaternion_binary_node1.cpp | 124 +- tests/quaternion/quaternion_comparison1.cpp | 39 +- tests/quaternion/quaternion_dot1.cpp | 13 +- tests/quaternion/quaternion_functions1.cpp | 37 +- tests/quaternion/quaternion_product1.cpp | 49 +- tests/quaternion/quaternion_scalar_node1.cpp | 114 +- tests/quaternion/quaternion_unary_node1.cpp | 91 +- tests/storage/CMakeLists.txt | 7 +- tests/storage/storage_promotion1.cpp | 46 +- tests/util/CMakeLists.txt | 7 +- tests/util/vector_hash1.cpp | 30 +- tests/vector/CMakeLists.txt | 7 +- tests/vector/cross1.cpp | 43 +- tests/vector/dynamic_allocated_vector1.cpp | 25 +- tests/vector/dynamic_external_vector1.cpp | 24 +- tests/vector/fixed_compiled_vector1.cpp | 34 +- tests/vector/fixed_external_vector1.cpp | 28 +- tests/vector/outer_product1.cpp | 78 +- tests/vector/perp_dot1.cpp | 27 +- tests/vector/subvector1.cpp | 82 +- tests/vector/triple_product1.cpp | 24 +- tests/vector/vector_binary_node1.cpp | 353 +- tests/vector/vector_comparison1.cpp | 39 +- tests/vector/vector_copy1.cpp | 90 +- tests/vector/vector_dot1.cpp | 27 +- tests/vector/vector_functions1.cpp | 189 +- tests/vector/vector_hadamard_product1.cpp | 115 +- tests/vector/vector_scalar_node1.cpp | 197 +- tests/vector/vector_temporary1.cpp | 9 +- tests/vector/vector_unary_node1.cpp | 166 +- 85 files changed, 5463 insertions(+), 7716 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d07a797..71beba4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,15 @@ # Set the minimum CMake version: cmake_minimum_required(VERSION 3.15) -# Allow solution folders: +# Policies: +cmake_policy(SET CMP0091 NEW) # Enable MSVC ABI selection + +# Enable solution folders globally: set_property(GLOBAL PROPERTY USE_FOLDERS ON) +# Just enable Debug and Release for multi-config generators: +set(CMAKE_CONFIGURATION_TYPES "Debug;Release") + # The project name: project(CML) @@ -16,10 +22,66 @@ set(CML_ROOT "${CML_SOURCE_DIR}") # Path to project-specific configuration files: list(APPEND CMAKE_MODULE_PATH ${CML_ROOT}/CMake) - -# Include project macros: include(CMLBuildMacros) +include(CMakeDependentOption) + +if(NOT DEFINED BUILD_SHARED_LIBS) + option(BUILD_SHARED_LIBS "Build shared libraries" OFF) +endif() + +if(NOT DEFINED BUILD_STATIC_RUNTIME) + cmake_dependent_option(BUILD_STATIC_RUNTIME + "Build against a static runtime" + ON # Default if shown when... + "NOT BUILD_SHARED_LIBS" + OFF # Default if not shown + ) +endif() + +# Determine the default runtime library for MSVC-like compilers: +if(NOT DEFINED MSVC_RUNTIME_LIBRARY) + if(BUILD_STATIC_RUNTIME) + set(MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + else() + set(MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + endif() +endif() + +if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/debug/bin) +endif() + +if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/debug/lib) +endif() + +if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG) + # Put debug DLLs into debug/bin for WIN32 systems: + if(WIN32) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/debug/bin) + else() + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}/debug/lib) + endif() +endif() + +if(NOT DEFINED CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE) + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin) +endif() + +if(NOT DEFINED CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib) +endif() + +if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE) + # Put release DLLs into bin for WIN32 systems: + if(WIN32) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/bin) + else() + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib) + endif() +endif() + # Figure out which version of CML is being built by parsing CML/version.h (this # is from the root Boost.CMake CMakeLists.txt file): cml_version_from_file( @@ -35,10 +97,7 @@ message(STATUS "Building CML ${CML_VERSION}") # Create the CML interface library: include(CML.cmake) -# Build tests if requested: -option(CML_BUILD_TESTING "Build CML tests" OFF) - -if(CML_BUILD_TESTING) +if(BUILD_TESTING) enable_testing() add_subdirectory(tests) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 842edfc..8c9a4db 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,7 +2,77 @@ # @@COPYRIGHT@@ # -------------------------------------------------------------------------- -include(CMLTestMacros) +# Function to add a single-file test to the build, using ${_name}.cpp as the +# test source. +function(cml_add_test _name) + # Define the executable name: + set(ExecName "${_name}") + + # Define the test name: + if(DEFINED CML_TEST_GROUP) + set(TestName "CML:${CML_TEST_GROUP}:${_name}") + else() + message(FATAL_ERROR "CML_TEST_GROUP must be defined") + endif() + + # Setup the build target: + add_executable(${ExecName} ${_name}.cpp) + + # MSVC-only C++ compiler options: + if(MSVC) + set(_msvc_common_options + /permissive- + /MP + /EHsc + /W4 # Enable strict warnings. + ) + + set(_cxx_is_msvc $) + set(_msvc_compile_options + /Zc:inline + /Zc:strictStrings + /Zc:__cplusplus + /Zc:lambda + /Zc:rvalueCast + /diagnostics:caret + /WL + ) + + set(_msvc_link_options + /NOIMPLIB + /NOEXP + ) + + target_compile_options(${ExecName} + PRIVATE + ${_msvc_common_options} + $<${_cxx_is_msvc}:${_msvc_compile_options}> + ) + + target_compile_features(${ExecName} + PRIVATE + cxx_std_17 + ) + + target_link_options(${ExecName} + PRIVATE $<${_cxx_is_msvc}:${_msvc_link_options}> + ) + + set_target_properties(${ExecName} PROPERTIES + FOLDER "cml-tests/${CML_TEST_GROUP}" + MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY} + ) + + get_target_property(_path ${_name} SOURCE_DIR) + get_target_property(_sources ${_name} SOURCES) + source_group(TREE "${_path}" FILES ${_sources}) + endif() + + target_link_libraries(${ExecName} cml cml_test_main) + + # Setup the test: + add_test(NAME ${TestName} COMMAND ${ExecName}) +endfunction() add_subdirectory(main) add_subdirectory(common) diff --git a/tests/common/CMakeLists.txt b/tests/common/CMakeLists.txt index 18e1a9a..d820d15 100644 --- a/tests/common/CMakeLists.txt +++ b/tests/common/CMakeLists.txt @@ -1,9 +1,8 @@ -# -*- cmake -*- ----------------------------------------------------------- +# *------------------------------------------------------------------------- # @@COPYRIGHT@@ -#*------------------------------------------------------------------------- +# *------------------------------------------------------------------------- -project(CML_Testing_Common) -set(CML_CURRENT_TEST_GROUP "Common") +set(CML_TEST_GROUP "common") cml_add_test(rv_from_this1) cml_add_test(type_util1) diff --git a/tests/common/rv_from_this1.cpp b/tests/common/rv_from_this1.cpp index 6661295..e7851a9 100644 --- a/tests/common/rv_from_this1.cpp +++ b/tests/common/rv_from_this1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -11,7 +9,8 @@ /* Testing headers: */ #include "catch_runner.h" -struct rv_from_this { +struct rv_from_this +{ #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS rv_from_this&& mover() &&; #endif @@ -21,15 +20,14 @@ struct rv_from_this { CATCH_TEST_CASE("rv_from_this1") { #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - CATCH_CHECK(true == - (std::is_same::value) - ); - CATCH_REQUIRE(true == - (std::is_same().refer()), rv_from_this&>::value) - ); + CATCH_CHECK(true + == (std::is_same::value)); + CATCH_REQUIRE(true + == (std::is_same().refer()), + rv_from_this&>::value)); #else - CATCH_REQUIRE(true == - (std::is_same().refer()), rv_from_this&>::value) - ); + CATCH_REQUIRE(true + == (std::is_same().refer()), + rv_from_this&>::value)); #endif -} \ No newline at end of file +} diff --git a/tests/common/temporary_of1.cpp b/tests/common/temporary_of1.cpp index 841d797..b1298f4 100644 --- a/tests/common/temporary_of1.cpp +++ b/tests/common/temporary_of1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -12,8 +10,6 @@ CATCH_TEST_CASE("const_temporary1") { - typedef cml::temporary_of_t const_type; + using const_type = cml::temporary_of_t; + CATCH_CHECK(std::is_same_v); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/common/type_map1.cpp b/tests/common/type_map1.cpp index e0eff46..112f01f 100644 --- a/tests/common/type_map1.cpp +++ b/tests/common/type_map1.cpp @@ -1,54 +1,45 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include /* Testing headers: */ #include "catch_runner.h" -template -struct table_item +template struct table_item { - typedef T1 first; - typedef T2 second; + using first = T1; + using second = T2; }; CATCH_TEST_CASE("map1") { using cml::type_map; - typedef type_map< - /**/ table_item - , table_item - , table_item - > int_table; + using int_table = type_map< + /**/ table_item, table_item, table_item>; - typedef int_table::find_second::type Ti; + using Ti = int_table::find_second::type; CATCH_CHECK(Ti::value); CATCH_CHECK((std::is_same::value)); - typedef int_table::find_first::type Ti2; + using Ti2 = int_table::find_first::type; CATCH_CHECK(Ti2::value); CATCH_CHECK((std::is_same::value)); - typedef int_table::find_first::type Tf1; + using Tf1 = int_table::find_first::type; CATCH_CHECK(Tf1::value); CATCH_CHECK((std::is_same::value)); - typedef int_table::find_second::type Tf2; + using Tf2 = int_table::find_second::type; CATCH_CHECK(!Tf2::value); CATCH_CHECK((std::is_same::value)); - typedef int_table::find_first::type Td1; + using Td1 = int_table::find_first::type; CATCH_CHECK(Td1::value); CATCH_CHECK((std::is_same::value)); - typedef int_table::find_second::type Td2; + using Td2 = int_table::find_second::type; CATCH_CHECK(!Td2::value); CATCH_CHECK((std::is_same::value)); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/common/type_table1.cpp b/tests/common/type_table1.cpp index 2384fc1..5b12da8 100644 --- a/tests/common/type_table1.cpp +++ b/tests/common/type_table1.cpp @@ -1,83 +1,72 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include /* Testing headers: */ #include "catch_runner.h" -template -struct table_item +template struct table_item { - typedef T1 first; - typedef T2 second; - typedef T type; + using first = T1; + using second = T2; + using type = T; }; CATCH_TEST_CASE("map1") { using cml::type_table; - typedef type_table< - /**/ table_item - , table_item - , table_item - > int_table; + using int_table = type_table< + /**/ table_item, table_item, + table_item>; - typedef int_table::find::type Tii; + using Tii = int_table::find::type; CATCH_CHECK(Tii::value); - typedef int_table::find::type Tid; + using Tid = int_table::find::type; CATCH_CHECK(Tid::value); - typedef int_table::find::type Tdi; + using Tdi = int_table::find::type; CATCH_CHECK(Tdi::value); - typedef int_table::find::type Tic; + using Tic = int_table::find::type; CATCH_CHECK(!Tic::value); - typedef int_table::find::type Tic; + using Tic = int_table::find::type; CATCH_CHECK(!Tic::value); } - -struct map_struct { - template - struct table_item - { - typedef T1 first; - typedef T2 second; - typedef T type; - }; - - typedef cml::type_table< - /**/ table_item - , table_item - , table_item - > int_table; +struct map_struct +{ + template struct table_item + { + using first = T1; + using second = T2; + using type = T; + }; + + using int_table = cml::type_table< + /**/ table_item, table_item, + table_item>; }; CATCH_TEST_CASE("map_struct1") { - typedef map_struct::int_table int_table; + using int_table = map_struct::int_table; - typedef int_table::find::type Tii; + using Tii = int_table::find::type; CATCH_CHECK(Tii::value); - typedef int_table::find::type Tid; + using Tid = int_table::find::type; CATCH_CHECK(Tid::value); - typedef int_table::find::type Tdi; + using Tdi = int_table::find::type; CATCH_CHECK(Tdi::value); - typedef int_table::find::type Tic; + using Tic = int_table::find::type; CATCH_CHECK(!Tic::value); - typedef int_table::find::type Tic; + using Tic = int_table::find::type; CATCH_CHECK(!Tic::value); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/common/type_util1.cpp b/tests/common/type_util1.cpp index 52b3687..e1bafe8 100644 --- a/tests/common/type_util1.cpp +++ b/tests/common/type_util1.cpp @@ -1,21 +1,39 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include /* Testing headers: */ #include "catch_runner.h" -struct scoop1 { const scoop1& actual() const; }; -struct scoop2 { scoop2& actual() const; }; -struct scoop3 { scoop3& actual(); }; -struct scoop4 { const scoop4& actual(); }; +struct scoop1 +{ + const scoop1& actual() const; +}; + +struct scoop2 +{ + scoop2& actual() const; +}; + +struct scoop3 +{ + scoop3& actual(); +}; -template struct scoop_base { T& actual(); }; -struct scoop5 : scoop_base {}; +struct scoop4 +{ + const scoop4& actual(); +}; + +template struct scoop_base +{ + T& actual(); +}; + +struct scoop5 : scoop_base +{}; CATCH_TEST_CASE("is_statically_polymorphic1") { @@ -32,43 +50,35 @@ CATCH_TEST_CASE("is_statically_polymorphic2") CATCH_TEST_CASE("actual_type_of1") { - CATCH_CHECK((std::is_same< - cml::actual_type_of_t, int>::value)); - CATCH_CHECK((std::is_same< - cml::actual_type_of_t, int>::value)); - CATCH_CHECK((std::is_same< - cml::actual_type_of_t, int>::value)); - CATCH_CHECK((std::is_same< - cml::actual_type_of_t, int>::value)); + CATCH_CHECK((std::is_same, int>::value)); + CATCH_CHECK((std::is_same, int>::value)); + CATCH_CHECK((std::is_same, int>::value)); + CATCH_CHECK((std::is_same, int>::value)); } CATCH_TEST_CASE("actual_type_of2") { - CATCH_CHECK((std::is_same< - cml::actual_type_of_t, scoop5>::value)); - CATCH_CHECK((std::is_same< - cml::actual_type_of_t>, scoop5>::value)); + CATCH_CHECK((std::is_same, scoop5>::value)); + CATCH_CHECK( + (std::is_same>, scoop5>::value)); } CATCH_TEST_CASE("actual_operand_type_of1") { - CATCH_CHECK((std::is_same, int&>::value)); - CATCH_CHECK((std::is_same, int const&>::value)); - CATCH_CHECK((std::is_same, int&&>::value)); + CATCH_CHECK((std::is_same, int&>::value)); + CATCH_CHECK((std::is_same, + int const&>::value)); + CATCH_CHECK( + (std::is_same, int&&>::value)); } CATCH_TEST_CASE("actual_operand_type_of2") { - CATCH_CHECK((std::is_same&>, scoop5&>::value)); - CATCH_CHECK((std::is_same const&>, scoop5 const&>::value)); - CATCH_CHECK((std::is_same&&>, scoop5&&>::value)); + CATCH_CHECK((std::is_same&>, + scoop5&>::value)); + CATCH_CHECK( + (std::is_same const&>, + scoop5 const&>::value)); + CATCH_CHECK((std::is_same&&>, + scoop5&&>::value)); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/main/CMakeLists.txt b/tests/main/CMakeLists.txt index b685aae..cf23242 100644 --- a/tests/main/CMakeLists.txt +++ b/tests/main/CMakeLists.txt @@ -2,11 +2,17 @@ # @@COPYRIGHT@@ # -------------------------------------------------------------------------- -project(CMLTestMain) - add_library(cml_test_main STATIC catch_main.cpp catch.hpp catch_runner.h) target_include_directories(cml_test_main PUBLIC ${CMAKE_CURRENT_LIST_DIR} PRIVATE ${CML_ROOT} ) -set_target_properties(cml_test_main PROPERTIES FOLDER "CML-Tests") \ No newline at end of file + +set_target_properties(cml_test_main + PROPERTIES FOLDER "cml-tests/main" + MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY} +) + +get_target_property(_path cml_test_main SOURCE_DIR) +get_target_property(_sources cml_test_main SOURCES) +source_group(TREE "${_path}" FILES ${_sources}) \ No newline at end of file diff --git a/tests/main/catch.hpp b/tests/main/catch.hpp index 0384171..08a0a02 100644 --- a/tests/main/catch.hpp +++ b/tests/main/catch.hpp @@ -604,7 +604,7 @@ namespace Catch { using const_iterator = const char*; private: - static constexpr char const* const s_empty = ""; + static constexpr auto s_empty = ""; char const* m_start = s_empty; size_type m_size = 0; @@ -980,7 +980,7 @@ struct NameAndTags { struct AutoReg : NonCopyable { AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept; - ~AutoReg(); + ~AutoReg() override; }; } // end namespace Catch @@ -1437,7 +1437,7 @@ namespace Catch { std::ostream* m_oss; public: ReusableStringStream(); - ~ReusableStringStream(); + ~ReusableStringStream() override; auto str() const -> std::string; @@ -2151,7 +2151,7 @@ struct ratio_string { auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); char timeStamp[timeStampSize]; - const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; + const auto fmt = "%Y-%m-%dT%H:%M:%SZ"; #ifdef _MSC_VER std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); @@ -2906,7 +2906,7 @@ namespace Catch { class Section : NonCopyable { public: Section( SectionInfo const& info ); - ~Section(); + ~Section() override; // This indicates whether the section should be executed or not explicit operator bool() const; @@ -3228,35 +3228,34 @@ namespace Catch { #include namespace Catch { -namespace Matchers { - namespace Impl { - - template struct MatchAllOf; - template struct MatchAnyOf; - template struct MatchNotOf; - - class MatcherUntypedBase { - public: - MatcherUntypedBase() = default; - MatcherUntypedBase ( MatcherUntypedBase const& ) = default; - MatcherUntypedBase& operator = ( MatcherUntypedBase const& ) = delete; - std::string toString() const; - - protected: - virtual ~MatcherUntypedBase(); - virtual std::string describe() const = 0; - mutable std::string m_cachedToString; - }; +namespace Matchers::Impl { + +template struct MatchAllOf; +template struct MatchAnyOf; +template struct MatchNotOf; + +class MatcherUntypedBase { + public: + MatcherUntypedBase() = default; + MatcherUntypedBase ( MatcherUntypedBase const& ) = default; + MatcherUntypedBase& operator = ( MatcherUntypedBase const& ) = delete; + std::string toString() const; + + protected: + virtual ~MatcherUntypedBase(); + virtual std::string describe() const = 0; + mutable std::string m_cachedToString; +}; #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wnon-virtual-dtor" #endif - template - struct MatcherMethod { - virtual bool match( ObjectT const& arg ) const = 0; - }; +template +struct MatcherMethod { + virtual bool match( ObjectT const& arg ) const = 0; +}; #if defined(__OBJC__) // Hack to fix Catch GH issue #1661. Could use id for generic Object support. @@ -3271,113 +3270,111 @@ namespace Matchers { # pragma clang diagnostic pop #endif - template - struct MatcherBase : MatcherUntypedBase, MatcherMethod { - - MatchAllOf operator && ( MatcherBase const& other ) const; - MatchAnyOf operator || ( MatcherBase const& other ) const; - MatchNotOf operator ! () const; - }; +template +struct MatcherBase : MatcherUntypedBase, MatcherMethod { - template - struct MatchAllOf : MatcherBase { - bool match( ArgT const& arg ) const override { - for( auto matcher : m_matchers ) { - if (!matcher->match(arg)) - return false; - } - return true; - } - std::string describe() const override { - std::string description; - description.reserve( 4 + m_matchers.size()*32 ); - description += "( "; - bool first = true; - for( auto matcher : m_matchers ) { - if( first ) - first = false; - else - description += " and "; - description += matcher->toString(); - } - description += " )"; - return description; - } + MatchAllOf operator && ( MatcherBase const& other ) const; + MatchAnyOf operator || ( MatcherBase const& other ) const; + MatchNotOf operator ! () const; +}; - MatchAllOf operator && ( MatcherBase const& other ) { - auto copy(*this); - copy.m_matchers.push_back( &other ); - return copy; - } +template +struct MatchAllOf : MatcherBase { + bool match( ArgT const& arg ) const override { + for( auto matcher : m_matchers ) { + if (!matcher->match(arg)) + return false; + } + return true; + } + std::string describe() const override { + std::string description; + description.reserve( 4 + m_matchers.size()*32 ); + description += "( "; + bool first = true; + for( auto matcher : m_matchers ) { + if( first ) + first = false; + else + description += " and "; + description += matcher->toString(); + } + description += " )"; + return description; + } - std::vector const*> m_matchers; - }; - template - struct MatchAnyOf : MatcherBase { + MatchAllOf operator && ( MatcherBase const& other ) { + auto copy(*this); + copy.m_matchers.push_back( &other ); + return copy; + } - bool match( ArgT const& arg ) const override { - for( auto matcher : m_matchers ) { - if (matcher->match(arg)) - return true; - } - return false; - } - std::string describe() const override { - std::string description; - description.reserve( 4 + m_matchers.size()*32 ); - description += "( "; - bool first = true; - for( auto matcher : m_matchers ) { - if( first ) - first = false; - else - description += " or "; - description += matcher->toString(); - } - description += " )"; - return description; - } + std::vector const*> m_matchers; +}; +template +struct MatchAnyOf : MatcherBase { - MatchAnyOf operator || ( MatcherBase const& other ) { - auto copy(*this); - copy.m_matchers.push_back( &other ); - return copy; - } + bool match( ArgT const& arg ) const override { + for( auto matcher : m_matchers ) { + if (matcher->match(arg)) + return true; + } + return false; + } + std::string describe() const override { + std::string description; + description.reserve( 4 + m_matchers.size()*32 ); + description += "( "; + bool first = true; + for( auto matcher : m_matchers ) { + if( first ) + first = false; + else + description += " or "; + description += matcher->toString(); + } + description += " )"; + return description; + } - std::vector const*> m_matchers; - }; + MatchAnyOf operator || ( MatcherBase const& other ) { + auto copy(*this); + copy.m_matchers.push_back( &other ); + return copy; + } - template - struct MatchNotOf : MatcherBase { + std::vector const*> m_matchers; +}; - MatchNotOf( MatcherBase const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {} +template +struct MatchNotOf : MatcherBase { - bool match( ArgT const& arg ) const override { - return !m_underlyingMatcher.match( arg ); - } + MatchNotOf( MatcherBase const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {} - std::string describe() const override { - return "not " + m_underlyingMatcher.toString(); - } - MatcherBase const& m_underlyingMatcher; - }; + bool match( ArgT const& arg ) const override { + return !m_underlyingMatcher.match( arg ); + } - template - MatchAllOf MatcherBase::operator && ( MatcherBase const& other ) const { - return MatchAllOf() && *this && other; - } - template - MatchAnyOf MatcherBase::operator || ( MatcherBase const& other ) const { - return MatchAnyOf() || *this || other; - } - template - MatchNotOf MatcherBase::operator ! () const { - return MatchNotOf( *this ); - } + std::string describe() const override { + return "not " + m_underlyingMatcher.toString(); + } + MatcherBase const& m_underlyingMatcher; +}; - } // namespace Impl +template +MatchAllOf MatcherBase::operator && ( MatcherBase const& other ) const { + return MatchAllOf() && *this && other; +} +template +MatchAnyOf MatcherBase::operator || ( MatcherBase const& other ) const { + return MatchAnyOf() || *this || other; +} +template +MatchNotOf MatcherBase::operator ! () const { + return MatchNotOf( *this ); +} -} // namespace Matchers +} using namespace Matchers; using Matchers::Impl::MatcherBase; @@ -3387,90 +3384,86 @@ using Matchers::Impl::MatcherBase; // end catch_matchers.h // start catch_matchers_exception.hpp -namespace Catch { -namespace Matchers { +namespace Catch::Matchers { namespace Exception { class ExceptionMessageMatcher : public MatcherBase { - std::string m_message; -public: + std::string m_message; + public: - ExceptionMessageMatcher(std::string const& message): - m_message(message) - {} + ExceptionMessageMatcher(std::string const& message): + m_message(message) + {} - bool match(std::exception const& ex) const override; + bool match(std::exception const& ex) const override; - std::string describe() const override; + std::string describe() const override; }; } // namespace Exception Exception::ExceptionMessageMatcher Message(std::string const& message); -} // namespace Matchers -} // namespace Catch +} // end catch_matchers_exception.hpp // start catch_matchers_floating.h -namespace Catch { -namespace Matchers { +namespace Catch::Matchers { - namespace Floating { +namespace Floating { - enum class FloatingPointKind : uint8_t; +enum class FloatingPointKind : uint8_t; - struct WithinAbsMatcher : MatcherBase { - WithinAbsMatcher(double target, double margin); - bool match(double const& matchee) const override; - std::string describe() const override; - private: - double m_target; - double m_margin; - }; +struct WithinAbsMatcher : MatcherBase { + WithinAbsMatcher(double target, double margin); + bool match(double const& matchee) const override; + std::string describe() const override; + private: + double m_target; + double m_margin; +}; - struct WithinUlpsMatcher : MatcherBase { - WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType); - bool match(double const& matchee) const override; - std::string describe() const override; - private: - double m_target; - uint64_t m_ulps; - FloatingPointKind m_type; - }; +struct WithinUlpsMatcher : MatcherBase { + WithinUlpsMatcher(double target, uint64_t ulps, FloatingPointKind baseType); + bool match(double const& matchee) const override; + std::string describe() const override; + private: + double m_target; + uint64_t m_ulps; + FloatingPointKind m_type; +}; - // Given IEEE-754 format for floats and doubles, we can assume - // that float -> double promotion is lossless. Given this, we can - // assume that if we do the standard relative comparison of - // |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get - // the same result if we do this for floats, as if we do this for - // doubles that were promoted from floats. - struct WithinRelMatcher : MatcherBase { - WithinRelMatcher(double target, double epsilon); - bool match(double const& matchee) const override; - std::string describe() const override; - private: - double m_target; - double m_epsilon; - }; +// Given IEEE-754 format for floats and doubles, we can assume +// that float -> double promotion is lossless. Given this, we can +// assume that if we do the standard relative comparison of +// |lhs - rhs| <= epsilon * max(fabs(lhs), fabs(rhs)), then we get +// the same result if we do this for floats, as if we do this for +// doubles that were promoted from floats. +struct WithinRelMatcher : MatcherBase { + WithinRelMatcher(double target, double epsilon); + bool match(double const& matchee) const override; + std::string describe() const override; + private: + double m_target; + double m_epsilon; +}; - } // namespace Floating +} // namespace Floating - // The following functions create the actual matcher objects. - // This allows the types to be inferred - Floating::WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff); - Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff); - Floating::WithinAbsMatcher WithinAbs(double target, double margin); - Floating::WithinRelMatcher WithinRel(double target, double eps); - // defaults epsilon to 100*numeric_limits::epsilon() - Floating::WithinRelMatcher WithinRel(double target); - Floating::WithinRelMatcher WithinRel(float target, float eps); - // defaults epsilon to 100*numeric_limits::epsilon() - Floating::WithinRelMatcher WithinRel(float target); +// The following functions create the actual matcher objects. +// This allows the types to be inferred +Floating::WithinUlpsMatcher WithinULP(double target, uint64_t maxUlpDiff); +Floating::WithinUlpsMatcher WithinULP(float target, uint64_t maxUlpDiff); +Floating::WithinAbsMatcher WithinAbs(double target, double margin); +Floating::WithinRelMatcher WithinRel(double target, double eps); +// defaults epsilon to 100*numeric_limits::epsilon() +Floating::WithinRelMatcher WithinRel(double target); +Floating::WithinRelMatcher WithinRel(float target, float eps); +// defaults epsilon to 100*numeric_limits::epsilon() +Floating::WithinRelMatcher WithinRel(float target); -} // namespace Matchers -} // namespace Catch +} // end catch_matchers_floating.h // start catch_matchers_generic.hpp @@ -3478,285 +3471,279 @@ namespace Matchers { #include #include -namespace Catch { -namespace Matchers { +namespace Catch::Matchers { namespace Generic { namespace Detail { - std::string finalizeDescription(const std::string& desc); +std::string finalizeDescription(const std::string& desc); } template class PredicateMatcher : public MatcherBase { - std::function m_predicate; - std::string m_description; -public: + std::function m_predicate; + std::string m_description; + public: - PredicateMatcher(std::function const& elem, std::string const& descr) - :m_predicate(std::move(elem)), - m_description(Detail::finalizeDescription(descr)) - {} + PredicateMatcher(std::function const& elem, std::string const& descr) + :m_predicate(std::move(elem)), + m_description(Detail::finalizeDescription(descr)) + {} - bool match( T const& item ) const override { - return m_predicate(item); - } + bool match( T const& item ) const override { + return m_predicate(item); + } - std::string describe() const override { - return m_description; - } + std::string describe() const override { + return m_description; + } }; } // namespace Generic - // The following functions create the actual matcher objects. - // The user has to explicitly specify type to the function, because - // inferring std::function is hard (but possible) and - // requires a lot of TMP. - template - Generic::PredicateMatcher Predicate(std::function const& predicate, std::string const& description = "") { - return Generic::PredicateMatcher(predicate, description); - } +// The following functions create the actual matcher objects. +// The user has to explicitly specify type to the function, because +// inferring std::function is hard (but possible) and +// requires a lot of TMP. +template +Generic::PredicateMatcher Predicate(std::function const& predicate, std::string const& description = "") { + return Generic::PredicateMatcher(predicate, description); +} -} // namespace Matchers -} // namespace Catch +} // end catch_matchers_generic.hpp // start catch_matchers_string.h #include -namespace Catch { -namespace Matchers { +namespace Catch::Matchers { - namespace StdString { +namespace StdString { - struct CasedString - { - CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ); - std::string adjustString( std::string const& str ) const; - std::string caseSensitivitySuffix() const; +struct CasedString +{ + CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ); + std::string adjustString( std::string const& str ) const; + std::string caseSensitivitySuffix() const; - CaseSensitive::Choice m_caseSensitivity; - std::string m_str; - }; + CaseSensitive::Choice m_caseSensitivity; + std::string m_str; +}; - struct StringMatcherBase : MatcherBase { - StringMatcherBase( std::string const& operation, CasedString const& comparator ); - std::string describe() const override; +struct StringMatcherBase : MatcherBase { + StringMatcherBase( std::string const& operation, CasedString const& comparator ); + std::string describe() const override; - CasedString m_comparator; - std::string m_operation; - }; + CasedString m_comparator; + std::string m_operation; +}; - struct EqualsMatcher : StringMatcherBase { - EqualsMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; - struct ContainsMatcher : StringMatcherBase { - ContainsMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; - struct StartsWithMatcher : StringMatcherBase { - StartsWithMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; - struct EndsWithMatcher : StringMatcherBase { - EndsWithMatcher( CasedString const& comparator ); - bool match( std::string const& source ) const override; - }; +struct EqualsMatcher : StringMatcherBase { + EqualsMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; +}; +struct ContainsMatcher : StringMatcherBase { + ContainsMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; +}; +struct StartsWithMatcher : StringMatcherBase { + StartsWithMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; +}; +struct EndsWithMatcher : StringMatcherBase { + EndsWithMatcher( CasedString const& comparator ); + bool match( std::string const& source ) const override; +}; - struct RegexMatcher : MatcherBase { - RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity ); - bool match( std::string const& matchee ) const override; - std::string describe() const override; +struct RegexMatcher : MatcherBase { + RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity ); + bool match( std::string const& matchee ) const override; + std::string describe() const override; - private: - std::string m_regex; - CaseSensitive::Choice m_caseSensitivity; - }; + private: + std::string m_regex; + CaseSensitive::Choice m_caseSensitivity; +}; - } // namespace StdString +} // namespace StdString - // The following functions create the actual matcher objects. - // This allows the types to be inferred +// The following functions create the actual matcher objects. +// This allows the types to be inferred - StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); - StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); +StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); +StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); +StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); +StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); +StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ); -} // namespace Matchers -} // namespace Catch +} // end catch_matchers_string.h // start catch_matchers_vector.h #include -namespace Catch { -namespace Matchers { +namespace Catch::Matchers { - namespace Vector { - template - struct ContainsElementMatcher : MatcherBase> { +namespace Vector { +template +struct ContainsElementMatcher : MatcherBase> { - ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {} + ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {} - bool match(std::vector const &v) const override { - for (auto const& el : v) { - if (el == m_comparator) { - return true; - } - } - return false; - } + bool match(std::vector const &v) const override { + for (auto const& el : v) { + if (el == m_comparator) { + return true; + } + } + return false; + } - std::string describe() const override { - return "Contains: " + ::Catch::Detail::stringify( m_comparator ); - } + std::string describe() const override { + return "Contains: " + ::Catch::Detail::stringify( m_comparator ); + } - T const& m_comparator; - }; + T const& m_comparator; +}; - template - struct ContainsMatcher : MatcherBase> { +template +struct ContainsMatcher : MatcherBase> { - ContainsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} + ContainsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} - bool match(std::vector const &v) const override { - // !TBD: see note in EqualsMatcher - if (m_comparator.size() > v.size()) - return false; - for (auto const& comparator : m_comparator) { - auto present = false; - for (const auto& el : v) { - if (el == comparator) { - present = true; - break; - } - } - if (!present) { - return false; - } - } - return true; - } - std::string describe() const override { - return "Contains: " + ::Catch::Detail::stringify( m_comparator ); - } + bool match(std::vector const &v) const override { + // !TBD: see note in EqualsMatcher + if (m_comparator.size() > v.size()) + return false; + for (auto const& comparator : m_comparator) { + auto present = false; + for (const auto& el : v) { + if (el == comparator) { + present = true; + break; + } + } + if (!present) { + return false; + } + } + return true; + } + std::string describe() const override { + return "Contains: " + ::Catch::Detail::stringify( m_comparator ); + } - std::vector const& m_comparator; - }; + std::vector const& m_comparator; +}; - template - struct EqualsMatcher : MatcherBase> { +template +struct EqualsMatcher : MatcherBase> { - EqualsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} + EqualsMatcher(std::vector const &comparator) : m_comparator( comparator ) {} - bool match(std::vector const &v) const override { - // !TBD: This currently works if all elements can be compared using != - // - a more general approach would be via a compare template that defaults - // to using !=. but could be specialised for, e.g. std::vector etc - // - then just call that directly - if (m_comparator.size() != v.size()) - return false; - for (std::size_t i = 0; i < v.size(); ++i) - if (m_comparator[i] != v[i]) - return false; - return true; - } - std::string describe() const override { - return "Equals: " + ::Catch::Detail::stringify( m_comparator ); - } - std::vector const& m_comparator; - }; + bool match(std::vector const &v) const override { + // !TBD: This currently works if all elements can be compared using != + // - a more general approach would be via a compare template that defaults + // to using !=. but could be specialised for, e.g. std::vector etc + // - then just call that directly + if (m_comparator.size() != v.size()) + return false; + for (std::size_t i = 0; i < v.size(); ++i) + if (m_comparator[i] != v[i]) + return false; + return true; + } + std::string describe() const override { + return "Equals: " + ::Catch::Detail::stringify( m_comparator ); + } + std::vector const& m_comparator; +}; - template - struct ApproxMatcher : MatcherBase> { +template +struct ApproxMatcher : MatcherBase> { - ApproxMatcher(std::vector const& comparator) : m_comparator( comparator ) {} + ApproxMatcher(std::vector const& comparator) : m_comparator( comparator ) {} - bool match(std::vector const &v) const override { - if (m_comparator.size() != v.size()) - return false; - for (std::size_t i = 0; i < v.size(); ++i) - if (m_comparator[i] != approx(v[i])) - return false; - return true; - } - std::string describe() const override { - return "is approx: " + ::Catch::Detail::stringify( m_comparator ); - } - template ::value>::type> - ApproxMatcher& epsilon( T const& newEpsilon ) { - approx.epsilon(newEpsilon); - return *this; - } - template ::value>::type> - ApproxMatcher& margin( T const& newMargin ) { - approx.margin(newMargin); - return *this; - } - template ::value>::type> - ApproxMatcher& scale( T const& newScale ) { - approx.scale(newScale); - return *this; - } + bool match(std::vector const &v) const override { + if (m_comparator.size() != v.size()) + return false; + for (std::size_t i = 0; i < v.size(); ++i) + if (m_comparator[i] != approx(v[i])) + return false; + return true; + } + std::string describe() const override { + return "is approx: " + ::Catch::Detail::stringify( m_comparator ); + } + template ::value>::type> + ApproxMatcher& epsilon( T const& newEpsilon ) { + approx.epsilon(newEpsilon); + return *this; + } + template ::value>::type> + ApproxMatcher& margin( T const& newMargin ) { + approx.margin(newMargin); + return *this; + } + template ::value>::type> + ApproxMatcher& scale( T const& newScale ) { + approx.scale(newScale); + return *this; + } - std::vector const& m_comparator; - mutable Catch::Detail::Approx approx = Catch::Detail::Approx::custom(); - }; + std::vector const& m_comparator; + mutable Catch::Detail::Approx approx = Catch::Detail::Approx::custom(); +}; - template - struct UnorderedEqualsMatcher : MatcherBase> { - UnorderedEqualsMatcher(std::vector const& target) : m_target(target) {} - bool match(std::vector const& vec) const override { - if (m_target.size() != vec.size()) { - return false; - } - return std::is_permutation(m_target.begin(), m_target.end(), vec.begin()); - } +template +struct UnorderedEqualsMatcher : MatcherBase> { + UnorderedEqualsMatcher(std::vector const& target) : m_target(target) {} + bool match(std::vector const& vec) const override { + if (m_target.size() != vec.size()) { + return false; + } + return std::is_permutation(m_target.begin(), m_target.end(), vec.begin()); + } - std::string describe() const override { - return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target); - } - private: - std::vector const& m_target; - }; + std::string describe() const override { + return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target); + } + private: + std::vector const& m_target; +}; - } // namespace Vector +} // namespace Vector - // The following functions create the actual matcher objects. - // This allows the types to be inferred +// The following functions create the actual matcher objects. +// This allows the types to be inferred - template, typename AllocMatch = AllocComp> - Vector::ContainsMatcher Contains( std::vector const& comparator ) { - return Vector::ContainsMatcher( comparator ); - } +template, typename AllocMatch = AllocComp> +Vector::ContainsMatcher Contains( std::vector const& comparator ) { + return Vector::ContainsMatcher( comparator ); +} - template> - Vector::ContainsElementMatcher VectorContains( T const& comparator ) { - return Vector::ContainsElementMatcher( comparator ); - } +template> +Vector::ContainsElementMatcher VectorContains( T const& comparator ) { + return Vector::ContainsElementMatcher( comparator ); +} - template, typename AllocMatch = AllocComp> - Vector::EqualsMatcher Equals( std::vector const& comparator ) { - return Vector::EqualsMatcher( comparator ); - } +template, typename AllocMatch = AllocComp> +Vector::EqualsMatcher Equals( std::vector const& comparator ) { + return Vector::EqualsMatcher( comparator ); +} - template, typename AllocMatch = AllocComp> - Vector::ApproxMatcher Approx( std::vector const& comparator ) { - return Vector::ApproxMatcher( comparator ); - } +template, typename AllocMatch = AllocComp> +Vector::ApproxMatcher Approx( std::vector const& comparator ) { + return Vector::ApproxMatcher( comparator ); +} - template, typename AllocMatch = AllocComp> - Vector::UnorderedEqualsMatcher UnorderedEquals(std::vector const& target) { - return Vector::UnorderedEqualsMatcher( target ); - } +template, typename AllocMatch = AllocComp> +Vector::UnorderedEqualsMatcher UnorderedEquals(std::vector const& target) { + return Vector::UnorderedEqualsMatcher( target ); +} -} // namespace Matchers -} // namespace Catch +} // end catch_matchers_vector.h namespace Catch { @@ -3919,7 +3906,7 @@ class GeneratorException : public std::exception { m_msg(msg) {} - const char* what() const noexcept override final; + const char* what() const noexcept final; }; namespace Generators { @@ -3934,7 +3921,7 @@ namespace Generators { template struct IGenerator : GeneratorUntypedBase { - virtual ~IGenerator() = default; + ~IGenerator() override = default; // Returns the current element of the generator // @@ -4108,226 +4095,224 @@ namespace Generators { // end catch_generators.hpp // start catch_generators_generic.hpp -namespace Catch { -namespace Generators { +namespace Catch::Generators { - template - class TakeGenerator : public IGenerator { - GeneratorWrapper m_generator; - size_t m_returned = 0; - size_t m_target; - public: - TakeGenerator(size_t target, GeneratorWrapper&& generator): - m_generator(std::move(generator)), - m_target(target) - { - assert(target != 0 && "Empty generators are not allowed"); - } - T const& get() const override { - return m_generator.get(); - } - bool next() override { - ++m_returned; - if (m_returned >= m_target) { - return false; - } - - const auto success = m_generator.next(); - // If the underlying generator does not contain enough values - // then we cut short as well - if (!success) { - m_returned = m_target; - } - return success; - } - }; +template +class TakeGenerator : public IGenerator { + GeneratorWrapper m_generator; + size_t m_returned = 0; + size_t m_target; + public: + TakeGenerator(size_t target, GeneratorWrapper&& generator): + m_generator(std::move(generator)), + m_target(target) + { + assert(target != 0 && "Empty generators are not allowed"); + } + T const& get() const override { + return m_generator.get(); + } + bool next() override { + ++m_returned; + if (m_returned >= m_target) { + return false; + } - template - GeneratorWrapper take(size_t target, GeneratorWrapper&& generator) { - return GeneratorWrapper(pf::make_unique>(target, std::move(generator))); + const auto success = m_generator.next(); + // If the underlying generator does not contain enough values + // then we cut short as well + if (!success) { + m_returned = m_target; } + return success; + } +}; - template - class FilterGenerator : public IGenerator { - GeneratorWrapper m_generator; - Predicate m_predicate; - public: - template - FilterGenerator(P&& pred, GeneratorWrapper&& generator): - m_generator(std::move(generator)), - m_predicate(std::forward

(pred)) - { - if (!m_predicate(m_generator.get())) { - // It might happen that there are no values that pass the - // filter. In that case we throw an exception. - auto has_initial_value = next(); - if (!has_initial_value) { - Catch::throw_exception(GeneratorException("No valid value found in filtered generator")); - } - } - } +template +GeneratorWrapper take(size_t target, GeneratorWrapper&& generator) { + return GeneratorWrapper(pf::make_unique>(target, std::move(generator))); +} - T const& get() const override { - return m_generator.get(); - } +template +class FilterGenerator : public IGenerator { + GeneratorWrapper m_generator; + Predicate m_predicate; + public: + template + FilterGenerator(P&& pred, GeneratorWrapper&& generator): + m_generator(std::move(generator)), + m_predicate(std::forward

(pred)) + { + if (!m_predicate(m_generator.get())) { + // It might happen that there are no values that pass the + // filter. In that case we throw an exception. + auto has_initial_value = next(); + if (!has_initial_value) { + Catch::throw_exception(GeneratorException("No valid value found in filtered generator")); + } + } + } - bool next() override { - bool success = m_generator.next(); - if (!success) { - return false; - } - while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true); - return success; - } - }; + T const& get() const override { + return m_generator.get(); + } - template - GeneratorWrapper filter(Predicate&& pred, GeneratorWrapper&& generator) { - return GeneratorWrapper(std::unique_ptr>(pf::make_unique>(std::forward(pred), std::move(generator)))); + bool next() override { + bool success = m_generator.next(); + if (!success) { + return false; } + while (!m_predicate(m_generator.get()) && (success = m_generator.next()) == true); + return success; + } +}; - template - class RepeatGenerator : public IGenerator { - static_assert(!std::is_same::value, - "RepeatGenerator currently does not support bools" - "because of std::vector specialization"); - GeneratorWrapper m_generator; - mutable std::vector m_returned; - size_t m_target_repeats; - size_t m_current_repeat = 0; - size_t m_repeat_index = 0; - public: - RepeatGenerator(size_t repeats, GeneratorWrapper&& generator): - m_generator(std::move(generator)), - m_target_repeats(repeats) - { - assert(m_target_repeats > 0 && "Repeat generator must repeat at least once"); - } - - T const& get() const override { - if (m_current_repeat == 0) { - m_returned.push_back(m_generator.get()); - return m_returned.back(); - } - return m_returned[m_repeat_index]; - } +template +GeneratorWrapper filter(Predicate&& pred, GeneratorWrapper&& generator) { + return GeneratorWrapper(std::unique_ptr>(pf::make_unique>(std::forward(pred), std::move(generator)))); +} - bool next() override { - // There are 2 basic cases: - // 1) We are still reading the generator - // 2) We are reading our own cache - - // In the first case, we need to poke the underlying generator. - // If it happily moves, we are left in that state, otherwise it is time to start reading from our cache - if (m_current_repeat == 0) { - const auto success = m_generator.next(); - if (!success) { - ++m_current_repeat; - } - return m_current_repeat < m_target_repeats; - } +template +class RepeatGenerator : public IGenerator { + static_assert(!std::is_same::value, + "RepeatGenerator currently does not support bools" + "because of std::vector specialization"); + GeneratorWrapper m_generator; + mutable std::vector m_returned; + size_t m_target_repeats; + size_t m_current_repeat = 0; + size_t m_repeat_index = 0; + public: + RepeatGenerator(size_t repeats, GeneratorWrapper&& generator): + m_generator(std::move(generator)), + m_target_repeats(repeats) + { + assert(m_target_repeats > 0 && "Repeat generator must repeat at least once"); + } - // In the second case, we need to move indices forward and check that we haven't run up against the end - ++m_repeat_index; - if (m_repeat_index == m_returned.size()) { - m_repeat_index = 0; - ++m_current_repeat; - } - return m_current_repeat < m_target_repeats; - } - }; + T const& get() const override { + if (m_current_repeat == 0) { + m_returned.push_back(m_generator.get()); + return m_returned.back(); + } + return m_returned[m_repeat_index]; + } - template - GeneratorWrapper repeat(size_t repeats, GeneratorWrapper&& generator) { - return GeneratorWrapper(pf::make_unique>(repeats, std::move(generator))); + bool next() override { + // There are 2 basic cases: + // 1) We are still reading the generator + // 2) We are reading our own cache + + // In the first case, we need to poke the underlying generator. + // If it happily moves, we are left in that state, otherwise it is time to start reading from our cache + if (m_current_repeat == 0) { + const auto success = m_generator.next(); + if (!success) { + ++m_current_repeat; + } + return m_current_repeat < m_target_repeats; } - template - class MapGenerator : public IGenerator { - // TBD: provide static assert for mapping function, for friendly error message - GeneratorWrapper m_generator; - Func m_function; - // To avoid returning dangling reference, we have to save the values - T m_cache; - public: - template - MapGenerator(F2&& function, GeneratorWrapper&& generator) : - m_generator(std::move(generator)), - m_function(std::forward(function)), - m_cache(m_function(m_generator.get())) - {} + // In the second case, we need to move indices forward and check that we haven't run up against the end + ++m_repeat_index; + if (m_repeat_index == m_returned.size()) { + m_repeat_index = 0; + ++m_current_repeat; + } + return m_current_repeat < m_target_repeats; + } +}; - T const& get() const override { - return m_cache; - } - bool next() override { - const auto success = m_generator.next(); - if (success) { - m_cache = m_function(m_generator.get()); - } - return success; - } - }; +template +GeneratorWrapper repeat(size_t repeats, GeneratorWrapper&& generator) { + return GeneratorWrapper(pf::make_unique>(repeats, std::move(generator))); +} - template > - GeneratorWrapper map(Func&& function, GeneratorWrapper&& generator) { - return GeneratorWrapper( - pf::make_unique>(std::forward(function), std::move(generator)) - ); +template +class MapGenerator : public IGenerator { + // TBD: provide static assert for mapping function, for friendly error message + GeneratorWrapper m_generator; + Func m_function; + // To avoid returning dangling reference, we have to save the values + T m_cache; + public: + template + MapGenerator(F2&& function, GeneratorWrapper&& generator) : + m_generator(std::move(generator)), + m_function(std::forward(function)), + m_cache(m_function(m_generator.get())) + {} + + T const& get() const override { + return m_cache; + } + bool next() override { + const auto success = m_generator.next(); + if (success) { + m_cache = m_function(m_generator.get()); } + return success; + } +}; - template - GeneratorWrapper map(Func&& function, GeneratorWrapper&& generator) { - return GeneratorWrapper( - pf::make_unique>(std::forward(function), std::move(generator)) - ); - } +template > +GeneratorWrapper map(Func&& function, GeneratorWrapper&& generator) { + return GeneratorWrapper( + pf::make_unique>(std::forward(function), std::move(generator)) + ); +} - template - class ChunkGenerator final : public IGenerator> { - std::vector m_chunk; - size_t m_chunk_size; - GeneratorWrapper m_generator; - bool m_used_up = false; - public: - ChunkGenerator(size_t size, GeneratorWrapper generator) : - m_chunk_size(size), m_generator(std::move(generator)) - { - m_chunk.reserve(m_chunk_size); - if (m_chunk_size != 0) { - m_chunk.push_back(m_generator.get()); - for (size_t i = 1; i < m_chunk_size; ++i) { - if (!m_generator.next()) { - Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk")); - } - m_chunk.push_back(m_generator.get()); - } - } - } - std::vector const& get() const override { - return m_chunk; - } - bool next() override { - m_chunk.clear(); - for (size_t idx = 0; idx < m_chunk_size; ++idx) { - if (!m_generator.next()) { - return false; - } - m_chunk.push_back(m_generator.get()); - } - return true; - } - }; +template +GeneratorWrapper map(Func&& function, GeneratorWrapper&& generator) { + return GeneratorWrapper( + pf::make_unique>(std::forward(function), std::move(generator)) + ); +} - template - GeneratorWrapper> chunk(size_t size, GeneratorWrapper&& generator) { - return GeneratorWrapper>( - pf::make_unique>(size, std::move(generator)) - ); +template +class ChunkGenerator final : public IGenerator> { + std::vector m_chunk; + size_t m_chunk_size; + GeneratorWrapper m_generator; + bool m_used_up = false; + public: + ChunkGenerator(size_t size, GeneratorWrapper generator) : + m_chunk_size(size), m_generator(std::move(generator)) + { + m_chunk.reserve(m_chunk_size); + if (m_chunk_size != 0) { + m_chunk.push_back(m_generator.get()); + for (size_t i = 1; i < m_chunk_size; ++i) { + if (!m_generator.next()) { + Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk")); + } + m_chunk.push_back(m_generator.get()); + } } + } + std::vector const& get() const override { + return m_chunk; + } + bool next() override { + m_chunk.clear(); + for (size_t idx = 0; idx < m_chunk_size; ++idx) { + if (!m_generator.next()) { + return false; + } + m_chunk.push_back(m_generator.get()); + } + return true; + } +}; -} // namespace Generators -} // namespace Catch +template +GeneratorWrapper> chunk(size_t size, GeneratorWrapper&& generator) { + return GeneratorWrapper>( + pf::make_unique>(size, std::move(generator)) + ); +} + +} // end catch_generators_generic.hpp // start catch_generators_specific.hpp @@ -4356,7 +4341,7 @@ namespace Catch { struct IMutableContext : IContext { - virtual ~IMutableContext(); + ~IMutableContext() override; virtual void setResultCapture( IResultCapture* resultCapture ) = 0; virtual void setRunner( IRunner* runner ) = 0; virtual void setConfig( IConfigPtr const& config ) = 0; @@ -4500,8 +4485,7 @@ namespace Catch { class TestSpec; struct IConfig : NonCopyable { - - virtual ~IConfig(); + ~IConfig() override; virtual bool allowThrows() const = 0; virtual std::ostream& stream() const = 0; @@ -4586,159 +4570,157 @@ namespace Catch { // end catch_random_number_generator.h #include -namespace Catch { -namespace Generators { +namespace Catch::Generators { template class RandomFloatingGenerator final : public IGenerator { - Catch::SimplePcg32& m_rng; - std::uniform_real_distribution m_dist; - Float m_current_number; -public: - - RandomFloatingGenerator(Float a, Float b): - m_rng(rng()), - m_dist(a, b) { - static_cast(next()); - } + Catch::SimplePcg32& m_rng; + std::uniform_real_distribution m_dist; + Float m_current_number; + public: + + RandomFloatingGenerator(Float a, Float b): + m_rng(rng()), + m_dist(a, b) { + static_cast(next()); + } - Float const& get() const override { - return m_current_number; - } - bool next() override { - m_current_number = m_dist(m_rng); - return true; - } + Float const& get() const override { + return m_current_number; + } + bool next() override { + m_current_number = m_dist(m_rng); + return true; + } }; template class RandomIntegerGenerator final : public IGenerator { - Catch::SimplePcg32& m_rng; - std::uniform_int_distribution m_dist; - Integer m_current_number; -public: - - RandomIntegerGenerator(Integer a, Integer b): - m_rng(rng()), - m_dist(a, b) { - static_cast(next()); - } + Catch::SimplePcg32& m_rng; + std::uniform_int_distribution m_dist; + Integer m_current_number; + public: + + RandomIntegerGenerator(Integer a, Integer b): + m_rng(rng()), + m_dist(a, b) { + static_cast(next()); + } - Integer const& get() const override { - return m_current_number; - } - bool next() override { - m_current_number = m_dist(m_rng); - return true; - } + Integer const& get() const override { + return m_current_number; + } + bool next() override { + m_current_number = m_dist(m_rng); + return true; + } }; // TODO: Ideally this would be also constrained against the various char types, // but I don't expect users to run into that in practice. template typename std::enable_if::value && !std::is_same::value, -GeneratorWrapper>::type + GeneratorWrapper>::type random(T a, T b) { - return GeneratorWrapper( - pf::make_unique>(a, b) + return GeneratorWrapper( + pf::make_unique>(a, b) ); } template typename std::enable_if::value, -GeneratorWrapper>::type + GeneratorWrapper>::type random(T a, T b) { - return GeneratorWrapper( - pf::make_unique>(a, b) + return GeneratorWrapper( + pf::make_unique>(a, b) ); } template class RangeGenerator final : public IGenerator { - T m_current; - T m_end; - T m_step; - bool m_positive; - -public: - RangeGenerator(T const& start, T const& end, T const& step): - m_current(start), - m_end(end), - m_step(step), - m_positive(m_step > T(0)) - { - assert(m_current != m_end && "Range start and end cannot be equal"); - assert(m_step != T(0) && "Step size cannot be zero"); - assert(((m_positive && m_current <= m_end) || (!m_positive && m_current >= m_end)) && "Step moves away from end"); - } + T m_current; + T m_end; + T m_step; + bool m_positive; + + public: + RangeGenerator(T const& start, T const& end, T const& step): + m_current(start), + m_end(end), + m_step(step), + m_positive(m_step > T(0)) + { + assert(m_current != m_end && "Range start and end cannot be equal"); + assert(m_step != T(0) && "Step size cannot be zero"); + assert(((m_positive && m_current <= m_end) || (!m_positive && m_current >= m_end)) && "Step moves away from end"); + } - RangeGenerator(T const& start, T const& end): - RangeGenerator(start, end, (start < end) ? T(1) : T(-1)) - {} + RangeGenerator(T const& start, T const& end): + RangeGenerator(start, end, (start < end) ? T(1) : T(-1)) + {} - T const& get() const override { - return m_current; - } + T const& get() const override { + return m_current; + } - bool next() override { - m_current += m_step; - return (m_positive) ? (m_current < m_end) : (m_current > m_end); - } + bool next() override { + m_current += m_step; + return (m_positive) ? (m_current < m_end) : (m_current > m_end); + } }; template GeneratorWrapper range(T const& start, T const& end, T const& step) { - static_assert(std::is_arithmetic::value && !std::is_same::value, "Type must be numeric"); - return GeneratorWrapper(pf::make_unique>(start, end, step)); + static_assert(std::is_arithmetic::value && !std::is_same::value, "Type must be numeric"); + return GeneratorWrapper(pf::make_unique>(start, end, step)); } template GeneratorWrapper range(T const& start, T const& end) { - static_assert(std::is_integral::value && !std::is_same::value, "Type must be an integer"); - return GeneratorWrapper(pf::make_unique>(start, end)); + static_assert(std::is_integral::value && !std::is_same::value, "Type must be an integer"); + return GeneratorWrapper(pf::make_unique>(start, end)); } template class IteratorGenerator final : public IGenerator { - static_assert(!std::is_same::value, - "IteratorGenerator currently does not support bools" - "because of std::vector specialization"); - - std::vector m_elems; - size_t m_current = 0; -public: - template - IteratorGenerator(InputIterator first, InputSentinel last):m_elems(first, last) { - if (m_elems.empty()) { - Catch::throw_exception(GeneratorException("IteratorGenerator received no valid values")); - } + static_assert(!std::is_same::value, + "IteratorGenerator currently does not support bools" + "because of std::vector specialization"); + + std::vector m_elems; + size_t m_current = 0; + public: + template + IteratorGenerator(InputIterator first, InputSentinel last):m_elems(first, last) { + if (m_elems.empty()) { + Catch::throw_exception(GeneratorException("IteratorGenerator received no valid values")); } + } - T const& get() const override { - return m_elems[m_current]; - } + T const& get() const override { + return m_elems[m_current]; + } - bool next() override { - ++m_current; - return m_current != m_elems.size(); - } + bool next() override { + ++m_current; + return m_current != m_elems.size(); + } }; template ::value_type> + typename InputSentinel, + typename ResultType = typename std::iterator_traits::value_type> GeneratorWrapper from_range(InputIterator from, InputSentinel to) { - return GeneratorWrapper(pf::make_unique>(from, to)); + return GeneratorWrapper(pf::make_unique>(from, to)); } template + typename ResultType = typename Container::value_type> GeneratorWrapper from_range(Container const& cnt) { - return GeneratorWrapper(pf::make_unique>(cnt.begin(), cnt.end())); + return GeneratorWrapper(pf::make_unique>(cnt.begin(), cnt.end())); } -} // namespace Generators -} // namespace Catch +} // end catch_generators_specific.hpp @@ -5309,7 +5291,7 @@ namespace Catch { Config() = default; Config( ConfigData const& data ); - virtual ~Config() = default; + ~Config() override = default; std::string const& getFilename() const; @@ -8482,320 +8464,315 @@ namespace Catch { #define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80 #endif -namespace Catch { -namespace clara { -namespace TextFlow { +namespace Catch::clara::TextFlow { inline auto isWhitespace(char c) -> bool { - static std::string chars = " \t\n\r"; - return chars.find(c) != std::string::npos; + static std::string chars = " \t\n\r"; + return chars.find(c) != std::string::npos; } inline auto isBreakableBefore(char c) -> bool { - static std::string chars = "[({<|"; - return chars.find(c) != std::string::npos; + static std::string chars = "[({<|"; + return chars.find(c) != std::string::npos; } inline auto isBreakableAfter(char c) -> bool { - static std::string chars = "])}>.,:;*+-=&/\\"; - return chars.find(c) != std::string::npos; + static std::string chars = "])}>.,:;*+-=&/\\"; + return chars.find(c) != std::string::npos; } class Columns; class Column { - std::vector m_strings; - size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH; - size_t m_indent = 0; - size_t m_initialIndent = std::string::npos; - -public: - class iterator { - friend Column; + std::vector m_strings; + size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH; + size_t m_indent = 0; + size_t m_initialIndent = std::string::npos; - Column const& m_column; - size_t m_stringIndex = 0; - size_t m_pos = 0; + public: + class iterator { + friend Column; - size_t m_len = 0; - size_t m_end = 0; - bool m_suffix = false; + Column const& m_column; + size_t m_stringIndex = 0; + size_t m_pos = 0; - iterator(Column const& column, size_t stringIndex) - : m_column(column), - m_stringIndex(stringIndex) {} + size_t m_len = 0; + size_t m_end = 0; + bool m_suffix = false; - auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; } + iterator(Column const& column, size_t stringIndex) + : m_column(column), + m_stringIndex(stringIndex) {} - auto isBoundary(size_t at) const -> bool { - assert(at > 0); - assert(at <= line().size()); + auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; } - return at == line().size() || - (isWhitespace(line()[at]) && !isWhitespace(line()[at - 1])) || - isBreakableBefore(line()[at]) || - isBreakableAfter(line()[at - 1]); - } + auto isBoundary(size_t at) const -> bool { + assert(at > 0); + assert(at <= line().size()); - void calcLength() { - assert(m_stringIndex < m_column.m_strings.size()); + return at == line().size() || + (isWhitespace(line()[at]) && !isWhitespace(line()[at - 1])) || + isBreakableBefore(line()[at]) || + isBreakableAfter(line()[at - 1]); + } - m_suffix = false; - auto width = m_column.m_width - indent(); - m_end = m_pos; - if (line()[m_pos] == '\n') { - ++m_end; - } - while (m_end < line().size() && line()[m_end] != '\n') - ++m_end; - - if (m_end < m_pos + width) { - m_len = m_end - m_pos; - } else { - size_t len = width; - while (len > 0 && !isBoundary(m_pos + len)) - --len; - while (len > 0 && isWhitespace(line()[m_pos + len - 1])) - --len; - - if (len > 0) { - m_len = len; - } else { - m_suffix = true; - m_len = width - 1; - } - } - } + void calcLength() { + assert(m_stringIndex < m_column.m_strings.size()); - auto indent() const -> size_t { - auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos; - return initial == std::string::npos ? m_column.m_indent : initial; - } + m_suffix = false; + auto width = m_column.m_width - indent(); + m_end = m_pos; + if (line()[m_pos] == '\n') { + ++m_end; + } + while (m_end < line().size() && line()[m_end] != '\n') + ++m_end; + + if (m_end < m_pos + width) { + m_len = m_end - m_pos; + } else { + size_t len = width; + while (len > 0 && !isBoundary(m_pos + len)) + --len; + while (len > 0 && isWhitespace(line()[m_pos + len - 1])) + --len; + + if (len > 0) { + m_len = len; + } else { + m_suffix = true; + m_len = width - 1; + } + } + } - auto addIndentAndSuffix(std::string const &plain) const -> std::string { - return std::string(indent(), ' ') + (m_suffix ? plain + "-" : plain); - } + auto indent() const -> size_t { + auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos; + return initial == std::string::npos ? m_column.m_indent : initial; + } - public: - using difference_type = std::ptrdiff_t; - using value_type = std::string; - using pointer = value_type * ; - using reference = value_type & ; - using iterator_category = std::forward_iterator_tag; - - explicit iterator(Column const& column) : m_column(column) { - assert(m_column.m_width > m_column.m_indent); - assert(m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent); - calcLength(); - if (m_len == 0) - m_stringIndex++; // Empty string - } + auto addIndentAndSuffix(std::string const &plain) const -> std::string { + return std::string(indent(), ' ') + (m_suffix ? plain + "-" : plain); + } - auto operator *() const -> std::string { - assert(m_stringIndex < m_column.m_strings.size()); - assert(m_pos <= m_end); - return addIndentAndSuffix(line().substr(m_pos, m_len)); - } + public: + using difference_type = std::ptrdiff_t; + using value_type = std::string; + using pointer = value_type * ; + using reference = value_type & ; + using iterator_category = std::forward_iterator_tag; + + explicit iterator(Column const& column) : m_column(column) { + assert(m_column.m_width > m_column.m_indent); + assert(m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent); + calcLength(); + if (m_len == 0) + m_stringIndex++; // Empty string + } + + auto operator *() const -> std::string { + assert(m_stringIndex < m_column.m_strings.size()); + assert(m_pos <= m_end); + return addIndentAndSuffix(line().substr(m_pos, m_len)); + } + + auto operator ++() -> iterator& { + m_pos += m_len; + if (m_pos < line().size() && line()[m_pos] == '\n') + m_pos += 1; + else + while (m_pos < line().size() && isWhitespace(line()[m_pos])) + ++m_pos; + + if (m_pos == line().size()) { + m_pos = 0; + ++m_stringIndex; + } + if (m_stringIndex < m_column.m_strings.size()) + calcLength(); + return *this; + } + auto operator ++(int) -> iterator { + iterator prev(*this); + operator++(); + return prev; + } - auto operator ++() -> iterator& { - m_pos += m_len; - if (m_pos < line().size() && line()[m_pos] == '\n') - m_pos += 1; - else - while (m_pos < line().size() && isWhitespace(line()[m_pos])) - ++m_pos; - - if (m_pos == line().size()) { - m_pos = 0; - ++m_stringIndex; - } - if (m_stringIndex < m_column.m_strings.size()) - calcLength(); - return *this; - } - auto operator ++(int) -> iterator { - iterator prev(*this); - operator++(); - return prev; - } + auto operator ==(iterator const& other) const -> bool { + return + m_pos == other.m_pos && + m_stringIndex == other.m_stringIndex && + &m_column == &other.m_column; + } + auto operator !=(iterator const& other) const -> bool { + return !operator==(other); + } + }; + using const_iterator = iterator; - auto operator ==(iterator const& other) const -> bool { - return - m_pos == other.m_pos && - m_stringIndex == other.m_stringIndex && - &m_column == &other.m_column; - } - auto operator !=(iterator const& other) const -> bool { - return !operator==(other); - } - }; - using const_iterator = iterator; + explicit Column(std::string const& text) { m_strings.push_back(text); } - explicit Column(std::string const& text) { m_strings.push_back(text); } + auto width(size_t newWidth) -> Column& { + assert(newWidth > 0); + m_width = newWidth; + return *this; + } + auto indent(size_t newIndent) -> Column& { + m_indent = newIndent; + return *this; + } + auto initialIndent(size_t newIndent) -> Column& { + m_initialIndent = newIndent; + return *this; + } - auto width(size_t newWidth) -> Column& { - assert(newWidth > 0); - m_width = newWidth; - return *this; - } - auto indent(size_t newIndent) -> Column& { - m_indent = newIndent; - return *this; - } - auto initialIndent(size_t newIndent) -> Column& { - m_initialIndent = newIndent; - return *this; - } + auto width() const -> size_t { return m_width; } + auto begin() const -> iterator { return iterator(*this); } + auto end() const -> iterator { return { *this, m_strings.size() }; } - auto width() const -> size_t { return m_width; } - auto begin() const -> iterator { return iterator(*this); } - auto end() const -> iterator { return { *this, m_strings.size() }; } - - inline friend std::ostream& operator << (std::ostream& os, Column const& col) { - bool first = true; - for (auto line : col) { - if (first) - first = false; - else - os << "\n"; - os << line; - } - return os; - } + inline friend std::ostream& operator << (std::ostream& os, Column const& col) { + bool first = true; + for (auto line : col) { + if (first) + first = false; + else + os << "\n"; + os << line; + } + return os; + } - auto operator + (Column const& other)->Columns; + auto operator + (Column const& other)->Columns; - auto toString() const -> std::string { - std::ostringstream oss; - oss << *this; - return oss.str(); - } + auto toString() const -> std::string { + std::ostringstream oss; + oss << *this; + return oss.str(); + } }; class Spacer : public Column { -public: - explicit Spacer(size_t spaceWidth) : Column("") { - width(spaceWidth); - } + public: + explicit Spacer(size_t spaceWidth) : Column("") { + width(spaceWidth); + } }; class Columns { - std::vector m_columns; - -public: + std::vector m_columns; - class iterator { - friend Columns; - struct EndTag {}; + public: - std::vector const& m_columns; - std::vector m_iterators; - size_t m_activeIterators; + class iterator { + friend Columns; + struct EndTag {}; - iterator(Columns const& columns, EndTag) - : m_columns(columns.m_columns), - m_activeIterators(0) { - m_iterators.reserve(m_columns.size()); + std::vector const& m_columns; + std::vector m_iterators; + size_t m_activeIterators; - for (auto const& col : m_columns) - m_iterators.push_back(col.end()); - } - - public: - using difference_type = std::ptrdiff_t; - using value_type = std::string; - using pointer = value_type * ; - using reference = value_type & ; - using iterator_category = std::forward_iterator_tag; + iterator(Columns const& columns, EndTag) + : m_columns(columns.m_columns), + m_activeIterators(0) { + m_iterators.reserve(m_columns.size()); - explicit iterator(Columns const& columns) - : m_columns(columns.m_columns), - m_activeIterators(m_columns.size()) { - m_iterators.reserve(m_columns.size()); - - for (auto const& col : m_columns) - m_iterators.push_back(col.begin()); - } + for (auto const& col : m_columns) + m_iterators.push_back(col.end()); + } - auto operator ==(iterator const& other) const -> bool { - return m_iterators == other.m_iterators; - } - auto operator !=(iterator const& other) const -> bool { - return m_iterators != other.m_iterators; - } - auto operator *() const -> std::string { - std::string row, padding; - - for (size_t i = 0; i < m_columns.size(); ++i) { - auto width = m_columns[i].width(); - if (m_iterators[i] != m_columns[i].end()) { - std::string col = *m_iterators[i]; - row += padding + col; - if (col.size() < width) - padding = std::string(width - col.size(), ' '); - else - padding = ""; - } else { - padding += std::string(width, ' '); - } - } - return row; - } - auto operator ++() -> iterator& { - for (size_t i = 0; i < m_columns.size(); ++i) { - if (m_iterators[i] != m_columns[i].end()) - ++m_iterators[i]; - } - return *this; - } - auto operator ++(int) -> iterator { - iterator prev(*this); - operator++(); - return prev; - } - }; - using const_iterator = iterator; + public: + using difference_type = std::ptrdiff_t; + using value_type = std::string; + using pointer = value_type * ; + using reference = value_type & ; + using iterator_category = std::forward_iterator_tag; + + explicit iterator(Columns const& columns) + : m_columns(columns.m_columns), + m_activeIterators(m_columns.size()) { + m_iterators.reserve(m_columns.size()); + + for (auto const& col : m_columns) + m_iterators.push_back(col.begin()); + } + + auto operator ==(iterator const& other) const -> bool { + return m_iterators == other.m_iterators; + } + auto operator !=(iterator const& other) const -> bool { + return m_iterators != other.m_iterators; + } + auto operator *() const -> std::string { + std::string row, padding; + + for (size_t i = 0; i < m_columns.size(); ++i) { + auto width = m_columns[i].width(); + if (m_iterators[i] != m_columns[i].end()) { + std::string col = *m_iterators[i]; + row += padding + col; + if (col.size() < width) + padding = std::string(width - col.size(), ' '); + else + padding = ""; + } else { + padding += std::string(width, ' '); + } + } + return row; + } + auto operator ++() -> iterator& { + for (size_t i = 0; i < m_columns.size(); ++i) { + if (m_iterators[i] != m_columns[i].end()) + ++m_iterators[i]; + } + return *this; + } + auto operator ++(int) -> iterator { + iterator prev(*this); + operator++(); + return prev; + } + }; + using const_iterator = iterator; - auto begin() const -> iterator { return iterator(*this); } - auto end() const -> iterator { return { *this, iterator::EndTag() }; } + auto begin() const -> iterator { return iterator(*this); } + auto end() const -> iterator { return { *this, iterator::EndTag() }; } - auto operator += (Column const& col) -> Columns& { - m_columns.push_back(col); - return *this; - } - auto operator + (Column const& col) -> Columns { - Columns combined = *this; - combined += col; - return combined; - } + auto operator += (Column const& col) -> Columns& { + m_columns.push_back(col); + return *this; + } + auto operator + (Column const& col) -> Columns { + Columns combined = *this; + combined += col; + return combined; + } - inline friend std::ostream& operator << (std::ostream& os, Columns const& cols) { + inline friend std::ostream& operator << (std::ostream& os, Columns const& cols) { - bool first = true; - for (auto line : cols) { - if (first) - first = false; - else - os << "\n"; - os << line; - } - return os; - } + bool first = true; + for (auto line : cols) { + if (first) + first = false; + else + os << "\n"; + os << line; + } + return os; + } - auto toString() const -> std::string { - std::ostringstream oss; - oss << *this; - return oss.str(); - } + auto toString() const -> std::string { + std::ostringstream oss; + oss << *this; + return oss.str(); + } }; inline auto Column::operator + (Column const& other) -> Columns { - Columns cols; - cols += *this; - cols += other; - return cols; -} -} - + Columns cols; + cols += *this; + cols += other; + return cols; } } @@ -8812,854 +8789,854 @@ inline auto Column::operator + (Column const& other) -> Columns { #define CATCH_PLATFORM_WINDOWS #endif -namespace Catch { namespace clara { +namespace Catch::clara { namespace detail { - // Traits for extracting arg and return type of lambdas (for single argument lambdas) - template - struct UnaryLambdaTraits : UnaryLambdaTraits {}; +// Traits for extracting arg and return type of lambdas (for single argument lambdas) +template +struct UnaryLambdaTraits : UnaryLambdaTraits {}; - template - struct UnaryLambdaTraits { - static const bool isValid = false; - }; +template +struct UnaryLambdaTraits { + static const bool isValid = false; +}; - template - struct UnaryLambdaTraits { - static const bool isValid = true; - using ArgType = typename std::remove_const::type>::type; - using ReturnType = ReturnT; - }; +template +struct UnaryLambdaTraits { + static const bool isValid = true; + using ArgType = typename std::remove_const::type>::type; + using ReturnType = ReturnT; +}; - class TokenStream; +class TokenStream; - // Transport for raw args (copied from main args, or supplied via init list for testing) - class Args { - friend TokenStream; - std::string m_exeName; - std::vector m_args; +// Transport for raw args (copied from main args, or supplied via init list for testing) +class Args { + friend TokenStream; + std::string m_exeName; + std::vector m_args; - public: - Args( int argc, char const* const* argv ) - : m_exeName(argv[0]), - m_args(argv + 1, argv + argc) {} + public: + Args( int argc, char const* const* argv ) + : m_exeName(argv[0]), + m_args(argv + 1, argv + argc) {} - Args( std::initializer_list args ) - : m_exeName( *args.begin() ), - m_args( args.begin()+1, args.end() ) - {} + Args( std::initializer_list args ) + : m_exeName( *args.begin() ), + m_args( args.begin()+1, args.end() ) + {} - auto exeName() const -> std::string { - return m_exeName; - } - }; + auto exeName() const -> std::string { + return m_exeName; + } +}; - // Wraps a token coming from a token stream. These may not directly correspond to strings as a single string - // may encode an option + its argument if the : or = form is used - enum class TokenType { - Option, Argument - }; - struct Token { - TokenType type; - std::string token; - }; +// Wraps a token coming from a token stream. These may not directly correspond to strings as a single string +// may encode an option + its argument if the : or = form is used +enum class TokenType { + Option, Argument +}; +struct Token { + TokenType type; + std::string token; +}; - inline auto isOptPrefix( char c ) -> bool { - return c == '-' +inline auto isOptPrefix( char c ) -> bool { + return c == '-' #ifdef CATCH_PLATFORM_WINDOWS - || c == '/' + || c == '/' #endif - ; - } - - // Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled - class TokenStream { - using Iterator = std::vector::const_iterator; - Iterator it; - Iterator itEnd; - std::vector m_tokenBuffer; - - void loadBuffer() { - m_tokenBuffer.resize( 0 ); - - // Skip any empty strings - while( it != itEnd && it->empty() ) - ++it; - - if( it != itEnd ) { - auto const &next = *it; - if( isOptPrefix( next[0] ) ) { - auto delimiterPos = next.find_first_of( " :=" ); - if( delimiterPos != std::string::npos ) { - m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } ); - m_tokenBuffer.push_back( { TokenType::Argument, next.substr( delimiterPos + 1 ) } ); - } else { - if( next[1] != '-' && next.size() > 2 ) { - std::string opt = "- "; - for( size_t i = 1; i < next.size(); ++i ) { - opt[1] = next[i]; - m_tokenBuffer.push_back( { TokenType::Option, opt } ); - } - } else { - m_tokenBuffer.push_back( { TokenType::Option, next } ); - } - } - } else { - m_tokenBuffer.push_back( { TokenType::Argument, next } ); - } - } - } - - public: - explicit TokenStream( Args const &args ) : TokenStream( args.m_args.begin(), args.m_args.end() ) {} - - TokenStream( Iterator it, Iterator itEnd ) : it( it ), itEnd( itEnd ) { - loadBuffer(); - } + ; +} - explicit operator bool() const { - return !m_tokenBuffer.empty() || it != itEnd; +// Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled +class TokenStream { + using Iterator = std::vector::const_iterator; + Iterator it; + Iterator itEnd; + std::vector m_tokenBuffer; + + void loadBuffer() { + m_tokenBuffer.resize( 0 ); + + // Skip any empty strings + while( it != itEnd && it->empty() ) + ++it; + + if( it != itEnd ) { + auto const &next = *it; + if( isOptPrefix( next[0] ) ) { + auto delimiterPos = next.find_first_of( " :=" ); + if( delimiterPos != std::string::npos ) { + m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } ); + m_tokenBuffer.push_back( { TokenType::Argument, next.substr( delimiterPos + 1 ) } ); + } else { + if( next[1] != '-' && next.size() > 2 ) { + std::string opt = "- "; + for( size_t i = 1; i < next.size(); ++i ) { + opt[1] = next[i]; + m_tokenBuffer.push_back( { TokenType::Option, opt } ); + } + } else { + m_tokenBuffer.push_back( { TokenType::Option, next } ); + } } + } else { + m_tokenBuffer.push_back( { TokenType::Argument, next } ); + } + } + } - auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); } + public: + explicit TokenStream( Args const &args ) : TokenStream( args.m_args.begin(), args.m_args.end() ) {} - auto operator*() const -> Token { - assert( !m_tokenBuffer.empty() ); - return m_tokenBuffer.front(); - } + TokenStream( Iterator it, Iterator itEnd ) : it( it ), itEnd( itEnd ) { + loadBuffer(); + } - auto operator->() const -> Token const * { - assert( !m_tokenBuffer.empty() ); - return &m_tokenBuffer.front(); - } + explicit operator bool() const { + return !m_tokenBuffer.empty() || it != itEnd; + } - auto operator++() -> TokenStream & { - if( m_tokenBuffer.size() >= 2 ) { - m_tokenBuffer.erase( m_tokenBuffer.begin() ); - } else { - if( it != itEnd ) - ++it; - loadBuffer(); - } - return *this; - } - }; + auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); } - class ResultBase { - public: - enum Type { - Ok, LogicError, RuntimeError - }; + auto operator*() const -> Token { + assert( !m_tokenBuffer.empty() ); + return m_tokenBuffer.front(); + } - protected: - ResultBase( Type type ) : m_type( type ) {} - virtual ~ResultBase() = default; + auto operator->() const -> Token const * { + assert( !m_tokenBuffer.empty() ); + return &m_tokenBuffer.front(); + } - virtual void enforceOk() const = 0; + auto operator++() -> TokenStream & { + if( m_tokenBuffer.size() >= 2 ) { + m_tokenBuffer.erase( m_tokenBuffer.begin() ); + } else { + if( it != itEnd ) + ++it; + loadBuffer(); + } + return *this; + } +}; - Type m_type; - }; +class ResultBase { + public: + enum Type { + Ok, LogicError, RuntimeError + }; - template - class ResultValueBase : public ResultBase { - public: - auto value() const -> T const & { - enforceOk(); - return m_value; - } + protected: + ResultBase( Type type ) : m_type( type ) {} + virtual ~ResultBase() = default; - protected: - ResultValueBase( Type type ) : ResultBase( type ) {} + virtual void enforceOk() const = 0; - ResultValueBase( ResultValueBase const &other ) : ResultBase( other ) { - if( m_type == ResultBase::Ok ) - new( &m_value ) T( other.m_value ); - } + Type m_type; +}; - ResultValueBase( Type, T const &value ) : ResultBase( Ok ) { - new( &m_value ) T( value ); - } +template +class ResultValueBase : public ResultBase { + public: + auto value() const -> T const & { + enforceOk(); + return m_value; + } - auto operator=( ResultValueBase const &other ) -> ResultValueBase & { - if( m_type == ResultBase::Ok ) - m_value.~T(); - ResultBase::operator=(other); - if( m_type == ResultBase::Ok ) - new( &m_value ) T( other.m_value ); - return *this; - } + protected: + ResultValueBase( Type type ) : ResultBase( type ) {} - ~ResultValueBase() override { - if( m_type == Ok ) - m_value.~T(); - } + ResultValueBase( ResultValueBase const &other ) : ResultBase( other ) { + if( m_type == ResultBase::Ok ) + new( &m_value ) T( other.m_value ); + } - union { - T m_value; - }; - }; + ResultValueBase( Type, T const &value ) : ResultBase( Ok ) { + new( &m_value ) T( value ); + } - template<> - class ResultValueBase : public ResultBase { - protected: - using ResultBase::ResultBase; - }; + auto operator=( ResultValueBase const &other ) -> ResultValueBase & { + if( m_type == ResultBase::Ok ) + m_value.~T(); + ResultBase::operator=(other); + if( m_type == ResultBase::Ok ) + new( &m_value ) T( other.m_value ); + return *this; + } - template - class BasicResult : public ResultValueBase { - public: - template - explicit BasicResult( BasicResult const &other ) - : ResultValueBase( other.type() ), - m_errorMessage( other.errorMessage() ) - { - assert( type() != ResultBase::Ok ); - } + ~ResultValueBase() override { + if( m_type == Ok ) + m_value.~T(); + } - template - static auto ok( U const &value ) -> BasicResult { return { ResultBase::Ok, value }; } - static auto ok() -> BasicResult { return { ResultBase::Ok }; } - static auto logicError( std::string const &message ) -> BasicResult { return { ResultBase::LogicError, message }; } - static auto runtimeError( std::string const &message ) -> BasicResult { return { ResultBase::RuntimeError, message }; } + union { + T m_value; + }; +}; - explicit operator bool() const { return m_type == ResultBase::Ok; } - auto type() const -> ResultBase::Type { return m_type; } - auto errorMessage() const -> std::string { return m_errorMessage; } +template<> +class ResultValueBase : public ResultBase { + protected: + using ResultBase::ResultBase; +}; - protected: - void enforceOk() const override { +template +class BasicResult : public ResultValueBase { + public: + template + explicit BasicResult( BasicResult const &other ) + : ResultValueBase( other.type() ), + m_errorMessage( other.errorMessage() ) + { + assert( type() != ResultBase::Ok ); + } - // Errors shouldn't reach this point, but if they do - // the actual error message will be in m_errorMessage - assert( m_type != ResultBase::LogicError ); - assert( m_type != ResultBase::RuntimeError ); - if( m_type != ResultBase::Ok ) - std::abort(); - } + template + static auto ok( U const &value ) -> BasicResult { return { ResultBase::Ok, value }; } + static auto ok() -> BasicResult { return { ResultBase::Ok }; } + static auto logicError( std::string const &message ) -> BasicResult { return { ResultBase::LogicError, message }; } + static auto runtimeError( std::string const &message ) -> BasicResult { return { ResultBase::RuntimeError, message }; } + + explicit operator bool() const { return m_type == ResultBase::Ok; } + auto type() const -> ResultBase::Type { return m_type; } + auto errorMessage() const -> std::string { return m_errorMessage; } + + protected: + void enforceOk() const override { + + // Errors shouldn't reach this point, but if they do + // the actual error message will be in m_errorMessage + assert( m_type != ResultBase::LogicError ); + assert( m_type != ResultBase::RuntimeError ); + if( m_type != ResultBase::Ok ) + std::abort(); + } - std::string m_errorMessage; // Only populated if resultType is an error + std::string m_errorMessage; // Only populated if resultType is an error - BasicResult( ResultBase::Type type, std::string const &message ) - : ResultValueBase(type), - m_errorMessage(message) - { - assert( m_type != ResultBase::Ok ); - } + BasicResult( ResultBase::Type type, std::string const &message ) + : ResultValueBase(type), + m_errorMessage(message) + { + assert( m_type != ResultBase::Ok ); + } - using ResultValueBase::ResultValueBase; - using ResultBase::m_type; - }; + using ResultValueBase::ResultValueBase; + using ResultBase::m_type; +}; - enum class ParseResultType { - Matched, NoMatch, ShortCircuitAll, ShortCircuitSame - }; +enum class ParseResultType { + Matched, NoMatch, ShortCircuitAll, ShortCircuitSame +}; - class ParseState { - public: +class ParseState { + public: - ParseState( ParseResultType type, TokenStream const &remainingTokens ) - : m_type(type), - m_remainingTokens( remainingTokens ) - {} + ParseState( ParseResultType type, TokenStream const &remainingTokens ) + : m_type(type), + m_remainingTokens( remainingTokens ) + {} - auto type() const -> ParseResultType { return m_type; } - auto remainingTokens() const -> TokenStream { return m_remainingTokens; } + auto type() const -> ParseResultType { return m_type; } + auto remainingTokens() const -> TokenStream { return m_remainingTokens; } - private: - ParseResultType m_type; - TokenStream m_remainingTokens; - }; + private: + ParseResultType m_type; + TokenStream m_remainingTokens; +}; - using Result = BasicResult; - using ParserResult = BasicResult; - using InternalParseResult = BasicResult; +using Result = BasicResult; +using ParserResult = BasicResult; +using InternalParseResult = BasicResult; - struct HelpColumns { - std::string left; - std::string right; - }; +struct HelpColumns { + std::string left; + std::string right; +}; - template - inline auto convertInto( std::string const &source, T& target ) -> ParserResult { - std::stringstream ss; - ss << source; - ss >> target; - if( ss.fail() ) - return ParserResult::runtimeError( "Unable to convert '" + source + "' to destination type" ); - else - return ParserResult::ok( ParseResultType::Matched ); - } - inline auto convertInto( std::string const &source, std::string& target ) -> ParserResult { - target = source; - return ParserResult::ok( ParseResultType::Matched ); - } - inline auto convertInto( std::string const &source, bool &target ) -> ParserResult { - std::string srcLC = source; - std::transform( srcLC.begin(), srcLC.end(), srcLC.begin(), []( unsigned char c ) { return static_cast( std::tolower(c) ); } ); - if (srcLC == "y" || srcLC == "1" || srcLC == "true" || srcLC == "yes" || srcLC == "on") - target = true; - else if (srcLC == "n" || srcLC == "0" || srcLC == "false" || srcLC == "no" || srcLC == "off") - target = false; - else - return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" ); - return ParserResult::ok( ParseResultType::Matched ); - } +template +inline auto convertInto( std::string const &source, T& target ) -> ParserResult { + std::stringstream ss; + ss << source; + ss >> target; + if( ss.fail() ) + return ParserResult::runtimeError( "Unable to convert '" + source + "' to destination type" ); + else + return ParserResult::ok( ParseResultType::Matched ); +} +inline auto convertInto( std::string const &source, std::string& target ) -> ParserResult { + target = source; + return ParserResult::ok( ParseResultType::Matched ); +} +inline auto convertInto( std::string const &source, bool &target ) -> ParserResult { + std::string srcLC = source; + std::transform( srcLC.begin(), srcLC.end(), srcLC.begin(), []( unsigned char c ) { return static_cast( std::tolower(c) ); } ); + if (srcLC == "y" || srcLC == "1" || srcLC == "true" || srcLC == "yes" || srcLC == "on") + target = true; + else if (srcLC == "n" || srcLC == "0" || srcLC == "false" || srcLC == "no" || srcLC == "off") + target = false; + else + return ParserResult::runtimeError( "Expected a boolean value but did not recognise: '" + source + "'" ); + return ParserResult::ok( ParseResultType::Matched ); +} #ifdef CLARA_CONFIG_OPTIONAL_TYPE - template - inline auto convertInto( std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE& target ) -> ParserResult { - T temp; - auto result = convertInto( source, temp ); - if( result ) - target = std::move(temp); - return result; - } +template +inline auto convertInto( std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE& target ) -> ParserResult { + T temp; + auto result = convertInto( source, temp ); + if( result ) + target = std::move(temp); + return result; +} #endif // CLARA_CONFIG_OPTIONAL_TYPE - struct NonCopyable { - NonCopyable() = default; - NonCopyable( NonCopyable const & ) = delete; - NonCopyable( NonCopyable && ) = delete; - NonCopyable &operator=( NonCopyable const & ) = delete; - NonCopyable &operator=( NonCopyable && ) = delete; - }; - - struct BoundRef : NonCopyable { - virtual ~BoundRef() = default; - virtual auto isContainer() const -> bool { return false; } - virtual auto isFlag() const -> bool { return false; } - }; - struct BoundValueRefBase : BoundRef { - virtual auto setValue( std::string const &arg ) -> ParserResult = 0; - }; - struct BoundFlagRefBase : BoundRef { - virtual auto setFlag( bool flag ) -> ParserResult = 0; - virtual auto isFlag() const -> bool { return true; } - }; - - template - struct BoundValueRef : BoundValueRefBase { - T &m_ref; - - explicit BoundValueRef( T &ref ) : m_ref( ref ) {} - - auto setValue( std::string const &arg ) -> ParserResult override { - return convertInto( arg, m_ref ); - } - }; - - template - struct BoundValueRef> : BoundValueRefBase { - std::vector &m_ref; +struct NonCopyable { + NonCopyable() = default; + NonCopyable( NonCopyable const & ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable &operator=( NonCopyable const & ) = delete; + NonCopyable &operator=( NonCopyable && ) = delete; +}; - explicit BoundValueRef( std::vector &ref ) : m_ref( ref ) {} +struct BoundRef : NonCopyable { + virtual ~BoundRef() = default; + virtual auto isContainer() const -> bool { return false; } + virtual auto isFlag() const -> bool { return false; } +}; +struct BoundValueRefBase : BoundRef { + virtual auto setValue( std::string const &arg ) -> ParserResult = 0; +}; +struct BoundFlagRefBase : BoundRef { + virtual auto setFlag( bool flag ) -> ParserResult = 0; + auto isFlag() const -> bool override { return true; } +}; - auto isContainer() const -> bool override { return true; } +template +struct BoundValueRef : BoundValueRefBase { + T &m_ref; - auto setValue( std::string const &arg ) -> ParserResult override { - T temp; - auto result = convertInto( arg, temp ); - if( result ) - m_ref.push_back( temp ); - return result; - } - }; + explicit BoundValueRef( T &ref ) : m_ref( ref ) {} - struct BoundFlagRef : BoundFlagRefBase { - bool &m_ref; + auto setValue( std::string const &arg ) -> ParserResult override { + return convertInto( arg, m_ref ); + } +}; - explicit BoundFlagRef( bool &ref ) : m_ref( ref ) {} +template +struct BoundValueRef> : BoundValueRefBase { + std::vector &m_ref; - auto setFlag( bool flag ) -> ParserResult override { - m_ref = flag; - return ParserResult::ok( ParseResultType::Matched ); - } - }; + explicit BoundValueRef( std::vector &ref ) : m_ref( ref ) {} - template - struct LambdaInvoker { - static_assert( std::is_same::value, "Lambda must return void or clara::ParserResult" ); + auto isContainer() const -> bool override { return true; } - template - static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { - return lambda( arg ); - } - }; + auto setValue( std::string const &arg ) -> ParserResult override { + T temp; + auto result = convertInto( arg, temp ); + if( result ) + m_ref.push_back( temp ); + return result; + } +}; - template<> - struct LambdaInvoker { - template - static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { - lambda( arg ); - return ParserResult::ok( ParseResultType::Matched ); - } - }; +struct BoundFlagRef : BoundFlagRefBase { + bool &m_ref; - template - inline auto invokeLambda( L const &lambda, std::string const &arg ) -> ParserResult { - ArgType temp{}; - auto result = convertInto( arg, temp ); - return !result - ? result - : LambdaInvoker::ReturnType>::invoke( lambda, temp ); - } + explicit BoundFlagRef( bool &ref ) : m_ref( ref ) {} - template - struct BoundLambda : BoundValueRefBase { - L m_lambda; + auto setFlag( bool flag ) -> ParserResult override { + m_ref = flag; + return ParserResult::ok( ParseResultType::Matched ); + } +}; - static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); - explicit BoundLambda( L const &lambda ) : m_lambda( lambda ) {} +template +struct LambdaInvoker { + static_assert( std::is_same::value, "Lambda must return void or clara::ParserResult" ); - auto setValue( std::string const &arg ) -> ParserResult override { - return invokeLambda::ArgType>( m_lambda, arg ); - } - }; + template + static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { + return lambda( arg ); + } +}; - template - struct BoundFlagLambda : BoundFlagRefBase { - L m_lambda; +template<> +struct LambdaInvoker { + template + static auto invoke( L const &lambda, ArgType const &arg ) -> ParserResult { + lambda( arg ); + return ParserResult::ok( ParseResultType::Matched ); + } +}; + +template +inline auto invokeLambda( L const &lambda, std::string const &arg ) -> ParserResult { + ArgType temp{}; + auto result = convertInto( arg, temp ); + return !result + ? result + : LambdaInvoker::ReturnType>::invoke( lambda, temp ); +} - static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); - static_assert( std::is_same::ArgType, bool>::value, "flags must be boolean" ); +template +struct BoundLambda : BoundValueRefBase { + L m_lambda; - explicit BoundFlagLambda( L const &lambda ) : m_lambda( lambda ) {} + static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); + explicit BoundLambda( L const &lambda ) : m_lambda( lambda ) {} - auto setFlag( bool flag ) -> ParserResult override { - return LambdaInvoker::ReturnType>::invoke( m_lambda, flag ); - } - }; + auto setValue( std::string const &arg ) -> ParserResult override { + return invokeLambda::ArgType>( m_lambda, arg ); + } +}; - enum class Optionality { Optional, Required }; +template +struct BoundFlagLambda : BoundFlagRefBase { + L m_lambda; - struct Parser; + static_assert( UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument" ); + static_assert( std::is_same::ArgType, bool>::value, "flags must be boolean" ); - class ParserBase { - public: - virtual ~ParserBase() = default; - virtual auto validate() const -> Result { return Result::ok(); } - virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0; - virtual auto cardinality() const -> size_t { return 1; } + explicit BoundFlagLambda( L const &lambda ) : m_lambda( lambda ) {} - auto parse( Args const &args ) const -> InternalParseResult { - return parse( args.exeName(), TokenStream( args ) ); - } - }; + auto setFlag( bool flag ) -> ParserResult override { + return LambdaInvoker::ReturnType>::invoke( m_lambda, flag ); + } +}; - template - class ComposableParserImpl : public ParserBase { - public: - template - auto operator|( T const &other ) const -> Parser; +enum class Optionality { Optional, Required }; - template - auto operator+( T const &other ) const -> Parser; - }; +struct Parser; - // Common code and state for Args and Opts - template - class ParserRefImpl : public ComposableParserImpl { - protected: - Optionality m_optionality = Optionality::Optional; - std::shared_ptr m_ref; - std::string m_hint; - std::string m_description; +class ParserBase { + public: + virtual ~ParserBase() = default; + virtual auto validate() const -> Result { return Result::ok(); } + virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0; + virtual auto cardinality() const -> size_t { return 1; } - explicit ParserRefImpl( std::shared_ptr const &ref ) : m_ref( ref ) {} + auto parse( Args const &args ) const -> InternalParseResult { + return parse( args.exeName(), TokenStream( args ) ); + } +}; - public: - template - ParserRefImpl( T &ref, std::string const &hint ) - : m_ref( std::make_shared>( ref ) ), - m_hint( hint ) - {} +template +class ComposableParserImpl : public ParserBase { + public: + template + auto operator|( T const &other ) const -> Parser; - template - ParserRefImpl( LambdaT const &ref, std::string const &hint ) - : m_ref( std::make_shared>( ref ) ), - m_hint(hint) - {} + template + auto operator+( T const &other ) const -> Parser; +}; - auto operator()( std::string const &description ) -> DerivedT & { - m_description = description; - return static_cast( *this ); - } +// Common code and state for Args and Opts +template +class ParserRefImpl : public ComposableParserImpl { + protected: + Optionality m_optionality = Optionality::Optional; + std::shared_ptr m_ref; + std::string m_hint; + std::string m_description; + + explicit ParserRefImpl( std::shared_ptr const &ref ) : m_ref( ref ) {} + + public: + template + ParserRefImpl( T &ref, std::string const &hint ) + : m_ref( std::make_shared>( ref ) ), + m_hint( hint ) + {} + + template + ParserRefImpl( LambdaT const &ref, std::string const &hint ) + : m_ref( std::make_shared>( ref ) ), + m_hint(hint) + {} + + auto operator()( std::string const &description ) -> DerivedT & { + m_description = description; + return static_cast( *this ); + } - auto optional() -> DerivedT & { - m_optionality = Optionality::Optional; - return static_cast( *this ); - }; + auto optional() -> DerivedT & { + m_optionality = Optionality::Optional; + return static_cast( *this ); + }; - auto required() -> DerivedT & { - m_optionality = Optionality::Required; - return static_cast( *this ); - }; + auto required() -> DerivedT & { + m_optionality = Optionality::Required; + return static_cast( *this ); + }; - auto isOptional() const -> bool { - return m_optionality == Optionality::Optional; - } + auto isOptional() const -> bool { + return m_optionality == Optionality::Optional; + } - auto cardinality() const -> size_t override { - if( m_ref->isContainer() ) - return 0; - else - return 1; - } + auto cardinality() const -> size_t override { + if( m_ref->isContainer() ) + return 0; + else + return 1; + } - auto hint() const -> std::string { return m_hint; } - }; + auto hint() const -> std::string { return m_hint; } +}; - class ExeName : public ComposableParserImpl { - std::shared_ptr m_name; - std::shared_ptr m_ref; +class ExeName : public ComposableParserImpl { + std::shared_ptr m_name; + std::shared_ptr m_ref; - template - static auto makeRef(LambdaT const &lambda) -> std::shared_ptr { - return std::make_shared>( lambda) ; - } + template + static auto makeRef(LambdaT const &lambda) -> std::shared_ptr { + return std::make_shared>( lambda) ; + } - public: - ExeName() : m_name( std::make_shared( "" ) ) {} + public: + ExeName() : m_name( std::make_shared( "" ) ) {} - explicit ExeName( std::string &ref ) : ExeName() { - m_ref = std::make_shared>( ref ); - } + explicit ExeName( std::string &ref ) : ExeName() { + m_ref = std::make_shared>( ref ); + } - template - explicit ExeName( LambdaT const& lambda ) : ExeName() { - m_ref = std::make_shared>( lambda ); - } + template + explicit ExeName( LambdaT const& lambda ) : ExeName() { + m_ref = std::make_shared>( lambda ); + } - // The exe name is not parsed out of the normal tokens, but is handled specially - auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { - return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); - } + // The exe name is not parsed out of the normal tokens, but is handled specially + auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); + } - auto name() const -> std::string { return *m_name; } - auto set( std::string const& newName ) -> ParserResult { + auto name() const -> std::string { return *m_name; } + auto set( std::string const& newName ) -> ParserResult { - auto lastSlash = newName.find_last_of( "\\/" ); - auto filename = ( lastSlash == std::string::npos ) - ? newName - : newName.substr( lastSlash+1 ); + auto lastSlash = newName.find_last_of( "\\/" ); + auto filename = ( lastSlash == std::string::npos ) + ? newName + : newName.substr( lastSlash+1 ); - *m_name = filename; - if( m_ref ) - return m_ref->setValue( filename ); - else - return ParserResult::ok( ParseResultType::Matched ); - } - }; + *m_name = filename; + if( m_ref ) + return m_ref->setValue( filename ); + else + return ParserResult::ok( ParseResultType::Matched ); + } +}; - class Arg : public ParserRefImpl { - public: - using ParserRefImpl::ParserRefImpl; +class Arg : public ParserRefImpl { + public: + using ParserRefImpl::ParserRefImpl; - auto parse( std::string const &, TokenStream const &tokens ) const -> InternalParseResult override { - auto validationResult = validate(); - if( !validationResult ) - return InternalParseResult( validationResult ); + auto parse( std::string const &, TokenStream const &tokens ) const -> InternalParseResult override { + auto validationResult = validate(); + if( !validationResult ) + return InternalParseResult( validationResult ); - auto remainingTokens = tokens; - auto const &token = *remainingTokens; - if( token.type != TokenType::Argument ) - return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); + auto remainingTokens = tokens; + auto const &token = *remainingTokens; + if( token.type != TokenType::Argument ) + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); - assert( !m_ref->isFlag() ); - auto valueRef = static_cast( m_ref.get() ); + assert( !m_ref->isFlag() ); + auto valueRef = static_cast( m_ref.get() ); - auto result = valueRef->setValue( remainingTokens->token ); - if( !result ) - return InternalParseResult( result ); - else - return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); - } - }; + auto result = valueRef->setValue( remainingTokens->token ); + if( !result ) + return InternalParseResult( result ); + else + return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); + } +}; - inline auto normaliseOpt( std::string const &optName ) -> std::string { +inline auto normaliseOpt( std::string const &optName ) -> std::string { #ifdef CATCH_PLATFORM_WINDOWS - if( optName[0] == '/' ) - return "-" + optName.substr( 1 ); - else + if( optName[0] == '/' ) + return "-" + optName.substr( 1 ); + else #endif - return optName; - } + return optName; +} - class Opt : public ParserRefImpl { - protected: - std::vector m_optNames; +class Opt : public ParserRefImpl { + protected: + std::vector m_optNames; - public: - template - explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared>( ref ) ) {} + public: + template + explicit Opt( LambdaT const &ref ) : ParserRefImpl( std::make_shared>( ref ) ) {} - explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared( ref ) ) {} + explicit Opt( bool &ref ) : ParserRefImpl( std::make_shared( ref ) ) {} - template - Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} + template + Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} - template - Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} + template + Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} - auto operator[]( std::string const &optName ) -> Opt & { - m_optNames.push_back( optName ); - return *this; - } + auto operator[]( std::string const &optName ) -> Opt & { + m_optNames.push_back( optName ); + return *this; + } - auto getHelpColumns() const -> std::vector { - std::ostringstream oss; - bool first = true; - for( auto const &opt : m_optNames ) { - if (first) - first = false; - else - oss << ", "; - oss << opt; - } - if( !m_hint.empty() ) - oss << " <" << m_hint << ">"; - return { { oss.str(), m_description } }; - } + auto getHelpColumns() const -> std::vector { + std::ostringstream oss; + bool first = true; + for( auto const &opt : m_optNames ) { + if (first) + first = false; + else + oss << ", "; + oss << opt; + } + if( !m_hint.empty() ) + oss << " <" << m_hint << ">"; + return { { oss.str(), m_description } }; + } - auto isMatch( std::string const &optToken ) const -> bool { - auto normalisedToken = normaliseOpt( optToken ); - for( auto const &name : m_optNames ) { - if( normaliseOpt( name ) == normalisedToken ) - return true; - } - return false; - } + auto isMatch( std::string const &optToken ) const -> bool { + auto normalisedToken = normaliseOpt( optToken ); + for( auto const &name : m_optNames ) { + if( normaliseOpt( name ) == normalisedToken ) + return true; + } + return false; + } - using ParserBase::parse; - - auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { - auto validationResult = validate(); - if( !validationResult ) - return InternalParseResult( validationResult ); - - auto remainingTokens = tokens; - if( remainingTokens && remainingTokens->type == TokenType::Option ) { - auto const &token = *remainingTokens; - if( isMatch(token.token ) ) { - if( m_ref->isFlag() ) { - auto flagRef = static_cast( m_ref.get() ); - auto result = flagRef->setFlag( true ); - if( !result ) - return InternalParseResult( result ); - if( result.value() == ParseResultType::ShortCircuitAll ) - return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); - } else { - auto valueRef = static_cast( m_ref.get() ); - ++remainingTokens; - if( !remainingTokens ) - return InternalParseResult::runtimeError( "Expected argument following " + token.token ); - auto const &argToken = *remainingTokens; - if( argToken.type != TokenType::Argument ) - return InternalParseResult::runtimeError( "Expected argument following " + token.token ); - auto result = valueRef->setValue( argToken.token ); - if( !result ) - return InternalParseResult( result ); - if( result.value() == ParseResultType::ShortCircuitAll ) - return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); - } - return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); - } - } - return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); - } + using ParserBase::parse; + + auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { + auto validationResult = validate(); + if( !validationResult ) + return InternalParseResult( validationResult ); + + auto remainingTokens = tokens; + if( remainingTokens && remainingTokens->type == TokenType::Option ) { + auto const &token = *remainingTokens; + if( isMatch(token.token ) ) { + if( m_ref->isFlag() ) { + auto flagRef = static_cast( m_ref.get() ); + auto result = flagRef->setFlag( true ); + if( !result ) + return InternalParseResult( result ); + if( result.value() == ParseResultType::ShortCircuitAll ) + return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); + } else { + auto valueRef = static_cast( m_ref.get() ); + ++remainingTokens; + if( !remainingTokens ) + return InternalParseResult::runtimeError( "Expected argument following " + token.token ); + auto const &argToken = *remainingTokens; + if( argToken.type != TokenType::Argument ) + return InternalParseResult::runtimeError( "Expected argument following " + token.token ); + auto result = valueRef->setValue( argToken.token ); + if( !result ) + return InternalParseResult( result ); + if( result.value() == ParseResultType::ShortCircuitAll ) + return InternalParseResult::ok( ParseState( result.value(), remainingTokens ) ); + } + return InternalParseResult::ok( ParseState( ParseResultType::Matched, ++remainingTokens ) ); + } + } + return InternalParseResult::ok( ParseState( ParseResultType::NoMatch, remainingTokens ) ); + } - auto validate() const -> Result override { - if( m_optNames.empty() ) - return Result::logicError( "No options supplied to Opt" ); - for( auto const &name : m_optNames ) { - if( name.empty() ) - return Result::logicError( "Option name cannot be empty" ); + auto validate() const -> Result override { + if( m_optNames.empty() ) + return Result::logicError( "No options supplied to Opt" ); + for( auto const &name : m_optNames ) { + if( name.empty() ) + return Result::logicError( "Option name cannot be empty" ); #ifdef CATCH_PLATFORM_WINDOWS - if( name[0] != '-' && name[0] != '/' ) - return Result::logicError( "Option name must begin with '-' or '/'" ); + if( name[0] != '-' && name[0] != '/' ) + return Result::logicError( "Option name must begin with '-' or '/'" ); #else if( name[0] != '-' ) return Result::logicError( "Option name must begin with '-'" ); #endif - } - return ParserRefImpl::validate(); - } - }; + } + return ParserRefImpl::validate(); + } +}; - struct Help : Opt { - Help( bool &showHelpFlag ) - : Opt([&]( bool flag ) { - showHelpFlag = flag; - return ParserResult::ok( ParseResultType::ShortCircuitAll ); - }) - { - static_cast( *this ) - ("display usage information") - ["-?"]["-h"]["--help"] - .optional(); - } - }; +struct Help : Opt { + Help( bool &showHelpFlag ) + : Opt([&]( bool flag ) { + showHelpFlag = flag; + return ParserResult::ok( ParseResultType::ShortCircuitAll ); + }) + { + static_cast( *this ) + ("display usage information") + ["-?"]["-h"]["--help"] + .optional(); + } +}; - struct Parser : ParserBase { +struct Parser : ParserBase { - mutable ExeName m_exeName; - std::vector m_options; - std::vector m_args; + mutable ExeName m_exeName; + std::vector m_options; + std::vector m_args; - auto operator|=( ExeName const &exeName ) -> Parser & { - m_exeName = exeName; - return *this; - } + auto operator|=( ExeName const &exeName ) -> Parser & { + m_exeName = exeName; + return *this; + } - auto operator|=( Arg const &arg ) -> Parser & { - m_args.push_back(arg); - return *this; - } + auto operator|=( Arg const &arg ) -> Parser & { + m_args.push_back(arg); + return *this; + } - auto operator|=( Opt const &opt ) -> Parser & { - m_options.push_back(opt); - return *this; - } + auto operator|=( Opt const &opt ) -> Parser & { + m_options.push_back(opt); + return *this; + } - auto operator|=( Parser const &other ) -> Parser & { - m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end()); - m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end()); - return *this; - } + auto operator|=( Parser const &other ) -> Parser & { + m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end()); + m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end()); + return *this; + } - template - auto operator|( T const &other ) const -> Parser { - return Parser( *this ) |= other; - } + template + auto operator|( T const &other ) const -> Parser { + return Parser( *this ) |= other; + } - // Forward deprecated interface with '+' instead of '|' - template - auto operator+=( T const &other ) -> Parser & { return operator|=( other ); } - template - auto operator+( T const &other ) const -> Parser { return operator|( other ); } + // Forward deprecated interface with '+' instead of '|' + template + auto operator+=( T const &other ) -> Parser & { return operator|=( other ); } + template + auto operator+( T const &other ) const -> Parser { return operator|( other ); } - auto getHelpColumns() const -> std::vector { - std::vector cols; - for (auto const &o : m_options) { - auto childCols = o.getHelpColumns(); - cols.insert( cols.end(), childCols.begin(), childCols.end() ); - } - return cols; - } + auto getHelpColumns() const -> std::vector { + std::vector cols; + for (auto const &o : m_options) { + auto childCols = o.getHelpColumns(); + cols.insert( cols.end(), childCols.begin(), childCols.end() ); + } + return cols; + } - void writeToStream( std::ostream &os ) const { - if (!m_exeName.name().empty()) { - os << "usage:\n" << " " << m_exeName.name() << " "; - bool required = true, first = true; - for( auto const &arg : m_args ) { - if (first) - first = false; - else - os << " "; - if( arg.isOptional() && required ) { - os << "["; - required = false; - } - os << "<" << arg.hint() << ">"; - if( arg.cardinality() == 0 ) - os << " ... "; - } - if( !required ) - os << "]"; - if( !m_options.empty() ) - os << " options"; - os << "\n\nwhere options are:" << std::endl; - } + void writeToStream( std::ostream &os ) const { + if (!m_exeName.name().empty()) { + os << "usage:\n" << " " << m_exeName.name() << " "; + bool required = true, first = true; + for( auto const &arg : m_args ) { + if (first) + first = false; + else + os << " "; + if( arg.isOptional() && required ) { + os << "["; + required = false; + } + os << "<" << arg.hint() << ">"; + if( arg.cardinality() == 0 ) + os << " ... "; + } + if( !required ) + os << "]"; + if( !m_options.empty() ) + os << " options"; + os << "\n\nwhere options are:" << std::endl; + } - auto rows = getHelpColumns(); - size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; - size_t optWidth = 0; - for( auto const &cols : rows ) - optWidth = (std::max)(optWidth, cols.left.size() + 2); + auto rows = getHelpColumns(); + size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; + size_t optWidth = 0; + for( auto const &cols : rows ) + optWidth = (std::max)(optWidth, cols.left.size() + 2); - optWidth = (std::min)(optWidth, consoleWidth/2); + optWidth = (std::min)(optWidth, consoleWidth/2); - for( auto const &cols : rows ) { - auto row = - TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + - TextFlow::Spacer(4) + - TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); - os << row << std::endl; - } - } + for( auto const &cols : rows ) { + auto row = + TextFlow::Column( cols.left ).width( optWidth ).indent( 2 ) + + TextFlow::Spacer(4) + + TextFlow::Column( cols.right ).width( consoleWidth - 7 - optWidth ); + os << row << std::endl; + } + } - friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { - parser.writeToStream( os ); - return os; - } + friend auto operator<<( std::ostream &os, Parser const &parser ) -> std::ostream& { + parser.writeToStream( os ); + return os; + } - auto validate() const -> Result override { - for( auto const &opt : m_options ) { - auto result = opt.validate(); - if( !result ) - return result; - } - for( auto const &arg : m_args ) { - auto result = arg.validate(); - if( !result ) - return result; - } - return Result::ok(); - } + auto validate() const -> Result override { + for( auto const &opt : m_options ) { + auto result = opt.validate(); + if( !result ) + return result; + } + for( auto const &arg : m_args ) { + auto result = arg.validate(); + if( !result ) + return result; + } + return Result::ok(); + } - using ParserBase::parse; + using ParserBase::parse; - auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override { + auto parse( std::string const& exeName, TokenStream const &tokens ) const -> InternalParseResult override { - struct ParserInfo { - ParserBase const* parser = nullptr; - size_t count = 0; - }; - const size_t totalParsers = m_options.size() + m_args.size(); - assert( totalParsers < 512 ); - // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do - ParserInfo parseInfos[512]; + struct ParserInfo { + ParserBase const* parser = nullptr; + size_t count = 0; + }; + const size_t totalParsers = m_options.size() + m_args.size(); + assert( totalParsers < 512 ); + // ParserInfo parseInfos[totalParsers]; // <-- this is what we really want to do + ParserInfo parseInfos[512]; - { - size_t i = 0; - for (auto const &opt : m_options) parseInfos[i++].parser = &opt; - for (auto const &arg : m_args) parseInfos[i++].parser = &arg; - } + { + size_t i = 0; + for (auto const &opt : m_options) parseInfos[i++].parser = &opt; + for (auto const &arg : m_args) parseInfos[i++].parser = &arg; + } - m_exeName.set( exeName ); - - auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); - while( result.value().remainingTokens() ) { - bool tokenParsed = false; - - for( size_t i = 0; i < totalParsers; ++i ) { - auto& parseInfo = parseInfos[i]; - if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) { - result = parseInfo.parser->parse(exeName, result.value().remainingTokens()); - if (!result) - return result; - if (result.value().type() != ParseResultType::NoMatch) { - tokenParsed = true; - ++parseInfo.count; - break; - } - } - } + m_exeName.set( exeName ); - if( result.value().type() == ParseResultType::ShortCircuitAll ) - return result; - if( !tokenParsed ) - return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token ); - } - // !TBD Check missing required options + auto result = InternalParseResult::ok( ParseState( ParseResultType::NoMatch, tokens ) ); + while( result.value().remainingTokens() ) { + bool tokenParsed = false; + + for( size_t i = 0; i < totalParsers; ++i ) { + auto& parseInfo = parseInfos[i]; + if( parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality() ) { + result = parseInfo.parser->parse(exeName, result.value().remainingTokens()); + if (!result) return result; + if (result.value().type() != ParseResultType::NoMatch) { + tokenParsed = true; + ++parseInfo.count; + break; + } } - }; + } - template - template - auto ComposableParserImpl::operator|( T const &other ) const -> Parser { - return Parser() | static_cast( *this ) | other; + if( result.value().type() == ParseResultType::ShortCircuitAll ) + return result; + if( !tokenParsed ) + return InternalParseResult::runtimeError( "Unrecognised token: " + result.value().remainingTokens()->token ); } + // !TBD Check missing required options + return result; + } +}; + +template +template +auto ComposableParserImpl::operator|( T const &other ) const -> Parser { + return Parser() | static_cast( *this ) | other; +} } // namespace detail // A Combined parser @@ -9686,7 +9663,7 @@ using detail::ParseResultType; // Result type for parser operation using detail::ParserResult; -}} // namespace Catch::clara +} // end clara.hpp #ifdef __clang__ @@ -10539,24 +10516,20 @@ namespace Catch { #include #include -namespace Catch { - - namespace Detail { - - std::unique_ptr makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector const& values ); +namespace Catch::Detail { - class EnumValuesRegistry : public IMutableEnumValuesRegistry { +std::unique_ptr makeEnumInfo( StringRef enumName, StringRef allValueNames, std::vector const& values ); - std::vector> m_enumInfos; +class EnumValuesRegistry : public IMutableEnumValuesRegistry { - EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector const& values) override; - }; + std::vector> m_enumInfos; - std::vector parseEnums( StringRef enums ); + EnumInfo const& registerEnum( StringRef enumName, StringRef allEnums, std::vector const& values) override; +}; - } // Detail +std::vector parseEnums( StringRef enums ); -} // Catch +} // end catch_enum_values_registry.h @@ -10646,7 +10619,7 @@ namespace Catch { class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { public: - ~ExceptionTranslatorRegistry(); + ~ExceptionTranslatorRegistry() override; virtual void registerTranslator( const IExceptionTranslator* translator ); std::string translateActiveException() const override; std::string tryTranslators() const; @@ -11334,19 +11307,17 @@ namespace Catch { // start catch_matchers.cpp namespace Catch { -namespace Matchers { - namespace Impl { +namespace Matchers::Impl { - std::string MatcherUntypedBase::toString() const { - if( m_cachedToString.empty() ) - m_cachedToString = describe(); - return m_cachedToString; - } +std::string MatcherUntypedBase::toString() const { + if( m_cachedToString.empty() ) + m_cachedToString = describe(); + return m_cachedToString; +} - MatcherUntypedBase::~MatcherUntypedBase() = default; +MatcherUntypedBase::~MatcherUntypedBase() = default; - } // namespace Impl -} // namespace Matchers +} using namespace Matchers; using Matchers::Impl::MatcherBase; @@ -11355,26 +11326,25 @@ using Matchers::Impl::MatcherBase; // end catch_matchers.cpp // start catch_matchers_exception.cpp -namespace Catch { -namespace Matchers { +namespace Catch::Matchers { namespace Exception { bool ExceptionMessageMatcher::match(std::exception const& ex) const { - return ex.what() == m_message; + return ex.what() == m_message; } std::string ExceptionMessageMatcher::describe() const { - return "exception message matches \"" + m_message + "\""; + return "exception message matches \"" + m_message + "\""; } } Exception::ExceptionMessageMatcher Message(std::string const& message) { - return Exception::ExceptionMessageMatcher(message); + return Exception::ExceptionMessageMatcher(message); } // namespace Exception -} // namespace Matchers -} // namespace Catch +} + // end catch_matchers_exception.cpp // start catch_matchers_floating.cpp @@ -11637,103 +11607,102 @@ std::string Catch::Matchers::Generic::Detail::finalizeDescription(const std::str #include -namespace Catch { -namespace Matchers { +namespace Catch::Matchers { - namespace StdString { +namespace StdString { - CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ) - : m_caseSensitivity( caseSensitivity ), - m_str( adjustString( str ) ) - {} - std::string CasedString::adjustString( std::string const& str ) const { - return m_caseSensitivity == CaseSensitive::No - ? toLower( str ) - : str; - } - std::string CasedString::caseSensitivitySuffix() const { - return m_caseSensitivity == CaseSensitive::No - ? " (case insensitive)" - : std::string(); - } +CasedString::CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ) + : m_caseSensitivity( caseSensitivity ), + m_str( adjustString( str ) ) +{} +std::string CasedString::adjustString( std::string const& str ) const { + return m_caseSensitivity == CaseSensitive::No + ? toLower( str ) + : str; +} +std::string CasedString::caseSensitivitySuffix() const { + return m_caseSensitivity == CaseSensitive::No + ? " (case insensitive)" + : std::string(); +} - StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator ) - : m_comparator( comparator ), - m_operation( operation ) { - } +StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator ) + : m_comparator( comparator ), + m_operation( operation ) { +} - std::string StringMatcherBase::describe() const { - std::string description; - description.reserve(5 + m_operation.size() + m_comparator.m_str.size() + - m_comparator.caseSensitivitySuffix().size()); - description += m_operation; - description += ": \""; - description += m_comparator.m_str; - description += "\""; - description += m_comparator.caseSensitivitySuffix(); - return description; - } +std::string StringMatcherBase::describe() const { + std::string description; + description.reserve(5 + m_operation.size() + m_comparator.m_str.size() + + m_comparator.caseSensitivitySuffix().size()); + description += m_operation; + description += ": \""; + description += m_comparator.m_str; + description += "\""; + description += m_comparator.caseSensitivitySuffix(); + return description; +} - EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {} +EqualsMatcher::EqualsMatcher( CasedString const& comparator ) : StringMatcherBase( "equals", comparator ) {} - bool EqualsMatcher::match( std::string const& source ) const { - return m_comparator.adjustString( source ) == m_comparator.m_str; - } +bool EqualsMatcher::match( std::string const& source ) const { + return m_comparator.adjustString( source ) == m_comparator.m_str; +} - ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {} +ContainsMatcher::ContainsMatcher( CasedString const& comparator ) : StringMatcherBase( "contains", comparator ) {} - bool ContainsMatcher::match( std::string const& source ) const { - return contains( m_comparator.adjustString( source ), m_comparator.m_str ); - } +bool ContainsMatcher::match( std::string const& source ) const { + return contains( m_comparator.adjustString( source ), m_comparator.m_str ); +} - StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {} +StartsWithMatcher::StartsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "starts with", comparator ) {} - bool StartsWithMatcher::match( std::string const& source ) const { - return startsWith( m_comparator.adjustString( source ), m_comparator.m_str ); - } +bool StartsWithMatcher::match( std::string const& source ) const { + return startsWith( m_comparator.adjustString( source ), m_comparator.m_str ); +} - EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {} +EndsWithMatcher::EndsWithMatcher( CasedString const& comparator ) : StringMatcherBase( "ends with", comparator ) {} - bool EndsWithMatcher::match( std::string const& source ) const { - return endsWith( m_comparator.adjustString( source ), m_comparator.m_str ); - } +bool EndsWithMatcher::match( std::string const& source ) const { + return endsWith( m_comparator.adjustString( source ), m_comparator.m_str ); +} - RegexMatcher::RegexMatcher(std::string regex, CaseSensitive::Choice caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {} +RegexMatcher::RegexMatcher(std::string regex, CaseSensitive::Choice caseSensitivity): m_regex(std::move(regex)), m_caseSensitivity(caseSensitivity) {} - bool RegexMatcher::match(std::string const& matchee) const { - auto flags = std::regex::ECMAScript; // ECMAScript is the default syntax option anyway - if (m_caseSensitivity == CaseSensitive::Choice::No) { - flags |= std::regex::icase; - } - auto reg = std::regex(m_regex, flags); - return std::regex_match(matchee, reg); - } +bool RegexMatcher::match(std::string const& matchee) const { + auto flags = std::regex::ECMAScript; // ECMAScript is the default syntax option anyway + if (m_caseSensitivity == CaseSensitive::Choice::No) { + flags |= std::regex::icase; + } + auto reg = std::regex(m_regex, flags); + return std::regex_match(matchee, reg); +} - std::string RegexMatcher::describe() const { - return "matches " + ::Catch::Detail::stringify(m_regex) + ((m_caseSensitivity == CaseSensitive::Choice::Yes)? " case sensitively" : " case insensitively"); - } +std::string RegexMatcher::describe() const { + return "matches " + ::Catch::Detail::stringify(m_regex) + ((m_caseSensitivity == CaseSensitive::Choice::Yes)? " case sensitively" : " case insensitively"); +} - } // namespace StdString +} // namespace StdString - StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) ); - } - StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) ); - } - StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) ); - } - StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { - return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) ); - } +StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::EqualsMatcher( StdString::CasedString( str, caseSensitivity) ); +} +StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::ContainsMatcher( StdString::CasedString( str, caseSensitivity) ); +} +StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::EndsWithMatcher( StdString::CasedString( str, caseSensitivity) ); +} +StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity ) { + return StdString::StartsWithMatcher( StdString::CasedString( str, caseSensitivity) ); +} - StdString::RegexMatcher Matches(std::string const& regex, CaseSensitive::Choice caseSensitivity) { - return StdString::RegexMatcher(regex, caseSensitivity); - } +StdString::RegexMatcher Matches(std::string const& regex, CaseSensitive::Choice caseSensitivity) { + return StdString::RegexMatcher(regex, caseSensitivity); +} + +} -} // namespace Matchers -} // namespace Catch // end catch_matchers_string.cpp // start catch_message.cpp @@ -12229,7 +12198,7 @@ namespace Catch { class TestRegistry : public ITestCaseRegistry { public: - virtual ~TestRegistry() = default; + ~TestRegistry() override = default; virtual void registerTest( TestCase const& testCase ); @@ -12523,7 +12492,7 @@ namespace Catch { GeneratorTracker( TestCaseTracking::NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) : TrackerBase( nameAndLocation, ctx, parent ) {} - ~GeneratorTracker(); + ~GeneratorTracker() override; static GeneratorTracker& acquire( TrackerContext& ctx, TestCaseTracking::NameAndLocation const& nameAndLocation ) { std::shared_ptr tracker; @@ -13584,7 +13553,8 @@ namespace Catch { setp( data, data + sizeof(data) ); } - ~StreamBufImpl() noexcept { + ~StreamBufImpl() noexcept override + { StreamBufImpl::sync(); } @@ -13771,7 +13741,7 @@ namespace Catch { return lc; } std::string trim( std::string const& str ) { - static char const* whitespaceChars = "\n\r\t "; + static auto whitespaceChars = "\n\r\t "; std::string::size_type start = str.find_first_not_of( whitespaceChars ); std::string::size_type end = str.find_last_not_of( whitespaceChars ); @@ -14443,7 +14413,7 @@ namespace TestCaseTracking { while( !parent->isSectionTracker() ) parent = &parent->parent(); - SectionTracker& parentSection = static_cast( *parent ); + auto& parentSection = static_cast( *parent ); addNextFilters( parentSection.m_filters ); } } @@ -14976,7 +14946,7 @@ namespace Detail { end = inc = -1; } - unsigned char const *bytes = static_cast(object); + auto bytes = static_cast(object); ReusableStringStream rss; rss << "0x" << std::setfill('0') << std::hex; for( ; i != end; i += inc ) @@ -16753,7 +16723,7 @@ namespace Catch { #endif char timeStamp[timeStampSize]; - const char * const fmt = "%Y-%m-%dT%H:%M:%SZ"; + const auto fmt = "%Y-%m-%dT%H:%M:%SZ"; #ifdef _MSC_VER std::strftime(timeStamp, timeStampSize, fmt, &timeInfo); diff --git a/tests/main/catch_main.cpp b/tests/main/catch_main.cpp index 3ff0148..a3995f2 100644 --- a/tests/main/catch_main.cpp +++ b/tests/main/catch_main.cpp @@ -1,12 +1,10 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file catch_main.cpp - */ #define CATCH_CONFIG_RUNNER #if defined(WIN32) -#define DO_NOT_USE_WMAIN +# define DO_NOT_USE_WMAIN #endif #include "catch.hpp" @@ -15,4 +13,4 @@ main(int argc, char** argv) { int result = Catch::Session().run(argc, argv); return result < 0xff ? result : 0xff; -} \ No newline at end of file +} diff --git a/tests/main/catch_runner.h b/tests/main/catch_runner.h index 1dac822..21580b5 100644 --- a/tests/main/catch_runner.h +++ b/tests/main/catch_runner.h @@ -1,15 +1,13 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #pragma once #ifndef cml_tests_main_catch_runner_h -#define cml_tests_main_catch_runner_h +# define cml_tests_main_catch_runner_h -#define CATCH_CONFIG_PREFIX_ALL -#include "catch.hpp" +# define CATCH_CONFIG_PREFIX_ALL +# include "catch.hpp" -#endif \ No newline at end of file +#endif diff --git a/tests/mathlib/CMakeLists.txt b/tests/mathlib/CMakeLists.txt index 3ed9805..9ccbf1a 100644 --- a/tests/mathlib/CMakeLists.txt +++ b/tests/mathlib/CMakeLists.txt @@ -1,15 +1,14 @@ -# -*- cmake -*- ----------------------------------------------------------- +# *------------------------------------------------------------------------- # @@COPYRIGHT@@ -#*------------------------------------------------------------------------- +# *------------------------------------------------------------------------- -project(CML_Testing_Mathlib) -set(CML_CURRENT_TEST_GROUP "Mathlib") +set(CML_TEST_GROUP "mathlib") cml_add_test(vector_angle1) cml_add_test(vector_transform1) cml_add_test(vector_rotation1) cml_add_test(vector_misc1) - + cml_add_test(matrix_generators1) cml_add_test(matrix_basis1) cml_add_test(matrix_translation1) @@ -18,10 +17,10 @@ cml_add_test(matrix_invert1) cml_add_test(matrix_rotation1) cml_add_test(matrix_projection1) cml_add_test(matrix_transform1) - + cml_add_test(quaternion_basis1) cml_add_test(quaternion_rotation1) - + cml_add_test(coordinate_conversion1) cml_add_test(random_unit1) cml_add_test(frustum1) \ No newline at end of file diff --git a/tests/mathlib/coordinate_conversion1.cpp b/tests/mathlib/coordinate_conversion1.cpp index be6a8e1..494a50d 100644 --- a/tests/mathlib/coordinate_conversion1.cpp +++ b/tests/mathlib/coordinate_conversion1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -12,7 +10,6 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("from cartesian, to_polar1") { cml::vector2d x; @@ -29,7 +26,6 @@ CATCH_TEST_CASE("from cartesian, to_polar2") CATCH_CHECK(x[1] == Approx(.7071067811865).epsilon(1e-12)); } - CATCH_TEST_CASE("from cartesian, to_cylindrical1") { cml::vector3d x; @@ -48,12 +44,11 @@ CATCH_TEST_CASE("from cartesian, to_cylindrical2") CATCH_CHECK(x[2] == Approx(1.).epsilon(1e-12)); } - CATCH_TEST_CASE("from cartesian, to_spherical1") { cml::vector3d x; - cml::spherical_to_cartesian( - x, 2, cml::colatitude, 1., cml::rad(45.), cml::rad(45.)); + cml::spherical_to_cartesian(x, 2, cml::colatitude, 1., cml::rad(45.), + cml::rad(45.)); CATCH_CHECK(x[0] == Approx(.5).epsilon(1e-12)); CATCH_CHECK(x[1] == Approx(.5).epsilon(1e-12)); CATCH_CHECK(x[2] == Approx(.7071067811865).epsilon(1e-12)); @@ -62,16 +57,13 @@ CATCH_TEST_CASE("from cartesian, to_spherical1") CATCH_TEST_CASE("from cartesian, to_spherical2") { cml::vector3d x; - cml::spherical_to_cartesian( - 1., cml::rad(45.), cml::rad(45.), 2, cml::colatitude, x); + cml::spherical_to_cartesian(1., cml::rad(45.), cml::rad(45.), 2, + cml::colatitude, x); CATCH_CHECK(x[0] == Approx(.5).epsilon(1e-12)); CATCH_CHECK(x[1] == Approx(.5).epsilon(1e-12)); CATCH_CHECK(x[2] == Approx(.7071067811865).epsilon(1e-12)); } - - - CATCH_TEST_CASE("to cartesian, from_polar1") { cml::vector2d x(std::sqrt(.5), std::sqrt(.5)); @@ -90,7 +82,6 @@ CATCH_TEST_CASE("to cartesian, from_polar2") CATCH_CHECK(theta == Approx(cml::rad(45.)).epsilon(1e-12)); } - CATCH_TEST_CASE("to cartesian, from_cylindrical1") { cml::vector3d x(std::sqrt(.5), std::sqrt(.5), 1.); @@ -121,7 +112,6 @@ CATCH_TEST_CASE("to cartesian, from_cylindrical3") CATCH_CHECK(height == Approx(1.).epsilon(1e-12)); } - CATCH_TEST_CASE("to cartesian, from_spherical1") { cml::vector3d x(.5, .5, std::sqrt(.5)); @@ -136,8 +126,8 @@ CATCH_TEST_CASE("to cartesian, from_spherical2") { cml::vector3d x(.5, .5, std::sqrt(.5)); double radius, theta, phi, tolerance = 1e-7; - cml::cartesian_to_spherical( - x, 2, cml::colatitude, radius, theta, phi, tolerance); + cml::cartesian_to_spherical(x, 2, cml::colatitude, radius, theta, phi, + tolerance); CATCH_CHECK(radius == Approx(1.).epsilon(1e-12)); CATCH_CHECK(theta == Approx(cml::rad(45.)).epsilon(1e-12)); CATCH_CHECK(phi == Approx(cml::rad(45.)).epsilon(1e-12)); @@ -147,13 +137,8 @@ CATCH_TEST_CASE("to cartesian, from_spherical3") { cml::vector3d x(.5, .5, std::sqrt(.5)); double radius, theta, phi; - cml::cartesian_to_spherical( - x, radius, theta, phi, 2, cml::colatitude); + cml::cartesian_to_spherical(x, radius, theta, phi, 2, cml::colatitude); CATCH_CHECK(radius == Approx(1.).epsilon(1e-12)); CATCH_CHECK(theta == Approx(cml::rad(45.)).epsilon(1e-12)); CATCH_CHECK(phi == Approx(cml::rad(45.)).epsilon(1e-12)); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/frustum1.cpp b/tests/mathlib/frustum1.cpp index ba271b2..19984bf 100644 --- a/tests/mathlib/frustum1.cpp +++ b/tests/mathlib/frustum1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -21,11 +19,11 @@ CATCH_TEST_CASE("orthographic_planes1") { cml::matrix44d O; - cml::matrix_orthographic_RH( - O, -.5, .5, -.5, .5, -1., 1., cml::z_clip_neg_one); + cml::matrix_orthographic_RH(O, -.5, .5, -.5, .5, -1., 1., + cml::z_clip_neg_one); // width x height, near, far - double planes[6][4]; // l, r, b, t, n ,f + double planes[6][4]; // l, r, b, t, n ,f cml::extract_frustum_planes(O, planes, cml::z_clip_neg_one); CATCH_CHECK(planes[0][0] == Approx(1.).epsilon(1.5e-8)); @@ -39,14 +37,14 @@ CATCH_TEST_CASE("orthographic_planes1") CATCH_TEST_CASE("orthographic_planes2") { cml::matrix44d O; - cml::matrix_orthographic_RH( - O, -.5, .5, -.5, .5, -1., 1., cml::z_clip_neg_one); + cml::matrix_orthographic_RH(O, -.5, .5, -.5, .5, -1., 1., + cml::z_clip_neg_one); // width x height, near, far cml::matrix44d M = cml::identity_4x4(); cml::matrix_rotation_world_y(M, cml::rad(180.)); - double planes[6][4]; // l, r, b, t, n ,f + double planes[6][4]; // l, r, b, t, n ,f cml::extract_frustum_planes(M, O, planes, cml::z_clip_neg_one); CATCH_CHECK(planes[0][0] == Approx(-1.).epsilon(1.5e-8)); @@ -60,11 +58,11 @@ CATCH_TEST_CASE("orthographic_planes2") CATCH_TEST_CASE("orthographic_planes_row1") { cml::matrix44d_r O; - cml::matrix_orthographic_RH( - O, -.5, .5, -.5, .5, -1., 1., cml::z_clip_neg_one); + cml::matrix_orthographic_RH(O, -.5, .5, -.5, .5, -1., 1., + cml::z_clip_neg_one); // width x height, near, far - double planes[6][4]; // l, r, b, t, n ,f + double planes[6][4]; // l, r, b, t, n ,f cml::extract_frustum_planes(O, planes, cml::z_clip_neg_one); CATCH_CHECK(planes[0][0] == Approx(1.).epsilon(1.5e-8)); @@ -78,14 +76,14 @@ CATCH_TEST_CASE("orthographic_planes_row1") CATCH_TEST_CASE("orthographic_planes_row2") { cml::matrix44d_r O; - cml::matrix_orthographic_RH( - O, -.5, .5, -.5, .5, -1., 1., cml::z_clip_neg_one); + cml::matrix_orthographic_RH(O, -.5, .5, -.5, .5, -1., 1., + cml::z_clip_neg_one); // width x height, near, far cml::matrix44d_r M = cml::identity_4x4(); cml::matrix_rotation_world_y(M, cml::rad(180.)); - double planes[6][4]; // l, r, b, t, n ,f + double planes[6][4]; // l, r, b, t, n ,f cml::extract_frustum_planes(M, O, planes, cml::z_clip_neg_one); CATCH_CHECK(planes[0][0] == Approx(-1.).epsilon(1.5e-8)); @@ -99,11 +97,11 @@ CATCH_TEST_CASE("orthographic_planes_row2") CATCH_TEST_CASE("perspective_planes1") { cml::matrix44d O; - cml::matrix_perspective_RH( - O, -.5, .5, -.5, .5, .001, 1., cml::z_clip_neg_one); + cml::matrix_perspective_RH(O, -.5, .5, -.5, .5, .001, 1., + cml::z_clip_neg_one); // l, r, b, t, near, far - double planes[6][4]; // l, r, b, t, n ,f + double planes[6][4]; // l, r, b, t, n ,f cml::extract_frustum_planes(O, planes, cml::z_clip_neg_one); CATCH_CHECK(planes[0][0] == Approx(.0019999960).epsilon(1.5e-8)); @@ -117,14 +115,14 @@ CATCH_TEST_CASE("perspective_planes1") CATCH_TEST_CASE("perspective_planes2") { cml::matrix44d O; - cml::matrix_perspective_RH( - O, -.5, .5, -.5, .5, .001, 1., cml::z_clip_neg_one); + cml::matrix_perspective_RH(O, -.5, .5, -.5, .5, .001, 1., + cml::z_clip_neg_one); // l, r, b, t, near, far cml::matrix44d M = cml::identity_4x4(); cml::matrix_rotation_world_y(M, cml::rad(180.)); - double planes[6][4]; // l, r, b, t, n ,f + double planes[6][4]; // l, r, b, t, n ,f cml::extract_frustum_planes(M, O, planes, cml::z_clip_neg_one); CATCH_CHECK(planes[0][0] == Approx(-.0019999960).epsilon(1.5e-8)); @@ -138,11 +136,11 @@ CATCH_TEST_CASE("perspective_planes2") CATCH_TEST_CASE("perspective_planes_row1") { cml::matrix44d_r O; - cml::matrix_perspective_RH( - O, -.5, .5, -.5, .5, .001, 1., cml::z_clip_neg_one); + cml::matrix_perspective_RH(O, -.5, .5, -.5, .5, .001, 1., + cml::z_clip_neg_one); // l, r, b, t, near, far - double planes[6][4]; // l, r, b, t, n ,f + double planes[6][4]; // l, r, b, t, n ,f cml::extract_frustum_planes(O, planes, cml::z_clip_neg_one); CATCH_CHECK(planes[0][0] == Approx(.0019999960).epsilon(1.5e-8)); @@ -156,14 +154,14 @@ CATCH_TEST_CASE("perspective_planes_row1") CATCH_TEST_CASE("perspective_planes_row2") { cml::matrix44d_r O; - cml::matrix_perspective_RH( - O, -.5, .5, -.5, .5, .001, 1., cml::z_clip_neg_one); + cml::matrix_perspective_RH(O, -.5, .5, -.5, .5, .001, 1., + cml::z_clip_neg_one); // l, r, b, t, near, far cml::matrix44d_r M = cml::identity_4x4(); cml::matrix_rotation_world_y(M, cml::rad(180.)); - double planes[6][4]; // l, r, b, t, n ,f + double planes[6][4]; // l, r, b, t, n ,f cml::extract_frustum_planes(M, O, planes, cml::z_clip_neg_one); CATCH_CHECK(planes[0][0] == Approx(-.0019999960).epsilon(1.5e-8)); @@ -173,6 +171,3 @@ CATCH_TEST_CASE("perspective_planes_row2") CATCH_CHECK(planes[4][2] == Approx(1.).epsilon(1.5e-8)); CATCH_CHECK(planes[5][2] == Approx(-1.).epsilon(1.5e-8)); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/matrix_basis1.cpp b/tests/mathlib/matrix_basis1.cpp index ac3f651..e75894c 100644 --- a/tests/mathlib/matrix_basis1.cpp +++ b/tests/mathlib/matrix_basis1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -13,10 +11,9 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("basis 2D, basis1") { - cml::matrix22d M; // column basis + cml::matrix22d M; // column basis cml::matrix_set_x_basis_vector_2D(M, cml::vector2d(1., 2.)); cml::matrix_set_y_basis_vector_2D(M, cml::vector2d(3., 4.)); @@ -32,7 +29,7 @@ CATCH_TEST_CASE("basis 2D, basis1") CATCH_TEST_CASE("basis 2D, basis2") { - cml::matrix22d M; // column basis + cml::matrix22d M; // column basis cml::matrix_set_transposed_x_basis_vector_2D(M, cml::vector2d(1., 2.)); cml::matrix_set_transposed_y_basis_vector_2D(M, cml::vector2d(3., 4.)); @@ -48,10 +45,10 @@ CATCH_TEST_CASE("basis 2D, basis2") CATCH_TEST_CASE("basis 2D, basis3") { - cml::matrix22d M; // column basis + cml::matrix22d M; // column basis - cml::matrix_set_basis_vectors_2D( - M, cml::vector2d(1., 2.), cml::vector2d(3., 4.)); + cml::matrix_set_basis_vectors_2D(M, cml::vector2d(1., 2.), + cml::vector2d(3., 4.)); cml::vectord b1, b2; cml::matrix_get_basis_vectors_2D(M, b1, b2); @@ -64,10 +61,10 @@ CATCH_TEST_CASE("basis 2D, basis3") CATCH_TEST_CASE("basis 2D, basis4") { - cml::matrix22d M; // column basis + cml::matrix22d M; // column basis - cml::matrix_set_transposed_basis_vectors_2D( - M, cml::vector2d(1., 2.), cml::vector2d(3., 4.)); + cml::matrix_set_transposed_basis_vectors_2D(M, cml::vector2d(1., 2.), + cml::vector2d(3., 4.)); cml::vectord b1, b2; cml::matrix_get_transposed_basis_vectors_2D(M, b1, b2); @@ -78,12 +75,9 @@ CATCH_TEST_CASE("basis 2D, basis4") CATCH_CHECK(b2[1] == 4.); } - - - CATCH_TEST_CASE("basis 3D, basis1") { - cml::matrix33d M; // column basis + cml::matrix33d M; // column basis cml::matrix_set_x_basis_vector(M, cml::vector3d(1., 2., 3.)); cml::matrix_set_y_basis_vector(M, cml::vector3d(4., 5., 6.)); @@ -108,7 +102,7 @@ CATCH_TEST_CASE("basis 3D, basis1") CATCH_TEST_CASE("basis 3D, basis2") { - cml::matrix33d M; // column basis + cml::matrix33d M; // column basis cml::matrix_set_transposed_x_basis_vector(M, cml::vector3d(1., 2., 3.)); cml::matrix_set_transposed_y_basis_vector(M, cml::vector3d(4., 5., 6.)); @@ -133,7 +127,7 @@ CATCH_TEST_CASE("basis 3D, basis2") CATCH_TEST_CASE("basis 3D, basis3") { - cml::matrix33d M; // column basis + cml::matrix33d M; // column basis cml::matrix_set_basis_vectors(M, cml::vector3d(1., 2., 3.), cml::vector3d(4., 5., 6.), cml::vector3d(7., 8., 9.)); @@ -156,7 +150,7 @@ CATCH_TEST_CASE("basis 3D, basis3") CATCH_TEST_CASE("basis 3D, basis4") { - cml::matrix33d M; // column basis + cml::matrix33d M; // column basis cml::matrix_set_transposed_basis_vectors(M, cml::vector3d(1., 2., 3.), cml::vector3d(4., 5., 6.), cml::vector3d(7., 8., 9.)); @@ -177,16 +171,9 @@ CATCH_TEST_CASE("basis 3D, basis4") CATCH_CHECK(b3[2] == 9.); } - - - CATCH_TEST_CASE("basis nD, basis1") { - auto M = cml::matrix34d_c( - 1., 0., 0., 3., - 0., 1., 0., 2., - 0., 0., 1., 1. - ); + auto M = cml::matrix34d_c(1., 0., 0., 3., 0., 1., 0., 2., 0., 0., 1., 1.); auto T = cml::matrix_get_basis_vector_nD(M, 3); CATCH_CHECK(T[0] == 3.); CATCH_CHECK(T[1] == 2.); @@ -195,18 +182,9 @@ CATCH_TEST_CASE("basis nD, basis1") CATCH_TEST_CASE("basis nD, basis2") { - auto M = cml::matrix43d_r( - 1., 0., 0., - 0., 1., 0., - 0., 0., 1., - 3., 2., 1. - ); + auto M = cml::matrix43d_r(1., 0., 0., 0., 1., 0., 0., 0., 1., 3., 2., 1.); auto T = cml::matrix_get_basis_vector_nD(M, 3); CATCH_CHECK(T[0] == 3.); CATCH_CHECK(T[1] == 2.); CATCH_CHECK(T[2] == 1.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/matrix_generators1.cpp b/tests/mathlib/matrix_generators1.cpp index cd894c5..098fa20 100644 --- a/tests/mathlib/matrix_generators1.cpp +++ b/tests/mathlib/matrix_generators1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -13,122 +11,114 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("zero, zero_2x2_1") { auto M = cml::zero_2x2(); - typedef decltype(M) matrix_type; + using matrix_type = decltype(M); CATCH_CHECK((std::is_same::value)); CATCH_CHECK(M.rows() == 2); CATCH_CHECK(M.cols() == 2); - CATCH_CHECK(M(0,0) == 0.); - CATCH_CHECK(M(0,1) == 0.); - CATCH_CHECK(M(1,0) == 0.); - CATCH_CHECK(M(1,1) == 0.); + CATCH_CHECK(M(0, 0) == 0.); + CATCH_CHECK(M(0, 1) == 0.); + CATCH_CHECK(M(1, 0) == 0.); + CATCH_CHECK(M(1, 1) == 0.); } CATCH_TEST_CASE("zero, zero_3x3_1") { auto M = cml::zero_3x3(); - typedef decltype(M) matrix_type; + using matrix_type = decltype(M); CATCH_CHECK((std::is_same::value)); CATCH_CHECK(M.rows() == 3); CATCH_CHECK(M.cols() == 3); - CATCH_CHECK(M(0,0) == 0.); - CATCH_CHECK(M(0,1) == 0.); - CATCH_CHECK(M(0,2) == 0.); - CATCH_CHECK(M(1,0) == 0.); - CATCH_CHECK(M(1,1) == 0.); - CATCH_CHECK(M(1,2) == 0.); - CATCH_CHECK(M(2,0) == 0.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); + CATCH_CHECK(M(0, 0) == 0.); + CATCH_CHECK(M(0, 1) == 0.); + CATCH_CHECK(M(0, 2) == 0.); + CATCH_CHECK(M(1, 0) == 0.); + CATCH_CHECK(M(1, 1) == 0.); + CATCH_CHECK(M(1, 2) == 0.); + CATCH_CHECK(M(2, 0) == 0.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); } CATCH_TEST_CASE("zero, zero_4x4_1") { auto M = cml::zero_4x4(); - typedef decltype(M) matrix_type; + using matrix_type = decltype(M); CATCH_CHECK((std::is_same::value)); CATCH_CHECK(M.rows() == 4); CATCH_CHECK(M.cols() == 4); - CATCH_CHECK(M(0,0) == 0.); - CATCH_CHECK(M(0,1) == 0.); - CATCH_CHECK(M(0,2) == 0.); - CATCH_CHECK(M(0,3) == 0.); - CATCH_CHECK(M(1,0) == 0.); - CATCH_CHECK(M(1,1) == 0.); - CATCH_CHECK(M(1,2) == 0.); - CATCH_CHECK(M(1,3) == 0.); - CATCH_CHECK(M(2,0) == 0.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); - CATCH_CHECK(M(3,0) == 0.); - CATCH_CHECK(M(3,1) == 0.); - CATCH_CHECK(M(3,2) == 0.); - CATCH_CHECK(M(3,3) == 0.); + CATCH_CHECK(M(0, 0) == 0.); + CATCH_CHECK(M(0, 1) == 0.); + CATCH_CHECK(M(0, 2) == 0.); + CATCH_CHECK(M(0, 3) == 0.); + CATCH_CHECK(M(1, 0) == 0.); + CATCH_CHECK(M(1, 1) == 0.); + CATCH_CHECK(M(1, 2) == 0.); + CATCH_CHECK(M(1, 3) == 0.); + CATCH_CHECK(M(2, 0) == 0.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); + CATCH_CHECK(M(3, 0) == 0.); + CATCH_CHECK(M(3, 1) == 0.); + CATCH_CHECK(M(3, 2) == 0.); + CATCH_CHECK(M(3, 3) == 0.); } - - - CATCH_TEST_CASE("zero, identity_2x2_1") { auto M = cml::identity_2x2(); - typedef decltype(M) matrix_type; + using matrix_type = decltype(M); CATCH_CHECK((std::is_same::value)); CATCH_CHECK(M.rows() == 2); CATCH_CHECK(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 0.); - CATCH_CHECK(M(1,0) == 0.); - CATCH_CHECK(M(1,1) == 1.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 0.); + CATCH_CHECK(M(1, 0) == 0.); + CATCH_CHECK(M(1, 1) == 1.); } CATCH_TEST_CASE("zero, identity_3x3_1") { auto M = cml::identity_3x3(); - typedef decltype(M) matrix_type; + using matrix_type = decltype(M); CATCH_CHECK((std::is_same::value)); CATCH_CHECK(M.rows() == 3); CATCH_CHECK(M.cols() == 3); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 0.); - CATCH_CHECK(M(0,2) == 0.); - CATCH_CHECK(M(1,0) == 0.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(1,2) == 0.); - CATCH_CHECK(M(2,0) == 0.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 1.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 0.); + CATCH_CHECK(M(0, 2) == 0.); + CATCH_CHECK(M(1, 0) == 0.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(1, 2) == 0.); + CATCH_CHECK(M(2, 0) == 0.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 1.); } CATCH_TEST_CASE("zero, identity_4x4_1") { auto M = cml::identity_4x4(); - typedef decltype(M) matrix_type; + using matrix_type = decltype(M); CATCH_CHECK((std::is_same::value)); CATCH_CHECK(M.rows() == 4); CATCH_CHECK(M.cols() == 4); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 0.); - CATCH_CHECK(M(0,2) == 0.); - CATCH_CHECK(M(0,3) == 0.); - CATCH_CHECK(M(1,0) == 0.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(1,2) == 0.); - CATCH_CHECK(M(1,3) == 0.); - CATCH_CHECK(M(2,0) == 0.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 1.); - CATCH_CHECK(M(2,3) == 0.); - CATCH_CHECK(M(3,0) == 0.); - CATCH_CHECK(M(3,1) == 0.); - CATCH_CHECK(M(3,2) == 0.); - CATCH_CHECK(M(3,3) == 1.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 0.); + CATCH_CHECK(M(0, 2) == 0.); + CATCH_CHECK(M(0, 3) == 0.); + CATCH_CHECK(M(1, 0) == 0.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(1, 2) == 0.); + CATCH_CHECK(M(1, 3) == 0.); + CATCH_CHECK(M(2, 0) == 0.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 1.); + CATCH_CHECK(M(2, 3) == 0.); + CATCH_CHECK(M(3, 0) == 0.); + CATCH_CHECK(M(3, 1) == 0.); + CATCH_CHECK(M(3, 2) == 0.); + CATCH_CHECK(M(3, 3) == 1.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/matrix_invert1.cpp b/tests/mathlib/matrix_invert1.cpp index 33a3df1..15c8c8f 100644 --- a/tests/mathlib/matrix_invert1.cpp +++ b/tests/mathlib/matrix_invert1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include @@ -15,76 +13,48 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("invert 2D, invert_2D_1") { - auto M = cml::matrix33d( - 1., 0., 3., - 0., 1., 2., - 0., 0., 1. - ); + auto M = cml::matrix33d(1., 0., 3., 0., 1., 2., 0., 0., 1.); cml::matrix_invert_RT_only_2D(M); - CATCH_CHECK(M.basis_element(2,0) == -3.); - CATCH_CHECK(M.basis_element(2,1) == -2.); + CATCH_CHECK(M.basis_element(2, 0) == -3.); + CATCH_CHECK(M.basis_element(2, 1) == -2.); } CATCH_TEST_CASE("invert 2D, invert_nD_1") { - auto M = cml::matrix33d_r( - 1., 0., 0., - 0., 1., 0., - 3., 2., 1. - ); + auto M = cml::matrix33d_r(1., 0., 0., 0., 1., 0., 3., 2., 1.); cml::matrix_invert_RT(M); - CATCH_CHECK(M.basis_element(2,0) == -3.); - CATCH_CHECK(M.basis_element(2,1) == -2.); + CATCH_CHECK(M.basis_element(2, 0) == -3.); + CATCH_CHECK(M.basis_element(2, 1) == -2.); } - - - CATCH_TEST_CASE("invert 3D, invert_3D_1") { - auto M = cml::matrix44d( - 1., 0., 0., 3., - 0., 1., 0., 2., - 0., 0., 1., 1., - 0., 0., 0., 1. - ); + auto M = cml::matrix44d(1., 0., 0., 3., 0., 1., 0., 2., 0., 0., 1., 1., 0., + 0., 0., 1.); cml::matrix_invert_RT_only(M); - CATCH_CHECK(M.basis_element(3,0) == -3.); - CATCH_CHECK(M.basis_element(3,1) == -2.); - CATCH_CHECK(M.basis_element(3,2) == -1.); + CATCH_CHECK(M.basis_element(3, 0) == -3.); + CATCH_CHECK(M.basis_element(3, 1) == -2.); + CATCH_CHECK(M.basis_element(3, 2) == -1.); } CATCH_TEST_CASE("invert 3D, invert_3D_2") { - auto M = cml::matrix44d_c( - 1., 0., 0., 3., - 0., 1., 0., 2., - 0., 0., 1., 1., - 0., 0., 0., 1. - ); + auto M = cml::matrix44d_c(1., 0., 0., 3., 0., 1., 0., 2., 0., 0., 1., 1., 0., + 0., 0., 1.); cml::matrix_invert_RT_only(M); - CATCH_CHECK(M.basis_element(3,0) == -3.); - CATCH_CHECK(M.basis_element(3,1) == -2.); - CATCH_CHECK(M.basis_element(3,2) == -1.); + CATCH_CHECK(M.basis_element(3, 0) == -3.); + CATCH_CHECK(M.basis_element(3, 1) == -2.); + CATCH_CHECK(M.basis_element(3, 2) == -1.); } CATCH_TEST_CASE("invert 3D, invert_nD_1") { - auto M = cml::matrix44d_r( - 1., 0., 0., 0., - 0., 1., 0., 0., - 0., 0., 1., 0., - 3., 2., 1., 1. - ); + auto M = cml::matrix44d_r(1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 3., + 2., 1., 1.); cml::matrix_invert_RT(M); - CATCH_CHECK(M.basis_element(3,0) == -3.); - CATCH_CHECK(M.basis_element(3,1) == -2.); - CATCH_CHECK(M.basis_element(3,2) == -1.); + CATCH_CHECK(M.basis_element(3, 0) == -3.); + CATCH_CHECK(M.basis_element(3, 1) == -2.); + CATCH_CHECK(M.basis_element(3, 2) == -1.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/matrix_projection1.cpp b/tests/mathlib/matrix_projection1.cpp index 1151586..fd92d85 100644 --- a/tests/mathlib/matrix_projection1.cpp +++ b/tests/mathlib/matrix_projection1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -13,12 +11,11 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("orthographic, rh1") { cml::matrix44d O; - cml::matrix_orthographic_RH( - O, -.5, .5, -.5, .5, -1., 1., cml::z_clip_neg_one); + cml::matrix_orthographic_RH(O, -.5, .5, -.5, .5, -1., 1., + cml::z_clip_neg_one); // l, r, b, t, near, far cml::vector4d o = O * cml::vector4d(.5, .5, 0., 1.); @@ -44,8 +41,7 @@ CATCH_TEST_CASE("orthographic, rh2") CATCH_TEST_CASE("orthographic, lh1") { cml::matrix44d O; - cml::matrix_orthographic_LH( - O, -.5, .5, -.5, .5, -1., 1., cml::z_clip_zero); + cml::matrix_orthographic_LH(O, -.5, .5, -.5, .5, -1., 1., cml::z_clip_zero); // l, r, b, t, near, far cml::vector4d o = O * cml::vector4d(.5, .5, 0., 1.); @@ -68,14 +64,11 @@ CATCH_TEST_CASE("orthographic, lh2") CATCH_CHECK(o[3] == Approx(1.).epsilon(1e-12)); } - - - CATCH_TEST_CASE("perspective, rh1") { cml::matrix44d P; - cml::matrix_perspective_RH( - P, -.5, .5, -.5, .5, .001, 1., cml::z_clip_neg_one); + cml::matrix_perspective_RH(P, -.5, .5, -.5, .5, .001, 1., + cml::z_clip_neg_one); // l, r, b, t, near, far cml::vector4d p = P * cml::vector4d(.5, .5, 1., 1.); @@ -101,8 +94,7 @@ CATCH_TEST_CASE("perspective, rh2") CATCH_TEST_CASE("perspective, lh1") { cml::matrix44d P; - cml::matrix_perspective_LH( - P, -.5, .5, -.5, .5, .001, 1., cml::z_clip_zero); + cml::matrix_perspective_LH(P, -.5, .5, -.5, .5, .001, 1., cml::z_clip_zero); // l, r, b, t, near, far cml::vector4d p = P * cml::vector4d(.5, .5, 1., 1.); @@ -124,7 +116,3 @@ CATCH_TEST_CASE("perspective, lh2") CATCH_CHECK(p[2] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(p[3] == Approx(1.).epsilon(1e-12)); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/matrix_rotation1.cpp b/tests/mathlib/matrix_rotation1.cpp index 78725f8..73bfd32 100644 --- a/tests/mathlib/matrix_rotation1.cpp +++ b/tests/mathlib/matrix_rotation1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -15,12 +13,11 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("rotation 2D, rotation1") { cml::matrix22d M; cml::matrix_rotation_2D(M, cml::rad(90.)); - auto v = M*cml::vector2d(0., 1.); + auto v = M * cml::vector2d(0., 1.); CATCH_CHECK(v[0] == Approx(-1.).epsilon(1e-12)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); } @@ -28,32 +25,32 @@ CATCH_TEST_CASE("rotation 2D, rotation1") CATCH_TEST_CASE("rotation 2D, align1") { cml::matrix22d M; - cml::matrix_rotation_align_2D(M, cml::vector2d(0.,1.)); + cml::matrix_rotation_align_2D(M, cml::vector2d(0., 1.)); - auto v = M*cml::vector2d(0., 1.); + auto v = M * cml::vector2d(0., 1.); CATCH_CHECK(v[0] == Approx(-1.).epsilon(1e-12)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); } - - - CATCH_TEST_CASE("rotation 3D, world_axis1") { - cml::matrix33d Mx; cml::matrix_rotation_world_x(Mx, cml::rad(90.)); - auto vx = Mx*cml::vector3d(0., 1., 0.); // 0,0,1 + cml::matrix33d Mx; + cml::matrix_rotation_world_x(Mx, cml::rad(90.)); + auto vx = Mx * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(0 == Approx(vx[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(vx[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(vx[2] == Approx(1.).epsilon(1e-12)); - cml::matrix33d My; cml::matrix_rotation_world_y(My, cml::rad(90.)); - auto vy = My*cml::vector3d(-1., 0., 0.); // 0,0,1 + cml::matrix33d My; + cml::matrix_rotation_world_y(My, cml::rad(90.)); + auto vy = My * cml::vector3d(-1., 0., 0.); // 0,0,1 CATCH_CHECK(0 == Approx(vy[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(vy[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(vy[2] == Approx(1.).epsilon(1e-12)); - cml::matrix33d Mz; cml::matrix_rotation_world_z(Mz, cml::rad(90.)); - auto vz = Mz*cml::vector3d(1., 0., 0.); // 0,1,0 + cml::matrix33d Mz; + cml::matrix_rotation_world_z(Mz, cml::rad(90.)); + auto vz = Mz * cml::vector3d(1., 0., 0.); // 0,1,0 CATCH_CHECK(0 == Approx(vz[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(vz[1] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(0 == Approx(vz[2]).epsilon(0).margin(1e-7)); @@ -62,9 +59,8 @@ CATCH_TEST_CASE("rotation 3D, world_axis1") CATCH_TEST_CASE("rotation 3D, rotation1") { cml::matrix33d M; - cml::matrix_rotation_axis_angle( - M, cml::vector3d(1., 0., 0.), cml::rad(90.)); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + cml::matrix_rotation_axis_angle(M, cml::vector3d(1., 0., 0.), cml::rad(90.)); + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(0 == Approx(v[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(v[2] == Approx(1.).epsilon(1e-12)); @@ -73,21 +69,19 @@ CATCH_TEST_CASE("rotation 3D, rotation1") CATCH_TEST_CASE("rotation 3D, int_rotation1") { cml::matrix33i M; - cml::matrix_rotation_axis_angle( - M, cml::vector3d(1., 0., 0.), cml::rad(90.)); + cml::matrix_rotation_axis_angle(M, cml::vector3d(1., 0., 0.), cml::rad(90.)); - CATCH_CHECK(M(0,0) == 1); - CATCH_CHECK(M(1,2) == -1); - CATCH_CHECK(M(2,1) == 1); + CATCH_CHECK(M(0, 0) == 1); + CATCH_CHECK(M(1, 2) == -1); + CATCH_CHECK(M(2, 1) == 1); } CATCH_TEST_CASE("rotation 3D, euler1") { cml::matrix33d M; - cml::matrix_rotation_euler( - M, cml::rad(90.), 0., 0., cml::euler_order_xyz); + cml::matrix_rotation_euler(M, cml::rad(90.), 0., 0., cml::euler_order_xyz); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(0 == Approx(v[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(v[2] == Approx(1.).epsilon(1e-12)); @@ -96,10 +90,10 @@ CATCH_TEST_CASE("rotation 3D, euler1") CATCH_TEST_CASE("rotation 3D, euler_derivaties1") { cml::matrix33d M; - cml::matrix_rotation_euler_derivatives( - M, 0, cml::rad(90.), 0., 0., cml::euler_order_xyz); + cml::matrix_rotation_euler_derivatives(M, 0, cml::rad(90.), 0., 0., + cml::euler_order_xyz); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(0 == Approx(v[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(v[1] == Approx(-1.).epsilon(1e-12)); CATCH_CHECK(0 == Approx(v[2]).epsilon(0).margin(1e-7)); @@ -108,10 +102,10 @@ CATCH_TEST_CASE("rotation 3D, euler_derivaties1") CATCH_TEST_CASE("rotation 3D, euler2") { cml::matrix33d M; - cml::matrix_rotation_euler( - M, cml::vector3d(cml::rad(90.), 0., 0.), cml::euler_order_xyz); + cml::matrix_rotation_euler(M, cml::vector3d(cml::rad(90.), 0., 0.), + cml::euler_order_xyz); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(0 == Approx(v[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(v[2] == Approx(1.).epsilon(1e-12)); @@ -120,10 +114,10 @@ CATCH_TEST_CASE("rotation 3D, euler2") CATCH_TEST_CASE("rotation 3D, euler_derivaties2") { cml::matrix33d M; - cml::matrix_rotation_euler_derivatives( - M, 0, cml::vector3d(cml::rad(90.), 0., 0.), cml::euler_order_xyz); + cml::matrix_rotation_euler_derivatives(M, 0, + cml::vector3d(cml::rad(90.), 0., 0.), cml::euler_order_xyz); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(0 == Approx(v[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(v[1] == Approx(-1.).epsilon(1e-12)); CATCH_CHECK(0 == Approx(v[2]).epsilon(0).margin(1e-7)); @@ -131,10 +125,12 @@ CATCH_TEST_CASE("rotation 3D, euler_derivaties2") CATCH_TEST_CASE("rotation 3D, quaternion1") { - cml::quaterniond q; cml::quaternion_rotation_axis_angle( - q, cml::vector3d(1., 0., 0.), cml::rad(90.)); - cml::matrix33d M; cml::matrix_rotation_quaternion(M, q); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + cml::quaterniond q; + cml::quaternion_rotation_axis_angle(q, cml::vector3d(1., 0., 0.), + cml::rad(90.)); + cml::matrix33d M; + cml::matrix_rotation_quaternion(M, q); + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(0 == Approx(v[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(v[2] == Approx(1.).epsilon(1e-12)); @@ -142,9 +138,10 @@ CATCH_TEST_CASE("rotation 3D, quaternion1") CATCH_TEST_CASE("rotation 3D, align_ref1") { - cml::matrix33d M; cml::matrix_rotation_align( - M, cml::vector3d(0., 0., 1.), cml::vector3d(1., 0., 0.)); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + cml::matrix33d M; + cml::matrix_rotation_align(M, cml::vector3d(0., 0., 1.), + cml::vector3d(1., 0., 0.)); + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(v[0] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(v[2]).epsilon(0).margin(1e-7)); @@ -152,10 +149,10 @@ CATCH_TEST_CASE("rotation 3D, align_ref1") CATCH_TEST_CASE("rotation 3D, aim_at_ref1") { - cml::matrix33d M; cml::matrix_rotation_aim_at(M, - cml::vector3d(0.,0.,0.), cml::vector3d(0., 0., 1.), - cml::vector3d(1., 0., 0.)); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + cml::matrix33d M; + cml::matrix_rotation_aim_at(M, cml::vector3d(0., 0., 0.), + cml::vector3d(0., 0., 1.), cml::vector3d(1., 0., 0.)); + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(v[0] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(v[2]).epsilon(0).margin(1e-7)); @@ -164,8 +161,8 @@ CATCH_TEST_CASE("rotation 3D, aim_at_ref1") CATCH_TEST_CASE("rotation 3D, to_axis_angle1") { cml::matrix33d M; - cml::matrix_rotation_axis_angle( - M, cml::vector3d(1., 2., 3.).normalize(), cml::rad(23.)); + cml::matrix_rotation_axis_angle(M, cml::vector3d(1., 2., 3.).normalize(), + cml::rad(23.)); cml::vector3d axis; double angle; @@ -179,12 +176,12 @@ CATCH_TEST_CASE("rotation 3D, to_axis_angle1") CATCH_TEST_CASE("rotation 3D, to_axis_angle_tuple1") { cml::matrix33d M; - cml::matrix_rotation_axis_angle( - M, cml::vector3d(1., 2., 3.).normalize(), cml::rad(23.)); + cml::matrix_rotation_axis_angle(M, cml::vector3d(1., 2., 3.).normalize(), + cml::rad(23.)); cml::vector3d axis; double angle; - std::tie(axis,angle) = cml::matrix_to_axis_angle(M); + std::tie(axis, angle) = cml::matrix_to_axis_angle(M); CATCH_CHECK(axis[0] == Approx(0.2672612419124244).epsilon(1e-12)); CATCH_CHECK(axis[1] == Approx(0.53452248382484879).epsilon(1e-12)); @@ -194,8 +191,8 @@ CATCH_TEST_CASE("rotation 3D, to_axis_angle_tuple1") CATCH_TEST_CASE("rotation 3D, to_euler1") { cml::matrix33d M; - cml::matrix_rotation_euler( - M, cml::rad(22.), cml::rad(10.), cml::rad(89.9), cml::euler_order_xyz); + cml::matrix_rotation_euler(M, cml::rad(22.), cml::rad(10.), cml::rad(89.9), + cml::euler_order_xyz); cml::vector3d v; cml::matrix_to_euler(M, v[0], v[1], v[2], cml::euler_order_xyz); @@ -208,8 +205,8 @@ CATCH_TEST_CASE("rotation 3D, to_euler1") CATCH_TEST_CASE("rotation 3D, to_euler2") { cml::matrix33d M; - cml::matrix_rotation_euler( - M, cml::rad(22.), cml::rad(10.), cml::rad(89.9), cml::euler_order_xyx); + cml::matrix_rotation_euler(M, cml::rad(22.), cml::rad(10.), cml::rad(89.9), + cml::euler_order_xyx); cml::vector3d v; cml::matrix_to_euler(M, v[0], v[1], v[2], cml::euler_order_xyx); @@ -222,8 +219,8 @@ CATCH_TEST_CASE("rotation 3D, to_euler2") CATCH_TEST_CASE("rotation 3D, to_euler_vector1") { cml::matrix33d M; - cml::matrix_rotation_euler( - M, cml::rad(22.), cml::rad(10.), cml::rad(89.9), cml::euler_order_xyz); + cml::matrix_rotation_euler(M, cml::rad(22.), cml::rad(10.), cml::rad(89.9), + cml::euler_order_xyz); auto v = cml::matrix_to_euler(M, cml::euler_order_xyz); CATCH_CHECK(v[0] == Approx(cml::rad(22.)).epsilon(1e-12)); @@ -234,15 +231,11 @@ CATCH_TEST_CASE("rotation 3D, to_euler_vector1") CATCH_TEST_CASE("rotation 3D, to_euler_vector2") { cml::matrix33d M; - cml::matrix_rotation_euler( - M, cml::rad(22.), cml::rad(10.), cml::rad(89.9), cml::euler_order_xyz); + cml::matrix_rotation_euler(M, cml::rad(22.), cml::rad(10.), cml::rad(89.9), + cml::euler_order_xyz); auto v = cml::matrix_to_euler(M, cml::euler_order_xyz); CATCH_CHECK(v[0] == Approx(cml::rad(22.)).epsilon(1e-12)); CATCH_CHECK(v[1] == Approx(cml::rad(10.)).epsilon(1e-12)); CATCH_CHECK(v[2] == Approx(cml::rad(89.9)).epsilon(1e-12)); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/matrix_scale1.cpp b/tests/mathlib/matrix_scale1.cpp index 645da8c..47ae0fb 100644 --- a/tests/mathlib/matrix_scale1.cpp +++ b/tests/mathlib/matrix_scale1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -13,95 +11,87 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("scale 2D, set1") { cml::matrix33d M; cml::matrix_scale_2D(M, 2., 2.); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(1,1) == 2.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(1, 1) == 2.); } CATCH_TEST_CASE("scale 2D, set2") { cml::matrix33d M; cml::matrix_scale_2D(M, cml::vector2d(2., 2.)); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(1,1) == 2.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(1, 1) == 2.); } CATCH_TEST_CASE("scale 2D, uniform1") { cml::matrix33d M; cml::matrix_uniform_scale_2D(M, 2.); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(1,1) == 2.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(1, 1) == 2.); } CATCH_TEST_CASE("scale 2D, inverse1") { cml::matrix33d M; cml::matrix_inverse_scale_2D(M, .5, .5); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(1,1) == 2.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(1, 1) == 2.); } CATCH_TEST_CASE("scale 2D, inverse2") { cml::matrix33d M; cml::matrix_inverse_scale_2D(M, cml::vector2d(.5, .5)); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(1,1) == 2.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(1, 1) == 2.); } - - - CATCH_TEST_CASE("scale 3D, set1") { cml::matrix44d M; cml::matrix_scale(M, 2., 2., 2.); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(1,1) == 2.); - CATCH_CHECK(M(2,2) == 2.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(1, 1) == 2.); + CATCH_CHECK(M(2, 2) == 2.); } CATCH_TEST_CASE("scale 3D, set2") { cml::matrix44d M; cml::matrix_scale(M, cml::vector3d(2., 2., 2.)); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(1,1) == 2.); - CATCH_CHECK(M(2,2) == 2.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(1, 1) == 2.); + CATCH_CHECK(M(2, 2) == 2.); } CATCH_TEST_CASE("scale 3D, uniform1") { cml::matrix44d M; cml::matrix_uniform_scale(M, 2.); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(1,1) == 2.); - CATCH_CHECK(M(2,2) == 2.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(1, 1) == 2.); + CATCH_CHECK(M(2, 2) == 2.); } CATCH_TEST_CASE("scale 3D, inverse1") { cml::matrix44d M; cml::matrix_inverse_scale(M, .5, .5, .5); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(1,1) == 2.); - CATCH_CHECK(M(2,2) == 2.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(1, 1) == 2.); + CATCH_CHECK(M(2, 2) == 2.); } CATCH_TEST_CASE("scale 3D, inverse2") { cml::matrix44d M; cml::matrix_inverse_scale(M, cml::vector3d(.5, .5, .5)); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(1,1) == 2.); - CATCH_CHECK(M(2,2) == 2.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(1, 1) == 2.); + CATCH_CHECK(M(2, 2) == 2.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/matrix_transform1.cpp b/tests/mathlib/matrix_transform1.cpp index 0552320..1471de1 100644 --- a/tests/mathlib/matrix_transform1.cpp +++ b/tests/mathlib/matrix_transform1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -17,17 +15,14 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("look at 3D, look_at_rh_1") { auto M = cml::zero_4x4(); - cml::matrix_look_at_RH(M, - cml::vector3d(1.,0.,0.), - cml::vector3d(0.,0.,0.), - cml::vector3d(0.,0.,1.)); + cml::matrix_look_at_RH(M, cml::vector3d(1., 0., 0.), + cml::vector3d(0., 0., 0.), cml::vector3d(0., 0., 1.)); auto v = cml::vector3d(1., 1., 1.); - auto w = cml::transform_point(M,v); + auto w = cml::transform_point(M, v); CATCH_CHECK(w[0] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(w[1] == Approx(1.).epsilon(1e-12)); @@ -37,39 +32,30 @@ CATCH_TEST_CASE("look at 3D, look_at_rh_1") CATCH_TEST_CASE("look at 3D, look_at_lh_1") { auto M = cml::zero_4x4(); - cml::matrix_look_at_LH(M, - cml::vector3d(1.,0.,0.), - cml::vector3d(0.,0.,0.), - cml::vector3d(0.,0.,1.)); + cml::matrix_look_at_LH(M, cml::vector3d(1., 0., 0.), + cml::vector3d(0., 0., 0.), cml::vector3d(0., 0., 1.)); auto v = cml::vector3d(1., 1., 1.); - auto w = cml::transform_point(M,v); + auto w = cml::transform_point(M, v); CATCH_CHECK(w[0] == Approx(-1.).epsilon(1e-12)); - CATCH_CHECK(w[1] == Approx( 1.).epsilon(1e-12)); - CATCH_CHECK(0 == Approx(w[2]).epsilon(0).margin( 1e-8)); + CATCH_CHECK(w[1] == Approx(1.).epsilon(1e-12)); + CATCH_CHECK(0 == Approx(w[2]).epsilon(0).margin(1e-8)); } - - - CATCH_TEST_CASE("affine 3D, test1") { cml::matrix44d M; - auto axis = cml::vector3d(1.,1.,1.).normalize(); - cml::vector3d xlate(2.,2.,2.); + auto axis = cml::vector3d(1., 1., 1.).normalize(); + cml::vector3d xlate(2., 2., 2.); cml::matrix_affine_transform(M, axis, cml::rad(22.5), xlate); - CATCH_CHECK(M(0,3) == 2.0); - CATCH_CHECK(M(1,3) == 2.0); - CATCH_CHECK(M(2,3) == 2.0); - CATCH_CHECK(M(3,3) == 1.0); + CATCH_CHECK(M(0, 3) == 2.0); + CATCH_CHECK(M(1, 3) == 2.0); + CATCH_CHECK(M(2, 3) == 2.0); + CATCH_CHECK(M(3, 3) == 1.0); - CATCH_CHECK(M(0,0) == Approx(0.9492530216742).epsilon(1e-12)); - CATCH_CHECK(M(1,1) == Approx(0.9492530216742).epsilon(1e-12)); - CATCH_CHECK(M(2,2) == Approx(0.9492530216742).epsilon(1e-12)); + CATCH_CHECK(M(0, 0) == Approx(0.9492530216742).epsilon(1e-12)); + CATCH_CHECK(M(1, 1) == Approx(0.9492530216742).epsilon(1e-12)); + CATCH_CHECK(M(2, 2) == Approx(0.9492530216742).epsilon(1e-12)); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/matrix_translation1.cpp b/tests/mathlib/matrix_translation1.cpp index 8949d4b..210300a 100644 --- a/tests/mathlib/matrix_translation1.cpp +++ b/tests/mathlib/matrix_translation1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -13,87 +11,82 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("set 2D, set1") { cml::matrix33d M; cml::matrix_set_translation_2D(M.identity(), 2., -3.); - CATCH_CHECK(M(0,2) == 2.); - CATCH_CHECK(M(1,2) == -3.); + CATCH_CHECK(M(0, 2) == 2.); + CATCH_CHECK(M(1, 2) == -3.); } CATCH_TEST_CASE("set 2D, set2") { cml::matrix33d_r M; cml::matrix_set_translation_2D(M.identity(), 2., -3.); - CATCH_CHECK(M(2,0) == 2.); - CATCH_CHECK(M(2,1) == -3.); + CATCH_CHECK(M(2, 0) == 2.); + CATCH_CHECK(M(2, 1) == -3.); } CATCH_TEST_CASE("set 2D, set3") { cml::matrix33d M; - cml::matrix_set_translation_2D(M.identity(), cml::vector2d(2.,-3.)); - CATCH_CHECK(M(0,2) == 2.); - CATCH_CHECK(M(1,2) == -3.); + cml::matrix_set_translation_2D(M.identity(), cml::vector2d(2., -3.)); + CATCH_CHECK(M(0, 2) == 2.); + CATCH_CHECK(M(1, 2) == -3.); } CATCH_TEST_CASE("set 2D, set4") { cml::matrix33d_r M; cml::matrix_set_translation_2D(M.identity(), cml::vector2d(2., -3.)); - CATCH_CHECK(M(2,0) == 2.); - CATCH_CHECK(M(2,1) == -3.); + CATCH_CHECK(M(2, 0) == 2.); + CATCH_CHECK(M(2, 1) == -3.); } - CATCH_TEST_CASE("set 2D, make1") { cml::matrix33d M; cml::matrix_translation_2D(M, 2., -3.); - CATCH_CHECK(M(0,2) == 2.); - CATCH_CHECK(M(1,2) == -3.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); + CATCH_CHECK(M(0, 2) == 2.); + CATCH_CHECK(M(1, 2) == -3.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); } CATCH_TEST_CASE("set 2D, make2") { cml::matrix33d_r M; cml::matrix_translation_2D(M, 2., -3.); - CATCH_CHECK(M(2,0) == 2.); - CATCH_CHECK(M(2,1) == -3.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); + CATCH_CHECK(M(2, 0) == 2.); + CATCH_CHECK(M(2, 1) == -3.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); } CATCH_TEST_CASE("set 2D, make3") { cml::matrix33d M; - cml::matrix_translation_2D(M, cml::vector2d(2.,-3.)); - CATCH_CHECK(M(0,2) == 2.); - CATCH_CHECK(M(1,2) == -3.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); + cml::matrix_translation_2D(M, cml::vector2d(2., -3.)); + CATCH_CHECK(M(0, 2) == 2.); + CATCH_CHECK(M(1, 2) == -3.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); } CATCH_TEST_CASE("set 2D, make4") { cml::matrix33d_r M; cml::matrix_translation_2D(M, cml::vector2d(2., -3.)); - CATCH_CHECK(M(2,0) == 2.); - CATCH_CHECK(M(2,1) == -3.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); + CATCH_CHECK(M(2, 0) == 2.); + CATCH_CHECK(M(2, 1) == -3.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); } - - - CATCH_TEST_CASE("get 2D, get1") { cml::matrix33d M; @@ -134,192 +127,182 @@ CATCH_TEST_CASE("get 2D, get4") CATCH_CHECK(T[1] == -3.); } - - - - CATCH_TEST_CASE("set 3D, set1") { cml::matrix44d M; cml::matrix_set_translation(M.identity(), 2., -3., 1.); - CATCH_CHECK(M(0,3) == 2.); - CATCH_CHECK(M(1,3) == -3.); - CATCH_CHECK(M(2,3) == 1.); + CATCH_CHECK(M(0, 3) == 2.); + CATCH_CHECK(M(1, 3) == -3.); + CATCH_CHECK(M(2, 3) == 1.); } CATCH_TEST_CASE("set 3D, set2") { cml::matrix44d_r M; cml::matrix_set_translation(M.identity(), 2., -3., 1.); - CATCH_CHECK(M(3,0) == 2.); - CATCH_CHECK(M(3,1) == -3.); - CATCH_CHECK(M(3,2) == 1.); + CATCH_CHECK(M(3, 0) == 2.); + CATCH_CHECK(M(3, 1) == -3.); + CATCH_CHECK(M(3, 2) == 1.); } CATCH_TEST_CASE("set 3D, set3") { cml::matrix44d M; - cml::matrix_set_translation(M.identity(), cml::vector3d(2.,-3., 1.)); - CATCH_CHECK(M(0,3) == 2.); - CATCH_CHECK(M(1,3) == -3.); - CATCH_CHECK(M(2,3) == 1.); + cml::matrix_set_translation(M.identity(), cml::vector3d(2., -3., 1.)); + CATCH_CHECK(M(0, 3) == 2.); + CATCH_CHECK(M(1, 3) == -3.); + CATCH_CHECK(M(2, 3) == 1.); } CATCH_TEST_CASE("set 3D, set4") { cml::matrix44d_r M; cml::matrix_set_translation(M.identity(), cml::vector3d(2., -3., 1.)); - CATCH_CHECK(M(3,0) == 2.); - CATCH_CHECK(M(3,1) == -3.); - CATCH_CHECK(M(3,2) == 1.); + CATCH_CHECK(M(3, 0) == 2.); + CATCH_CHECK(M(3, 1) == -3.); + CATCH_CHECK(M(3, 2) == 1.); } - CATCH_TEST_CASE("set 3D, set2D_1") { cml::matrix44d M; cml::matrix_set_translation(M.identity(), 2., -3.); - CATCH_CHECK(M(0,3) == 2.); - CATCH_CHECK(M(1,3) == -3.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 3) == 2.); + CATCH_CHECK(M(1, 3) == -3.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("set 3D, set2D_2") { cml::matrix44d_r M; cml::matrix_set_translation(M.identity(), 2., -3.); - CATCH_CHECK(M(3,0) == 2.); - CATCH_CHECK(M(3,1) == -3.); - CATCH_CHECK(M(3,2) == 0.); + CATCH_CHECK(M(3, 0) == 2.); + CATCH_CHECK(M(3, 1) == -3.); + CATCH_CHECK(M(3, 2) == 0.); } CATCH_TEST_CASE("set 3D, set2D_3") { cml::matrix44d M; - cml::matrix_set_translation(M.identity(), cml::vector2d(2.,-3.)); - CATCH_CHECK(M(0,3) == 2.); - CATCH_CHECK(M(1,3) == -3.); - CATCH_CHECK(M(2,3) == 0.); + cml::matrix_set_translation(M.identity(), cml::vector2d(2., -3.)); + CATCH_CHECK(M(0, 3) == 2.); + CATCH_CHECK(M(1, 3) == -3.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("set 3D, set2D_4") { cml::matrix44d_r M; cml::matrix_set_translation(M.identity(), cml::vector2d(2., -3.)); - CATCH_CHECK(M(3,0) == 2.); - CATCH_CHECK(M(3,1) == -3.); - CATCH_CHECK(M(3,2) == 0.); + CATCH_CHECK(M(3, 0) == 2.); + CATCH_CHECK(M(3, 1) == -3.); + CATCH_CHECK(M(3, 2) == 0.); } - CATCH_TEST_CASE("set 3D, make1") { cml::matrix44d M; cml::matrix_translation(M, 2., -3., 1.); - CATCH_CHECK(M(0,3) == 2.); - CATCH_CHECK(M(1,3) == -3.); - CATCH_CHECK(M(2,3) == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); - CATCH_CHECK(M(3,3) == 1.); + CATCH_CHECK(M(0, 3) == 2.); + CATCH_CHECK(M(1, 3) == -3.); + CATCH_CHECK(M(2, 3) == 1.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); + CATCH_CHECK(M(3, 3) == 1.); } CATCH_TEST_CASE("set 3D, make2") { cml::matrix44d_r M; cml::matrix_translation(M, 2., -3., 1.); - CATCH_CHECK(M(3,0) == 2.); - CATCH_CHECK(M(3,1) == -3.); - CATCH_CHECK(M(3,2) == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); - CATCH_CHECK(M(3,3) == 1.); + CATCH_CHECK(M(3, 0) == 2.); + CATCH_CHECK(M(3, 1) == -3.); + CATCH_CHECK(M(3, 2) == 1.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); + CATCH_CHECK(M(3, 3) == 1.); } CATCH_TEST_CASE("set 3D, make3") { cml::matrix44d M; - cml::matrix_translation(M, cml::vector3d(2.,-3., 1.)); - CATCH_CHECK(M(0,3) == 2.); - CATCH_CHECK(M(1,3) == -3.); - CATCH_CHECK(M(2,3) == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); - CATCH_CHECK(M(3,3) == 1.); + cml::matrix_translation(M, cml::vector3d(2., -3., 1.)); + CATCH_CHECK(M(0, 3) == 2.); + CATCH_CHECK(M(1, 3) == -3.); + CATCH_CHECK(M(2, 3) == 1.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); + CATCH_CHECK(M(3, 3) == 1.); } CATCH_TEST_CASE("set 3D, make4") { cml::matrix44d_r M; cml::matrix_translation(M, cml::vector3d(2., -3., 1.)); - CATCH_CHECK(M(3,0) == 2.); - CATCH_CHECK(M(3,1) == -3.); - CATCH_CHECK(M(3,2) == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); - CATCH_CHECK(M(3,3) == 1.); + CATCH_CHECK(M(3, 0) == 2.); + CATCH_CHECK(M(3, 1) == -3.); + CATCH_CHECK(M(3, 2) == 1.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); + CATCH_CHECK(M(3, 3) == 1.); } - CATCH_TEST_CASE("set 3D, make2D_1") { cml::matrix44d M; cml::matrix_translation(M, 2., -3.); - CATCH_CHECK(M(0,3) == 2.); - CATCH_CHECK(M(1,3) == -3.); - CATCH_CHECK(M(2,3) == 0.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); - CATCH_CHECK(M(3,3) == 1.); + CATCH_CHECK(M(0, 3) == 2.); + CATCH_CHECK(M(1, 3) == -3.); + CATCH_CHECK(M(2, 3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); + CATCH_CHECK(M(3, 3) == 1.); } CATCH_TEST_CASE("set 3D, make2D_2") { cml::matrix44d_r M; cml::matrix_translation(M, 2., -3.); - CATCH_CHECK(M(3,0) == 2.); - CATCH_CHECK(M(3,1) == -3.); - CATCH_CHECK(M(3,2) == 0.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); - CATCH_CHECK(M(3,3) == 1.); + CATCH_CHECK(M(3, 0) == 2.); + CATCH_CHECK(M(3, 1) == -3.); + CATCH_CHECK(M(3, 2) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); + CATCH_CHECK(M(3, 3) == 1.); } CATCH_TEST_CASE("set 3D, make2D_3") { cml::matrix44d M; - cml::matrix_translation(M, cml::vector2d(2.,-3.)); - CATCH_CHECK(M(0,3) == 2.); - CATCH_CHECK(M(1,3) == -3.); - CATCH_CHECK(M(2,3) == 0.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); - CATCH_CHECK(M(3,3) == 1.); + cml::matrix_translation(M, cml::vector2d(2., -3.)); + CATCH_CHECK(M(0, 3) == 2.); + CATCH_CHECK(M(1, 3) == -3.); + CATCH_CHECK(M(2, 3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); + CATCH_CHECK(M(3, 3) == 1.); } CATCH_TEST_CASE("set 3D, make2D_4") { cml::matrix44d_r M; cml::matrix_translation(M, cml::vector2d(2., -3.)); - CATCH_CHECK(M(3,0) == 2.); - CATCH_CHECK(M(3,1) == -3.); - CATCH_CHECK(M(3,2) == 0.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,1) == 1.); - CATCH_CHECK(M(2,2) == 1.); - CATCH_CHECK(M(3,3) == 1.); + CATCH_CHECK(M(3, 0) == 2.); + CATCH_CHECK(M(3, 1) == -3.); + CATCH_CHECK(M(3, 2) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 1) == 1.); + CATCH_CHECK(M(2, 2) == 1.); + CATCH_CHECK(M(3, 3) == 1.); } - - - CATCH_TEST_CASE("get 3D, get1") { cml::matrix44d M; @@ -363,7 +346,3 @@ CATCH_TEST_CASE("get 3D, get4") CATCH_CHECK(T[1] == -3.); CATCH_CHECK(T[2] == 1.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/quaternion_basis1.cpp b/tests/mathlib/quaternion_basis1.cpp index 2eda34e..e510789 100644 --- a/tests/mathlib/quaternion_basis1.cpp +++ b/tests/mathlib/quaternion_basis1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -50,6 +48,3 @@ CATCH_TEST_CASE("rp1") CATCH_CHECK(qz[1] == Approx(0.13333333333333336).epsilon(1e-12)); CATCH_CHECK(qz[2] == Approx(0.66666666666666674).epsilon(1e-12)); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/quaternion_rotation1.cpp b/tests/mathlib/quaternion_rotation1.cpp index 202f601..8e714fc 100644 --- a/tests/mathlib/quaternion_rotation1.cpp +++ b/tests/mathlib/quaternion_rotation1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -17,19 +15,22 @@ CATCH_TEST_CASE("world_axis1") { - cml::quaterniond qx; cml::quaternion_rotation_world_x(qx, M_PI/3.); + cml::quaterniond qx; + cml::quaternion_rotation_world_x(qx, M_PI / 3.); CATCH_CHECK(qx.real() == Approx(0.86602540378443871).epsilon(1e-12)); CATCH_CHECK(qx.imaginary()[0] == Approx(0.49999999999999994).epsilon(1e-12)); CATCH_CHECK(qx.imaginary()[1] == 0.); CATCH_CHECK(qx.imaginary()[2] == 0.); - cml::quaterniond qy; cml::quaternion_rotation_world_y(qy, M_PI/2.); + cml::quaterniond qy; + cml::quaternion_rotation_world_y(qy, M_PI / 2.); CATCH_CHECK(qy.real() == Approx(0.70710678118654757).epsilon(1e-12)); CATCH_CHECK(qy.imaginary()[0] == 0.); CATCH_CHECK(qy.imaginary()[1] == Approx(0.70710678118654757).epsilon(1e-12)); CATCH_CHECK(qy.imaginary()[2] == 0.); - cml::quaterniond qz; cml::quaternion_rotation_world_z(qz, M_PI); + cml::quaterniond qz; + cml::quaternion_rotation_world_z(qz, M_PI); CATCH_CHECK(0 == Approx(qz.real()).epsilon(0).margin(2e-16)); CATCH_CHECK(qz.imaginary()[0] == 0.); CATCH_CHECK(qz.imaginary()[1] == 0.); @@ -38,8 +39,9 @@ CATCH_TEST_CASE("world_axis1") CATCH_TEST_CASE("axis_angle1") { - cml::quaterniond q; cml::quaternion_rotation_axis_angle( - q, cml::vector3d(1.,1.,1.).normalize(), M_PI/3.); + cml::quaterniond q; + cml::quaternion_rotation_axis_angle(q, cml::vector3d(1., 1., 1.).normalize(), + M_PI / 3.); CATCH_CHECK(q.real() == Approx(0.86602540378443871).epsilon(1e-12)); CATCH_CHECK(q.imaginary()[0] == Approx(0.28867513459481287).epsilon(1e-12)); CATCH_CHECK(q.imaginary()[1] == Approx(0.28867513459481287).epsilon(1e-12)); @@ -48,9 +50,11 @@ CATCH_TEST_CASE("axis_angle1") CATCH_TEST_CASE("matrix1") { - cml::matrix33d M; cml::matrix_rotation_axis_angle( - M, cml::vector3d(1.,1.,1.).normalize(), M_PI/3.); - cml::quaterniond q; cml::quaternion_rotation_matrix(q, M); + cml::matrix33d M; + cml::matrix_rotation_axis_angle(M, cml::vector3d(1., 1., 1.).normalize(), + M_PI / 3.); + cml::quaterniond q; + cml::quaternion_rotation_matrix(q, M); CATCH_CHECK(q.real() == Approx(0.86602540378443871).epsilon(1e-12)); CATCH_CHECK(q.imaginary()[0] == Approx(0.28867513459481287).epsilon(1e-12)); @@ -60,10 +64,12 @@ CATCH_TEST_CASE("matrix1") CATCH_TEST_CASE("align_ref1") { - cml::quaterniond q; cml::quaternion_rotation_align( - q, cml::vector3d(0., 0., 1.), cml::vector3d(1., 0., 0.)); - cml::matrix33d M; cml::matrix_rotation_quaternion(M, q); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + cml::quaterniond q; + cml::quaternion_rotation_align(q, cml::vector3d(0., 0., 1.), + cml::vector3d(1., 0., 0.)); + cml::matrix33d M; + cml::matrix_rotation_quaternion(M, q); + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(v[0] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(v[2]).epsilon(0).margin(1e-7)); @@ -71,11 +77,12 @@ CATCH_TEST_CASE("align_ref1") CATCH_TEST_CASE("aim_at_ref1") { - cml::quaterniond q; cml::quaternion_rotation_aim_at( - q, cml::vector3d(0.,0.,0.), cml::vector3d(0., 0., 1.), - cml::vector3d(1., 0., 0.)); - cml::matrix33d M; cml::matrix_rotation_quaternion(M, q); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + cml::quaterniond q; + cml::quaternion_rotation_aim_at(q, cml::vector3d(0., 0., 0.), + cml::vector3d(0., 0., 1.), cml::vector3d(1., 0., 0.)); + cml::matrix33d M; + cml::matrix_rotation_quaternion(M, q); + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(v[0] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(v[2]).epsilon(0).margin(1e-7)); @@ -84,10 +91,11 @@ CATCH_TEST_CASE("aim_at_ref1") CATCH_TEST_CASE("euler1") { cml::quaterniond q; - cml::quaternion_rotation_euler( - q, cml::rad(90.), 0., 0., cml::euler_order_xyz); - cml::matrix33d M; cml::matrix_rotation_quaternion(M, q); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + cml::quaternion_rotation_euler(q, cml::rad(90.), 0., 0., + cml::euler_order_xyz); + cml::matrix33d M; + cml::matrix_rotation_quaternion(M, q); + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(0 == Approx(v[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(v[2] == Approx(1.).epsilon(1e-12)); @@ -96,10 +104,11 @@ CATCH_TEST_CASE("euler1") CATCH_TEST_CASE("euler2") { cml::quaterniond q; - cml::quaternion_rotation_euler( - q, cml::vector3d(cml::rad(90.), 0., 0.), cml::euler_order_xyz); - cml::matrix33d M; cml::matrix_rotation_quaternion(M, q); - auto v = M*cml::vector3d(0., 1., 0.); // 0,0,1 + cml::quaternion_rotation_euler(q, cml::vector3d(cml::rad(90.), 0., 0.), + cml::euler_order_xyz); + cml::matrix33d M; + cml::matrix_rotation_quaternion(M, q); + auto v = M * cml::vector3d(0., 1., 0.); // 0,0,1 CATCH_CHECK(0 == Approx(v[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(v[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(v[2] == Approx(1.).epsilon(1e-12)); @@ -108,8 +117,8 @@ CATCH_TEST_CASE("euler2") CATCH_TEST_CASE("to_axis_angle1") { cml::quaterniond q; - cml::quaternion_rotation_axis_angle( - q, cml::vector3d(1., 2., 3.).normalize(), cml::rad(23.)); + cml::quaternion_rotation_axis_angle(q, cml::vector3d(1., 2., 3.).normalize(), + cml::rad(23.)); cml::vector3d axis; double angle; @@ -123,12 +132,12 @@ CATCH_TEST_CASE("to_axis_angle1") CATCH_TEST_CASE("to_axis_angle_tuple1") { cml::quaterniond q; - cml::quaternion_rotation_axis_angle( - q, cml::vector3d(1., 2., 3.).normalize(), cml::rad(23.)); + cml::quaternion_rotation_axis_angle(q, cml::vector3d(1., 2., 3.).normalize(), + cml::rad(23.)); cml::vector3d axis; double angle; - std::tie(axis,angle) = cml::quaternion_to_axis_angle(q); + std::tie(axis, angle) = cml::quaternion_to_axis_angle(q); CATCH_CHECK(axis[0] == Approx(0.2672612419124244).epsilon(1e-12)); CATCH_CHECK(axis[1] == Approx(0.53452248382484879).epsilon(1e-12)); @@ -138,8 +147,8 @@ CATCH_TEST_CASE("to_axis_angle_tuple1") CATCH_TEST_CASE("to_euler1") { cml::quaterniond q; - cml::quaternion_rotation_euler( - q, cml::rad(22.), cml::rad(10.), cml::rad(89.9), cml::euler_order_xyz); + cml::quaternion_rotation_euler(q, cml::rad(22.), cml::rad(10.), + cml::rad(89.9), cml::euler_order_xyz); cml::vector3d v; cml::quaternion_to_euler(q, v[0], v[1], v[2], cml::euler_order_xyz); @@ -152,8 +161,8 @@ CATCH_TEST_CASE("to_euler1") CATCH_TEST_CASE("to_euler2") { cml::quaterniond q; - cml::quaternion_rotation_euler( - q, cml::rad(22.), cml::rad(10.), cml::rad(89.9), cml::euler_order_xyx); + cml::quaternion_rotation_euler(q, cml::rad(22.), cml::rad(10.), + cml::rad(89.9), cml::euler_order_xyx); cml::vector3d v; cml::quaternion_to_euler(q, v[0], v[1], v[2], cml::euler_order_xyx); @@ -166,8 +175,8 @@ CATCH_TEST_CASE("to_euler2") CATCH_TEST_CASE("to_euler_vector1") { cml::quaterniond q; - cml::quaternion_rotation_euler( - q, cml::rad(22.), cml::rad(10.), cml::rad(89.9), cml::euler_order_xyz); + cml::quaternion_rotation_euler(q, cml::rad(22.), cml::rad(10.), + cml::rad(89.9), cml::euler_order_xyz); auto v = cml::quaternion_to_euler(q, cml::euler_order_xyz); CATCH_CHECK(v[0] == Approx(cml::rad(22.)).epsilon(1e-12)); @@ -178,14 +187,11 @@ CATCH_TEST_CASE("to_euler_vector1") CATCH_TEST_CASE("to_euler_vector2") { cml::quaterniond q; - cml::quaternion_rotation_euler( - q, cml::rad(22.), cml::rad(10.), cml::rad(89.9), cml::euler_order_xyz); + cml::quaternion_rotation_euler(q, cml::rad(22.), cml::rad(10.), + cml::rad(89.9), cml::euler_order_xyz); auto v = cml::quaternion_to_euler(q, cml::euler_order_xyz); CATCH_CHECK(v[0] == Approx(cml::rad(22.)).epsilon(1e-12)); CATCH_CHECK(v[1] == Approx(cml::rad(10.)).epsilon(1e-12)); CATCH_CHECK(v[2] == Approx(cml::rad(89.9)).epsilon(1e-12)); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/random_unit1.cpp b/tests/mathlib/random_unit1.cpp index e37235f..12df5d4 100644 --- a/tests/mathlib/random_unit1.cpp +++ b/tests/mathlib/random_unit1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include @@ -32,24 +30,21 @@ CATCH_TEST_CASE("random_unit2") CATCH_TEST_CASE("random_cone1") { - cml::vector2d n, d(1.,0.); + cml::vector2d n, d(1., 0.); cml::random_unit(n, d, cml::rad(15.)); CATCH_CHECK(n.length_squared() == Approx(1.).epsilon(1e-12)); } CATCH_TEST_CASE("random_cone2") { - cml::vector3d n, d(0.,0.,1.); + cml::vector3d n, d(0., 0., 1.); cml::random_unit(n, d, cml::rad(30.)); CATCH_CHECK(n.length_squared() == Approx(1.).epsilon(1e-12)); } CATCH_TEST_CASE("random_cone3") { - cml::vector4d n, d(0.,0.,0.,1.); + cml::vector4d n, d(0., 0., 0., 1.); cml::random_unit(n, d, cml::rad(60.)); CATCH_CHECK(n.length_squared() == Approx(1.).epsilon(1e-12)); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/vector_angle1.cpp b/tests/mathlib/vector_angle1.cpp index 41c18bb..aeb2033 100644 --- a/tests/mathlib/vector_angle1.cpp +++ b/tests/mathlib/vector_angle1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -13,57 +11,52 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("signed_2D_1") { auto v1 = cml::vector2d(1., 0.); auto v2 = cml::vector2d(0., 1.); - auto a = cml::signed_angle_2D(v1,v2); - CATCH_CHECK(a == Approx(M_PI/2.).epsilon(1e-12)); + auto a = cml::signed_angle_2D(v1, v2); + CATCH_CHECK(a == Approx(M_PI / 2.).epsilon(1e-12)); } CATCH_TEST_CASE("signed_2D_2") { auto v1 = cml::vector2d(1., 0.); auto v2 = cml::vector2d(0., 1.); - auto a = cml::signed_angle_2D(v2,v1); - CATCH_CHECK(a == Approx(- M_PI/2.).epsilon(1e-12)); + auto a = cml::signed_angle_2D(v2, v1); + CATCH_CHECK(a == Approx(-M_PI / 2.).epsilon(1e-12)); } CATCH_TEST_CASE("unsigned_2D_2") { auto v1 = cml::vector2d(1., 0.); auto v2 = cml::vector2d(0., 1.); - auto a = cml::unsigned_angle_2D(v2,v1); - CATCH_CHECK(a == Approx(M_PI/2.).epsilon(1e-12)); + auto a = cml::unsigned_angle_2D(v2, v1); + CATCH_CHECK(a == Approx(M_PI / 2.).epsilon(1e-12)); } - CATCH_TEST_CASE("signed_3D_1") { auto v1 = cml::vector3d(1., 0., 0.); auto v2 = cml::vector3d(0., 1., 0.); auto reference = cml::vector3d(0., 0., 1.); - auto a = cml::signed_angle(v1,v2, reference); - CATCH_CHECK(a == Approx(M_PI/2.).epsilon(1e-12)); + auto a = cml::signed_angle(v1, v2, reference); + CATCH_CHECK(a == Approx(M_PI / 2.).epsilon(1e-12)); } CATCH_TEST_CASE("signed_3D_2") { auto v1 = cml::vector3d(1., 0., 0.); auto v2 = cml::vector3d(0., 1., 0.); - auto reference = - cml::vector3d(0., 0., 1.); + auto reference = -cml::vector3d(0., 0., 1.); auto a = cml::signed_angle(v1, v2, reference); - CATCH_CHECK(a == Approx(- M_PI/2.).epsilon(1e-12)); + CATCH_CHECK(a == Approx(-M_PI / 2.).epsilon(1e-12)); } CATCH_TEST_CASE("unsigned_3D_1") { auto v1 = cml::vector3d(1., 0., 0.); auto v2 = cml::vector3d(0., 1., 0.); - auto a = cml::unsigned_angle(v1,v2); - CATCH_CHECK(a == Approx(M_PI/2.).epsilon(1e-12)); + auto a = cml::unsigned_angle(v1, v2); + CATCH_CHECK(a == Approx(M_PI / 2.).epsilon(1e-12)); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/vector_misc1.cpp b/tests/mathlib/vector_misc1.cpp index 1f80e0c..5f9a15d 100644 --- a/tests/mathlib/vector_misc1.cpp +++ b/tests/mathlib/vector_misc1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include @@ -39,6 +37,3 @@ CATCH_TEST_CASE("city_block1") auto c = cml::manhattan_distance(v1, v2); CATCH_CHECK(c == Approx(5.).epsilon(1e-12)); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/vector_rotation1.cpp b/tests/mathlib/vector_rotation1.cpp index 58bd5ca..ea988d2 100644 --- a/tests/mathlib/vector_rotation1.cpp +++ b/tests/mathlib/vector_rotation1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -12,28 +10,23 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("rotation 3D, world_axis1") { - auto vx = cml::rotate_vector( - cml::vector3d(0., 1., 0.), cml::vector3d(1., 0., 0.), cml::rad(90.)); + auto vx = cml::rotate_vector(cml::vector3d(0., 1., 0.), + cml::vector3d(1., 0., 0.), cml::rad(90.)); CATCH_CHECK(0 == Approx(vx[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(vx[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(vx[2] == Approx(1.).epsilon(1e-12)); - auto vy = cml::rotate_vector( - cml::vector3d(-1., 0., 0.), cml::vector3d(0., 1., 0.), cml::rad(90.)); + auto vy = cml::rotate_vector(cml::vector3d(-1., 0., 0.), + cml::vector3d(0., 1., 0.), cml::rad(90.)); CATCH_CHECK(0 == Approx(vy[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(0 == Approx(vy[1]).epsilon(0).margin(1e-7)); CATCH_CHECK(vy[2] == Approx(1.).epsilon(1e-12)); - auto vz = cml::rotate_vector( - cml::vector3d(1., 0., 0.), cml::vector3d(0., 0., 1.), cml::rad(90.)); + auto vz = cml::rotate_vector(cml::vector3d(1., 0., 0.), + cml::vector3d(0., 0., 1.), cml::rad(90.)); CATCH_CHECK(0 == Approx(vz[0]).epsilon(0).margin(1e-7)); CATCH_CHECK(vz[1] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(0 == Approx(vz[2]).epsilon(0).margin(1e-7)); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/mathlib/vector_transform1.cpp b/tests/mathlib/vector_transform1.cpp index 5a61084..eac4998 100644 --- a/tests/mathlib/vector_transform1.cpp +++ b/tests/mathlib/vector_transform1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -13,14 +11,11 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("transform 2D, vector1") { auto v = cml::vector2d(1., 1.); - auto M = cml::matrix22d( - 1., 2., - 0., 1.); - auto w = cml::transform_vector_2D(M,v); + auto M = cml::matrix22d(1., 2., 0., 1.); + auto w = cml::transform_vector_2D(M, v); CATCH_CHECK(w[0] == Approx(3.).epsilon(1e-12)); CATCH_CHECK(w[1] == Approx(1.).epsilon(1e-12)); } @@ -28,10 +23,8 @@ CATCH_TEST_CASE("transform 2D, vector1") CATCH_TEST_CASE("transform 2D, vector2") { auto v = cml::vector2d(1., 1.); - auto M = cml::matrix22d_r( - 1., 2., - 0., 1.); - auto w = cml::transform_vector_2D(M,v); + auto M = cml::matrix22d_r(1., 2., 0., 1.); + auto w = cml::transform_vector_2D(M, v); CATCH_CHECK(w[0] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(w[1] == Approx(3.).epsilon(1e-12)); } @@ -39,12 +32,8 @@ CATCH_TEST_CASE("transform 2D, vector2") CATCH_TEST_CASE("transform 2D, point1") { auto p = cml::vector2d(2., 2.); - auto M = cml::matrix33d( - 1., 0., 1., - 0., 1., 0., - 0., 0., 2. - ); - auto q = cml::transform_point_2D(M,p); + auto M = cml::matrix33d(1., 0., 1., 0., 1., 0., 0., 0., 2.); + auto q = cml::transform_point_2D(M, p); CATCH_CHECK(q[0] == Approx(3.).epsilon(1e-12)); CATCH_CHECK(q[1] == Approx(2.).epsilon(1e-12)); } @@ -52,27 +41,17 @@ CATCH_TEST_CASE("transform 2D, point1") CATCH_TEST_CASE("transform 2D, point2") { auto p = cml::vector2d(2., 2.); - auto M = cml::matrix33d_r( - 1., 0., 0., - 0., 1., 0., - 1., 0., 2. - ); - auto q = cml::transform_point_2D(M,p); + auto M = cml::matrix33d_r(1., 0., 0., 0., 1., 0., 1., 0., 2.); + auto q = cml::transform_point_2D(M, p); CATCH_CHECK(q[0] == Approx(3.).epsilon(1e-12)); CATCH_CHECK(q[1] == Approx(2.).epsilon(1e-12)); } - - - CATCH_TEST_CASE("transform 3D, vector1") { auto v = cml::vector3d(1., 1., 1.); - auto M = cml::matrix33d( - 1., 0., 2., - 0., 1., 0., - 0., 0., 1.); - auto w = cml::transform_vector(M,v); + auto M = cml::matrix33d(1., 0., 2., 0., 1., 0., 0., 0., 1.); + auto w = cml::transform_vector(M, v); CATCH_CHECK(w[0] == Approx(3.).epsilon(1e-12)); CATCH_CHECK(w[1] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(w[2] == Approx(1.).epsilon(1e-12)); @@ -81,11 +60,8 @@ CATCH_TEST_CASE("transform 3D, vector1") CATCH_TEST_CASE("transform 3D, vector2") { auto v = cml::vector3d(1., 1., 1.); - auto M = cml::matrix33d_r( - 1., 0., 2., - 0., 1., 0., - 0., 0., 1.); - auto w = cml::transform_vector(M,v); + auto M = cml::matrix33d_r(1., 0., 2., 0., 1., 0., 0., 0., 1.); + auto w = cml::transform_vector(M, v); CATCH_CHECK(w[0] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(w[1] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(w[2] == Approx(3.).epsilon(1e-12)); @@ -94,13 +70,9 @@ CATCH_TEST_CASE("transform 3D, vector2") CATCH_TEST_CASE("transform 3D, point1") { auto p = cml::vector3d(2., 2., 2.); - auto M = cml::matrix44d( - 1., 0., 0., 1., - 0., 1., 0., 0., - 0., 0., 1., 0., - 0., 0., 0., 2. - ); - auto q = cml::transform_point(M,p); + auto M = cml::matrix44d(1., 0., 0., 1., 0., 1., 0., 0., 0., 0., 1., 0., 0., + 0., 0., 2.); + auto q = cml::transform_point(M, p); CATCH_CHECK(q[0] == Approx(3.).epsilon(1e-12)); CATCH_CHECK(q[1] == Approx(2.).epsilon(1e-12)); CATCH_CHECK(q[2] == Approx(2.).epsilon(1e-12)); @@ -109,13 +81,9 @@ CATCH_TEST_CASE("transform 3D, point1") CATCH_TEST_CASE("transform 3D, point2") { auto p = cml::vector3d(2., 2., 2.); - auto M = cml::matrix44d_r( - 1., 0., 0., 0., - 0., 1., 0., 0., - 0., 0., 1., 0., - 1., 0., 0., 2. - ); - auto q = cml::transform_point(M,p); + auto M = cml::matrix44d_r(1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1., 0., 1., + 0., 0., 2.); + auto q = cml::transform_point(M, p); CATCH_CHECK(q[0] == Approx(3.).epsilon(1e-12)); CATCH_CHECK(q[1] == Approx(2.).epsilon(1e-12)); CATCH_CHECK(q[2] == Approx(2.).epsilon(1e-12)); @@ -124,13 +92,9 @@ CATCH_TEST_CASE("transform 3D, point2") CATCH_TEST_CASE("transform 3D, hvector1") { auto v = cml::vector4d(1., 1., 1., 0.); - auto M = cml::matrix44d( - 1., 2., 3., 4., - 0., 1., 0., 0., - 0., 0., 1., 0., - 0., 0., 0., 1. - ); - auto w = cml::transform_vector_4D(M,v); + auto M = cml::matrix44d(1., 2., 3., 4., 0., 1., 0., 0., 0., 0., 1., 0., 0., + 0., 0., 1.); + auto w = cml::transform_vector_4D(M, v); CATCH_CHECK(w[0] == Approx(6.).epsilon(1e-12)); CATCH_CHECK(w[1] == 1.); CATCH_CHECK(w[2] == 1.); @@ -140,13 +104,9 @@ CATCH_TEST_CASE("transform 3D, hvector1") CATCH_TEST_CASE("transform 3D, hvector2") { auto v = cml::vector4d(1., 1., 1., 0.); - auto M = cml::matrix44d_r( - 1., 2., 3., 4., - 0., 1., 0., 0., - 0., 0., 1., 0., - 0., 0., 0., 1. - ); - auto w = cml::transform_vector_4D(M,v); + auto M = cml::matrix44d_r(1., 2., 3., 4., 0., 1., 0., 0., 0., 0., 1., 0., 0., + 0., 0., 1.); + auto w = cml::transform_vector_4D(M, v); CATCH_CHECK(w[0] == 1.); CATCH_CHECK(w[1] == Approx(3.).epsilon(1e-12)); CATCH_CHECK(w[2] == Approx(4.).epsilon(1e-12)); @@ -156,13 +116,9 @@ CATCH_TEST_CASE("transform 3D, hvector2") CATCH_TEST_CASE("transform 3D, hpoint1") { auto p = cml::vector3d(2., 2., 2.); - auto M = cml::matrix44d( - 1., 0., 0., 1., - 0., 1., 0., 0., - 0., 0., 1., 0., - 0., 0., 0., 2. - ); - auto q = cml::transform_point_4D(M,p); + auto M = cml::matrix44d(1., 0., 0., 1., 0., 1., 0., 0., 0., 0., 1., 0., 0., + 0., 0., 2.); + auto q = cml::transform_point_4D(M, p); CATCH_CHECK(q[0] == Approx(1.5).epsilon(1e-12)); CATCH_CHECK(q[1] == Approx(1.).epsilon(1e-12)); CATCH_CHECK(q[2] == Approx(1.).epsilon(1e-12)); @@ -171,18 +127,10 @@ CATCH_TEST_CASE("transform 3D, hpoint1") CATCH_TEST_CASE("transform 3D, hpoint2") { auto p = cml::vector3d(2., 2., 2.); - auto M = cml::matrix44d_r( - 1., 0., 0., 1., - 0., 1., 0., 0., - 0., 0., 1., 0., - 0., 0., 0., 2. - ); - auto q = cml::transform_point_4D(M,p); + auto M = cml::matrix44d_r(1., 0., 0., 1., 0., 1., 0., 0., 0., 0., 1., 0., 0., + 0., 0., 2.); + auto q = cml::transform_point_4D(M, p); CATCH_CHECK(q[0] == Approx(.5).epsilon(1e-12)); CATCH_CHECK(q[1] == Approx(.5).epsilon(1e-12)); CATCH_CHECK(q[2] == Approx(.5).epsilon(1e-12)); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/CMakeLists.txt b/tests/matrix/CMakeLists.txt index 109ed05..403209c 100644 --- a/tests/matrix/CMakeLists.txt +++ b/tests/matrix/CMakeLists.txt @@ -1,9 +1,8 @@ -# -*- cmake -*- ----------------------------------------------------------- +# *------------------------------------------------------------------------- # @@COPYRIGHT@@ -#*------------------------------------------------------------------------- +# *------------------------------------------------------------------------- -project(CML_Testing_Matrix) -set(CML_CURRENT_TEST_GROUP "Matrix") +set(CML_TEST_GROUP "matrix") cml_add_test(matrix_promotion1) cml_add_test(fixed_compiled_matrix1) diff --git a/tests/matrix/basis1.cpp b/tests/matrix/basis1.cpp index 6f97621..9b996c0 100644 --- a/tests/matrix/basis1.cpp +++ b/tests/matrix/basis1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -17,163 +15,114 @@ CATCH_TEST_CASE("fixed basis1") { // col basis: - auto M = cml::matrix44d( - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - ); + auto M = cml::matrix44d(1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., + 1., 36., 81., 100.); auto basis = cml::basis(M, 1); CATCH_CHECK(basis.size() == 4); - for(int i = 0; i < basis.size(); ++ i) - CATCH_CHECK(basis[i] == M.basis_element(1,i)); + for(int i = 0; i < basis.size(); ++i) + CATCH_CHECK(basis[i] == M.basis_element(1, i)); } CATCH_TEST_CASE("fixed basis2") { - auto M = cml::matrix44d_r( - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - ); + auto M = cml::matrix44d_r(1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., + 1., 36., 81., 100.); auto basis = cml::basis(M, 2); CATCH_CHECK(basis.size() == 4); - for(int i = 0; i < basis.size(); ++ i) - CATCH_CHECK(basis[i] == M.basis_element(2,i)); + for(int i = 0; i < basis.size(); ++i) + CATCH_CHECK(basis[i] == M.basis_element(2, i)); } CATCH_TEST_CASE("fixed external basis1") { double avM[16] = { - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - }; + 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., 36., 81., 100.}; auto M = cml::external44d(avM); auto basis = cml::basis(M, 1); CATCH_CHECK(basis.size() == 4); - for(int i = 0; i < basis.size(); ++ i) - CATCH_CHECK(basis[i] == M.basis_element(1,i)); + for(int i = 0; i < basis.size(); ++i) + CATCH_CHECK(basis[i] == M.basis_element(1, i)); } CATCH_TEST_CASE("fixed external basis2") { double avM[16] = { - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - }; + 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., 36., 81., 100.}; auto M = cml::external44d(avM); auto basis = cml::basis(M, 2); CATCH_CHECK(basis.size() == 4); - for(int i = 0; i < basis.size(); ++ i) - CATCH_CHECK(basis[i] == M.basis_element(2,i)); + for(int i = 0; i < basis.size(); ++i) + CATCH_CHECK(basis[i] == M.basis_element(2, i)); } CATCH_TEST_CASE("dynamic external basis1") { double avM[16] = { - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - }; - auto M = cml::externalmnd(4,4, avM); + 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., 36., 81., 100.}; + auto M = cml::externalmnd(4, 4, avM); auto basis = cml::basis(M, 1); CATCH_CHECK(basis.size() == 4); - for(int i = 0; i < basis.size(); ++ i) - CATCH_CHECK(basis[i] == M.basis_element(1,i)); + for(int i = 0; i < basis.size(); ++i) + CATCH_CHECK(basis[i] == M.basis_element(1, i)); } CATCH_TEST_CASE("dynamic external basis2") { double avM[16] = { - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - }; - auto M = cml::externalmnd(4,4, avM); + 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., 36., 81., 100.}; + auto M = cml::externalmnd(4, 4, avM); auto basis = cml::basis(M, 2); CATCH_CHECK(basis.size() == 4); - for(int i = 0; i < basis.size(); ++ i) - CATCH_CHECK(basis[i] == M.basis_element(2,i)); + for(int i = 0; i < basis.size(); ++i) + CATCH_CHECK(basis[i] == M.basis_element(2, i)); } CATCH_TEST_CASE("dynamic basis1") { - auto M = cml::matrixd( - 4,4, - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - ); + auto M = cml::matrixd(4, 4, 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., + 36., 1., 36., 81., 100.); auto basis = cml::basis(M, 1); CATCH_CHECK(basis.size() == 4); - for(int i = 0; i < basis.size(); ++ i) - CATCH_CHECK(basis[i] == M.basis_element(1,i)); + for(int i = 0; i < basis.size(); ++i) + CATCH_CHECK(basis[i] == M.basis_element(1, i)); } CATCH_TEST_CASE("dynamic basis2") { - auto M = cml::matrixd( - 4,4, - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - ); + auto M = cml::matrixd(4, 4, 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., + 36., 1., 36., 81., 100.); auto basis = cml::basis(M, 2); CATCH_CHECK(basis.size() == 4); - for(int i = 0; i < basis.size(); ++ i) - CATCH_CHECK(basis[i] == M.basis_element(2,i)); + for(int i = 0; i < basis.size(); ++i) + CATCH_CHECK(basis[i] == M.basis_element(2, i)); } CATCH_TEST_CASE("mixed basis3") { - auto M1 = cml::matrix22d( - 1., 2., - 3., 4. - ); - auto M2 = cml::matrix22d( - 5., 6., - 7., 8. - ); + auto M1 = cml::matrix22d(1., 2., 3., 4.); + auto M2 = cml::matrix22d(5., 6., 7., 8.); auto M = M1 - M2; - auto basis = cml::basis(M,1); - for(int i = 0; i < basis.size(); ++ i) - CATCH_CHECK(basis[i] == M.basis_element(i,1)); + auto basis = cml::basis(M, 1); + for(int i = 0; i < basis.size(); ++i) + CATCH_CHECK(basis[i] == M.basis_element(i, 1)); } CATCH_TEST_CASE("mixed basis2") { - auto M1 = cml::matrix22d( - 1., 2., - 3., 4. - ); - auto M2 = cml::matrix22d( - 5., 6., - 7., 8. - ); + auto M1 = cml::matrix22d(1., 2., 3., 4.); + auto M2 = cml::matrix22d(5., 6., 7., 8.); auto M = M1 - M2; - auto basis = cml::basis(M,1); - for(int i = 0; i < basis.size(); ++ i) - CATCH_CHECK(basis[i] == M.basis_element(1,i)); + auto basis = cml::basis(M, 1); + for(int i = 0; i < basis.size(); ++i) + CATCH_CHECK(basis[i] == M.basis_element(1, i)); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/determinant1.cpp b/tests/matrix/determinant1.cpp index ee28182..0d5ff0b 100644 --- a/tests/matrix/determinant1.cpp +++ b/tests/matrix/determinant1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include @@ -17,62 +15,39 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, det_2x2") { - auto M = cml::matrix22d( - 2., -1., - 3., 3. - ); + auto M = cml::matrix22d(2., -1., 3., 3.); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(9).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, det_3x3") { - auto M = cml::matrix33d( - 2., 0., 2., - 3., 3., 4., - 5., 5., 4. - ); + auto M = cml::matrix33d(2., 0., 2., 3., 3., 4., 5., 5., 4.); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(-16).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, det_4x4") { - auto M = cml::matrix44d( - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto M = cml::matrix44d(2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., + -2., 3.4, -1.); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(-120).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, det_5x5") { - auto M = cml::matrix>( - 2., 0., 2., .5, 2., - 3., 3., 4., -2., -1., - 5., 5., 4., 2., 1., - -1., -2., 3., -1., 5., - 1., 6., 7., .5, 1. - ); + auto M = cml::matrix>(2., 0., 2., .5, 2., 3., 3., 4., + -2., -1., 5., 5., 4., 2., 1., -1., -2., 3., -1., 5., 1., 6., 7., .5, 1.); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(464).epsilon(1e-12)); } - - - CATCH_TEST_CASE("fixed external, det_2x2") { - double avM[] = { - 2., -1., - 3., 3. - }; + double avM[] = {2., -1., 3., 3.}; auto M = cml::external22d(avM); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(9).epsilon(1e-12)); @@ -80,11 +55,7 @@ CATCH_TEST_CASE("fixed external, det_2x2") CATCH_TEST_CASE("fixed external, det_3x3") { - double avM[] = { - 2., 0., 2., - 3., 3., 4., - 5., 5., 4. - }; + double avM[] = {2., 0., 2., 3., 3., 4., 5., 5., 4.}; auto M = cml::external33d(avM); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(-16).epsilon(1e-12)); @@ -93,11 +64,7 @@ CATCH_TEST_CASE("fixed external, det_3x3") CATCH_TEST_CASE("fixed external, det_4x4") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto M = cml::external44d(avM); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(-120).epsilon(1e-12)); @@ -105,40 +72,25 @@ CATCH_TEST_CASE("fixed external, det_4x4") CATCH_TEST_CASE("fixed external, det_5x5") { - double avM[] = { - 2., 0., 2., .5, 2., - 3., 3., 4., -2., -1., - 5., 5., 4., 2., 1., - -1., -2., 3., -1., 5., - 1., 6., 7., .5, 1. - }; - auto M = cml::matrix>(avM); + double avM[] = {2., 0., 2., .5, 2., 3., 3., 4., -2., -1., 5., 5., 4., 2., 1., + -1., -2., 3., -1., 5., 1., 6., 7., .5, 1.}; + auto M = cml::matrix>(avM); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(464).epsilon(1e-12)); } - - - CATCH_TEST_CASE("dynamic external, det_2x2") { - double avM[] = { - 2., -1., - 3., 3. - }; - auto M = cml::externalmnd(2,2, avM); + double avM[] = {2., -1., 3., 3.}; + auto M = cml::externalmnd(2, 2, avM); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(9).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic external, det_3x3") { - double avM[] = { - 2., 0., 2., - 3., 3., 4., - 5., 5., 4. - }; - auto M = cml::externalmnd(3,3, avM); + double avM[] = {2., 0., 2., 3., 3., 4., 5., 5., 4.}; + auto M = cml::externalmnd(3, 3, avM); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(-16).epsilon(1e-12)); } @@ -146,83 +98,48 @@ CATCH_TEST_CASE("dynamic external, det_3x3") CATCH_TEST_CASE("dynamic external, det_4x4") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; - auto M = cml::externalmnd(4,4, avM); + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; + auto M = cml::externalmnd(4, 4, avM); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(-120).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic external, det_5x5") { - double avM[] = { - 2., 0., 2., .5, 2., - 3., 3., 4., -2., -1., - 5., 5., 4., 2., 1., - -1., -2., 3., -1., 5., - 1., 6., 7., .5, 1. - }; - auto M = cml::matrix>(5,5, avM); + double avM[] = {2., 0., 2., .5, 2., 3., 3., 4., -2., -1., 5., 5., 4., 2., 1., + -1., -2., 3., -1., 5., 1., 6., 7., .5, 1.}; + auto M = cml::matrix>(5, 5, avM); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(464).epsilon(1e-12)); } - - - CATCH_TEST_CASE("dynamic, det_2x2") { - auto M = cml::matrixd( - 2,2, - 2., -1., - 3., 3. - ); + auto M = cml::matrixd(2, 2, 2., -1., 3., 3.); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(9).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, det_3x3") { - auto M = cml::matrixd( - 3,3, - 2., 0., 2., - 3., 3., 4., - 5., 5., 4. - ); + auto M = cml::matrixd(3, 3, 2., 0., 2., 3., 3., 4., 5., 5., 4.); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(-16).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, det_4x4") { - auto M = cml::matrixd( - 4,4, - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto M = cml::matrixd(4, 4, 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., + -1., -2., 3.4, -1.); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(-120).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, det_5x5") { - auto M = cml::matrix>( - 5,5, - 2., 0., 2., .5, 2., - 3., 3., 4., -2., -1., - 5., 5., 4., 2., 1., - -1., -2., 3., -1., 5., - 1., 6., 7., .5, 1. - ); + auto M = cml::matrix>(5, 5, 2., 0., 2., .5, 2., 3., 3., + 4., -2., -1., 5., 5., 4., 2., 1., -1., -2., 3., -1., 5., 1., 6., 7., .5, + 1.); auto result = cml::determinant(M); CATCH_CHECK(result == Approx(464).epsilon(1e-12)); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/dynamic_allocated_matrix1.cpp b/tests/matrix/dynamic_allocated_matrix1.cpp index e1f326b..f51d620 100644 --- a/tests/matrix/dynamic_allocated_matrix1.cpp +++ b/tests/matrix/dynamic_allocated_matrix1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -12,389 +10,313 @@ CATCH_TEST_CASE("typecheck") { - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); + CATCH_CHECK((std::is_same::value)); + CATCH_CHECK((std::is_same::value)); + CATCH_CHECK((std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); } CATCH_TEST_CASE("alloc1") { - cml::matrixd M(3,4); + cml::matrixd M(3, 4); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); } CATCH_TEST_CASE("alloc2") { - cml::matrixd_c M(3,4); + cml::matrixd_c M(3, 4); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); } CATCH_TEST_CASE("resize1") { - cml::matrixd M(2,2); + cml::matrixd M(2, 2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - M.resize(3,4); + M.resize(3, 4); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); } CATCH_TEST_CASE("resize2") { - cml::matrixd_c M(2,2); + cml::matrixd_c M(2, 2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - M.resize(3,4); + M.resize(3, 4); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); } CATCH_TEST_CASE("array_construct1") { - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; - cml::matrixd M(3,4, aM); + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; + cml::matrixd M(3, 4, aM); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_construct2") { - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; - cml::matrixd_c M(3,4, aM); + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; + cml::matrixd_c M(3, 4, aM); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_assign1") { - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; - cml::matrixd M(3,4); + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; + cml::matrixd M(3, 4); M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_assign2") { - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; - cml::matrixd_c M(3,4); + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; + cml::matrixd_c M(3, 4); M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_construct1") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrixd M(aM); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_construct2") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrixd_c M(aM); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_temp_construct1") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrixd M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_temp_construct2") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrixd_c M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_assign1") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrixd M; M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_assign2") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrixd_c M; M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("element_construct1") { - cml::matrixd M( - 3, 4, - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - ); + cml::matrixd M(3, 4, 1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("element_construct2") { - cml::matrixd_c M( - 3, 4, - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - ); + cml::matrixd_c M(3, 4, 1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("pointer_construct1") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; - cml::matrixd M(3,4, &aM[0][0]); + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; + cml::matrixd M(3, 4, &aM[0][0]); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("pointer_construct2") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; - cml::matrixd_c M(&aM[0][0], 3,4); + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; + cml::matrixd_c M(&aM[0][0], 3, 4); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_assign1") { - cml::matrixd M(3,4); - M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + cml::matrixd M(3, 4); + M = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_assign2") { - cml::matrixd_c M(3,4); - M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + cml::matrixd_c M(3, 4); + M = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("fill1") { - cml::matrixd M(5,5); + cml::matrixd M(5, 5); M.fill(1.); CATCH_REQUIRE(M.rows() == 5); CATCH_REQUIRE(M.cols() == 5); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(4,4) == 1.); + CATCH_CHECK(M(4, 4) == 1.); } CATCH_TEST_CASE("size_check1") { - cml::matrixd M(3,4); + cml::matrixd M(3, 4); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); - CATCH_REQUIRE_THROWS_AS( - (M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9. - }), cml::incompatible_matrix_size_error); + CATCH_REQUIRE_THROWS_AS((M = {1., 2., 3., 4., 5., 6., 7., 8., 9.}), + cml::incompatible_matrix_size_error); } CATCH_TEST_CASE("size_check2") { - cml::matrixd_c M(3,4); + cml::matrixd_c M(3, 4); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); - CATCH_REQUIRE_THROWS_AS( - (M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9. - }), cml::incompatible_matrix_size_error); + CATCH_REQUIRE_THROWS_AS((M = {1., 2., 3., 4., 5., 6., 7., 8., 9.}), + cml::incompatible_matrix_size_error); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/dynamic_external_matrix1.cpp b/tests/matrix/dynamic_external_matrix1.cpp index 9c841ed..8d2a45a 100644 --- a/tests/matrix/dynamic_external_matrix1.cpp +++ b/tests/matrix/dynamic_external_matrix1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -12,20 +10,20 @@ CATCH_TEST_CASE("typecheck") { - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); } CATCH_TEST_CASE("array_construct1") { - double data[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; - cml::externalmnd M(data, 3,4); + double data[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; + cml::externalmnd M(data, 3, 4); // Note: external<> refers to the wrapped data in the layout assigned to // the matrix. @@ -33,22 +31,17 @@ CATCH_TEST_CASE("array_construct1") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_construct2") { - double data[] = { - 1., 5., 9., - 2., 6., 0., - 3., 7., 0., - 4., 8., 0. - }; - cml::externalmnd_c M(data, 3,4); + double data[] = {1., 5., 9., 2., 6., 0., 3., 7., 0., 4., 8., 0.}; + cml::externalmnd_c M(data, 3, 4); // Note: external<> refers to the wrapped data in the layout assigned to // the matrix. @@ -56,22 +49,18 @@ CATCH_TEST_CASE("array_construct2") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_assign1") { - double data[3*4]; - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; - cml::externalmnd_c M(data, 3,4); + double data[3 * 4]; + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; + cml::externalmnd_c M(data, 3, 4); M = aM; // Note: external<> copies arrays using row-major layout. @@ -79,22 +68,18 @@ CATCH_TEST_CASE("array_assign1") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_assign2") { - double data[3*4]; - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; - cml::externalmnd_c M(data, 3,4); + double data[3 * 4]; + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; + cml::externalmnd_c M(data, 3, 4); M = aM; // Note: external<> copies arrays using row-major layout. @@ -102,20 +87,16 @@ CATCH_TEST_CASE("array_assign2") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_construct1") { - double data[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double data[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::externalmnd M(data); // Note: external<> refers to the wrapped data in the layout assigned to // the matrix. @@ -124,21 +105,16 @@ CATCH_TEST_CASE("array2_construct1") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0][0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_construct2") { - double data[4][3] = { - { 1., 5., 9. }, - { 2., 6., 0. }, - { 3., 7., 0. }, - { 4., 8., 0. } - }; + double data[4][3] = {{1., 5., 9.}, {2., 6., 0.}, {3., 7., 0.}, {4., 8., 0.}}; cml::externalmnd_c M(data); // Note: external<> refers to the wrapped data in the layout assigned to // the matrix. @@ -147,22 +123,18 @@ CATCH_TEST_CASE("array2_construct2") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0][0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_assign1") { - double data[3*4]; - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; - cml::externalmnd_c M(data, 3,4); + double data[3 * 4]; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; + cml::externalmnd_c M(data, 3, 4); M = aM; // Note: external<> copies arrays using row-major layout. @@ -170,22 +142,18 @@ CATCH_TEST_CASE("array2_assign1") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_assign2") { - double data[3*4]; - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; - cml::externalmnd_c M(data, 3,4); + double data[3 * 4]; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; + cml::externalmnd_c M(data, 3, 4); M = aM; // Note: external<> copies arrays using row-major layout. @@ -193,117 +161,98 @@ CATCH_TEST_CASE("array2_assign2") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_assign1") { - double data[3*4]; - cml::externalmnd_c M(data, 3,4); - M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + double data[3 * 4]; + cml::externalmnd_c M(data, 3, 4); + M = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; // Note: external<> copies arrays using row-major layout. CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_assign2") { - double data[3*4]; - cml::externalmnd_c M(data, 3,4); - M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + double data[3 * 4]; + cml::externalmnd_c M(data, 3, 4); + M = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; // Note: external<> copies arrays using row-major layout. CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("fill1") { - double data[5*5]; - cml::externalmnd_c M(data, 5,5); + double data[5 * 5]; + cml::externalmnd_c M(data, 5, 5); M.fill(1.); CATCH_REQUIRE(M.rows() == 5); CATCH_REQUIRE(M.cols() == 5); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(4,4) == 1.); + CATCH_CHECK(M(4, 4) == 1.); } CATCH_TEST_CASE("resize1") { - double data[3*4]; - cml::externalmnd_c M(3,4, data); + double data[3 * 4]; + cml::externalmnd_c M(3, 4, data); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); - CATCH_REQUIRE_NOTHROW(M.resize(4,3)); + CATCH_REQUIRE_NOTHROW(M.resize(4, 3)); } CATCH_TEST_CASE("resize2") { - double data[3*4]; - cml::externalmnd_c M(3,4, data); + double data[3 * 4]; + cml::externalmnd_c M(3, 4, data); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); - CATCH_REQUIRE_THROWS_AS(M.resize(3,3), cml::matrix_size_error); + CATCH_REQUIRE_THROWS_AS(M.resize(3, 3), cml::matrix_size_error); } CATCH_TEST_CASE("size_check1") { - double data[3*4]; - cml::externalmnd_c M(data, 3,4); + double data[3 * 4]; + cml::externalmnd_c M(data, 3, 4); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); - CATCH_REQUIRE_THROWS_AS( - (M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9. - }), cml::incompatible_matrix_size_error); + CATCH_REQUIRE_THROWS_AS((M = {1., 2., 3., 4., 5., 6., 7., 8., 9.}), + cml::incompatible_matrix_size_error); } CATCH_TEST_CASE("size_check2") { - double data[3*4]; - cml::externalmnd_c M(data, 3,4); + double data[3 * 4]; + cml::externalmnd_c M(data, 3, 4); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); - CATCH_REQUIRE_THROWS_AS( - (M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9. - }), cml::incompatible_matrix_size_error); + CATCH_REQUIRE_THROWS_AS((M = {1., 2., 3., 4., 5., 6., 7., 8., 9.}), + cml::incompatible_matrix_size_error); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/fixed_compiled_matrix1.cpp b/tests/matrix/fixed_compiled_matrix1.cpp index 086609f..a600869 100644 --- a/tests/matrix/fixed_compiled_matrix1.cpp +++ b/tests/matrix/fixed_compiled_matrix1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -12,426 +10,341 @@ CATCH_TEST_CASE("typecheck") { - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); + CATCH_CHECK((std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); } CATCH_TEST_CASE("array_construct1") { - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; cml::matrix34d M(aM); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_construct2") { - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; cml::matrix34d_c M(aM); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_temp_construct1") { - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; cml::matrix34d M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_temp_construct2") { - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; cml::matrix34d_c M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_assign1") { - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; cml::matrix34d M; M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_assign2") { - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; cml::matrix34d_c M; M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_construct1") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrix34d M(aM); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_construct2") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrix34d_c M(aM); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_temp_construct1") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrix34d M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_temp_construct2") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrix34d_c M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_assign1") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrix34d M; M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_assign2") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrix34d_c M; M = aM; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("elements_construct1") { - cml::matrix34d M( - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - ); + cml::matrix34d M(1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("element_construct2") { - cml::matrix34d_c M( - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - ); + cml::matrix34d_c M(1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("pointer_construct1") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrix34d M(&aM[0][0]); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("pointer_construct2") { - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::matrix34d_c M(&aM[0][0]); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_construct1") { - cml::matrix34d M { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + cml::matrix34d M{1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_construct2") { - cml::matrix34d_c M { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + cml::matrix34d_c M{1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_temp_construct1") { - cml::matrix34d M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + cml::matrix34d M = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_temp_construct2") { - cml::matrix34d_c M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + cml::matrix34d_c M = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_assign1") { cml::matrix34d M; - M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + M = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_assign2") { cml::matrix34d_c M; - M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + M = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("fill1") @@ -441,7 +354,7 @@ CATCH_TEST_CASE("fill1") CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(2,3) == 1.); + CATCH_CHECK(M(2, 3) == 1.); } CATCH_TEST_CASE("size_check1") @@ -449,12 +362,8 @@ CATCH_TEST_CASE("size_check1") cml::matrix34d M; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); - CATCH_REQUIRE_THROWS_AS( - (M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9. - }), cml::incompatible_matrix_size_error); + CATCH_REQUIRE_THROWS_AS((M = {1., 2., 3., 4., 5., 6., 7., 8., 9.}), + cml::incompatible_matrix_size_error); } CATCH_TEST_CASE("size_check2") @@ -462,13 +371,6 @@ CATCH_TEST_CASE("size_check2") cml::matrix34d_c M; CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); - CATCH_REQUIRE_THROWS_AS( - (M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9. - }), cml::incompatible_matrix_size_error); + CATCH_REQUIRE_THROWS_AS((M = {1., 2., 3., 4., 5., 6., 7., 8., 9.}), + cml::incompatible_matrix_size_error); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/fixed_external_matrix1.cpp b/tests/matrix/fixed_external_matrix1.cpp index 84c61bc..8babf19 100644 --- a/tests/matrix/fixed_external_matrix1.cpp +++ b/tests/matrix/fixed_external_matrix1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -12,19 +10,19 @@ CATCH_TEST_CASE("typecheck") { - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); - CATCH_CHECK((std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); + CATCH_CHECK( + (std::is_same::value)); } CATCH_TEST_CASE("array_construct1") { - double data[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + double data[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; cml::external34d M(data); // Note: external<> refers to the wrapped data in the layout assigned to // the matrix. @@ -33,21 +31,16 @@ CATCH_TEST_CASE("array_construct1") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_construct2") { - double data[] = { - 1., 5., 9., - 2., 6., 0., - 3., 7., 0., - 4., 8., 0. - }; + double data[] = {1., 5., 9., 2., 6., 0., 3., 7., 0., 4., 8., 0.}; cml::external34d_c M(data); // Note: external<> refers to the wrapped data in the layout assigned to // the matrix. @@ -56,21 +49,17 @@ CATCH_TEST_CASE("array_construct2") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_assign1") { - double data[3*4]; - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + double data[3 * 4]; + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; cml::external34d M(data); M = aM; // Note: external<> copies arrays using row-major layout. @@ -79,21 +68,17 @@ CATCH_TEST_CASE("array_assign1") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array_assign2") { - double data[3*4]; - double aM[] = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + double data[3 * 4]; + double aM[] = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; cml::external34d_c M(data); M = aM; // Note: external<> copies arrays using row-major layout. @@ -102,20 +87,16 @@ CATCH_TEST_CASE("array_assign2") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_construct1") { - double data[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double data[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::external34d M(data); // Note: external<> refers to the wrapped data in the layout assigned to // the matrix. @@ -124,21 +105,16 @@ CATCH_TEST_CASE("array2_construct1") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0][0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_construct2") { - double data[4][3] = { - { 1., 5., 9. }, - { 2., 6., 0. }, - { 3., 7., 0. }, - { 4., 8., 0. } - }; + double data[4][3] = {{1., 5., 9.}, {2., 6., 0.}, {3., 7., 0.}, {4., 8., 0.}}; cml::external34d_c M(data); // Note: external<> refers to the wrapped data in the layout assigned to // the matrix. @@ -147,21 +123,17 @@ CATCH_TEST_CASE("array2_construct2") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0][0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_assign1") { - double data[3*4]; - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double data[3 * 4]; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::external34d M(data); M = aM; // Note: external<> copies arrays using row-major layout. @@ -170,21 +142,17 @@ CATCH_TEST_CASE("array2_assign1") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("array2_assign2") { - double data[3*4]; - double aM[3][4] = { - { 1., 2., 3., 4. }, - { 5., 6., 7., 8. }, - { 9., 0., 0., 0. } - }; + double data[3 * 4]; + double aM[3][4] = {{1., 2., 3., 4.}, {5., 6., 7., 8.}, {9., 0., 0., 0.}}; cml::external34d_c M(data); M = aM; // Note: external<> copies arrays using row-major layout. @@ -193,97 +161,78 @@ CATCH_TEST_CASE("array2_assign2") CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_assign1") { - double data[3*4]; + double data[3 * 4]; cml::external34d M(data); - M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + M = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; // Note: external<> copies arrays using row-major layout. CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("list_assign2") { - double data[3*4]; + double data[3 * 4]; cml::external34d_c M(data); - M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9., 0., 0., 0. - }; + M = {1., 2., 3., 4., 5., 6., 7., 8., 9., 0., 0., 0.}; // Note: external<> copies arrays using row-major layout. CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(2,0) == 9.); - CATCH_CHECK(M(2,1) == 0.); - CATCH_CHECK(M(2,2) == 0.); - CATCH_CHECK(M(2,3) == 0.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(2, 0) == 9.); + CATCH_CHECK(M(2, 1) == 0.); + CATCH_CHECK(M(2, 2) == 0.); + CATCH_CHECK(M(2, 3) == 0.); } CATCH_TEST_CASE("fill1") { - double data[3*4]; + double data[3 * 4]; cml::external34d_c M(data); M.fill(1.); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_CHECK(M.data()[0] == 1.); - CATCH_CHECK(M(2,3) == 1.); + CATCH_CHECK(M(2, 3) == 1.); } CATCH_TEST_CASE("size_check1") { - double data[3*4]; + double data[3 * 4]; cml::external34d M(data); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); - CATCH_REQUIRE_THROWS_AS( - (M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9. - }), cml::incompatible_matrix_size_error); + CATCH_REQUIRE_THROWS_AS((M = {1., 2., 3., 4., 5., 6., 7., 8., 9.}), + cml::incompatible_matrix_size_error); } CATCH_TEST_CASE("size_check2") { - double data[3*4]; + double data[3 * 4]; cml::external34d_c M(data); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE(M.data() == &data[0]); - CATCH_REQUIRE_THROWS_AS( - (M = { - 1., 2., 3., 4., - 5., 6., 7., 8., - 9. - }), cml::incompatible_matrix_size_error); + CATCH_REQUIRE_THROWS_AS((M = {1., 2., 3., 4., 5., 6., 7., 8., 9.}), + cml::incompatible_matrix_size_error); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/lu1.cpp b/tests/matrix/lu1.cpp index 0bc3373..6234d10 100644 --- a/tests/matrix/lu1.cpp +++ b/tests/matrix/lu1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -16,730 +14,520 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, lu1") { - auto M = cml::matrix44d( - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto M = cml::matrix44d(2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., + -2., 3.4, -1.); auto LU = cml::lu(M); - double D = LU(0,0)*LU(1,1)*LU(2,2)*LU(3,3); + double D = LU(0, 0) * LU(1, 1) * LU(2, 2) * LU(3, 3); CATCH_CHECK(D == Approx(-120.).epsilon(1e-12)); - auto expected = cml::matrix44d( - 2., 0., 2., .6, - 1.5, 3., 1., -2.9, - 2.5, (1.+2./3.), -(2.+2./3.), (5.+1./3.), - -.5, (-2./3.), -1.9, 7.5 - ); + auto expected = cml::matrix44d(2., 0., 2., .6, 1.5, 3., 1., -2.9, 2.5, + (1. + 2. / 3.), -(2. + 2. / 3.), (5. + 1. / 3.), -.5, (-2. / 3.), -1.9, + 7.5); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(LU(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(LU(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, lu_pivot1") { - auto M = cml::matrix44d( - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto M = cml::matrix44d(2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., + -2., 3.4, -1.); auto lup = cml::lu_pivot(M); CATCH_CHECK(lup.sign == -1); - auto expected = cml::matrix44d( - 5., 5., 4., 2., - .4, -2., .4, -.2, - -.2, .5, 4., -.5, - .6, 0., .4, -3. - ); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(lup.lu(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(5., 5., 4., 2., .4, -2., .4, -.2, -.2, .5, 4., + -.5, .6, 0., .4, -3.); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(lup.lu(i, j) == Approx(expected(i, j)).epsilon(1e-12)); - std::array order = { 2, 0, 3, 1 }; - for(int i = 0; i < 4; ++ i) - CATCH_CHECK(lup.order[i] == order[i]); + std::array order = {2, 0, 3, 1}; + for(int i = 0; i < 4; ++i) CATCH_CHECK(lup.order[i] == order[i]); } CATCH_TEST_CASE("fixed, lu_pivot2") { - auto M = cml::matrix44d( - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto M = cml::matrix44d(2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., + -2., 3.4, -1.); cml::lu_pivot_result lup(M); cml::lu_pivot(lup); CATCH_CHECK(lup.sign == -1); - auto expected = cml::matrix44d( - 5., 5., 4., 2., - .4, -2., .4, -.2, - -.2, .5, 4., -.5, - .6, 0., .4, -3. - ); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(lup.lu(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(5., 5., 4., 2., .4, -2., .4, -.2, -.2, .5, 4., + -.5, .6, 0., .4, -3.); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(lup.lu(i, j) == Approx(expected(i, j)).epsilon(1e-12)); - std::array order = { 2, 0, 3, 1 }; - for(int i = 0; i < 4; ++ i) - CATCH_CHECK(lup.order[i] == order[i]); + std::array order = {2, 0, 3, 1}; + for(int i = 0; i < 4; ++i) CATCH_CHECK(lup.order[i] == order[i]); } - CATCH_TEST_CASE("fixed, lu_solve1") { - auto A = cml::matrix44d( - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto A = cml::matrix44d(2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., + -2., 3.4, -1.); auto LU = cml::lu(A); auto b = cml::vector4d(5., 1., 8., 3.); auto x = cml::lu_solve(LU, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, lu_solve2") { - auto A = cml::matrix44d( - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto A = cml::matrix44d(2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., + -2., 3.4, -1.); auto LU = cml::lu(A); auto b = cml::vector4d(5., 1., 8., 3.); auto x = cml::vector4d(); cml::lu_solve(LU, x, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } - CATCH_TEST_CASE("fixed, lu_pivot_solve1") { - auto A = cml::matrix44d( - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto A = cml::matrix44d(2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., + -2., 3.4, -1.); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); auto b = cml::vector4d(5., 1., 8., 3.); auto x = cml::lu_solve(lup, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, lu_pivot_solve2") { - auto A = cml::matrix44d( - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto A = cml::matrix44d(2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., + -2., 3.4, -1.); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); auto b = cml::vector4d(5., 1., 8., 3.); auto x = cml::vector4d(); cml::lu_solve(lup, x, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, lu_pivot_solve3") { - auto A = cml::matrix44d( - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto A = cml::matrix44d(2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., + -2., 3.4, -1.); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); auto b = cml::vector4d(5., 1., 8., 3.); auto x = b; cml::lu_solve(lup, x, x); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } - - - CATCH_TEST_CASE("fixed external, lu1") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto M = cml::external44d(avM); auto LU = cml::lu(M); - double D = LU(0,0)*LU(1,1)*LU(2,2)*LU(3,3); + double D = LU(0, 0) * LU(1, 1) * LU(2, 2) * LU(3, 3); CATCH_CHECK(D == Approx(-120.).epsilon(1e-12)); - auto expected = cml::matrix44d( - 2., 0., 2., .6, - 1.5, 3., 1., -2.9, - 2.5, (1.+2./3.), -(2.+2./3.), (5.+1./3.), - -.5, (-2./3.), -1.9, 7.5 - ); + auto expected = cml::matrix44d(2., 0., 2., .6, 1.5, 3., 1., -2.9, 2.5, + (1. + 2. / 3.), -(2. + 2. / 3.), (5. + 1. / 3.), -.5, (-2. / 3.), -1.9, + 7.5); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(LU(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(LU(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("fixed external, lu_pivot1") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto M = cml::external44d(avM); auto lup = cml::lu_pivot(M); CATCH_CHECK(lup.sign == -1); - auto expected = cml::matrix44d( - 5., 5., 4., 2., - .4, -2., .4, -.2, - -.2, .5, 4., -.5, - .6, 0., .4, -3. - ); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(lup.lu(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(5., 5., 4., 2., .4, -2., .4, -.2, -.2, .5, 4., + -.5, .6, 0., .4, -3.); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(lup.lu(i, j) == Approx(expected(i, j)).epsilon(1e-12)); - std::array order = { 2, 0, 3, 1 }; - for(int i = 0; i < 4; ++ i) - CATCH_CHECK(lup.order[i] == order[i]); + std::array order = {2, 0, 3, 1}; + for(int i = 0; i < 4; ++i) CATCH_CHECK(lup.order[i] == order[i]); } CATCH_TEST_CASE("fixed external, lu_pivot2") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto M = cml::external44d(avM); cml::lu_pivot_result lup(M); cml::lu_pivot(lup); CATCH_CHECK(lup.sign == -1); - auto expected = cml::matrix44d( - 5., 5., 4., 2., - .4, -2., .4, -.2, - -.2, .5, 4., -.5, - .6, 0., .4, -3. - ); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(lup.lu(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(5., 5., 4., 2., .4, -2., .4, -.2, -.2, .5, 4., + -.5, .6, 0., .4, -3.); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(lup.lu(i, j) == Approx(expected(i, j)).epsilon(1e-12)); - std::array order = { 2, 0, 3, 1 }; - for(int i = 0; i < 4; ++ i) - CATCH_CHECK(lup.order[i] == order[i]); + std::array order = {2, 0, 3, 1}; + for(int i = 0; i < 4; ++i) CATCH_CHECK(lup.order[i] == order[i]); } - CATCH_TEST_CASE("fixed external, lu_solve1") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto A = cml::external44d(avM); auto LU = cml::lu(A); - double avb[] = { 5., 1., 8., 3. }; + double avb[] = {5., 1., 8., 3.}; auto b = cml::external4d(avb); auto x = cml::lu_solve(LU, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("fixed external, lu_solve2") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto A = cml::external44d(avM); auto LU = cml::lu(A); - double avb[] = { 5., 1., 8., 3. }; + double avb[] = {5., 1., 8., 3.}; auto b = cml::external4d(avb); double avx[4]; auto x = cml::external4d(avx); cml::lu_solve(LU, x, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } - CATCH_TEST_CASE("fixed external, lu_pivot_solve1") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto A = cml::external44d(avM); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); - double avb[] = { 5., 1., 8., 3. }; + double avb[] = {5., 1., 8., 3.}; auto b = cml::external4d(avb); auto x = cml::lu_solve(lup, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("fixed external, lu_pivot_solve2") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto A = cml::external44d(avM); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); - double avb[] = { 5., 1., 8., 3. }; + double avb[] = {5., 1., 8., 3.}; auto b = cml::external4d(avb); double avx[4]; auto x = cml::external4d(avx); cml::lu_solve(lup, x, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("fixed external, lu_pivot_solve3") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto A = cml::external44d(avM); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); - double avb[] = { 5., 1., 8., 3. }; + double avb[] = {5., 1., 8., 3.}; auto b = cml::external4d(avb); - double avx[4] = { 5., 1., 8., 3. }; + double avx[4] = {5., 1., 8., 3.}; auto x = cml::external4d(avx); cml::lu_solve(lup, x, x); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } - - - CATCH_TEST_CASE("dynamic external, lu1") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; - auto M = cml::externalmnd(4,4, avM); + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; + auto M = cml::externalmnd(4, 4, avM); auto LU = cml::lu(M); - double D = LU(0,0)*LU(1,1)*LU(2,2)*LU(3,3); + double D = LU(0, 0) * LU(1, 1) * LU(2, 2) * LU(3, 3); CATCH_CHECK(D == Approx(-120.).epsilon(1e-12)); - auto expected = cml::matrix44d( - 2., 0., 2., .6, - 1.5, 3., 1., -2.9, - 2.5, (1.+2./3.), -(2.+2./3.), (5.+1./3.), - -.5, (-2./3.), -1.9, 7.5 - ); + auto expected = cml::matrix44d(2., 0., 2., .6, 1.5, 3., 1., -2.9, 2.5, + (1. + 2. / 3.), -(2. + 2. / 3.), (5. + 1. / 3.), -.5, (-2. / 3.), -1.9, + 7.5); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(LU(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(LU(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic external, lu_pivot1") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; - auto M = cml::externalmnd(4,4, avM); + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; + auto M = cml::externalmnd(4, 4, avM); auto lup = cml::lu_pivot(M); CATCH_CHECK(lup.sign == -1); - auto expected = cml::matrix44d( - 5., 5., 4., 2., - .4, -2., .4, -.2, - -.2, .5, 4., -.5, - .6, 0., .4, -3. - ); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(lup.lu(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(5., 5., 4., 2., .4, -2., .4, -.2, -.2, .5, 4., + -.5, .6, 0., .4, -3.); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(lup.lu(i, j) == Approx(expected(i, j)).epsilon(1e-12)); - std::array order = { 2, 0, 3, 1 }; - for(int i = 0; i < 4; ++ i) - CATCH_CHECK(lup.order[i] == order[i]); + std::array order = {2, 0, 3, 1}; + for(int i = 0; i < 4; ++i) CATCH_CHECK(lup.order[i] == order[i]); } CATCH_TEST_CASE("dynamic external, lu_pivot2") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; - auto M = cml::externalmnd(4,4, avM); + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; + auto M = cml::externalmnd(4, 4, avM); cml::lu_pivot_result lup(M); cml::lu_pivot(lup); CATCH_CHECK(lup.sign == -1); - auto expected = cml::matrix44d( - 5., 5., 4., 2., - .4, -2., .4, -.2, - -.2, .5, 4., -.5, - .6, 0., .4, -3. - ); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(lup.lu(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(5., 5., 4., 2., .4, -2., .4, -.2, -.2, .5, 4., + -.5, .6, 0., .4, -3.); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(lup.lu(i, j) == Approx(expected(i, j)).epsilon(1e-12)); - std::array order = { 2, 0, 3, 1 }; - for(int i = 0; i < 4; ++ i) - CATCH_CHECK(lup.order[i] == order[i]); + std::array order = {2, 0, 3, 1}; + for(int i = 0; i < 4; ++i) CATCH_CHECK(lup.order[i] == order[i]); } - CATCH_TEST_CASE("dynamic external, lu_solve1") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; - auto A = cml::externalmnd(4,4, avM); + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; + auto A = cml::externalmnd(4, 4, avM); auto LU = cml::lu(A); - double avb[] = { 5., 1., 8., 3. }; + double avb[] = {5., 1., 8., 3.}; auto b = cml::externalnd(4, avb); auto x = cml::lu_solve(LU, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic external, lu_solve2") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto A = cml::external44d(avM); auto LU = cml::lu(A); - double avb[] = { 5., 1., 8., 3. }; + double avb[] = {5., 1., 8., 3.}; auto b = cml::externalnd(4, avb); double avx[4]; auto x = cml::externalnd(4, avx); cml::lu_solve(LU, x, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } - CATCH_TEST_CASE("dynamic external, lu_pivot_solve1") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto A = cml::external44d(avM); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); - double avb[] = { 5., 1., 8., 3. }; + double avb[] = {5., 1., 8., 3.}; auto b = cml::externalnd(4, avb); auto x = cml::lu_solve(lup, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic external, lu_pivot_solve2") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto A = cml::external44d(avM); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); - double avb[] = { 5., 1., 8., 3. }; + double avb[] = {5., 1., 8., 3.}; auto b = cml::externalnd(4, avb); double avx[4]; auto x = cml::externalnd(4, avx); cml::lu_solve(lup, x, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic external, lu_pivot_solve3") { double avM[] = { - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - }; + 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., -1., -2., 3.4, -1.}; auto A = cml::external44d(avM); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); - double avb[] = { 5., 1., 8., 3. }; + double avb[] = {5., 1., 8., 3.}; auto b = cml::externalnd(4, avb); - double avx[] = { 5., 1., 8., 3. }; + double avx[] = {5., 1., 8., 3.}; auto x = cml::externalnd(4, avx); cml::lu_solve(lup, x, x); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } - - - CATCH_TEST_CASE("dynamic, lu1") { - auto M = cml::matrixd( - 4,4, - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto M = cml::matrixd(4, 4, 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., + -1., -2., 3.4, -1.); auto LU = cml::lu(M); - double D = LU(0,0)*LU(1,1)*LU(2,2)*LU(3,3); + double D = LU(0, 0) * LU(1, 1) * LU(2, 2) * LU(3, 3); CATCH_CHECK(D == Approx(-120.).epsilon(1e-12)); - auto expected = cml::matrix44d( - 2., 0., 2., .6, - 1.5, 3., 1., -2.9, - 2.5, (1.+2./3.), -(2.+2./3.), (5.+1./3.), - -.5, (-2./3.), -1.9, 7.5 - ); + auto expected = cml::matrix44d(2., 0., 2., .6, 1.5, 3., 1., -2.9, 2.5, + (1. + 2. / 3.), -(2. + 2. / 3.), (5. + 1. / 3.), -.5, (-2. / 3.), -1.9, + 7.5); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(LU(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(LU(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, lu_pivot1") { - auto M = cml::matrixd( - 4,4, - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto M = cml::matrixd(4, 4, 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., + -1., -2., 3.4, -1.); auto lup = cml::lu_pivot(M); CATCH_CHECK(lup.sign == -1); - auto expected = cml::matrix44d( - 5., 5., 4., 2., - .4, -2., .4, -.2, - -.2, .5, 4., -.5, - .6, 0., .4, -3. - ); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(lup.lu(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(5., 5., 4., 2., .4, -2., .4, -.2, -.2, .5, 4., + -.5, .6, 0., .4, -3.); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(lup.lu(i, j) == Approx(expected(i, j)).epsilon(1e-12)); - std::array order = { 2, 0, 3, 1 }; - for(int i = 0; i < 4; ++ i) - CATCH_CHECK(lup.order[i] == order[i]); + std::array order = {2, 0, 3, 1}; + for(int i = 0; i < 4; ++i) CATCH_CHECK(lup.order[i] == order[i]); } CATCH_TEST_CASE("dynamic, lu_pivot2") { - auto M = cml::matrixd( - 4,4, - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto M = cml::matrixd(4, 4, 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., + -1., -2., 3.4, -1.); cml::lu_pivot_result lup(M); cml::lu_pivot(lup); CATCH_CHECK(lup.sign == -1); - auto expected = cml::matrix44d( - 5., 5., 4., 2., - .4, -2., .4, -.2, - -.2, .5, 4., -.5, - .6, 0., .4, -3. - ); - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(lup.lu(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(5., 5., 4., 2., .4, -2., .4, -.2, -.2, .5, 4., + -.5, .6, 0., .4, -3.); + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(lup.lu(i, j) == Approx(expected(i, j)).epsilon(1e-12)); - std::array order = { 2, 0, 3, 1 }; - for(int i = 0; i < 4; ++ i) - CATCH_CHECK(lup.order[i] == order[i]); + std::array order = {2, 0, 3, 1}; + for(int i = 0; i < 4; ++i) CATCH_CHECK(lup.order[i] == order[i]); } - CATCH_TEST_CASE("dynamic, lu_solve1") { - auto A = cml::matrixd( - 4,4, - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto A = cml::matrixd(4, 4, 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., + -1., -2., 3.4, -1.); auto LU = cml::lu(A); auto b = cml::vectord(5., 1., 8., 3.); auto x = cml::lu_solve(LU, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, lu_solve2") { - auto A = cml::matrixd( - 4,4, - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto A = cml::matrixd(4, 4, 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., + -1., -2., 3.4, -1.); auto LU = cml::lu(A); auto b = cml::vectord(5., 1., 8., 3.); auto x = cml::vectord(4); cml::lu_solve(LU, x, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } - CATCH_TEST_CASE("dynamic, lu_pivot_solve1") { - auto A = cml::matrixd( - 4,4, - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto A = cml::matrixd(4, 4, 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., + -1., -2., 3.4, -1.); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); auto b = cml::vectord(5., 1., 8., 3.); auto x = cml::lu_solve(lup, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, lu_pivot_solve2") { - auto A = cml::matrixd( - 4,4, - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto A = cml::matrixd(4, 4, 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., + -1., -2., 3.4, -1.); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); auto b = cml::vectord(5., 1., 8., 3.); auto x = cml::vectord(4); cml::lu_solve(lup, x, b); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, lu_pivot_solve3") { - auto A = cml::matrixd( - 4,4, - 2., 0., 2., .6, - 3., 3., 4., -2., - 5., 5., 4., 2., - -1., -2., 3.4, -1. - ); + auto A = cml::matrixd(4, 4, 2., 0., 2., .6, 3., 3., 4., -2., 5., 5., 4., 2., + -1., -2., 3.4, -1.); auto lup = cml::lu_pivot(A); CATCH_CHECK(lup.sign == -1); auto b = cml::vectord(5., 1., 8., 3.); auto x = b; cml::lu_solve(lup, x, x); - auto Ax = A*x; - for(int i = 0; i < 4; ++ i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); + auto Ax = A * x; + for(int i = 0; i < 4; ++i) CATCH_CHECK(Ax[i] == Approx(b[i]).epsilon(1e-12)); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/matrix_binary_node1.cpp b/tests/matrix/matrix_binary_node1.cpp index 59d9401..821e0d1 100644 --- a/tests/matrix/matrix_binary_node1.cpp +++ b/tests/matrix/matrix_binary_node1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -17,500 +15,358 @@ CATCH_TEST_CASE("binary_types1") { - typedef cml::matrix> matrix_type; + using matrix_type = cml::matrix>; { CATCH_CHECK(cml::is_statically_polymorphic::value); } { auto xpr = matrix_type() + matrix_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { auto xpr = matrix_type() - matrix_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { matrix_type M; auto xpr = matrix_type() + M; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { matrix_type M; auto xpr = M + matrix_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { matrix_type M; auto xpr = matrix_type() - M; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { matrix_type M; auto xpr = M - matrix_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { matrix_type M1, M2; auto xpr = M1 + M2; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { matrix_type M1, M2; auto xpr = M1 - M2; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } } - CATCH_TEST_CASE("fixed, binary_minus1") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 5., 6., - 7., 8. - ); + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M2(5., 6., 7., 8.); - cml::matrix> M; + cml::matrix> M; M = M1 - M2; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -4.); - CATCH_CHECK(M(0,1) == -4.); - CATCH_CHECK(M(1,0) == -4.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -4.); + CATCH_CHECK(M(0, 1) == -4.); + CATCH_CHECK(M(1, 0) == -4.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("fixed, binary_minus2") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 5., 6., - 7., 8. - ); + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M2(5., 6., 7., 8.); - cml::matrix> M = M1 - M2; + cml::matrix> M = M1 - M2; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -4.); - CATCH_CHECK(M(0,1) == -4.); - CATCH_CHECK(M(1,0) == -4.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -4.); + CATCH_CHECK(M(0, 1) == -4.); + CATCH_CHECK(M(1, 0) == -4.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("fixed, binary_plus1") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 5., 6., - 7., 8. - ); + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M2(5., 6., 7., 8.); - cml::matrix> M; + cml::matrix> M; M = M1 + M2; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 6.); - CATCH_CHECK(M(0,1) == 8.); - CATCH_CHECK(M(1,0) == 10.); - CATCH_CHECK(M(1,1) == 12.); + CATCH_CHECK(M(0, 0) == 6.); + CATCH_CHECK(M(0, 1) == 8.); + CATCH_CHECK(M(1, 0) == 10.); + CATCH_CHECK(M(1, 1) == 12.); } CATCH_TEST_CASE("fixed, binary_plus2") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 5., 6., - 7., 8. - ); + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M2(5., 6., 7., 8.); - cml::matrix> M = M1 + M2; + cml::matrix> M = M1 + M2; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 6.); - CATCH_CHECK(M(0,1) == 8.); - CATCH_CHECK(M(1,0) == 10.); - CATCH_CHECK(M(1,1) == 12.); + CATCH_CHECK(M(0, 0) == 6.); + CATCH_CHECK(M(0, 1) == 8.); + CATCH_CHECK(M(1, 0) == 10.); + CATCH_CHECK(M(1, 1) == 12.); } CATCH_TEST_CASE("fixed, multiple_plus1") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 5., 6., - 7., 8. - ); - cml::matrix> M3( - 9., 10., - 11., 12. - ); - cml::matrix> M; + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M2(5., 6., 7., 8.); + cml::matrix> M3(9., 10., 11., 12.); + cml::matrix> M; M = M1 + M2 + M3; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 15.); - CATCH_CHECK(M(0,1) == 18.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 24.); + CATCH_CHECK(M(0, 0) == 15.); + CATCH_CHECK(M(0, 1) == 18.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 24.); } CATCH_TEST_CASE("fixed, multiple_plus2") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 5., 6., - 7., 8. - ); - cml::matrix> M3( - 9., 10., - 11., 12. - ); - cml::matrix> M = M1 + M2 + M3; + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M2(5., 6., 7., 8.); + cml::matrix> M3(9., 10., 11., 12.); + cml::matrix> M = M1 + M2 + M3; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 15.); - CATCH_CHECK(M(0,1) == 18.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 24.); + CATCH_CHECK(M(0, 0) == 15.); + CATCH_CHECK(M(0, 1) == 18.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 24.); } CATCH_TEST_CASE("fixed, mixed_op1") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 5., 6., - 7., 8. - ); - cml::matrix> M3( - 9., 10., - 11., 12. - ); - cml::matrix> M; + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M2(5., 6., 7., 8.); + cml::matrix> M3(9., 10., 11., 12.); + cml::matrix> M; M = M1 + (M3 - M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 6.); - CATCH_CHECK(M(1,0) == 7.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 6.); + CATCH_CHECK(M(1, 0) == 7.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("fixed, mixed_op2") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 5., 6., - 7., 8. - ); - cml::matrix> M3( - 9., 10., - 11., 12. - ); - cml::matrix> M = M1 + (M3 - M2); + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M2(5., 6., 7., 8.); + cml::matrix> M3(9., 10., 11., 12.); + cml::matrix> M = M1 + (M3 - M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 6.); - CATCH_CHECK(M(1,0) == 7.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 6.); + CATCH_CHECK(M(1, 0) == 7.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("fixed, assign_minus1") { - cml::matrix> M1( - 5., 6., - 7., 8. - ); - cml::matrix> M( - 1., 2., - 3., 4. - ); + cml::matrix> M1(5., 6., 7., 8.); + cml::matrix> M(1., 2., 3., 4.); M -= M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -4.); - CATCH_CHECK(M(0,1) == -4.); - CATCH_CHECK(M(1,0) == -4.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -4.); + CATCH_CHECK(M(0, 1) == -4.); + CATCH_CHECK(M(1, 0) == -4.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("fixed, assign_plus1") { - cml::matrix> M1( - 5., 6., - 7., 8. - ); - cml::matrix> M( - 1., 2., - 3., 4. - ); + cml::matrix> M1(5., 6., 7., 8.); + cml::matrix> M(1., 2., 3., 4.); M += M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 6.); - CATCH_CHECK(M(0,1) == 8.); - CATCH_CHECK(M(1,0) == 10.); - CATCH_CHECK(M(1,1) == 12.); + CATCH_CHECK(M(0, 0) == 6.); + CATCH_CHECK(M(0, 1) == 8.); + CATCH_CHECK(M(1, 0) == 10.); + CATCH_CHECK(M(1, 1) == 12.); } - - - CATCH_TEST_CASE("fixed external, binary_minus1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1); - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M2(aM2); + double aM2[] = {5., 6., 7., 8.}; + cml::matrix> M2(aM2); double data[4]; - cml::matrix> M(data); + cml::matrix> M(data); M = M1 - M2; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -4.); - CATCH_CHECK(M(0,1) == -4.); - CATCH_CHECK(M(1,0) == -4.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -4.); + CATCH_CHECK(M(0, 1) == -4.); + CATCH_CHECK(M(1, 0) == -4.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("fixed external, binary_plus1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1); - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M2(aM2); + double aM2[] = {5., 6., 7., 8.}; + cml::matrix> M2(aM2); double data[4]; - cml::matrix> M(data); + cml::matrix> M(data); M = M1 + M2; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 6.); - CATCH_CHECK(M(0,1) == 8.); - CATCH_CHECK(M(1,0) == 10.); - CATCH_CHECK(M(1,1) == 12.); + CATCH_CHECK(M(0, 0) == 6.); + CATCH_CHECK(M(0, 1) == 8.); + CATCH_CHECK(M(1, 0) == 10.); + CATCH_CHECK(M(1, 1) == 12.); } CATCH_TEST_CASE("fixed external, multiple_plus1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1); - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M2(aM2); + double aM2[] = {5., 6., 7., 8.}; + cml::matrix> M2(aM2); - double aM3[] = { - 9., 10., - 11., 12. - }; - cml::matrix> M3(aM3); + double aM3[] = {9., 10., 11., 12.}; + cml::matrix> M3(aM3); double data[4]; - cml::matrix> M(data); + cml::matrix> M(data); M = M1 + M2 + M3; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 15.); - CATCH_CHECK(M(0,1) == 18.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 24.); + CATCH_CHECK(M(0, 0) == 15.); + CATCH_CHECK(M(0, 1) == 18.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 24.); } CATCH_TEST_CASE("fixed external, mixed_op1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1); - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M2(aM2); + double aM2[] = {5., 6., 7., 8.}; + cml::matrix> M2(aM2); - double aM3[] = { - 9., 10., - 11., 12. - }; - cml::matrix> M3(aM3); + double aM3[] = {9., 10., 11., 12.}; + cml::matrix> M3(aM3); double data[4]; - cml::matrix> M(data); + cml::matrix> M(data); M = M1 + (M3 - M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 6.); - CATCH_CHECK(M(1,0) == 7.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 6.); + CATCH_CHECK(M(1, 0) == 7.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("fixed external, assign_minus1") { - double aM1[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M1(aM1); - - double data[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M(data); + double aM1[] = {5., 6., 7., 8.}; + cml::matrix> M1(aM1); + + double data[] = {1., 2., 3., 4.}; + cml::matrix> M(data); M -= M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -4.); - CATCH_CHECK(M(0,1) == -4.); - CATCH_CHECK(M(1,0) == -4.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -4.); + CATCH_CHECK(M(0, 1) == -4.); + CATCH_CHECK(M(1, 0) == -4.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("fixed external, assign_plus1") { - double aM1[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M1(aM1); - - double data[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M(data); + double aM1[] = {5., 6., 7., 8.}; + cml::matrix> M1(aM1); + + double data[] = {1., 2., 3., 4.}; + cml::matrix> M(data); M += M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 6.); - CATCH_CHECK(M(0,1) == 8.); - CATCH_CHECK(M(1,0) == 10.); - CATCH_CHECK(M(1,1) == 12.); + CATCH_CHECK(M(0, 0) == 6.); + CATCH_CHECK(M(0, 1) == 8.); + CATCH_CHECK(M(1, 0) == 10.); + CATCH_CHECK(M(1, 1) == 12.); } - - CATCH_TEST_CASE("dynamic external, binary_minus1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1, 2,2); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1, 2, 2); - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M2(aM2, 2,2); + double aM2[] = {5., 6., 7., 8.}; + cml::matrix> M2(aM2, 2, 2); double data[2][2]; cml::matrix> M(data); @@ -518,25 +374,19 @@ CATCH_TEST_CASE("dynamic external, binary_minus1") CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -4.); - CATCH_CHECK(M(0,1) == -4.); - CATCH_CHECK(M(1,0) == -4.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -4.); + CATCH_CHECK(M(0, 1) == -4.); + CATCH_CHECK(M(1, 0) == -4.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("dynamic external, binary_plus1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1, 2,2); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1, 2, 2); - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M2(aM2, 2,2); + double aM2[] = {5., 6., 7., 8.}; + cml::matrix> M2(aM2, 2, 2); double data[2][2]; cml::matrix> M(data); @@ -544,31 +394,22 @@ CATCH_TEST_CASE("dynamic external, binary_plus1") CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 6.); - CATCH_CHECK(M(0,1) == 8.); - CATCH_CHECK(M(1,0) == 10.); - CATCH_CHECK(M(1,1) == 12.); + CATCH_CHECK(M(0, 0) == 6.); + CATCH_CHECK(M(0, 1) == 8.); + CATCH_CHECK(M(1, 0) == 10.); + CATCH_CHECK(M(1, 1) == 12.); } CATCH_TEST_CASE("dynamic external, multiple_plus1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1, 2,2); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1, 2, 2); - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M2(aM2, 2,2); + double aM2[] = {5., 6., 7., 8.}; + cml::matrix> M2(aM2, 2, 2); - double aM3[] = { - 9., 10., - 11., 12. - }; - cml::matrix> M3(aM3, 2,2); + double aM3[] = {9., 10., 11., 12.}; + cml::matrix> M3(aM3, 2, 2); double data[2][2]; cml::matrix> M(data); @@ -576,31 +417,22 @@ CATCH_TEST_CASE("dynamic external, multiple_plus1") CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 15.); - CATCH_CHECK(M(0,1) == 18.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 24.); + CATCH_CHECK(M(0, 0) == 15.); + CATCH_CHECK(M(0, 1) == 18.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 24.); } CATCH_TEST_CASE("dynamic external, mixed_op1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1, 2,2); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1, 2, 2); - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M2(aM2, 2,2); + double aM2[] = {5., 6., 7., 8.}; + cml::matrix> M2(aM2, 2, 2); - double aM3[] = { - 9., 10., - 11., 12. - }; - cml::matrix> M3(aM3, 2,2); + double aM3[] = {9., 10., 11., 12.}; + cml::matrix> M3(aM3, 2, 2); double data[2][2]; cml::matrix> M(data); @@ -608,305 +440,191 @@ CATCH_TEST_CASE("dynamic external, mixed_op1") CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 6.); - CATCH_CHECK(M(1,0) == 7.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 6.); + CATCH_CHECK(M(1, 0) == 7.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("dynamic external, assign_minus1") { - double aM1[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M1(aM1, 2,2); - - double data[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M(data, 2,2); + double aM1[] = {5., 6., 7., 8.}; + cml::matrix> M1(aM1, 2, 2); + + double data[] = {1., 2., 3., 4.}; + cml::matrix> M(data, 2, 2); M -= M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -4.); - CATCH_CHECK(M(0,1) == -4.); - CATCH_CHECK(M(1,0) == -4.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -4.); + CATCH_CHECK(M(0, 1) == -4.); + CATCH_CHECK(M(1, 0) == -4.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("dynamic external, assign_plus1") { - double aM1[] = { - 5., 6., - 7., 8. - }; - cml::matrix> M1(aM1, 2,2); - - double data[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M(data, 2,2); + double aM1[] = {5., 6., 7., 8.}; + cml::matrix> M1(aM1, 2, 2); + + double data[] = {1., 2., 3., 4.}; + cml::matrix> M(data, 2, 2); M += M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 6.); - CATCH_CHECK(M(0,1) == 8.); - CATCH_CHECK(M(1,0) == 10.); - CATCH_CHECK(M(1,1) == 12.); + CATCH_CHECK(M(0, 0) == 6.); + CATCH_CHECK(M(0, 1) == 8.); + CATCH_CHECK(M(1, 0) == 10.); + CATCH_CHECK(M(1, 1) == 12.); } - - CATCH_TEST_CASE("dynamic, binary_minus1") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 2,2, - 5., 6., - 7., 8. - ); + cml::matrix> M1(2, 2, 1., 2., 3., 4.); + cml::matrix> M2(2, 2, 5., 6., 7., 8.); cml::matrix> M; M = M1 - M2; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -4.); - CATCH_CHECK(M(0,1) == -4.); - CATCH_CHECK(M(1,0) == -4.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -4.); + CATCH_CHECK(M(0, 1) == -4.); + CATCH_CHECK(M(1, 0) == -4.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("dynamic, binary_minus2") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 2,2, - 5., 6., - 7., 8. - ); + cml::matrix> M1(2, 2, 1., 2., 3., 4.); + cml::matrix> M2(2, 2, 5., 6., 7., 8.); cml::matrix> M = M1 - M2; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -4.); - CATCH_CHECK(M(0,1) == -4.); - CATCH_CHECK(M(1,0) == -4.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -4.); + CATCH_CHECK(M(0, 1) == -4.); + CATCH_CHECK(M(1, 0) == -4.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("dynamic, binary_plus1") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 2,2, - 5., 6., - 7., 8. - ); + cml::matrix> M1(2, 2, 1., 2., 3., 4.); + cml::matrix> M2(2, 2, 5., 6., 7., 8.); cml::matrix> M; M = M1 + M2; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 6.); - CATCH_CHECK(M(0,1) == 8.); - CATCH_CHECK(M(1,0) == 10.); - CATCH_CHECK(M(1,1) == 12.); + CATCH_CHECK(M(0, 0) == 6.); + CATCH_CHECK(M(0, 1) == 8.); + CATCH_CHECK(M(1, 0) == 10.); + CATCH_CHECK(M(1, 1) == 12.); } CATCH_TEST_CASE("dynamic, binary_plus2") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 2,2, - 5., 6., - 7., 8. - ); + cml::matrix> M1(2, 2, 1., 2., 3., 4.); + cml::matrix> M2(2, 2, 5., 6., 7., 8.); cml::matrix> M = M1 + M2; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 6.); - CATCH_CHECK(M(0,1) == 8.); - CATCH_CHECK(M(1,0) == 10.); - CATCH_CHECK(M(1,1) == 12.); + CATCH_CHECK(M(0, 0) == 6.); + CATCH_CHECK(M(0, 1) == 8.); + CATCH_CHECK(M(1, 0) == 10.); + CATCH_CHECK(M(1, 1) == 12.); } CATCH_TEST_CASE("dynamic, multiple_plus1") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 2,2, - 5., 6., - 7., 8. - ); - cml::matrix> M3( - 2,2, - 9., 10., - 11., 12. - ); + cml::matrix> M1(2, 2, 1., 2., 3., 4.); + cml::matrix> M2(2, 2, 5., 6., 7., 8.); + cml::matrix> M3(2, 2, 9., 10., 11., 12.); cml::matrix> M; M = M1 + M2 + M3; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 15.); - CATCH_CHECK(M(0,1) == 18.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 24.); + CATCH_CHECK(M(0, 0) == 15.); + CATCH_CHECK(M(0, 1) == 18.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 24.); } CATCH_TEST_CASE("dynamic, multiple_plus2") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 2,2, - 5., 6., - 7., 8. - ); - cml::matrix> M3( - 2,2, - 9., 10., - 11., 12. - ); + cml::matrix> M1(2, 2, 1., 2., 3., 4.); + cml::matrix> M2(2, 2, 5., 6., 7., 8.); + cml::matrix> M3(2, 2, 9., 10., 11., 12.); cml::matrix> M = M1 + M2 + M3; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 15.); - CATCH_CHECK(M(0,1) == 18.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 24.); + CATCH_CHECK(M(0, 0) == 15.); + CATCH_CHECK(M(0, 1) == 18.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 24.); } CATCH_TEST_CASE("dynamic, mixed_op1") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 2,2, - 5., 6., - 7., 8. - ); - cml::matrix> M3( - 2,2, - 9., 10., - 11., 12. - ); + cml::matrix> M1(2, 2, 1., 2., 3., 4.); + cml::matrix> M2(2, 2, 5., 6., 7., 8.); + cml::matrix> M3(2, 2, 9., 10., 11., 12.); cml::matrix> M; M = M1 + (M3 - M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 6.); - CATCH_CHECK(M(1,0) == 7.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 6.); + CATCH_CHECK(M(1, 0) == 7.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("dynamic, mixed_op2") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); - cml::matrix> M2( - 2,2, - 5., 6., - 7., 8. - ); - cml::matrix> M3( - 2,2, - 9., 10., - 11., 12. - ); + cml::matrix> M1(2, 2, 1., 2., 3., 4.); + cml::matrix> M2(2, 2, 5., 6., 7., 8.); + cml::matrix> M3(2, 2, 9., 10., 11., 12.); cml::matrix> M = M1 + (M3 - M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 6.); - CATCH_CHECK(M(1,0) == 7.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 6.); + CATCH_CHECK(M(1, 0) == 7.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("dynamic, assign_minus1") { - cml::matrix> M1( - 2,2, - 5., 6., - 7., 8. - ); - cml::matrix> M( - 2,2, - 1., 2., - 3., 4. - ); + cml::matrix> M1(2, 2, 5., 6., 7., 8.); + cml::matrix> M(2, 2, 1., 2., 3., 4.); M -= M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -4.); - CATCH_CHECK(M(0,1) == -4.); - CATCH_CHECK(M(1,0) == -4.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -4.); + CATCH_CHECK(M(0, 1) == -4.); + CATCH_CHECK(M(1, 0) == -4.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("dynamic, assign_plus1") { - cml::matrix> M1( - 2,2, - 5., 6., - 7., 8. - ); - cml::matrix> M( - 2,2, - 1., 2., - 3., 4. - ); + cml::matrix> M1(2, 2, 5., 6., 7., 8.); + cml::matrix> M(2, 2, 1., 2., 3., 4.); M += M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 6.); - CATCH_CHECK(M(0,1) == 8.); - CATCH_CHECK(M(1,0) == 10.); - CATCH_CHECK(M(1,1) == 12.); + CATCH_CHECK(M(0, 0) == 6.); + CATCH_CHECK(M(0, 1) == 8.); + CATCH_CHECK(M(1, 0) == 10.); + CATCH_CHECK(M(1, 1) == 12.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/matrix_comparison1.cpp b/tests/matrix/matrix_comparison1.cpp index a1276ee..f1ca118 100644 --- a/tests/matrix/matrix_comparison1.cpp +++ b/tests/matrix/matrix_comparison1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -18,39 +16,20 @@ CATCH_TEST_CASE("equal1") { - auto M = cml::matrix33d( - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - ); + auto M = cml::matrix33d(1., 2., 3., 1., 4., 9., 1., 16., 25.); M.transpose(); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); CATCH_CHECK(M == expected); } CATCH_TEST_CASE("not_equal1") { - auto M = cml::matrix33d( - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - ); + auto M = cml::matrix33d(1., 2., 3., 1., 4., 9., 1., 16., 25.); M.transpose(); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 24. - ); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 24.); CATCH_CHECK(M != expected); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/matrix_functions1.cpp b/tests/matrix/matrix_functions1.cpp index ffabe8d..cf0db37 100644 --- a/tests/matrix/matrix_functions1.cpp +++ b/tests/matrix/matrix_functions1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: //#include @@ -14,31 +12,30 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, zero1") { cml::matrix22d M; M.zero(); - CATCH_CHECK(M(0,0) == 0.); - CATCH_CHECK(M(0,1) == 0.); - CATCH_CHECK(M(1,0) == 0.); - CATCH_CHECK(M(1,1) == 0.); + CATCH_CHECK(M(0, 0) == 0.); + CATCH_CHECK(M(0, 1) == 0.); + CATCH_CHECK(M(1, 0) == 0.); + CATCH_CHECK(M(1, 1) == 0.); } CATCH_TEST_CASE("fixed, identity1") { cml::matrix22d M; M.identity(); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 0.); - CATCH_CHECK(M(1,0) == 0.); - CATCH_CHECK(M(1,1) == 1.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 0.); + CATCH_CHECK(M(1, 0) == 0.); + CATCH_CHECK(M(1, 1) == 1.); } CATCH_TEST_CASE("fixed, random1") { cml::matrix22d M; - M.random(0.,1.); + M.random(0., 1.); for(const auto& v : M) { CATCH_CHECK(v >= 0.); CATCH_CHECK(v < 1.); @@ -52,13 +49,13 @@ CATCH_TEST_CASE("fixed, set_basis_element1") M.set_basis_element(0, 1, 2.); M.set_basis_element(0, 2, 3.); - CATCH_CHECK(M.basis_element(0,0) == 1.); - CATCH_CHECK(M.basis_element(0,1) == 2.); - CATCH_CHECK(M.basis_element(0,2) == 3.); + CATCH_CHECK(M.basis_element(0, 0) == 1.); + CATCH_CHECK(M.basis_element(0, 1) == 2.); + CATCH_CHECK(M.basis_element(0, 2) == 3.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(1,0) == 2.); - CATCH_CHECK(M(2,0) == 3.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(1, 0) == 2.); + CATCH_CHECK(M(2, 0) == 3.); } CATCH_TEST_CASE("fixed, set_basis_element2") @@ -68,13 +65,13 @@ CATCH_TEST_CASE("fixed, set_basis_element2") M.set_basis_element(0, 1, 2.); M.set_basis_element(0, 2, 3.); - CATCH_CHECK(M.basis_element(0,0) == 1.); - CATCH_CHECK(M.basis_element(0,1) == 2.); - CATCH_CHECK(M.basis_element(0,2) == 3.); + CATCH_CHECK(M.basis_element(0, 0) == 1.); + CATCH_CHECK(M.basis_element(0, 1) == 2.); + CATCH_CHECK(M.basis_element(0, 2) == 3.); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(0,2) == 3.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(0, 2) == 3.); } CATCH_TEST_CASE("fixed, set_row1") @@ -84,11 +81,11 @@ CATCH_TEST_CASE("fixed, set_row1") M.set_row(0, vector3d(1., 2., 3.)); M.set_row(1, vector3d(4., 5., 6.)); M.set_row(2, vector3d(7., 8., 9.)); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(0,2) == 3.); - CATCH_CHECK(M(2,0) == 7.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(0, 2) == 3.); + CATCH_CHECK(M(2, 0) == 7.); } CATCH_TEST_CASE("fixed, set_col1") @@ -98,25 +95,17 @@ CATCH_TEST_CASE("fixed, set_col1") M.set_col(0, vector3d(1., 4., 7.)); M.set_col(1, vector3d(2., 5., 8.)); M.set_col(2, vector3d(3., 6., 9.)); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(0,2) == 3.); - CATCH_CHECK(M(2,0) == 7.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(0, 2) == 3.); + CATCH_CHECK(M(2, 0) == 7.); } CATCH_TEST_CASE("fixed, trace1") { - auto M = cml::matrix44d( - 242., 20., -33., -1., - 12., -48., 45., -9., - 46., -32., -27., 13., - -44., 43., 6., -5. - ); + auto M = cml::matrix44d(242., 20., -33., -1., 12., -48., 45., -9., 46., -32., + -27., 13., -44., 43., 6., -5.); double expected = 242. - 48. - 27. - 5.; CATCH_CHECK(M.trace() == Approx(expected).epsilon(1e-12)); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/matrix_hadamard_product1.cpp b/tests/matrix/matrix_hadamard_product1.cpp index 0c21725..c7c2454 100644 --- a/tests/matrix/matrix_hadamard_product1.cpp +++ b/tests/matrix/matrix_hadamard_product1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -15,229 +13,161 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, hadamard1") { - cml::matrix22d M1( - 1., 2., - 3., 4. - ); - cml::matrix22d M2( - 5., 6., - 7., 8. - ); - - auto M = cml::hadamard(M1,M2); + cml::matrix22d M1(1., 2., 3., 4.); + cml::matrix22d M2(5., 6., 7., 8.); + + auto M = cml::hadamard(M1, M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 12.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 32.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 12.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 32.); } - CATCH_TEST_CASE("fixed external, hadamard1") { - double aM1[] = { - 1., 2., - 3., 4. - }; + double aM1[] = {1., 2., 3., 4.}; cml::external22d M1(aM1); - double aM2[] = { - 5., 6., - 7., 8. - }; + double aM2[] = {5., 6., 7., 8.}; cml::external22d M2(aM2); - auto M = cml::hadamard(M1,M2); + auto M = cml::hadamard(M1, M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 12.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 32.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 12.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 32.); } - CATCH_TEST_CASE("dynamic external, hadamard1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::externalmnd M1(2,2, aM1); - - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::externalmnd M2(2,2, aM2); - - auto M = cml::hadamard(M1,M2); + double aM1[] = {1., 2., 3., 4.}; + cml::externalmnd M1(2, 2, aM1); + + double aM2[] = {5., 6., 7., 8.}; + cml::externalmnd M2(2, 2, aM2); + + auto M = cml::hadamard(M1, M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 12.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 32.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 12.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 32.); } CATCH_TEST_CASE("dynamic, hadamard1") { - cml::matrixd M1(2,2, - 1., 2., - 3., 4. - ); - cml::matrixd M2(2,2, - 5., 6., - 7., 8. - ); - - auto M = cml::hadamard(M1,M2); + cml::matrixd M1(2, 2, 1., 2., 3., 4.); + cml::matrixd M2(2, 2, 5., 6., 7., 8.); + + auto M = cml::hadamard(M1, M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 12.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 32.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 12.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 32.); } - CATCH_TEST_CASE("mixed fixed, dynamic1") { - cml::matrix22d M1( - 1., 2., - 3., 4. - ); - cml::matrixd M2(2,2, - 5., 6., - 7., 8. - ); - - auto M = cml::hadamard(M1,M2); + cml::matrix22d M1(1., 2., 3., 4.); + cml::matrixd M2(2, 2, 5., 6., 7., 8.); + + auto M = cml::hadamard(M1, M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 12.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 32.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 12.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 32.); } CATCH_TEST_CASE("mixed fixed, fixed external1") { - cml::matrix22d M1( - 1., 2., - 3., 4. - ); - - double aM2[] = { - 5., 6., - 7., 8. - }; + cml::matrix22d M1(1., 2., 3., 4.); + + double aM2[] = {5., 6., 7., 8.}; cml::external22d M2(aM2); - auto M = cml::hadamard(M1,M2); + auto M = cml::hadamard(M1, M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 12.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 32.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 12.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 32.); } CATCH_TEST_CASE("mixed fixed, dynamic external1") { - cml::matrix22d M1( - 1., 2., - 3., 4. - ); - - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::externalmnd M2(2,2, aM2); - - auto M = cml::hadamard(M1,M2); + cml::matrix22d M1(1., 2., 3., 4.); + + double aM2[] = {5., 6., 7., 8.}; + cml::externalmnd M2(2, 2, aM2); + + auto M = cml::hadamard(M1, M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 12.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 32.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 12.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 32.); } - CATCH_TEST_CASE("mixed dynamic, fixed external1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::externalmnd M1(2,2, aM1); - - double aM2[] = { - 5., 6., - 7., 8. - }; + double aM1[] = {1., 2., 3., 4.}; + cml::externalmnd M1(2, 2, aM1); + + double aM2[] = {5., 6., 7., 8.}; cml::external22d M2(aM2); - auto M = cml::hadamard(M1,M2); + auto M = cml::hadamard(M1, M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 12.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 32.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 12.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 32.); } CATCH_TEST_CASE("mixed dynamic, dynamic external1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::externalmnd M1(2,2, aM1); - - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::externalmnd M2(2,2,aM2); - - auto M = cml::hadamard(M1,M2); + double aM1[] = {1., 2., 3., 4.}; + cml::externalmnd M1(2, 2, aM1); + + double aM2[] = {5., 6., 7., 8.}; + cml::externalmnd M2(2, 2, aM2); + + auto M = cml::hadamard(M1, M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 12.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 32.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 12.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 32.); } CATCH_TEST_CASE("mixed fixed external, dynamic external1") { - double aM1[] = { - 1., 2., - 3., 4. - }; + double aM1[] = {1., 2., 3., 4.}; cml::external22d M1(aM1); - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::externalmnd M2(2,2, aM2); + double aM2[] = {5., 6., 7., 8.}; + cml::externalmnd M2(2, 2, aM2); - auto M = cml::hadamard(M1,M2); + auto M = cml::hadamard(M1, M2); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 5.); - CATCH_CHECK(M(0,1) == 12.); - CATCH_CHECK(M(1,0) == 21.); - CATCH_CHECK(M(1,1) == 32.); + CATCH_CHECK(M(0, 0) == 5.); + CATCH_CHECK(M(0, 1) == 12.); + CATCH_CHECK(M(1, 0) == 21.); + CATCH_CHECK(M(1, 1) == 32.); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/matrix_inverse1.cpp b/tests/matrix/matrix_inverse1.cpp index 312a441..c1194f3 100644 --- a/tests/matrix/matrix_inverse1.cpp +++ b/tests/matrix/matrix_inverse1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -15,325 +13,215 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, inverse_assign_2x2") { - cml::matrix22d M( - 1., 2., - 3., 4. - ); + cml::matrix22d M(1., 2., 3., 4.); M.inverse(); - CATCH_CHECK(M(0,0) == Approx(-2.0).epsilon(1e-12)); - CATCH_CHECK(M(0,1) == Approx( 1.0).epsilon(1e-12)); - CATCH_CHECK(M(1,0) == Approx( 1.5).epsilon(1e-12)); - CATCH_CHECK(M(1,1) == Approx(-0.5).epsilon(1e-12)); + CATCH_CHECK(M(0, 0) == Approx(-2.0).epsilon(1e-12)); + CATCH_CHECK(M(0, 1) == Approx(1.0).epsilon(1e-12)); + CATCH_CHECK(M(1, 0) == Approx(1.5).epsilon(1e-12)); + CATCH_CHECK(M(1, 1) == Approx(-0.5).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, inverse_assign_3x3") { - cml::matrix33d M( - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - ); + cml::matrix33d M(1., 2., 3., 1., 4., 9., 1., 16., 25.); M.inverse(); - auto expected = cml::matrix33d( - 22., 1., -3., - 8., -11., 3., - -6., 7., -1. - ); - expected *= 1./20.; + auto expected = cml::matrix33d(22., 1., -3., 8., -11., 3., -6., 7., -1.); + expected *= 1. / 20.; - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(M(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) + CATCH_CHECK(M(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, inverse_assign_4x4") { - cml::matrix44d M( - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - ); + cml::matrix44d M(1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., 36., + 81., 100.); M.inverse(); - auto expected = cml::matrix44d( - 242., 20., -33., -1., - 12., -48., 45., -9., - 46., -32., -27., 13., - -44., 43., 6., -5. - ); - expected *= 1./228.; - - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(M(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(242., 20., -33., -1., 12., -48., 45., -9., 46., + -32., -27., 13., -44., 43., 6., -5.); + expected *= 1. / 228.; + + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(M(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, inverse_2x2") { - auto M = cml::inverse( - cml::matrix22d( - 1., 2., - 3., 4. - ) - ); - CATCH_CHECK(M(0,0) == Approx(-2.0).epsilon(1e-12)); - CATCH_CHECK(M(0,1) == Approx( 1.0).epsilon(1e-12)); - CATCH_CHECK(M(1,0) == Approx( 1.5).epsilon(1e-12)); - CATCH_CHECK(M(1,1) == Approx(-0.5).epsilon(1e-12)); + auto M = cml::inverse(cml::matrix22d(1., 2., 3., 4.)); + CATCH_CHECK(M(0, 0) == Approx(-2.0).epsilon(1e-12)); + CATCH_CHECK(M(0, 1) == Approx(1.0).epsilon(1e-12)); + CATCH_CHECK(M(1, 0) == Approx(1.5).epsilon(1e-12)); + CATCH_CHECK(M(1, 1) == Approx(-0.5).epsilon(1e-12)); } - - - CATCH_TEST_CASE("fixed external, inverse_assign_2x2") { - double avM[] = { - 1., 2., - 3., 4. - }; + double avM[] = {1., 2., 3., 4.}; cml::external22d M(avM); M.inverse(); - CATCH_CHECK(M(0,0) == Approx(-2.0).epsilon(1e-12)); - CATCH_CHECK(M(0,1) == Approx( 1.0).epsilon(1e-12)); - CATCH_CHECK(M(1,0) == Approx( 1.5).epsilon(1e-12)); - CATCH_CHECK(M(1,1) == Approx(-0.5).epsilon(1e-12)); + CATCH_CHECK(M(0, 0) == Approx(-2.0).epsilon(1e-12)); + CATCH_CHECK(M(0, 1) == Approx(1.0).epsilon(1e-12)); + CATCH_CHECK(M(1, 0) == Approx(1.5).epsilon(1e-12)); + CATCH_CHECK(M(1, 1) == Approx(-0.5).epsilon(1e-12)); } CATCH_TEST_CASE("fixed external, inverse_assign_3x3") { - double avM[] = { - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - }; + double avM[] = {1., 2., 3., 1., 4., 9., 1., 16., 25.}; cml::external33d M(avM); M.inverse(); - auto expected = cml::matrix33d( - 22., 1., -3., - 8., -11., 3., - -6., 7., -1. - ); - expected *= 1./20.; + auto expected = cml::matrix33d(22., 1., -3., 8., -11., 3., -6., 7., -1.); + expected *= 1. / 20.; - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(M(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) + CATCH_CHECK(M(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("fixed external, inverse_assign_4x4") { double avM[] = { - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - }; + 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., 36., 81., 100.}; cml::external44d M(avM); M.inverse(); - auto expected = cml::matrix44d( - 242., 20., -33., -1., - 12., -48., 45., -9., - 46., -32., -27., 13., - -44., 43., 6., -5. - ); - expected *= 1./228.; - - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(M(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(242., 20., -33., -1., 12., -48., 45., -9., 46., + -32., -27., 13., -44., 43., 6., -5.); + expected *= 1. / 228.; + + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(M(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("fixed external, inverse_2x2") { - double avM[] = { - 1., 2., - 3., 4. - }; + double avM[] = {1., 2., 3., 4.}; auto M = cml::inverse(cml::external22d(avM)); - CATCH_CHECK(M(0,0) == Approx(-2.0).epsilon(1e-12)); - CATCH_CHECK(M(0,1) == Approx( 1.0).epsilon(1e-12)); - CATCH_CHECK(M(1,0) == Approx( 1.5).epsilon(1e-12)); - CATCH_CHECK(M(1,1) == Approx(-0.5).epsilon(1e-12)); + CATCH_CHECK(M(0, 0) == Approx(-2.0).epsilon(1e-12)); + CATCH_CHECK(M(0, 1) == Approx(1.0).epsilon(1e-12)); + CATCH_CHECK(M(1, 0) == Approx(1.5).epsilon(1e-12)); + CATCH_CHECK(M(1, 1) == Approx(-0.5).epsilon(1e-12)); } - - - CATCH_TEST_CASE("dynamic external, inverse_assign_2x2") { - double avM[] = { - 1., 2., - 3., 4. - }; - cml::externalmnd M(2,2, avM); + double avM[] = {1., 2., 3., 4.}; + cml::externalmnd M(2, 2, avM); M.inverse(); - CATCH_CHECK(M(0,0) == Approx(-2.0).epsilon(1e-12)); - CATCH_CHECK(M(0,1) == Approx( 1.0).epsilon(1e-12)); - CATCH_CHECK(M(1,0) == Approx( 1.5).epsilon(1e-12)); - CATCH_CHECK(M(1,1) == Approx(-0.5).epsilon(1e-12)); + CATCH_CHECK(M(0, 0) == Approx(-2.0).epsilon(1e-12)); + CATCH_CHECK(M(0, 1) == Approx(1.0).epsilon(1e-12)); + CATCH_CHECK(M(1, 0) == Approx(1.5).epsilon(1e-12)); + CATCH_CHECK(M(1, 1) == Approx(-0.5).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic external, inverse_assign_3x3") { - double avM[] = { - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - }; - cml::externalmnd M(3,3, avM); + double avM[] = {1., 2., 3., 1., 4., 9., 1., 16., 25.}; + cml::externalmnd M(3, 3, avM); M.inverse(); - auto expected = cml::matrix33d( - 22., 1., -3., - 8., -11., 3., - -6., 7., -1. - ); - expected *= 1./20.; + auto expected = cml::matrix33d(22., 1., -3., 8., -11., 3., -6., 7., -1.); + expected *= 1. / 20.; - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(M(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) + CATCH_CHECK(M(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic external, inverse_assign_4x4") { double avM[] = { - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - }; - cml::externalmnd M(4,4, avM); + 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., 36., 81., 100.}; + cml::externalmnd M(4, 4, avM); M.inverse(); - auto expected = cml::matrix44d( - 242., 20., -33., -1., - 12., -48., 45., -9., - 46., -32., -27., 13., - -44., 43., 6., -5. - ); - expected *= 1./228.; - - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(M(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(242., 20., -33., -1., 12., -48., 45., -9., 46., + -32., -27., 13., -44., 43., 6., -5.); + expected *= 1. / 228.; + + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(M(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic external, inverse_2x2") { - double avM[] = { - 1., 2., - 3., 4. - }; - auto M = cml::inverse(cml::externalmnd(2,2, avM)); - CATCH_CHECK(M(0,0) == Approx(-2.0).epsilon(1e-12)); - CATCH_CHECK(M(0,1) == Approx( 1.0).epsilon(1e-12)); - CATCH_CHECK(M(1,0) == Approx( 1.5).epsilon(1e-12)); - CATCH_CHECK(M(1,1) == Approx(-0.5).epsilon(1e-12)); + double avM[] = {1., 2., 3., 4.}; + auto M = cml::inverse(cml::externalmnd(2, 2, avM)); + CATCH_CHECK(M(0, 0) == Approx(-2.0).epsilon(1e-12)); + CATCH_CHECK(M(0, 1) == Approx(1.0).epsilon(1e-12)); + CATCH_CHECK(M(1, 0) == Approx(1.5).epsilon(1e-12)); + CATCH_CHECK(M(1, 1) == Approx(-0.5).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic external, size_check1") { - double avM[3*4]; - cml::externalmnd M(3,4, avM); + double avM[3 * 4]; + cml::externalmnd M(3, 4, avM); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE_THROWS_AS(M.inverse(), cml::non_square_matrix_error); } - - - CATCH_TEST_CASE("dynamic, inverse_assign_2x2") { - cml::matrixd M( - 2,2, - 1., 2., - 3., 4. - ); + cml::matrixd M(2, 2, 1., 2., 3., 4.); M.inverse(); - CATCH_CHECK(M(0,0) == Approx(-2.0).epsilon(1e-12)); - CATCH_CHECK(M(0,1) == Approx( 1.0).epsilon(1e-12)); - CATCH_CHECK(M(1,0) == Approx( 1.5).epsilon(1e-12)); - CATCH_CHECK(M(1,1) == Approx(-0.5).epsilon(1e-12)); + CATCH_CHECK(M(0, 0) == Approx(-2.0).epsilon(1e-12)); + CATCH_CHECK(M(0, 1) == Approx(1.0).epsilon(1e-12)); + CATCH_CHECK(M(1, 0) == Approx(1.5).epsilon(1e-12)); + CATCH_CHECK(M(1, 1) == Approx(-0.5).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, inverse_assign_3x3") { - cml::matrixd M( - 3,3, - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - ); + cml::matrixd M(3, 3, 1., 2., 3., 1., 4., 9., 1., 16., 25.); M.inverse(); - auto expected = cml::matrix33d( - 22., 1., -3., - 8., -11., 3., - -6., 7., -1. - ); - expected *= 1./20.; + auto expected = cml::matrix33d(22., 1., -3., 8., -11., 3., -6., 7., -1.); + expected *= 1. / 20.; - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(M(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) + CATCH_CHECK(M(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, inverse_assign_4x4") { - cml::matrixd M( - 4,4, - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - ); + cml::matrixd M(4, 4, 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., + 36., 81., 100.); M.inverse(); - auto expected = cml::matrix44d( - 242., 20., -33., -1., - 12., -48., 45., -9., - 46., -32., -27., 13., - -44., 43., 6., -5. - ); - expected *= 1./228.; - - for(int i = 0; i < 4; ++ i) - for(int j = 0; j < 4; ++ j) - CATCH_CHECK(M(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + auto expected = cml::matrix44d(242., 20., -33., -1., 12., -48., 45., -9., 46., + -32., -27., 13., -44., 43., 6., -5.); + expected *= 1. / 228.; + + for(int i = 0; i < 4; ++i) + for(int j = 0; j < 4; ++j) + CATCH_CHECK(M(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, inverse_2x2") { - auto M = cml::inverse( - cml::matrixd( - 2,2, - 1., 2., - 3., 4. - ) - ); - CATCH_CHECK(M(0,0) == Approx(-2.0).epsilon(1e-12)); - CATCH_CHECK(M(0,1) == Approx( 1.0).epsilon(1e-12)); - CATCH_CHECK(M(1,0) == Approx( 1.5).epsilon(1e-12)); - CATCH_CHECK(M(1,1) == Approx(-0.5).epsilon(1e-12)); + auto M = cml::inverse(cml::matrixd(2, 2, 1., 2., 3., 4.)); + CATCH_CHECK(M(0, 0) == Approx(-2.0).epsilon(1e-12)); + CATCH_CHECK(M(0, 1) == Approx(1.0).epsilon(1e-12)); + CATCH_CHECK(M(1, 0) == Approx(1.5).epsilon(1e-12)); + CATCH_CHECK(M(1, 1) == Approx(-0.5).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, size_check1") { - cml::matrixd M(3,4); + cml::matrixd M(3, 4); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 4); CATCH_REQUIRE_THROWS_AS(M.inverse(), cml::non_square_matrix_error); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/matrix_matrix_product1.cpp b/tests/matrix/matrix_matrix_product1.cpp index 85ef5a4..f12934d 100644 --- a/tests/matrix/matrix_matrix_product1.cpp +++ b/tests/matrix/matrix_matrix_product1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -15,653 +13,476 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, product1") { - cml::matrix22d M1( - 1., 2., - 3., 4. - ); - cml::matrix22d M2( - 5., 6., - 7., 8. - ); - - auto M = M1*M2; + cml::matrix22d M1(1., 2., 3., 4.); + cml::matrix22d M2(5., 6., 7., 8.); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 19.); - CATCH_CHECK(M(0,1) == 22.); - CATCH_CHECK(M(1,0) == 43.); - CATCH_CHECK(M(1,1) == 50.); + CATCH_CHECK(M(0, 0) == 19.); + CATCH_CHECK(M(0, 1) == 22.); + CATCH_CHECK(M(1, 0) == 43.); + CATCH_CHECK(M(1, 1) == 50.); } CATCH_TEST_CASE("fixed, product2") { - cml::matrix> M1( - 1., 1., - 2., 2., - 3., 3. - ); - cml::matrix23d M2( - 1., 2., 3., - 1., 2., 3. - ); - - auto M = M1*M2; + cml::matrix> M1(1., 1., 2., 2., 3., 3.); + cml::matrix23d M2(1., 2., 3., 1., 2., 3.); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } - - - CATCH_TEST_CASE("fixed external, product1") { - double aM1[] = { - 1., 2., - 3., 4. - }; + double aM1[] = {1., 2., 3., 4.}; cml::external22d M1(aM1); - double aM2[] = { - 5., 6., - 7., 8. - }; + double aM2[] = {5., 6., 7., 8.}; cml::external22d M2(aM2); - auto M = M1*M2; + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 19.); - CATCH_CHECK(M(0,1) == 22.); - CATCH_CHECK(M(1,0) == 43.); - CATCH_CHECK(M(1,1) == 50.); + CATCH_CHECK(M(0, 0) == 19.); + CATCH_CHECK(M(0, 1) == 22.); + CATCH_CHECK(M(1, 0) == 43.); + CATCH_CHECK(M(1, 1) == 50.); } CATCH_TEST_CASE("fixed external, product2") { - double aM1[] = { - 1., 1., - 2., 2., - 3., 3. - }; - cml::matrix> M1(aM1); - - double aM2[] = { - 1., 2., 3., - 1., 2., 3. - }; + double aM1[] = {1., 1., 2., 2., 3., 3.}; + cml::matrix> M1(aM1); + + double aM2[] = {1., 2., 3., 1., 2., 3.}; cml::external23d M2(aM2); - auto M = M1*M2; + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } - - - CATCH_TEST_CASE("dynamic external, product1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::externalmnd M1(2,2, aM1); - - double aM2[] = { - 5., 6., - 7., 8. - }; - cml::externalmnd M2(2,2, aM2); - - auto M = M1*M2; + double aM1[] = {1., 2., 3., 4.}; + cml::externalmnd M1(2, 2, aM1); + + double aM2[] = {5., 6., 7., 8.}; + cml::externalmnd M2(2, 2, aM2); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 19.); - CATCH_CHECK(M(0,1) == 22.); - CATCH_CHECK(M(1,0) == 43.); - CATCH_CHECK(M(1,1) == 50.); + CATCH_CHECK(M(0, 0) == 19.); + CATCH_CHECK(M(0, 1) == 22.); + CATCH_CHECK(M(1, 0) == 43.); + CATCH_CHECK(M(1, 1) == 50.); } CATCH_TEST_CASE("dynamic external, product2") { - double aM1[] = { - 1., 1., - 2., 2., - 3., 3. - }; - cml::externalmnd M1(3,2, aM1); - - double aM2[] = { - 1., 2., 3., - 1., 2., 3. - }; - cml::externalmnd M2(2,3, aM2); - - auto M = M1*M2; + double aM1[] = {1., 1., 2., 2., 3., 3.}; + cml::externalmnd M1(3, 2, aM1); + + double aM2[] = {1., 2., 3., 1., 2., 3.}; + cml::externalmnd M2(2, 3, aM2); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("dynamic external, size_checking1") { double aM1[4], aM2[6]; CATCH_REQUIRE_THROWS_AS( - (cml::externalmnd(2,2, aM1) * cml::externalmnd(3,2, aM2)), + (cml::externalmnd(2, 2, aM1) * cml::externalmnd(3, 2, aM2)), cml::incompatible_matrix_inner_size_error); } - - - CATCH_TEST_CASE("dynamic, product1") { - cml::matrixd M1(2,2, - 1., 2., - 3., 4. - ); - cml::matrixd M2(2,2, - 5., 6., - 7., 8. - ); - - auto M = M1*M2; + cml::matrixd M1(2, 2, 1., 2., 3., 4.); + cml::matrixd M2(2, 2, 5., 6., 7., 8.); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 19.); - CATCH_CHECK(M(0,1) == 22.); - CATCH_CHECK(M(1,0) == 43.); - CATCH_CHECK(M(1,1) == 50.); + CATCH_CHECK(M(0, 0) == 19.); + CATCH_CHECK(M(0, 1) == 22.); + CATCH_CHECK(M(1, 0) == 43.); + CATCH_CHECK(M(1, 1) == 50.); } CATCH_TEST_CASE("dynamic, product2") { - cml::matrixd M1(3,2, - 1., 1., - 2., 2., - 3., 3. - ); - cml::matrixd M2(2,3, - 1., 2., 3., - 1., 2., 3. - ); - - auto M = M1*M2; + cml::matrixd M1(3, 2, 1., 1., 2., 2., 3., 3.); + cml::matrixd M2(2, 3, 1., 2., 3., 1., 2., 3.); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("dynamic, size_checking1") { - CATCH_REQUIRE_THROWS_AS( - (cml::matrixd(2,2) * cml::matrixd(3,2)), + CATCH_REQUIRE_THROWS_AS((cml::matrixd(2, 2) * cml::matrixd(3, 2)), cml::incompatible_matrix_inner_size_error); } - - - CATCH_TEST_CASE("mixed fixed, dynamic1") { - cml::matrix> M1( - 1., 1., - 2., 2., - 3., 3. - ); - cml::matrixd M2(2,3, - 1., 2., 3., - 1., 2., 3. - ); - - auto M = M1*M2; + cml::matrix> M1(1., 1., 2., 2., 3., 3.); + cml::matrixd M2(2, 3, 1., 2., 3., 1., 2., 3.); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("mixed fixed, external1") { - cml::matrix> M1( - 1., 1., - 2., 2., - 3., 3. - ); - - double aM2[] = { - 1., 2., 3., - 1., 2., 3. - }; + cml::matrix> M1(1., 1., 2., 2., 3., 3.); + + double aM2[] = {1., 2., 3., 1., 2., 3.}; cml::external23d M2(aM2); - auto M = M1*M2; + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("mixed fixed, external2") { - cml::matrix> M1( - 1., 1., - 2., 2., - 3., 3. - ); - - double aM2[] = { - 1., 2., 3., - 1., 2., 3. - }; - cml::externalmnd M2(2,3, aM2); - - auto M = M1*M2; + cml::matrix> M1(1., 1., 2., 2., 3., 3.); + + double aM2[] = {1., 2., 3., 1., 2., 3.}; + cml::externalmnd M2(2, 3, aM2); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } - - - CATCH_TEST_CASE("mixed dynamic, fixed1") { - cml::matrixd M1(3,2, - 1., 1., - 2., 2., - 3., 3. - ); - cml::matrix23d M2( - 1., 2., 3., - 1., 2., 3. - ); - - auto M = M1*M2; + cml::matrixd M1(3, 2, 1., 1., 2., 2., 3., 3.); + cml::matrix23d M2(1., 2., 3., 1., 2., 3.); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("mixed dynamic, external1") { - cml::matrixd M1(3,2, - 1., 1., - 2., 2., - 3., 3. - ); - - double aM2[] = { - 1., 2., 3., - 1., 2., 3. - }; + cml::matrixd M1(3, 2, 1., 1., 2., 2., 3., 3.); + + double aM2[] = {1., 2., 3., 1., 2., 3.}; cml::external23d M2(aM2); - auto M = M1*M2; + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("mixed dynamic, external2") { - cml::matrixd M1(3,2, - 1., 1., - 2., 2., - 3., 3. - ); - - double aM2[] = { - 1., 2., 3., - 1., 2., 3. - }; - cml::externalmnd M2(2,3, aM2); - - auto M = M1*M2; + cml::matrixd M1(3, 2, 1., 1., 2., 2., 3., 3.); + + double aM2[] = {1., 2., 3., 1., 2., 3.}; + cml::externalmnd M2(2, 3, aM2); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } - - - CATCH_TEST_CASE("mixed fixed external, fixed1") { - double aM1[] = { - 1., 1., - 2., 2., - 3., 3. - }; - cml::matrix> M1(aM1); - - cml::matrix23d M2( - 1., 2., 3., - 1., 2., 3. - ); - - auto M = M1*M2; + double aM1[] = {1., 1., 2., 2., 3., 3.}; + cml::matrix> M1(aM1); + + cml::matrix23d M2(1., 2., 3., 1., 2., 3.); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("mixed fixed external, dynamic1") { - double aM1[] = { - 1., 1., - 2., 2., - 3., 3. - }; - cml::matrix> M1(aM1); - - cml::matrixd M2(2,3, - 1., 2., 3., - 1., 2., 3. - ); - - auto M = M1*M2; + double aM1[] = {1., 1., 2., 2., 3., 3.}; + cml::matrix> M1(aM1); + + cml::matrixd M2(2, 3, 1., 2., 3., 1., 2., 3.); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("mixed fixed external, external1") { - double aM1[] = { - 1., 1., - 2., 2., - 3., 3. - }; - cml::matrix> M1(aM1); - - double aM2[] = { - 1., 2., 3., - 1., 2., 3. - }; + double aM1[] = {1., 1., 2., 2., 3., 3.}; + cml::matrix> M1(aM1); + + double aM2[] = {1., 2., 3., 1., 2., 3.}; cml::external23d M2(aM2); - auto M = M1*M2; + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("mixed fixed external, external2") { - double aM1[] = { - 1., 1., - 2., 2., - 3., 3. - }; - cml::matrix> M1(aM1); - - double aM2[] = { - 1., 2., 3., - 1., 2., 3. - }; - cml::externalmnd M2(2,3, aM2); - - auto M = M1*M2; + double aM1[] = {1., 1., 2., 2., 3., 3.}; + cml::matrix> M1(aM1); + + double aM2[] = {1., 2., 3., 1., 2., 3.}; + cml::externalmnd M2(2, 3, aM2); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } - - - CATCH_TEST_CASE("mixed dynamic external, fixed1") { - double aM1[] = { - 1., 1., - 2., 2., - 3., 3. - }; - cml::matrix> M1(3,2, aM1); - - cml::matrix23d M2( - 1., 2., 3., - 1., 2., 3. - ); - - auto M = M1*M2; + double aM1[] = {1., 1., 2., 2., 3., 3.}; + cml::matrix> M1(3, 2, aM1); + + cml::matrix23d M2(1., 2., 3., 1., 2., 3.); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("mixed dynamic external, dynamic1") { - double aM1[] = { - 1., 1., - 2., 2., - 3., 3. - }; - cml::matrix> M1(3,2, aM1); - - cml::matrixd M2(2,3, - 1., 2., 3., - 1., 2., 3. - ); - - auto M = M1*M2; + double aM1[] = {1., 1., 2., 2., 3., 3.}; + cml::matrix> M1(3, 2, aM1); + + cml::matrixd M2(2, 3, 1., 2., 3., 1., 2., 3.); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("mixed dynamic external, external1") { - double aM1[] = { - 1., 1., - 2., 2., - 3., 3. - }; - cml::matrix> M1(3,2, aM1); - - double aM2[] = { - 1., 2., 3., - 1., 2., 3. - }; + double aM1[] = {1., 1., 2., 2., 3., 3.}; + cml::matrix> M1(3, 2, aM1); + + double aM2[] = {1., 2., 3., 1., 2., 3.}; cml::external23d M2(aM2); - auto M = M1*M2; + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } CATCH_TEST_CASE("mixed dynamic external, external2") { - double aM1[] = { - 1., 1., - 2., 2., - 3., 3. - }; - cml::matrix> M1(3,2, aM1); - - double aM2[] = { - 1., 2., 3., - 1., 2., 3. - }; - cml::externalmnd M2(aM2, 2,3); - - auto M = M1*M2; + double aM1[] = {1., 1., 2., 2., 3., 3.}; + cml::matrix> M1(3, 2, aM1); + + double aM2[] = {1., 2., 3., 1., 2., 3.}; + cml::externalmnd M2(aM2, 2, 3); + + auto M = M1 * M2; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(M.rows() == 3); CATCH_REQUIRE(M.cols() == 3); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(0,2) == 6.); - CATCH_CHECK(M(1,0) == 4.); - CATCH_CHECK(M(1,1) == 8.); - CATCH_CHECK(M(1,2) == 12.); - CATCH_CHECK(M(2,0) == 6.); - CATCH_CHECK(M(2,1) == 12.); - CATCH_CHECK(M(2,2) == 18.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(0, 2) == 6.); + CATCH_CHECK(M(1, 0) == 4.); + CATCH_CHECK(M(1, 1) == 8.); + CATCH_CHECK(M(1, 2) == 12.); + CATCH_CHECK(M(2, 0) == 6.); + CATCH_CHECK(M(2, 1) == 12.); + CATCH_CHECK(M(2, 2) == 18.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/matrix_promotion1.cpp b/tests/matrix/matrix_promotion1.cpp index d5b3e5d..e387248 100644 --- a/tests/matrix/matrix_promotion1.cpp +++ b/tests/matrix/matrix_promotion1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -18,134 +16,114 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed fixed1") { - typedef cml::matrix_inner_product_promote< - cml::matrix22d, cml::matrix22d> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("fixed dynamic1") { - typedef cml::matrix_inner_product_promote< - cml::matrix22d, cml::matrixd> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("fixed external1") { - typedef cml::matrix_inner_product_promote< - cml::matrix22d, cml::external22d> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("fixed external2") { - typedef cml::matrix_inner_product_promote< - cml::matrix22d, cml::externalmnd> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("dynamic fixed1") { - typedef cml::matrix_inner_product_promote< - cml::matrixd, cml::matrix22d> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("dynamic dynamic1") { - typedef cml::matrix_inner_product_promote< - cml::matrixd, cml::matrixd> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("dynamic external1") { - typedef cml::matrix_inner_product_promote< - cml::matrixd, cml::external22d> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("dynamic external2") { - typedef cml::matrix_inner_product_promote< - cml::matrixd, cml::externalmnd> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("fixed external fixed1") { - typedef cml::matrix_inner_product_promote< - cml::external22d, cml::matrix22d> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("fixed external dynamic1") { - typedef cml::matrix_inner_product_promote< - cml::external22d, cml::matrixd> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("fixed external external1") { - typedef cml::matrix_inner_product_promote< - cml::external22d, cml::external22d> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("fixed external external2") { - typedef cml::matrix_inner_product_promote< - cml::external22d, cml::externalmnd> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("dynamic external fixed1") { - typedef cml::matrix_inner_product_promote< - cml::externalmnd, cml::matrix22d> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("dynamic external dynamic1") { - typedef cml::matrix_inner_product_promote< - cml::externalmnd, cml::matrixd> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("dynamic external external1") { - typedef cml::matrix_inner_product_promote< - cml::externalmnd, cml::external22d> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } CATCH_TEST_CASE("dynamic external external2") { - typedef cml::matrix_inner_product_promote< - cml::externalmnd, cml::externalmnd> promoter_type; - typedef promoter_type::type type; + using promoter_type = cml::matrix_inner_product_promote; + using type = promoter_type::type; CATCH_CHECK((std::is_same::value)); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/matrix_scalar_node1.cpp b/tests/matrix/matrix_scalar_node1.cpp index f354371..b090d28 100644 --- a/tests/matrix/matrix_scalar_node1.cpp +++ b/tests/matrix/matrix_scalar_node1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include @@ -17,284 +15,224 @@ CATCH_TEST_CASE("scalar_types1") { - typedef cml::matrix22d matrix_type; + using matrix_type = cml::matrix22d; { - auto xpr = matrix_type()*int(); - typedef decltype(xpr) xpr_type; + auto xpr = matrix_type() * int(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); - CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { - auto xpr = int()*matrix_type(); - typedef decltype(xpr) xpr_type; - CATCH_CHECK( - std::is_rvalue_reference::value - ); + auto xpr = int() * matrix_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { - auto xpr = matrix_type()/int(); - typedef decltype(xpr) xpr_type; + auto xpr = matrix_type() / int(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); - CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { double v = 0.; - auto xpr = matrix_type()*v; - typedef decltype(xpr) xpr_type; - CATCH_CHECK( - std::is_rvalue_reference::value - ); + auto xpr = matrix_type() * v; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_lvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { double v = 0.; - auto xpr = v*matrix_type(); - typedef decltype(xpr) xpr_type; + auto xpr = v * matrix_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); - CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { double v = 0.; - auto xpr = matrix_type()/v; - typedef decltype(xpr) xpr_type; - CATCH_CHECK( - std::is_rvalue_reference::value - ); + auto xpr = matrix_type() / v; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_lvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } } CATCH_TEST_CASE("fixed scalar_multiply1") { - cml::matrix22d M1( - 1., 2., - 3., 4. - ); + cml::matrix22d M1(1., 2., 3., 4.); cml::matrix22d M; - M = 2.*M1; + M = 2. * M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("fixed scalar_multiply2") { - cml::matrix22d M1( - 1., 2., - 3., 4. - ); - cml::matrix22d M = 2.*M1; + cml::matrix22d M1(1., 2., 3., 4.); + cml::matrix22d M = 2. * M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("fixed scalar_divide1") { - cml::matrix22d M1( - 2., 4., - 6., 8. - ); + cml::matrix22d M1(2., 4., 6., 8.); cml::matrix22d M; - M = M1/2.; + M = M1 / 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("fixed scalar_divide2") { - cml::matrix22d M1( - 2., 4., - 6., 8. - ); - cml::matrix22d M = M1/2.; + cml::matrix22d M1(2., 4., 6., 8.); + cml::matrix22d M = M1 / 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("fixed scalar_multiply_assign1") { - cml::matrix22d M( - 1., 2., - 3., 4. - ); + cml::matrix22d M(1., 2., 3., 4.); M *= 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("fixed scalar_multiply_assign2") { cml::matrix22d M; - M = (cml::matrix22d( - 1., 2., - 3., 4. - ) *= 2.); + M = (cml::matrix22d(1., 2., 3., 4.) *= 2.); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("fixed scalar_divide_assign1") { - cml::matrix22d M( - 2., 4., - 6., 8. - ); + cml::matrix22d M(2., 4., 6., 8.); M /= 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("fixed scalar_divide_assign2") { cml::matrix22d M; - M = (cml::matrix22d( - 2., 4., - 6., 8. - ) /= 2.); + M = (cml::matrix22d(2., 4., 6., 8.) /= 2.); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("fixed external scalar_multiply1") { - double aM[] = { - 1., 2., - 3., 4. - }; + double aM[] = {1., 2., 3., 4.}; cml::external22d M1(aM); double data[2][2]; cml::external22d M(data); - M = 2.*M1; + M = 2. * M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("fixed external scalar_divide1") { - double aM[] = { - 2., 4., - 6., 8. - }; + double aM[] = {2., 4., 6., 8.}; cml::external22d M1(aM); double data[2][2]; cml::external22d M(data); - M = M1/2.; + M = M1 / 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("fixed external scalar_multiply_assign1") { - double data[] = { - 1., 2., - 3., 4. - }; + double data[] = {1., 2., 3., 4.}; cml::external22d M(data); M *= 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("fixed external scalar_multiply_assign2") { #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - double aM[] = { - 1., 2., - 3., 4. - }; + double aM[] = {1., 2., 3., 4.}; cml::external22d M; M = (cml::external22d(aM) *= 2.); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); #else CATCH_WARN("Assignment to temporary external vectors not supported"); #endif @@ -302,36 +240,30 @@ CATCH_TEST_CASE("fixed external scalar_multiply_assign2") CATCH_TEST_CASE("fixed external scalar_divide_assign1") { - double data[] = { - 2., 4., - 6., 8. - }; + double data[] = {2., 4., 6., 8.}; cml::external22d M(data); M /= 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("fixed external scalar_divide_assign2") { #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - double aM[] = { - 2., 4., - 6., 8. - }; + double aM[] = {2., 4., 6., 8.}; cml::external22d M; M = (cml::external22d(aM) /= 2.); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); #else CATCH_WARN("Assignment to temporary external vectors not supported"); #endif @@ -339,76 +271,64 @@ CATCH_TEST_CASE("fixed external scalar_divide_assign2") CATCH_TEST_CASE("dynamic external scalar_multiply1") { - double aM[] = { - 1., 2., - 3., 4. - }; - cml::externalmnd M1(aM, 2,2); + double aM[] = {1., 2., 3., 4.}; + cml::externalmnd M1(aM, 2, 2); double data[2][2]; cml::externalmnd M(data); - M = 2.*M1; + M = 2. * M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("dynamic external scalar_divide1") { - double aM[] = { - 2., 4., - 6., 8. - }; - cml::externalmnd M1(aM, 2,2); + double aM[] = {2., 4., 6., 8.}; + cml::externalmnd M1(aM, 2, 2); double data[2][2]; cml::externalmnd M(data); - M = M1/2.; + M = M1 / 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("dynamic external scalar_multiply_assign1") { - double data[] = { - 1., 2., - 3., 4. - }; - cml::externalmnd M(data, 2,2); + double data[] = {1., 2., 3., 4.}; + cml::externalmnd M(data, 2, 2); M *= 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("dynamic external scalar_multiply_assign2") { #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - double aM[] = { - 1., 2., - 3., 4. - }; + double aM[] = {1., 2., 3., 4.}; cml::externalmnd M; - M = (cml::externalmnd(aM, 2,2) *= 2.); + M = (cml::externalmnd(aM, 2, 2) *= 2.); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); #else CATCH_WARN("Assignment to temporary external vectors not supported"); #endif @@ -416,36 +336,30 @@ CATCH_TEST_CASE("dynamic external scalar_multiply_assign2") CATCH_TEST_CASE("dynamic external scalar_divide_assign1") { - double data[] = { - 2., 4., - 6., 8. - }; - cml::externalmnd M(2,2, data); + double data[] = {2., 4., 6., 8.}; + cml::externalmnd M(2, 2, data); M /= 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("dynamic external scalar_divide_assign2") { #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - double aM[] = { - 2., 4., - 6., 8. - }; + double aM[] = {2., 4., 6., 8.}; cml::externalmnd M; - M = (cml::externalmnd(2,2, aM) /= 2.); + M = (cml::externalmnd(2, 2, aM) /= 2.); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); #else CATCH_WARN("Assignment to temporary external vectors not supported"); #endif @@ -453,133 +367,98 @@ CATCH_TEST_CASE("dynamic external scalar_divide_assign2") CATCH_TEST_CASE("dynamic scalar_multiply1") { - cml::matrixd M1( - 2,2, - 1., 2., - 3., 4. - ); + cml::matrixd M1(2, 2, 1., 2., 3., 4.); cml::matrixd M; - M = 2.*M1; + M = 2. * M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("dynamic scalar_multiply2") { - cml::matrixd M1( - 2,2, - 1., 2., - 3., 4. - ); - cml::matrixd M = 2.*M1; + cml::matrixd M1(2, 2, 1., 2., 3., 4.); + cml::matrixd M = 2. * M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("dynamic scalar_divide1") { - cml::matrixd M1( - 2,2, - 2., 4., - 6., 8. - ); + cml::matrixd M1(2, 2, 2., 4., 6., 8.); cml::matrixd M; - M = M1/2.; + M = M1 / 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("dynamic scalar_divide2") { - cml::matrixd M1( - 2,2, - 2., 4., - 6., 8. - ); - cml::matrixd M = M1/2.; + cml::matrixd M1(2, 2, 2., 4., 6., 8.); + cml::matrixd M = M1 / 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("dynamic scalar_multiply_assign1") { - cml::matrixd M( - 2,2, - 1., 2., - 3., 4. - ); + cml::matrixd M(2, 2, 1., 2., 3., 4.); M *= 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("dynamic scalar_multiply_assign2") { cml::matrixd M; - M = (cml::matrixd( - 2,2, - 1., 2., - 3., 4. - ) *= 2.); + M = (cml::matrixd(2, 2, 1., 2., 3., 4.) *= 2.); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 2.); - CATCH_CHECK(M(0,1) == 4.); - CATCH_CHECK(M(1,0) == 6.); - CATCH_CHECK(M(1,1) == 8.); + CATCH_CHECK(M(0, 0) == 2.); + CATCH_CHECK(M(0, 1) == 4.); + CATCH_CHECK(M(1, 0) == 6.); + CATCH_CHECK(M(1, 1) == 8.); } CATCH_TEST_CASE("dynamic scalar_divide_assign1") { - cml::matrixd M( - 2,2, - 2., 4., - 6., 8. - ); + cml::matrixd M(2, 2, 2., 4., 6., 8.); M /= 2.; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("dynamic scalar_divide_assign2") { cml::matrixd M; - M = (cml::matrixd( - 2,2, - 2., 4., - 6., 8. - ) /= 2.); + M = (cml::matrixd(2, 2, 2., 4., 6., 8.) /= 2.); CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/matrix_transpose1.cpp b/tests/matrix/matrix_transpose1.cpp index f486cfc..1be8dd3 100644 --- a/tests/matrix/matrix_transpose1.cpp +++ b/tests/matrix/matrix_transpose1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -17,252 +15,135 @@ CATCH_TEST_CASE("fixed transpose_assign_3x3") { - auto M = cml::matrix33d( - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - ); + auto M = cml::matrix33d(1., 2., 3., 1., 4., 9., 1., 16., 25.); M.transpose(); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(M(i,j) == expected(i,j)); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(M(i, j) == expected(i, j)); } CATCH_TEST_CASE("fixed transpose_3x3_1") { - auto M = cml::matrix33d( - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - ); + auto M = cml::matrix33d(1., 2., 3., 1., 4., 9., 1., 16., 25.); auto T = cml::transpose(M); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(T(i,j) == expected(i,j)); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(T(i, j) == expected(i, j)); } CATCH_TEST_CASE("fixed transpose_3x3_2") { - auto T = cml::transpose( - cml::matrix33d( - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - ) - ); - - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(T(i,j) == expected(i,j)); + auto T = cml::transpose(cml::matrix33d(1., 2., 3., 1., 4., 9., 1., 16., 25.)); + + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(T(i, j) == expected(i, j)); } CATCH_TEST_CASE("fixed external transpose_assign_3x3") { - double avM[] = { - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - }; + double avM[] = {1., 2., 3., 1., 4., 9., 1., 16., 25.}; cml::external33d M(avM); M.transpose(); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(M(i,j) == expected(i,j)); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(M(i, j) == expected(i, j)); } CATCH_TEST_CASE("fixed external transpose_3x3_1") { - double avM[] = { - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - }; + double avM[] = {1., 2., 3., 1., 4., 9., 1., 16., 25.}; cml::external33d M(avM); auto T = cml::transpose(M); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(T(i,j) == expected(i,j)); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(T(i, j) == expected(i, j)); } CATCH_TEST_CASE("fixed external transpose_3x3_2") { - double avM[] = { - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - }; + double avM[] = {1., 2., 3., 1., 4., 9., 1., 16., 25.}; auto T = cml::transpose(cml::external33d(avM)); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(T(i,j) == expected(i,j)); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(T(i, j) == expected(i, j)); } CATCH_TEST_CASE("dynamic external transpose_assign_3x3") { - double avM[] = { - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - }; - cml::externalmnd M(3,3, avM); + double avM[] = {1., 2., 3., 1., 4., 9., 1., 16., 25.}; + cml::externalmnd M(3, 3, avM); M.transpose(); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(M(i,j) == expected(i,j)); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(M(i, j) == expected(i, j)); } CATCH_TEST_CASE("dynamic external transpose_3x3_1") { - double avM[] = { - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - }; - cml::externalmnd M(3,3, avM); + double avM[] = {1., 2., 3., 1., 4., 9., 1., 16., 25.}; + cml::externalmnd M(3, 3, avM); auto T = cml::transpose(M); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(T(i,j) == expected(i,j)); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(T(i, j) == expected(i, j)); } CATCH_TEST_CASE("dynamic external transpose_3x3_2") { - double avM[] = { - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - }; - - auto T = cml::transpose(cml::externalmnd(3,3, avM)); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(T(i,j) == expected(i,j)); + double avM[] = {1., 2., 3., 1., 4., 9., 1., 16., 25.}; + + auto T = cml::transpose(cml::externalmnd(3, 3, avM)); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(T(i, j) == expected(i, j)); } CATCH_TEST_CASE("dynamic transpose_assign_3x3") { - auto M = cml::matrixd( - 3,3, - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - ); + auto M = cml::matrixd(3, 3, 1., 2., 3., 1., 4., 9., 1., 16., 25.); M.transpose(); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(M(i,j) == expected(i,j)); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(M(i, j) == expected(i, j)); } CATCH_TEST_CASE("dynamic transpose_3x3_1") { - auto M = cml::matrixd( - 3,3, - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - ); + auto M = cml::matrixd(3, 3, 1., 2., 3., 1., 4., 9., 1., 16., 25.); auto T = cml::transpose(M); - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(T(i,j) == expected(i,j)); + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(T(i, j) == expected(i, j)); } CATCH_TEST_CASE("dynamic transpose_3x3_2") { - auto T = cml::transpose( - cml::matrixd( - 3,3, - 1., 2., 3., - 1., 4., 9., - 1., 16., 25. - ) - ); - - auto expected = cml::matrix33d( - 1., 1., 1., - 2., 4., 16., - 3., 9., 25. - ); - - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(T(i,j) == expected(i,j)); -} + auto T = + cml::transpose(cml::matrixd(3, 3, 1., 2., 3., 1., 4., 9., 1., 16., 25.)); -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 + auto expected = cml::matrix33d(1., 1., 1., 2., 4., 16., 3., 9., 25.); + + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) CATCH_CHECK(T(i, j) == expected(i, j)); +} diff --git a/tests/matrix/matrix_unary_node1.cpp b/tests/matrix/matrix_unary_node1.cpp index 0da72cb..fa8e60a 100644 --- a/tests/matrix/matrix_unary_node1.cpp +++ b/tests/matrix/matrix_unary_node1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -17,328 +15,268 @@ CATCH_TEST_CASE("unary_types1") { - typedef cml::matrix> matrix_type; + using matrix_type = cml::matrix>; { CATCH_CHECK(cml::is_statically_polymorphic::value); } { - auto xpr = - matrix_type(); - typedef decltype(xpr) xpr_type; + auto xpr = -matrix_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { - auto xpr = + matrix_type(); - typedef decltype(xpr) xpr_type; + auto xpr = +matrix_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { matrix_type M; - auto xpr = - M; - typedef decltype(xpr) xpr_type; + auto xpr = -M; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { matrix_type M; - auto xpr = + M; - typedef decltype(xpr) xpr_type; + auto xpr = +M; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } } CATCH_TEST_CASE("fixed unary_minus1") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M; - M = - M1; + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M; + M = -M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -1.); - CATCH_CHECK(M(0,1) == -2.); - CATCH_CHECK(M(1,0) == -3.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -1.); + CATCH_CHECK(M(0, 1) == -2.); + CATCH_CHECK(M(1, 0) == -3.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("fixed unary_minus2") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M = - M1; + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M = -M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -1.); - CATCH_CHECK(M(0,1) == -2.); - CATCH_CHECK(M(1,0) == -3.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -1.); + CATCH_CHECK(M(0, 1) == -2.); + CATCH_CHECK(M(1, 0) == -3.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("fixed unary_plus1") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M; - M = + M1; + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M; + M = +M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("fixed unary_plus2") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M = + M1; + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M = +M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("fixed double_negate1") { - cml::matrix> M1( - 1., 2., - 3., 4. - ); - cml::matrix> M; - auto xpr = - (-M1); + cml::matrix> M1(1., 2., 3., 4.); + cml::matrix> M; + auto xpr = -(-M1); M = xpr; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("fixed external unary_minus1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1); double data[2][2]; - cml::matrix> M(data); - M = - M1; + cml::matrix> M(data); + M = -M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -1.); - CATCH_CHECK(M(0,1) == -2.); - CATCH_CHECK(M(1,0) == -3.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -1.); + CATCH_CHECK(M(0, 1) == -2.); + CATCH_CHECK(M(1, 0) == -3.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("fixed external unary_plus1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1); double data[2][2]; - cml::matrix> M(data); - M = + M1; + cml::matrix> M(data); + M = +M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("fixed external double_negate1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1); double data[2][2]; - cml::matrix> M(data); + cml::matrix> M(data); - auto xpr = - (-M1); + auto xpr = -(-M1); M = xpr; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("dynamic external unary_minus1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1, 2,2); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1, 2, 2); double data[2][2]; cml::matrix> M(data); - M = - M1; + M = -M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -1.); - CATCH_CHECK(M(0,1) == -2.); - CATCH_CHECK(M(1,0) == -3.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -1.); + CATCH_CHECK(M(0, 1) == -2.); + CATCH_CHECK(M(1, 0) == -3.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("dynamic external unary_plus1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1, 2,2); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1, 2, 2); double data[2][2]; cml::matrix> M(data); - M = + M1; + M = +M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("dynamic external double_negate1") { - double aM1[] = { - 1., 2., - 3., 4. - }; - cml::matrix> M1(aM1, 2,2); + double aM1[] = {1., 2., 3., 4.}; + cml::matrix> M1(aM1, 2, 2); double data[2][2]; cml::matrix> M(data); - auto xpr = - (-M1); + auto xpr = -(-M1); M = xpr; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("dynamic unary_minus1") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); + cml::matrix> M1(2, 2, 1., 2., 3., 4.); cml::matrix> M; - M = - M1; + M = -M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -1.); - CATCH_CHECK(M(0,1) == -2.); - CATCH_CHECK(M(1,0) == -3.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -1.); + CATCH_CHECK(M(0, 1) == -2.); + CATCH_CHECK(M(1, 0) == -3.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("dynamic unary_minus2") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); - cml::matrix> M = - M1; + cml::matrix> M1(2, 2, 1., 2., 3., 4.); + cml::matrix> M = -M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == -1.); - CATCH_CHECK(M(0,1) == -2.); - CATCH_CHECK(M(1,0) == -3.); - CATCH_CHECK(M(1,1) == -4.); + CATCH_CHECK(M(0, 0) == -1.); + CATCH_CHECK(M(0, 1) == -2.); + CATCH_CHECK(M(1, 0) == -3.); + CATCH_CHECK(M(1, 1) == -4.); } CATCH_TEST_CASE("dynamic unary_plus1") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); + cml::matrix> M1(2, 2, 1., 2., 3., 4.); cml::matrix> M; - M = + M1; + M = +M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("dynamic unary_plus2") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); - cml::matrix> M = + M1; + cml::matrix> M1(2, 2, 1., 2., 3., 4.); + cml::matrix> M = +M1; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } CATCH_TEST_CASE("dynamic double_negate1") { - cml::matrix> M1( - 2,2, - 1., 2., - 3., 4. - ); + cml::matrix> M1(2, 2, 1., 2., 3., 4.); cml::matrix> M; - auto xpr = - (-M1); + auto xpr = -(-M1); M = xpr; CATCH_REQUIRE(M.rows() == 2); CATCH_REQUIRE(M.cols() == 2); - CATCH_CHECK(M(0,0) == 1.); - CATCH_CHECK(M(0,1) == 2.); - CATCH_CHECK(M(1,0) == 3.); - CATCH_CHECK(M(1,1) == 4.); + CATCH_CHECK(M(0, 0) == 1.); + CATCH_CHECK(M(0, 1) == 2.); + CATCH_CHECK(M(1, 0) == 3.); + CATCH_CHECK(M(1, 1) == 4.); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/matrix_vector_product1.cpp b/tests/matrix/matrix_vector_product1.cpp index be7265e..bf98c84 100644 --- a/tests/matrix/matrix_vector_product1.cpp +++ b/tests/matrix/matrix_vector_product1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -23,15 +21,10 @@ CATCH_TEST_CASE("fixed product1") { - cml::matrix22d M( - 1., 2., - 3., 4. - ); - cml::vector2d v1( - 5., 6. - ); - - auto v = M*v1; + cml::matrix22d M(1., 2., 3., 4.); + cml::vector2d v1(5., 6.); + + auto v = M * v1; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(v.size() == 2); CATCH_CHECK(v[0] == 17.); @@ -40,15 +33,10 @@ CATCH_TEST_CASE("fixed product1") CATCH_TEST_CASE("fixed product2") { - cml::matrix22d M( - 1., 2., - 3., 4. - ); - cml::vector2d v1( - 5., 6. - ); - - auto v = v1*M; + cml::matrix22d M(1., 2., 3., 4.); + cml::vector2d v1(5., 6.); + + auto v = v1 * M; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(v.size() == 2); CATCH_CHECK(v[0] == 23.); @@ -57,13 +45,13 @@ CATCH_TEST_CASE("fixed product2") CATCH_TEST_CASE("fixed external product1") { - double aM[] = { 1., 2., 3., 4. }; + double aM[] = {1., 2., 3., 4.}; cml::external22d M(aM); - double av1[] = { 5., 6. }; + double av1[] = {5., 6.}; cml::external2d v1(av1); - auto v = M*v1; + auto v = M * v1; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(v.size() == 2); CATCH_CHECK(v[0] == 17.); @@ -72,13 +60,13 @@ CATCH_TEST_CASE("fixed external product1") CATCH_TEST_CASE("fixed external product2") { - double aM[] = { 1., 2., 3., 4. }; + double aM[] = {1., 2., 3., 4.}; cml::external22d M(aM); - double av1[] = { 5., 6. }; + double av1[] = {5., 6.}; cml::external2d v1(av1); - auto v = v1*M; + auto v = v1 * M; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(v.size() == 2); CATCH_CHECK(v[0] == 23.); @@ -87,13 +75,13 @@ CATCH_TEST_CASE("fixed external product2") CATCH_TEST_CASE("dynamic external product1") { - double aM[] = { 1., 2., 3., 4. }; - cml::externalmnd M(aM, 2,2); + double aM[] = {1., 2., 3., 4.}; + cml::externalmnd M(aM, 2, 2); - double av1[] = { 5., 6. }; + double av1[] = {5., 6.}; cml::externalnd v1(2, av1); - auto v = M*v1; + auto v = M * v1; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(v.size() == 2); CATCH_CHECK(v[0] == 17.); @@ -102,13 +90,13 @@ CATCH_TEST_CASE("dynamic external product1") CATCH_TEST_CASE("dynamic external product2") { - double aM[] = { 1., 2., 3., 4. }; - cml::externalmnd M(aM, 2,2); + double aM[] = {1., 2., 3., 4.}; + cml::externalmnd M(aM, 2, 2); - double av1[] = { 5., 6. }; + double av1[] = {5., 6.}; cml::externalnd v1(2, av1); - auto v = v1*M; + auto v = v1 * M; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(v.size() == 2); CATCH_CHECK(v[0] == 23.); @@ -119,7 +107,7 @@ CATCH_TEST_CASE("dynamic external size_checking1") { double aM1[4], av1[3]; CATCH_REQUIRE_THROWS_AS( - (cml::externalmnd(aM1, 2,2) * cml::externalnd(3, av1)), + (cml::externalmnd(aM1, 2, 2) * cml::externalnd(3, av1)), cml::incompatible_matrix_inner_size_error); } @@ -127,22 +115,16 @@ CATCH_TEST_CASE("dynamic external size_checking2") { double aM1[4], av1[3]; CATCH_REQUIRE_THROWS_AS( - (cml::externalnd(3, av1) * cml::externalmnd(2,2, aM1)), + (cml::externalnd(3, av1) * cml::externalmnd(2, 2, aM1)), cml::incompatible_matrix_inner_size_error); } CATCH_TEST_CASE("dynamic product1") { - cml::matrixd M( - 2,2, - 1., 2., - 3., 4. - ); - cml::vectord v1( - 5., 6. - ); - - auto v = M*v1; + cml::matrixd M(2, 2, 1., 2., 3., 4.); + cml::vectord v1(5., 6.); + + auto v = M * v1; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(v.size() == 2); CATCH_CHECK(v[0] == 17.); @@ -151,16 +133,10 @@ CATCH_TEST_CASE("dynamic product1") CATCH_TEST_CASE("dynamic product2") { - cml::matrixd M( - 2,2, - 1., 2., - 3., 4. - ); - cml::vectord v1( - 5., 6. - ); - - auto v = v1*M; + cml::matrixd M(2, 2, 1., 2., 3., 4.); + cml::vectord v1(5., 6.); + + auto v = v1 * M; CATCH_REQUIRE((std::is_same::value)); CATCH_REQUIRE(v.size() == 2); CATCH_CHECK(v[0] == 23.); @@ -169,17 +145,12 @@ CATCH_TEST_CASE("dynamic product2") CATCH_TEST_CASE("dynamic size_checking1") { - CATCH_REQUIRE_THROWS_AS( - (cml::matrixd(2,2) * cml::vectord(3)), + CATCH_REQUIRE_THROWS_AS((cml::matrixd(2, 2) * cml::vectord(3)), cml::incompatible_matrix_inner_size_error); } CATCH_TEST_CASE("dynamic size_checking2") { - CATCH_REQUIRE_THROWS_AS( - (cml::vectord(3) * cml::matrixd(2,2)), + CATCH_REQUIRE_THROWS_AS((cml::vectord(3) * cml::matrixd(2, 2)), cml::incompatible_matrix_inner_size_error); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/matrix/rowcol1.cpp b/tests/matrix/rowcol1.cpp index 99fc2dd..1dd4bfe 100644 --- a/tests/matrix/rowcol1.cpp +++ b/tests/matrix/rowcol1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -15,187 +13,126 @@ CATCH_TEST_CASE("fixed row1") { - auto M = cml::matrix44d( - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - ); + auto M = cml::matrix44d(1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., + 1., 36., 81., 100.); auto row1 = cml::row(M, 1); CATCH_CHECK(row1.size() == 4); - for(int j = 0; j < row1.size(); ++ j) - CATCH_CHECK(row1[j] == M(1,j)); + for(int j = 0; j < row1.size(); ++j) CATCH_CHECK(row1[j] == M(1, j)); } CATCH_TEST_CASE("fixed col1") { - auto M = cml::matrix44d( - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - ); + auto M = cml::matrix44d(1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., + 1., 36., 81., 100.); auto col3 = cml::col(M, 3); CATCH_CHECK(col3.size() == 4); - for(int i = 0; i < col3.size(); ++ i) - CATCH_CHECK(col3[i] == M(i,3)); + for(int i = 0; i < col3.size(); ++i) CATCH_CHECK(col3[i] == M(i, 3)); } CATCH_TEST_CASE("fixed external row1") { double avM[16] = { - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - }; + 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., 36., 81., 100.}; auto M = cml::external44d(avM); auto row1 = cml::row(M, 1); CATCH_CHECK(row1.size() == 4); - for(int j = 0; j < row1.size(); ++ j) - CATCH_CHECK(row1[j] == M(1,j)); + for(int j = 0; j < row1.size(); ++j) CATCH_CHECK(row1[j] == M(1, j)); } CATCH_TEST_CASE("fixed external col1") { double avM[16] = { - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - }; + 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., 36., 81., 100.}; auto M = cml::external44d(avM); auto col3 = cml::col(M, 3); CATCH_CHECK(col3.size() == 4); - for(int i = 0; i < col3.size(); ++ i) - CATCH_CHECK(col3[i] == M(i,3)); + for(int i = 0; i < col3.size(); ++i) CATCH_CHECK(col3[i] == M(i, 3)); } CATCH_TEST_CASE("dynamic external row1") { double avM[16] = { - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - }; - auto M = cml::externalmnd(4,4, avM); + 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., 36., 81., 100.}; + auto M = cml::externalmnd(4, 4, avM); auto row1 = cml::row(M, 1); CATCH_CHECK(row1.size() == 4); - for(int j = 0; j < row1.size(); ++ j) - CATCH_CHECK(row1[j] == M(1,j)); + for(int j = 0; j < row1.size(); ++j) CATCH_CHECK(row1[j] == M(1, j)); } CATCH_TEST_CASE("dynamic external col1") { double avM[16] = { - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - }; - auto M = cml::externalmnd(4,4, avM); + 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., 36., 1., 36., 81., 100.}; + auto M = cml::externalmnd(4, 4, avM); auto col3 = cml::col(M, 3); CATCH_CHECK(col3.size() == 4); - for(int i = 0; i < col3.size(); ++ i) - CATCH_CHECK(col3[i] == M(i,3)); + for(int i = 0; i < col3.size(); ++i) CATCH_CHECK(col3[i] == M(i, 3)); } CATCH_TEST_CASE("dynamic row1") { - auto M = cml::matrixd( - 4,4, - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - ); + auto M = cml::matrixd(4, 4, 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., + 36., 1., 36., 81., 100.); auto row1 = cml::row(M, 1); CATCH_CHECK(row1.size() == 4); - for(int j = 0; j < row1.size(); ++ j) - CATCH_CHECK(row1[j] == M(1,j)); + for(int j = 0; j < row1.size(); ++j) CATCH_CHECK(row1[j] == M(1, j)); } CATCH_TEST_CASE("dynamic col1") { - auto M = cml::matrixd( - 4,4, - 1., 2., 3., 4., - 1., 4., 9., 16., - 1., 16., 25., 36., - 1., 36., 81., 100. - ); + auto M = cml::matrixd(4, 4, 1., 2., 3., 4., 1., 4., 9., 16., 1., 16., 25., + 36., 1., 36., 81., 100.); auto col3 = cml::col(M, 3); CATCH_CHECK(col3.size() == 4); - for(int i = 0; i < col3.size(); ++ i) - CATCH_CHECK(col3[i] == M(i,3)); + for(int i = 0; i < col3.size(); ++i) CATCH_CHECK(col3[i] == M(i, 3)); } CATCH_TEST_CASE("mixed row1") { auto v = cml::vector3d(1., 2., 3.); - auto C = cml::outer(v,v); + auto C = cml::outer(v, v); CATCH_REQUIRE(C.rows() == 3); CATCH_REQUIRE(C.cols() == 3); - auto row1 = cml::row(C,1); - for(int j = 0; j < row1.size(); ++ j) - CATCH_CHECK(row1[j] == C(1,j)); + auto row1 = cml::row(C, 1); + for(int j = 0; j < row1.size(); ++j) CATCH_CHECK(row1[j] == C(1, j)); } CATCH_TEST_CASE("mixed col1") { auto v = cml::vector3d(1., 2., 3.); - auto C = cml::outer(v,v); + auto C = cml::outer(v, v); CATCH_REQUIRE(C.rows() == 3); CATCH_REQUIRE(C.cols() == 3); - auto col1 = cml::col(C,1); - for(int i = 0; i < col1.size(); ++ i) - CATCH_CHECK(col1[i] == C(i,1)); + auto col1 = cml::col(C, 1); + for(int i = 0; i < col1.size(); ++i) CATCH_CHECK(col1[i] == C(i, 1)); } CATCH_TEST_CASE("mixed row2") { - auto M1 = cml::matrix22d( - 1., 2., - 3., 4. - ); - auto M2 = cml::matrix22d( - 5., 6., - 7., 8. - ); + auto M1 = cml::matrix22d(1., 2., 3., 4.); + auto M2 = cml::matrix22d(5., 6., 7., 8.); auto M = M1 - M2; - auto row2 = cml::row(M,1); - for(int j = 0; j < row2.size(); ++ j) - CATCH_CHECK(row2[j] == M(1,j)); + auto row2 = cml::row(M, 1); + for(int j = 0; j < row2.size(); ++j) CATCH_CHECK(row2[j] == M(1, j)); } CATCH_TEST_CASE("mixed col2") { - auto M1 = cml::matrix22d( - 1., 2., - 3., 4. - ); - auto M2 = cml::matrix22d( - 5., 6., - 7., 8. - ); + auto M1 = cml::matrix22d(1., 2., 3., 4.); + auto M2 = cml::matrix22d(5., 6., 7., 8.); auto M = M1 - M2; - auto col2 = cml::col(M,1); - for(int i = 0; i < col2.size(); ++ i) - CATCH_CHECK(col2[i] == M(i,1)); + auto col2 = cml::col(M, 1); + for(int i = 0; i < col2.size(); ++i) CATCH_CHECK(col2[i] == M(i, 1)); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/quaternion/CMakeLists.txt b/tests/quaternion/CMakeLists.txt index 0adc52a..da7f3d9 100644 --- a/tests/quaternion/CMakeLists.txt +++ b/tests/quaternion/CMakeLists.txt @@ -1,12 +1,10 @@ -# -*- cmake -*- ----------------------------------------------------------- +# *------------------------------------------------------------------------- # @@COPYRIGHT@@ -#*------------------------------------------------------------------------- +# *------------------------------------------------------------------------- -project(CML_Testing_Quaternion) -set(CML_CURRENT_TEST_GROUP "Quaternion") +set(CML_TEST_GROUP "quaternion") cml_add_test(fixed_compiled_quaternion1) -#ADD_CML_TEST(quaternion_copy1) ## Not implemented yet. cml_add_test(quaternion_unary_node1) cml_add_test(quaternion_binary_node1) cml_add_test(quaternion_scalar_node1) @@ -16,4 +14,5 @@ cml_add_test(quaternion_product1) cml_add_test(quaternion_dot1) cml_add_test(imaginary1) cml_add_test(conjugate1) -cml_add_test(inverse1) \ No newline at end of file +cml_add_test(inverse1) +# ADD_CML_TEST(quaternion_copy1) ## Not implemented yet. \ No newline at end of file diff --git a/tests/quaternion/conjugate1.cpp b/tests/quaternion/conjugate1.cpp index dd3397e..12642f6 100644 --- a/tests/quaternion/conjugate1.cpp +++ b/tests/quaternion/conjugate1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -14,86 +12,80 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, readable1") { const cml::quaterniond_ip q(1., 2., 3., 4.); auto xpr = q.conjugate(); - CATCH_CHECK(xpr[0] == - 1.); - CATCH_CHECK(xpr[1] == - 2.); - CATCH_CHECK(xpr[2] == - 3.); - CATCH_CHECK(xpr[3] == 4.); + CATCH_CHECK(xpr[0] == -1.); + CATCH_CHECK(xpr[1] == -2.); + CATCH_CHECK(xpr[2] == -3.); + CATCH_CHECK(xpr[3] == 4.); } CATCH_TEST_CASE("fixed, readable2") { const cml::quaterniond_rp q(1., 2., 3., 4.); auto xpr = q.conjugate(); - CATCH_CHECK(xpr[0] == 1.); - CATCH_CHECK(xpr[1] == - 2.); - CATCH_CHECK(xpr[2] == - 3.); - CATCH_CHECK(xpr[3] == - 4.); + CATCH_CHECK(xpr[0] == 1.); + CATCH_CHECK(xpr[1] == -2.); + CATCH_CHECK(xpr[2] == -3.); + CATCH_CHECK(xpr[3] == -4.); } CATCH_TEST_CASE("fixed, writable1") { - cml::quaterniond_ip q = { 1., 2., 3., 4. }; + cml::quaterniond_ip q = {1., 2., 3., 4.}; q.conjugate(); - CATCH_CHECK(q[0] == - 1.); - CATCH_CHECK(q[1] == - 2.); - CATCH_CHECK(q[2] == - 3.); - CATCH_CHECK(q[3] == 4.); + CATCH_CHECK(q[0] == -1.); + CATCH_CHECK(q[1] == -2.); + CATCH_CHECK(q[2] == -3.); + CATCH_CHECK(q[3] == 4.); } CATCH_TEST_CASE("fixed, writable2") { - cml::quaterniond_rp q = { 1., 2., 3., 4. }; + cml::quaterniond_rp q = {1., 2., 3., 4.}; q.conjugate(); - CATCH_CHECK(q[0] == 1.); - CATCH_CHECK(q[1] == - 2.); - CATCH_CHECK(q[2] == - 3.); - CATCH_CHECK(q[3] == - 4.); + CATCH_CHECK(q[0] == 1.); + CATCH_CHECK(q[1] == -2.); + CATCH_CHECK(q[2] == -3.); + CATCH_CHECK(q[3] == -4.); } CATCH_TEST_CASE("fixed, function1") { - cml::quaterniond_ip q = { 1., 2., 3., 4. }; + cml::quaterniond_ip q = {1., 2., 3., 4.}; auto xpr = cml::conjugate(q); - CATCH_CHECK(xpr[0] == - 1.); - CATCH_CHECK(xpr[1] == - 2.); - CATCH_CHECK(xpr[2] == - 3.); - CATCH_CHECK(xpr[3] == 4.); + CATCH_CHECK(xpr[0] == -1.); + CATCH_CHECK(xpr[1] == -2.); + CATCH_CHECK(xpr[2] == -3.); + CATCH_CHECK(xpr[3] == 4.); } CATCH_TEST_CASE("fixed, function2") { - cml::quaterniond_rp q = { 1., 2., 3., 4. }; + cml::quaterniond_rp q = {1., 2., 3., 4.}; auto xpr = cml::conjugate(q); - CATCH_CHECK(xpr[0] == 1.); - CATCH_CHECK(xpr[1] == - 2.); - CATCH_CHECK(xpr[2] == - 3.); - CATCH_CHECK(xpr[3] == - 4.); + CATCH_CHECK(xpr[0] == 1.); + CATCH_CHECK(xpr[1] == -2.); + CATCH_CHECK(xpr[2] == -3.); + CATCH_CHECK(xpr[3] == -4.); } CATCH_TEST_CASE("fixed, temporary1") { auto xpr = cml::conjugate(cml::quaterniond_ip(1., 2., 3., 4.)); - CATCH_CHECK(xpr[0] == - 1.); - CATCH_CHECK(xpr[1] == - 2.); - CATCH_CHECK(xpr[2] == - 3.); - CATCH_CHECK(xpr[3] == 4.); + CATCH_CHECK(xpr[0] == -1.); + CATCH_CHECK(xpr[1] == -2.); + CATCH_CHECK(xpr[2] == -3.); + CATCH_CHECK(xpr[3] == 4.); } CATCH_TEST_CASE("fixed, conjugate2") { auto xpr = cml::conjugate(cml::quaterniond_rp(1., 2., 3., 4.)); - CATCH_CHECK(xpr[0] == 1.); - CATCH_CHECK(xpr[1] == - 2.); - CATCH_CHECK(xpr[2] == - 3.); - CATCH_CHECK(xpr[3] == - 4.); + CATCH_CHECK(xpr[0] == 1.); + CATCH_CHECK(xpr[1] == -2.); + CATCH_CHECK(xpr[2] == -3.); + CATCH_CHECK(xpr[3] == -4.); } - - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/quaternion/fixed_compiled_quaternion1.cpp b/tests/quaternion/fixed_compiled_quaternion1.cpp index 9737db2..6e07087 100644 --- a/tests/quaternion/fixed_compiled_quaternion1.cpp +++ b/tests/quaternion/fixed_compiled_quaternion1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -16,7 +14,7 @@ CATCH_TEST_CASE("array_construct1") { - double data[] = { 1., 2., 3., 4. }; + double data[] = {1., 2., 3., 4.}; cml::quaterniond_ip q(data); CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_ip::X] == 1.); @@ -25,7 +23,7 @@ CATCH_TEST_CASE("array_construct1") CATCH_TEST_CASE("array_construct2") { - double data[] = { 1., 2., 3., 4. }; + double data[] = {1., 2., 3., 4.}; cml::quaterniond_rp q(data); CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_rp::X] == 2.); @@ -34,7 +32,7 @@ CATCH_TEST_CASE("array_construct2") CATCH_TEST_CASE("array_temp_construct1") { - double data[] = { 1., 2., 3., 4. }; + double data[] = {1., 2., 3., 4.}; cml::quaterniond_ip q = data; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_ip::X] == 1.); @@ -43,7 +41,7 @@ CATCH_TEST_CASE("array_temp_construct1") CATCH_TEST_CASE("array_temp_construct2") { - double data[] = { 1., 2., 3., 4. }; + double data[] = {1., 2., 3., 4.}; cml::quaterniond_rp q = data; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_rp::X] == 2.); @@ -100,7 +98,7 @@ CATCH_TEST_CASE("combine_construct4") CATCH_TEST_CASE("combine_construct5") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::quaterniond_ip q(data, 4.); CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_ip::X] == 1.); @@ -109,7 +107,7 @@ CATCH_TEST_CASE("combine_construct5") CATCH_TEST_CASE("combine_construct6") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::quaterniond_rp q(data, 4.); CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_rp::X] == 1.); @@ -118,7 +116,7 @@ CATCH_TEST_CASE("combine_construct6") CATCH_TEST_CASE("combine_construct7") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::quaterniond_ip q(4., data); CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_ip::X] == 1.); @@ -127,7 +125,7 @@ CATCH_TEST_CASE("combine_construct7") CATCH_TEST_CASE("combine_construct8") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::quaterniond_rp q(4., data); CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_rp::X] == 1.); @@ -136,7 +134,7 @@ CATCH_TEST_CASE("combine_construct8") CATCH_TEST_CASE("array_assign1") { - double data[] = { 1., 2., 3., 4. }; + double data[] = {1., 2., 3., 4.}; cml::quaterniond_ip q; q = data; CATCH_REQUIRE(q.size() == 4); @@ -146,7 +144,7 @@ CATCH_TEST_CASE("array_assign1") CATCH_TEST_CASE("array_assign2") { - double data[] = { 1., 2., 3., 4. }; + double data[] = {1., 2., 3., 4.}; cml::quaterniond_rp q; q = data; CATCH_REQUIRE(q.size() == 4); @@ -156,7 +154,7 @@ CATCH_TEST_CASE("array_assign2") CATCH_TEST_CASE("pointer_construct1") { - double data[] = { 1., 2., 3., 4. }; + double data[] = {1., 2., 3., 4.}; cml::quaterniond_ip q(&data[0]); CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_ip::X] == 1.); @@ -165,7 +163,7 @@ CATCH_TEST_CASE("pointer_construct1") CATCH_TEST_CASE("pointer_construct2") { - double data[] = { 1., 2., 3., 4. }; + double data[] = {1., 2., 3., 4.}; cml::quaterniond_rp q(&data[0]); CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_rp::X] == 2.); @@ -174,7 +172,7 @@ CATCH_TEST_CASE("pointer_construct2") CATCH_TEST_CASE("list_temp_construct1") { - cml::quaterniond_ip q = { 1., 2., 3., 4. }; + cml::quaterniond_ip q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_ip::X] == 1.); CATCH_CHECK(q[cml::quaterniond_ip::W] == 4.); @@ -182,7 +180,7 @@ CATCH_TEST_CASE("list_temp_construct1") CATCH_TEST_CASE("list_temp_construct2") { - cml::quaterniond_rp q = { 1., 2., 3., 4. }; + cml::quaterniond_rp q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_rp::X] == 2.); CATCH_CHECK(q[cml::quaterniond_rp::W] == 1.); @@ -191,7 +189,7 @@ CATCH_TEST_CASE("list_temp_construct2") CATCH_TEST_CASE("list_assign1") { cml::quaterniond_ip q; - q = { 1., 2., 3., 4. }; + q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_ip::X] == 1.); CATCH_CHECK(q[cml::quaterniond_ip::W] == 4.); @@ -200,7 +198,7 @@ CATCH_TEST_CASE("list_assign1") CATCH_TEST_CASE("list_assign2") { cml::quaterniond_rp q; - q = { 1., 2., 3., 4. }; + q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[cml::quaterniond_rp::X] == 2.); CATCH_CHECK(q[cml::quaterniond_rp::W] == 1.); @@ -246,13 +244,12 @@ CATCH_TEST_CASE("size_check1") { cml::quaterniond_rp q; CATCH_REQUIRE(q.size() == 4); - CATCH_REQUIRE_THROWS_AS( - (q = { 1., 2., 3. }), cml::quaternion_size_error); + CATCH_REQUIRE_THROWS_AS((q = {1., 2., 3.}), cml::quaternion_size_error); } CATCH_TEST_CASE("coordinates1") { - double data[] = { 1., 2., 3., 4. }; + double data[] = {1., 2., 3., 4.}; const cml::quaterniond_ip q(data); CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q.x() == 1.); @@ -263,7 +260,7 @@ CATCH_TEST_CASE("coordinates1") CATCH_TEST_CASE("coordinates2") { - double data[] = { 1., 2., 3., 4. }; + double data[] = {1., 2., 3., 4.}; const cml::quaterniond_rp q(data); CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q.x() == 2.); @@ -299,6 +296,3 @@ CATCH_TEST_CASE("coordinate_assign2") CATCH_CHECK(q[cml::quaterniond_rp::Y] == 3.); CATCH_CHECK(q[cml::quaterniond_rp::Z] == 4.); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/quaternion/imaginary1.cpp b/tests/quaternion/imaginary1.cpp index b904fef..290190c 100644 --- a/tests/quaternion/imaginary1.cpp +++ b/tests/quaternion/imaginary1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -15,7 +13,6 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, readable1") { const cml::quaterniond_ip q(1., 2., 3., 4.); @@ -38,7 +35,7 @@ CATCH_TEST_CASE("fixed, readable2") CATCH_TEST_CASE("fixed, function1") { - cml::quaterniond_ip q = { 1., 2., 3., 4. }; + cml::quaterniond_ip q = {1., 2., 3., 4.}; auto xpr = cml::imaginary(q); CATCH_REQUIRE(cml::int_c::value == 3); CATCH_CHECK(xpr[0] == 1.); @@ -48,7 +45,7 @@ CATCH_TEST_CASE("fixed, function1") CATCH_TEST_CASE("fixed, function2") { - cml::quaterniond_rp q = { 1., 2., 3., 4. }; + cml::quaterniond_rp q = {1., 2., 3., 4.}; auto xpr = cml::imaginary(q); CATCH_REQUIRE(cml::int_c::value == 3); CATCH_CHECK(xpr[0] == 2.); @@ -73,8 +70,3 @@ CATCH_TEST_CASE("fixed, temporary2") CATCH_CHECK(xpr[1] == 3.); CATCH_CHECK(xpr[2] == 4.); } - - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/quaternion/inverse1.cpp b/tests/quaternion/inverse1.cpp index b5d7285..e72dfd2 100644 --- a/tests/quaternion/inverse1.cpp +++ b/tests/quaternion/inverse1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -14,16 +12,15 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, readable1") { const cml::quaterniond_ip q(1., 2., 3., 4.); auto n = q.norm(); auto xpr = q.inverse(); - CATCH_CHECK(xpr[0] == - 1./n); - CATCH_CHECK(xpr[1] == - 2./n); - CATCH_CHECK(xpr[2] == - 3./n); - CATCH_CHECK(xpr[3] == 4./n); + CATCH_CHECK(xpr[0] == -1. / n); + CATCH_CHECK(xpr[1] == -2. / n); + CATCH_CHECK(xpr[2] == -3. / n); + CATCH_CHECK(xpr[3] == 4. / n); } CATCH_TEST_CASE("fixed, readable2") @@ -31,77 +28,72 @@ CATCH_TEST_CASE("fixed, readable2") const cml::quaterniond_rp q(1., 2., 3., 4.); auto n = q.norm(); auto xpr = q.inverse(); - CATCH_CHECK(xpr[0] == 1./n); - CATCH_CHECK(xpr[1] == - 2./n); - CATCH_CHECK(xpr[2] == - 3./n); - CATCH_CHECK(xpr[3] == - 4./n); + CATCH_CHECK(xpr[0] == 1. / n); + CATCH_CHECK(xpr[1] == -2. / n); + CATCH_CHECK(xpr[2] == -3. / n); + CATCH_CHECK(xpr[3] == -4. / n); } CATCH_TEST_CASE("fixed, writable1") { - cml::quaterniond_ip q = { 1., 2., 3., 4. }; + cml::quaterniond_ip q = {1., 2., 3., 4.}; auto n = q.norm(); q.inverse(); - CATCH_CHECK(q[0] == - 1./n); - CATCH_CHECK(q[1] == - 2./n); - CATCH_CHECK(q[2] == - 3./n); - CATCH_CHECK(q[3] == 4./n); + CATCH_CHECK(q[0] == -1. / n); + CATCH_CHECK(q[1] == -2. / n); + CATCH_CHECK(q[2] == -3. / n); + CATCH_CHECK(q[3] == 4. / n); } CATCH_TEST_CASE("fixed, writable2") { - cml::quaterniond_rp q = { 1., 2., 3., 4. }; + cml::quaterniond_rp q = {1., 2., 3., 4.}; auto n = q.norm(); q.inverse(); - CATCH_CHECK(q[0] == 1./n); - CATCH_CHECK(q[1] == - 2./n); - CATCH_CHECK(q[2] == - 3./n); - CATCH_CHECK(q[3] == - 4./n); + CATCH_CHECK(q[0] == 1. / n); + CATCH_CHECK(q[1] == -2. / n); + CATCH_CHECK(q[2] == -3. / n); + CATCH_CHECK(q[3] == -4. / n); } CATCH_TEST_CASE("fixed, function1") { - cml::quaterniond_ip q = { 1., 2., 3., 4. }; + cml::quaterniond_ip q = {1., 2., 3., 4.}; auto n = q.norm(); auto xpr = cml::inverse(q); - CATCH_CHECK(xpr[0] == - 1./n); - CATCH_CHECK(xpr[1] == - 2./n); - CATCH_CHECK(xpr[2] == - 3./n); - CATCH_CHECK(xpr[3] == 4./n); + CATCH_CHECK(xpr[0] == -1. / n); + CATCH_CHECK(xpr[1] == -2. / n); + CATCH_CHECK(xpr[2] == -3. / n); + CATCH_CHECK(xpr[3] == 4. / n); } CATCH_TEST_CASE("fixed, function2") { - cml::quaterniond_rp q = { 1., 2., 3., 4. }; + cml::quaterniond_rp q = {1., 2., 3., 4.}; auto n = q.norm(); auto xpr = cml::inverse(q); - CATCH_CHECK(xpr[0] == 1./n); - CATCH_CHECK(xpr[1] == - 2./n); - CATCH_CHECK(xpr[2] == - 3./n); - CATCH_CHECK(xpr[3] == - 4./n); + CATCH_CHECK(xpr[0] == 1. / n); + CATCH_CHECK(xpr[1] == -2. / n); + CATCH_CHECK(xpr[2] == -3. / n); + CATCH_CHECK(xpr[3] == -4. / n); } CATCH_TEST_CASE("fixed, temporary1") { auto xpr = cml::inverse(cml::quaterniond_ip(1., 2., 3., 4.)); auto n = cml::quaterniond_ip(1., 2., 3., 4.).norm(); - CATCH_CHECK(xpr[0] == - 1./n); - CATCH_CHECK(xpr[1] == - 2./n); - CATCH_CHECK(xpr[2] == - 3./n); - CATCH_CHECK(xpr[3] == 4./n); + CATCH_CHECK(xpr[0] == -1. / n); + CATCH_CHECK(xpr[1] == -2. / n); + CATCH_CHECK(xpr[2] == -3. / n); + CATCH_CHECK(xpr[3] == 4. / n); } CATCH_TEST_CASE("fixed, inverse2") { auto xpr = cml::inverse(cml::quaterniond_rp(1., 2., 3., 4.)); auto n = cml::quaterniond_rp(1., 2., 3., 4.).norm(); - CATCH_CHECK(xpr[0] == 1./n); - CATCH_CHECK(xpr[1] == - 2./n); - CATCH_CHECK(xpr[2] == - 3./n); - CATCH_CHECK(xpr[3] == - 4./n); + CATCH_CHECK(xpr[0] == 1. / n); + CATCH_CHECK(xpr[1] == -2. / n); + CATCH_CHECK(xpr[2] == -3. / n); + CATCH_CHECK(xpr[3] == -4. / n); } - - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/quaternion/quaternion_binary_node1.cpp b/tests/quaternion/quaternion_binary_node1.cpp index 15e97a2..b337ed0 100644 --- a/tests/quaternion/quaternion_binary_node1.cpp +++ b/tests/quaternion/quaternion_binary_node1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -16,104 +14,86 @@ CATCH_TEST_CASE("binary_types1") { - typedef cml::quaterniond quaternion_type; + using quaternion_type = cml::quaterniond; { CATCH_CHECK(cml::is_statically_polymorphic::value); } { auto xpr = quaternion_type() + quaternion_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { auto xpr = quaternion_type() - quaternion_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { quaternion_type M; auto xpr = quaternion_type() + M; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { quaternion_type M; auto xpr = M + quaternion_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { quaternion_type M; auto xpr = quaternion_type() - M; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { quaternion_type M; auto xpr = M - quaternion_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { quaternion_type M1, M2; auto xpr = M1 + M2; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { quaternion_type M1, M2; auto xpr = M1 - M2; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } } - - CATCH_TEST_CASE("fixed, binary_minus1") { - cml::quaterniond q = { 1., 2., 3., 4. }; - cml::quaterniond r = { 4., 5., 6., 7. }; + cml::quaterniond q = {1., 2., 3., 4.}; + cml::quaterniond r = {4., 5., 6., 7.}; cml::quaterniond w; w = q - r; CATCH_REQUIRE(w.size() == 4); @@ -125,8 +105,8 @@ CATCH_TEST_CASE("fixed, binary_minus1") CATCH_TEST_CASE("fixed, binary_minus2") { - cml::quaterniond q = { 1., 2., 3., 4. }; - cml::quaterniond r = { 4., 5., 6., 7. }; + cml::quaterniond q = {1., 2., 3., 4.}; + cml::quaterniond r = {4., 5., 6., 7.}; cml::quaterniond w = q - r; CATCH_REQUIRE(w.size() == 4); CATCH_CHECK(w[0] == -3.); @@ -137,8 +117,8 @@ CATCH_TEST_CASE("fixed, binary_minus2") CATCH_TEST_CASE("fixed, binary_plus1") { - cml::quaterniond q = { 1., 2., 3., 4. }; - cml::quaterniond r = { 4., 5., 6., 7. }; + cml::quaterniond q = {1., 2., 3., 4.}; + cml::quaterniond r = {4., 5., 6., 7.}; cml::quaterniond w; w = q + r; CATCH_REQUIRE(w.size() == 4); @@ -150,8 +130,8 @@ CATCH_TEST_CASE("fixed, binary_plus1") CATCH_TEST_CASE("fixed, binary_plus2") { - cml::quaterniond q = { 1., 2., 3., 4. }; - cml::quaterniond r = { 4., 5., 6., 7. }; + cml::quaterniond q = {1., 2., 3., 4.}; + cml::quaterniond r = {4., 5., 6., 7.}; cml::quaterniond w = q + r; CATCH_REQUIRE(w.size() == 4); CATCH_CHECK(w[0] == 5.); @@ -162,9 +142,9 @@ CATCH_TEST_CASE("fixed, binary_plus2") CATCH_TEST_CASE("fixed, multiple_plus1") { - cml::quaterniond q = { 1., 2., 3., 1. }; - cml::quaterniond r = { 4., 5., 6., 2. }; - cml::quaterniond s = { 7., 8., 9., 3. }; + cml::quaterniond q = {1., 2., 3., 1.}; + cml::quaterniond r = {4., 5., 6., 2.}; + cml::quaterniond s = {7., 8., 9., 3.}; cml::quaterniond w; w = q + (r + s); CATCH_REQUIRE(w.size() == 4); @@ -176,9 +156,9 @@ CATCH_TEST_CASE("fixed, multiple_plus1") CATCH_TEST_CASE("fixed, multiple_plus2") { - cml::quaterniond q = { 1., 2., 3., 1. }; - cml::quaterniond r = { 4., 5., 6., 2. }; - cml::quaterniond s = { 7., 8., 9., 3. }; + cml::quaterniond q = {1., 2., 3., 1.}; + cml::quaterniond r = {4., 5., 6., 2.}; + cml::quaterniond s = {7., 8., 9., 3.}; cml::quaterniond w = q + (r + s); CATCH_REQUIRE(w.size() == 4); CATCH_CHECK(w[0] == 12.); @@ -189,9 +169,9 @@ CATCH_TEST_CASE("fixed, multiple_plus2") CATCH_TEST_CASE("fixed, mixed_op1") { - cml::quaterniond q = { 1., 2., 3., 1. }; - cml::quaterniond r = { 4., 5., 6., 2. }; - cml::quaterniond s = { 7., 8., 9., 3. }; + cml::quaterniond q = {1., 2., 3., 1.}; + cml::quaterniond r = {4., 5., 6., 2.}; + cml::quaterniond s = {7., 8., 9., 3.}; cml::quaterniond w; w = r - (q + s); CATCH_REQUIRE(w.size() == 4); @@ -203,9 +183,9 @@ CATCH_TEST_CASE("fixed, mixed_op1") CATCH_TEST_CASE("fixed, mixed_op2") { - cml::quaterniond q = { 1., 2., 3., 1. }; - cml::quaterniond r = { 4., 5., 6., 2. }; - cml::quaterniond s = { 7., 8., 9., 3. }; + cml::quaterniond q = {1., 2., 3., 1.}; + cml::quaterniond r = {4., 5., 6., 2.}; + cml::quaterniond s = {7., 8., 9., 3.}; cml::quaterniond w = r - (q + s); CATCH_REQUIRE(w.size() == 4); CATCH_CHECK(w[0] == -4.); @@ -216,8 +196,8 @@ CATCH_TEST_CASE("fixed, mixed_op2") CATCH_TEST_CASE("fixed, assign_minus1") { - cml::quaterniond w = { 1., 2., 3., 4. }; - cml::quaterniond v = { 4., 5., 6., 7. }; + cml::quaterniond w = {1., 2., 3., 4.}; + cml::quaterniond v = {4., 5., 6., 7.}; w -= v; CATCH_CHECK(w[0] == -3.); CATCH_CHECK(w[1] == -3.); @@ -227,15 +207,11 @@ CATCH_TEST_CASE("fixed, assign_minus1") CATCH_TEST_CASE("fixed, assign_plus1") { - cml::quaterniond w = { 1., 2., 3., 4. }; - cml::quaterniond v = { 4., 5., 6., 7. }; + cml::quaterniond w = {1., 2., 3., 4.}; + cml::quaterniond v = {4., 5., 6., 7.}; w += v; CATCH_CHECK(w[0] == 5.); CATCH_CHECK(w[1] == 7.); CATCH_CHECK(w[2] == 9.); CATCH_CHECK(w[3] == 11.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/quaternion/quaternion_comparison1.cpp b/tests/quaternion/quaternion_comparison1.cpp index b7580ab..80785e0 100644 --- a/tests/quaternion/quaternion_comparison1.cpp +++ b/tests/quaternion/quaternion_comparison1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include @@ -17,66 +15,63 @@ CATCH_TEST_CASE("less_greater1") { - cml::quaterniond v = { 1., 2., 3., 4. }; - cml::quaterniond w = { 2., 2., 2., 2. }; + cml::quaterniond v = {1., 2., 3., 4.}; + cml::quaterniond w = {2., 2., 2., 2.}; CATCH_REQUIRE(v < w); CATCH_REQUIRE(w > v); } CATCH_TEST_CASE("less_greater2") { - cml::quaterniond v = { 1., 2., 3., 4. }; - cml::quaterniond w = { 1., 2., 2., 4. }; + cml::quaterniond v = {1., 2., 3., 4.}; + cml::quaterniond w = {1., 2., 2., 4.}; CATCH_REQUIRE(w < v); CATCH_REQUIRE(v > w); } CATCH_TEST_CASE("less_greater3") { - cml::quaterniond v = { 1., 2., 3., 4. }; - cml::quaterniond w = { 1., 2., 3., 4. }; + cml::quaterniond v = {1., 2., 3., 4.}; + cml::quaterniond w = {1., 2., 3., 4.}; CATCH_REQUIRE(!(w < v)); CATCH_REQUIRE(!(v < w)); } CATCH_TEST_CASE("less_equal1") { - cml::quaterniond v = { 1., 2., 3., 4. }; - cml::quaterniond w = { 1., 2., 3., 4. }; + cml::quaterniond v = {1., 2., 3., 4.}; + cml::quaterniond w = {1., 2., 3., 4.}; CATCH_REQUIRE(v <= w); CATCH_REQUIRE(w <= v); } CATCH_TEST_CASE("less_equal2") { - cml::quaterniond v = { 1., 2., 3., 4. }; - cml::quaterniond w = { 1., 2., 4., 4. }; + cml::quaterniond v = {1., 2., 3., 4.}; + cml::quaterniond w = {1., 2., 4., 4.}; CATCH_REQUIRE(v <= w); CATCH_REQUIRE(!(w <= v)); } CATCH_TEST_CASE("greater_equal1") { - cml::quaterniond v = { 1., 2., 3., 4. }; - cml::quaterniond w = { 1., 2., 3., 4. }; + cml::quaterniond v = {1., 2., 3., 4.}; + cml::quaterniond w = {1., 2., 3., 4.}; CATCH_REQUIRE(v >= w); CATCH_REQUIRE(w >= v); } CATCH_TEST_CASE("greater_equal2") { - cml::quaterniond v = { 1., 2., 3., 4. }; - cml::quaterniond w = { 1., 2., 4., 4. }; + cml::quaterniond v = {1., 2., 3., 4.}; + cml::quaterniond w = {1., 2., 4., 4.}; CATCH_REQUIRE(w >= v); CATCH_REQUIRE(!(v >= w)); } CATCH_TEST_CASE("equal1") { - cml::quaterniond v = { 1., 2., 3., 4. }; - cml::quaterniond w = { 1., 2., 3., 4. }; + cml::quaterniond v = {1., 2., 3., 4.}; + cml::quaterniond w = {1., 2., 3., 4.}; CATCH_REQUIRE(w == v); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/quaternion/quaternion_dot1.cpp b/tests/quaternion/quaternion_dot1.cpp index 33fa71e..bfa5a04 100644 --- a/tests/quaternion/quaternion_dot1.cpp +++ b/tests/quaternion/quaternion_dot1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -15,11 +13,8 @@ CATCH_TEST_CASE("dot1") { - cml::quaterniond v1 = { 1., 1., 1., 1. }; - cml::quaterniond v2 = { 2., 2., 2., 2. }; - double dp = cml::dot(v1,v2); + cml::quaterniond v1 = {1., 1., 1., 1.}; + cml::quaterniond v2 = {2., 2., 2., 2.}; + double dp = cml::dot(v1, v2); CATCH_CHECK(dp == 8.); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/quaternion/quaternion_functions1.cpp b/tests/quaternion/quaternion_functions1.cpp index 36668a2..e0ca7c3 100644 --- a/tests/quaternion/quaternion_functions1.cpp +++ b/tests/quaternion/quaternion_functions1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -13,45 +11,44 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, real1") { - cml::quaterniond_ip q = { 1., 2., 3., 4. }; + cml::quaterniond_ip q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(cml::real(q) == 4.); } CATCH_TEST_CASE("fixed, real2") { - cml::quaterniond_rp q = { 1., 2., 3., 4. }; + cml::quaterniond_rp q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(cml::real(q) == 1.); } CATCH_TEST_CASE("fixed, length_squared1") { - cml::quaterniond q = { 1., 2., 3., 4. }; + cml::quaterniond q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(cml::length_squared(q) == Approx(30.).epsilon(1.5e-8)); } CATCH_TEST_CASE("fixed, length1") { - cml::quaterniond q = { 1., 2., 3., 4. }; + cml::quaterniond q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(cml::length(q) == Approx(std::sqrt(30.)).epsilon(1.5e-8)); } CATCH_TEST_CASE("fixed, norm1") { - cml::quaterniond q = { 1., 2., 3., 4. }; + cml::quaterniond q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(cml::norm(q) == Approx(30.).epsilon(1.5e-8)); } CATCH_TEST_CASE("fixed, normalize1") { - cml::quaterniond q = { 1., 2., 3., 4. }; + cml::quaterniond q = {1., 2., 3., 4.}; q.normalize(); double l2 = q.length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1.5e-8)); @@ -59,14 +56,14 @@ CATCH_TEST_CASE("fixed, normalize1") CATCH_TEST_CASE("fixed, normalize2") { - cml::quaterniond q = { 1., 2., 3., 4. }; + cml::quaterniond q = {1., 2., 3., 4.}; double l2 = cml::normalize(q).length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1.5e-8)); } CATCH_TEST_CASE("fixed, identity1") { - cml::quaterniond q = { 1., 2., 3., 4. }; + cml::quaterniond q = {1., 2., 3., 4.}; double l2 = cml::identity(q).length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1.5e-8)); } @@ -84,7 +81,7 @@ CATCH_TEST_CASE("fixed, zero1") CATCH_TEST_CASE("fixed, log1") { - cml::quaterniond_ip q = { 1., 2., 3., 4. }; + cml::quaterniond_ip q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); auto lnq = cml::log(q); CATCH_CHECK(lnq[0] == Approx(0.200991168205).epsilon(1.5e-8)); @@ -95,7 +92,7 @@ CATCH_TEST_CASE("fixed, log1") CATCH_TEST_CASE("fixed, log2") { - cml::quaterniond_rp q = { 1., 2., 3., 4. }; + cml::quaterniond_rp q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); auto lnq = cml::log(q); CATCH_CHECK(lnq[0] == Approx(1.700598690831).epsilon(1.5e-8)); @@ -124,7 +121,7 @@ CATCH_TEST_CASE("fixed, log4") CATCH_TEST_CASE("fixed, exp1") { - cml::quaterniond_ip q = { 1., 2., 3., 4. }; + cml::quaterniond_ip q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); auto lnq = cml::exp(q); CATCH_CHECK(lnq[0] == Approx(-8.24002526676).epsilon(1.5e-8)); @@ -135,10 +132,10 @@ CATCH_TEST_CASE("fixed, exp1") CATCH_TEST_CASE("fixed, exp2") { - cml::quaterniond_rp q = { 1., 2., 3., 4. }; + cml::quaterniond_rp q = {1., 2., 3., 4.}; CATCH_REQUIRE(q.size() == 4); auto lnq = cml::exp(q); - CATCH_CHECK(lnq[0] == Approx( 1.693922723683).epsilon(1.5e-8)); + CATCH_CHECK(lnq[0] == Approx(1.693922723683).epsilon(1.5e-8)); CATCH_CHECK(lnq[1] == Approx(-0.78955962454).epsilon(1.5e-8)); CATCH_CHECK(lnq[2] == Approx(-1.184339436812).epsilon(1.5e-8)); CATCH_CHECK(lnq[3] == Approx(-1.579119249083).epsilon(1.5e-8)); @@ -156,12 +153,8 @@ CATCH_TEST_CASE("fixed, exp3") CATCH_TEST_CASE("fixed, exp4") { auto lnq = cml::quaterniond_rp(1., 2., 3., 4.).exp(); - CATCH_CHECK(lnq[0] == Approx( 1.693922723683).epsilon(1.5e-8)); + CATCH_CHECK(lnq[0] == Approx(1.693922723683).epsilon(1.5e-8)); CATCH_CHECK(lnq[1] == Approx(-0.78955962454).epsilon(1.5e-8)); CATCH_CHECK(lnq[2] == Approx(-1.184339436812).epsilon(1.5e-8)); CATCH_CHECK(lnq[3] == Approx(-1.579119249083).epsilon(1.5e-8)); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/quaternion/quaternion_product1.cpp b/tests/quaternion/quaternion_product1.cpp index f29bb9b..107d412 100644 --- a/tests/quaternion/quaternion_product1.cpp +++ b/tests/quaternion/quaternion_product1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include @@ -17,12 +15,11 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, ip1") { - cml::quaterniond_ip q = { 1., 2., 3., 4. }; - cml::quaterniond_ip r = { 4., 3., 2., 1. }; - auto w = q*r; + cml::quaterniond_ip q = {1., 2., 3., 4.}; + cml::quaterniond_ip r = {4., 3., 2., 1.}; + auto w = q * r; CATCH_CHECK(w[0] == 12.); CATCH_CHECK(w[1] == 24.); CATCH_CHECK(w[2] == 6.); @@ -31,9 +28,9 @@ CATCH_TEST_CASE("fixed, ip1") CATCH_TEST_CASE("fixed, rp1") { - cml::quaterniond_rp q = { 1., 2., 3., 4. }; - cml::quaterniond_rp r = { 4., 3., 2., 1. }; - auto w = q*r; + cml::quaterniond_rp q = {1., 2., 3., 4.}; + cml::quaterniond_rp r = {4., 3., 2., 1.}; + auto w = q * r; CATCH_CHECK(w[0] == -12.); CATCH_CHECK(w[1] == 6.); CATCH_CHECK(w[2] == 24.); @@ -42,9 +39,9 @@ CATCH_TEST_CASE("fixed, rp1") CATCH_TEST_CASE("fixed, in1") { - cml::quaterniond_in q = { 1., 2., 3., 4. }; - cml::quaterniond_in r = { 4., 3., 2., 1. }; - auto w = q*r; + cml::quaterniond_in q = {1., 2., 3., 4.}; + cml::quaterniond_in r = {4., 3., 2., 1.}; + auto w = q * r; CATCH_CHECK(w[0] == 22.); CATCH_CHECK(w[1] == 4.); CATCH_CHECK(w[2] == 16.); @@ -53,9 +50,9 @@ CATCH_TEST_CASE("fixed, in1") CATCH_TEST_CASE("fixed, rn1") { - cml::quaterniond_rn q = { 1., 2., 3., 4. }; - cml::quaterniond_rn r = { 4., 3., 2., 1. }; - auto w = q*r; + cml::quaterniond_rn q = {1., 2., 3., 4.}; + cml::quaterniond_rn r = {4., 3., 2., 1.}; + auto w = q * r; CATCH_CHECK(w[0] == -12.); CATCH_CHECK(w[1] == 16.); CATCH_CHECK(w[2] == 4.); @@ -64,8 +61,8 @@ CATCH_TEST_CASE("fixed, rn1") CATCH_TEST_CASE("fixed, ip_assign1") { - cml::quaterniond_ip q = { 1., 2., 3., 4. }; - cml::quaterniond_ip r = { 4., 3., 2., 1. }; + cml::quaterniond_ip q = {1., 2., 3., 4.}; + cml::quaterniond_ip r = {4., 3., 2., 1.}; q *= r; CATCH_CHECK(q[0] == 12.); CATCH_CHECK(q[1] == 24.); @@ -75,8 +72,8 @@ CATCH_TEST_CASE("fixed, ip_assign1") CATCH_TEST_CASE("fixed, rp_assign1") { - cml::quaterniond_rp q = { 1., 2., 3., 4. }; - cml::quaterniond_rp r = { 4., 3., 2., 1. }; + cml::quaterniond_rp q = {1., 2., 3., 4.}; + cml::quaterniond_rp r = {4., 3., 2., 1.}; q *= r; CATCH_CHECK(q[0] == -12.); CATCH_CHECK(q[1] == 6.); @@ -86,8 +83,8 @@ CATCH_TEST_CASE("fixed, rp_assign1") CATCH_TEST_CASE("fixed, in_assign1") { - cml::quaterniond_in q = { 1., 2., 3., 4. }; - cml::quaterniond_in r = { 4., 3., 2., 1. }; + cml::quaterniond_in q = {1., 2., 3., 4.}; + cml::quaterniond_in r = {4., 3., 2., 1.}; q *= r; CATCH_CHECK(q[0] == 22.); CATCH_CHECK(q[1] == 4.); @@ -97,15 +94,11 @@ CATCH_TEST_CASE("fixed, in_assign1") CATCH_TEST_CASE("fixed, rn_assign1") { - cml::quaterniond_rn q = { 1., 2., 3., 4. }; - cml::quaterniond_rn r = { 4., 3., 2., 1. }; + cml::quaterniond_rn q = {1., 2., 3., 4.}; + cml::quaterniond_rn r = {4., 3., 2., 1.}; q *= r; CATCH_CHECK(q[0] == -12.); CATCH_CHECK(q[1] == 16.); CATCH_CHECK(q[2] == 4.); CATCH_CHECK(q[3] == 22.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/quaternion/quaternion_scalar_node1.cpp b/tests/quaternion/quaternion_scalar_node1.cpp index 25ce4ce..86945f4 100644 --- a/tests/quaternion/quaternion_scalar_node1.cpp +++ b/tests/quaternion/quaternion_scalar_node1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -16,96 +14,71 @@ CATCH_TEST_CASE("scalar_types1") { - typedef cml::quaterniond quaternion_type; + using quaternion_type = cml::quaterniond; { - auto xpr = quaternion_type()*int(); - typedef decltype(xpr) xpr_type; + auto xpr = quaternion_type() * int(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); - CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { - auto xpr = int()*quaternion_type(); - typedef decltype(xpr) xpr_type; - CATCH_CHECK( - std::is_rvalue_reference::value - ); + auto xpr = int() * quaternion_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { - auto xpr = quaternion_type()/int(); - typedef decltype(xpr) xpr_type; - CATCH_CHECK( - std::is_rvalue_reference::value - ); + auto xpr = quaternion_type() / int(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { double v = 0.; - auto xpr = quaternion_type()*v; - typedef decltype(xpr) xpr_type; + auto xpr = quaternion_type() * v; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); - CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_lvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { double v = 0.; - auto xpr = v*quaternion_type(); - typedef decltype(xpr) xpr_type; - CATCH_CHECK( - std::is_lvalue_reference::value - ); + auto xpr = v * quaternion_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { double v = 0.; - auto xpr = quaternion_type()/v; - typedef decltype(xpr) xpr_type; + auto xpr = quaternion_type() / v; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); - CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_lvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } } - CATCH_TEST_CASE("fixed, scalar_multiply1") { - cml::quaterniond q = { 1., 2., 3., 4. }; + cml::quaterniond q = {1., 2., 3., 4.}; cml::quaterniond r; - r = 2.*q; + r = 2. * q; CATCH_REQUIRE(r.size() == 4); CATCH_CHECK(r[0] == 2.); CATCH_CHECK(r[1] == 4.); @@ -115,8 +88,8 @@ CATCH_TEST_CASE("fixed, scalar_multiply1") CATCH_TEST_CASE("fixed, scalar_multiply2") { - cml::quaterniond q = { 1., 2., 3., 4. }; - cml::quaterniond r = 2.*q; + cml::quaterniond q = {1., 2., 3., 4.}; + cml::quaterniond r = 2. * q; CATCH_REQUIRE(r.size() == 4); CATCH_CHECK(r[0] == 2.); CATCH_CHECK(r[1] == 4.); @@ -126,9 +99,9 @@ CATCH_TEST_CASE("fixed, scalar_multiply2") CATCH_TEST_CASE("fixed, scalar_divide1") { - cml::quaterniond q = { 2., 4., 6., 8. }; + cml::quaterniond q = {2., 4., 6., 8.}; cml::quaterniond r; - r = q/2; + r = q / 2; CATCH_REQUIRE(r.size() == 4); CATCH_CHECK(r[0] == 1.); CATCH_CHECK(r[1] == 2.); @@ -138,8 +111,8 @@ CATCH_TEST_CASE("fixed, scalar_divide1") CATCH_TEST_CASE("fixed, scalar_divide2") { - cml::quaterniond q = { 2., 4., 6., 8. }; - cml::quaterniond r = q/2; + cml::quaterniond q = {2., 4., 6., 8.}; + cml::quaterniond r = q / 2; CATCH_REQUIRE(r.size() == 4); CATCH_CHECK(r[0] == 1.); CATCH_CHECK(r[1] == 2.); @@ -149,7 +122,7 @@ CATCH_TEST_CASE("fixed, scalar_divide2") CATCH_TEST_CASE("fixed, scalar_multiply_assign1") { - cml::quaterniond q = { 1., 2., 3., 4. }; + cml::quaterniond q = {1., 2., 3., 4.}; q *= 2; CATCH_REQUIRE(q.size() == 4); CATCH_CHECK(q[0] == 2.); @@ -168,8 +141,3 @@ CATCH_TEST_CASE("fixed, scalar_multiply_assign2") CATCH_CHECK(q[2] == 6.); CATCH_CHECK(q[3] == 8.); } - - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/quaternion/quaternion_unary_node1.cpp b/tests/quaternion/quaternion_unary_node1.cpp index 9fdf97d..09c956d 100644 --- a/tests/quaternion/quaternion_unary_node1.cpp +++ b/tests/quaternion/quaternion_unary_node1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -16,100 +14,91 @@ CATCH_TEST_CASE("unary_types1") { - typedef cml::quaterniond quaternion_type; + using quaternion_type = cml::quaterniond; { CATCH_CHECK(cml::is_statically_polymorphic::value); } { - auto xpr = - quaternion_type(); - typedef decltype(xpr) xpr_type; + auto xpr = -quaternion_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { - auto xpr = + quaternion_type(); - typedef decltype(xpr) xpr_type; + auto xpr = +quaternion_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { quaternion_type M; - auto xpr = - M; - typedef decltype(xpr) xpr_type; + auto xpr = -M; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { quaternion_type M; - auto xpr = + M; - typedef decltype(xpr) xpr_type; + auto xpr = +M; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } } - CATCH_TEST_CASE("fixed, unary_minus1") { - cml::quaterniond q = { 1., 2., 3., 4. }; + cml::quaterniond q = {1., 2., 3., 4.}; cml::quaterniond r; - r = - q; + r = -q; CATCH_REQUIRE(r.size() == 4); - CATCH_CHECK(r[0] == - 1.); - CATCH_CHECK(r[1] == - 2.); - CATCH_CHECK(r[2] == - 3.); - CATCH_CHECK(r[3] == - 4.); + CATCH_CHECK(r[0] == -1.); + CATCH_CHECK(r[1] == -2.); + CATCH_CHECK(r[2] == -3.); + CATCH_CHECK(r[3] == -4.); } CATCH_TEST_CASE("fixed, unary_minus2") { - cml::quaterniond q = { 1., 2., 3., 4. }; - cml::quaterniond r = - q; + cml::quaterniond q = {1., 2., 3., 4.}; + cml::quaterniond r = -q; CATCH_REQUIRE(r.size() == 4); - CATCH_CHECK(r[0] == - 1.); - CATCH_CHECK(r[1] == - 2.); - CATCH_CHECK(r[2] == - 3.); - CATCH_CHECK(r[3] == - 4.); + CATCH_CHECK(r[0] == -1.); + CATCH_CHECK(r[1] == -2.); + CATCH_CHECK(r[2] == -3.); + CATCH_CHECK(r[3] == -4.); } CATCH_TEST_CASE("fixed, unary_plus1") { - cml::quaterniond q = { 1., 2., 3., 4. }; + cml::quaterniond q = {1., 2., 3., 4.}; cml::quaterniond r; - r = + q; + r = +q; CATCH_REQUIRE(r.size() == 4); - CATCH_CHECK(r[0] == + 1.); - CATCH_CHECK(r[1] == + 2.); - CATCH_CHECK(r[2] == + 3.); - CATCH_CHECK(r[3] == + 4.); + CATCH_CHECK(r[0] == +1.); + CATCH_CHECK(r[1] == +2.); + CATCH_CHECK(r[2] == +3.); + CATCH_CHECK(r[3] == +4.); } CATCH_TEST_CASE("fixed, unary_plus2") { - cml::quaterniond q = { 1., 2., 3., 4. }; - cml::quaterniond r = + q; + cml::quaterniond q = {1., 2., 3., 4.}; + cml::quaterniond r = +q; CATCH_REQUIRE(r.size() == 4); - CATCH_CHECK(r[0] == + 1.); - CATCH_CHECK(r[1] == + 2.); - CATCH_CHECK(r[2] == + 3.); - CATCH_CHECK(r[3] == + 4.); + CATCH_CHECK(r[0] == +1.); + CATCH_CHECK(r[1] == +2.); + CATCH_CHECK(r[2] == +3.); + CATCH_CHECK(r[3] == +4.); } CATCH_TEST_CASE("fixed, double_negate1") { - cml::quaterniond q = { 1., 2., 3., 4. }; - cml::quaterniond r = - (- q); + cml::quaterniond q = {1., 2., 3., 4.}; + cml::quaterniond r = -(-q); CATCH_REQUIRE(r.size() == 4); CATCH_CHECK(r[0] == 1.); CATCH_CHECK(r[1] == 2.); CATCH_CHECK(r[2] == 3.); CATCH_CHECK(r[3] == 4.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/storage/CMakeLists.txt b/tests/storage/CMakeLists.txt index ed694dd..f03263a 100644 --- a/tests/storage/CMakeLists.txt +++ b/tests/storage/CMakeLists.txt @@ -1,8 +1,7 @@ -# -*- cmake -*- ----------------------------------------------------------- +# *------------------------------------------------------------------------- # @@COPYRIGHT@@ -#*------------------------------------------------------------------------- +# *------------------------------------------------------------------------- -project(CML_Testing_Storage) -set(CML_CURRENT_TEST_GROUP "Storage") +set(CML_TEST_GROUP "storage") cml_add_test(storage_promotion1) \ No newline at end of file diff --git a/tests/storage/storage_promotion1.cpp b/tests/storage/storage_promotion1.cpp index 4c740c3..75089e2 100644 --- a/tests/storage/storage_promotion1.cpp +++ b/tests/storage/storage_promotion1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -12,10 +10,10 @@ #include "catch_runner.h" template - using promote_t = typename cml::storage_promote::type; +using promote_t = typename cml::storage_promote::type; template - using check_c = std::is_same, S>; +using check_c = std::is_same, S>; CATCH_TEST_CASE("basic1") { @@ -26,26 +24,22 @@ CATCH_TEST_CASE("basic1") using cml::vector_storage_tag; using cml::rebind_t; - typedef rebind_t, vector_storage_tag> compiled_type; - typedef rebind_t, vector_storage_tag> allocated_type; - typedef rebind_t, vector_storage_tag> external_type; - typedef rebind_t, vector_storage_tag> any_type; - -#define _CHECK(_S1, _S2, _S) \ - CATCH_CHECK((check_c<_S1, _S2, _S>::value)) - - _CHECK( compiled_type, compiled_type, compiled<> ); - _CHECK( compiled_type, allocated_type, compiled<> ); - _CHECK( compiled_type, external_type, compiled<> ); - _CHECK( compiled_type, any_type, compiled<> ); - _CHECK( allocated_type, allocated_type, allocated<> ); - _CHECK( allocated_type, external_type, allocated<> ); - _CHECK( allocated_type, any_type, allocated<> ); - _CHECK( external_type, external_type, external<> ); - _CHECK( external_type, any_type, external<> ); - _CHECK( any_type, any_type, any_storage<> ); + using compiled_type = rebind_t, vector_storage_tag>; + using allocated_type = rebind_t, vector_storage_tag>; + using external_type = rebind_t, vector_storage_tag>; + using any_type = rebind_t, vector_storage_tag>; + +#define _CHECK(_S1, _S2, _S) CATCH_CHECK((check_c<_S1, _S2, _S>::value)) + + _CHECK(compiled_type, compiled_type, compiled<>); + _CHECK(compiled_type, allocated_type, compiled<>); + _CHECK(compiled_type, external_type, compiled<>); + _CHECK(compiled_type, any_type, compiled<>); + _CHECK(allocated_type, allocated_type, allocated<>); + _CHECK(allocated_type, external_type, allocated<>); + _CHECK(allocated_type, any_type, allocated<>); + _CHECK(external_type, external_type, external<>); + _CHECK(external_type, any_type, external<>); + _CHECK(any_type, any_type, any_storage<>); #undef _CHECK } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt index 0e4bdb5..11dd965 100644 --- a/tests/util/CMakeLists.txt +++ b/tests/util/CMakeLists.txt @@ -1,8 +1,7 @@ -# -*- cmake -*- ----------------------------------------------------------- +# *------------------------------------------------------------------------- # @@COPYRIGHT@@ -#*------------------------------------------------------------------------- +# *------------------------------------------------------------------------- -project(CML_Testing_Util) -set(CML_CURRENT_TEST_GROUP "Util") +set(CML_TEST_GROUP "util") cml_add_test(vector_hash1) \ No newline at end of file diff --git a/tests/util/vector_hash1.cpp b/tests/util/vector_hash1.cpp index 20e2068..7a739e4 100644 --- a/tests/util/vector_hash1.cpp +++ b/tests/util/vector_hash1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -20,24 +18,22 @@ #include "catch_runner.h" -typedef std::unordered_set vector3d_table; +using vector3d_table = std::unordered_set; CATCH_TEST_CASE("fixed, table1") { - cml::vector3d p0(1.,2.,3.); + cml::vector3d p0(1., 2., 3.); vector3d_table table; CATCH_REQUIRE(table.insert(p0).second); CATCH_REQUIRE(table.size() == 1); CATCH_REQUIRE(table.find(p0) != table.end()); } - - -typedef std::unordered_set external3d_table; +using external3d_table = std::unordered_set; CATCH_TEST_CASE("fixed external, table1") { - double av0[] = { 1., 2., 3. }; + double av0[] = {1., 2., 3.}; cml::external3d p0(av0); external3d_table table; CATCH_REQUIRE(table.insert(p0).second); @@ -45,33 +41,25 @@ CATCH_TEST_CASE("fixed external, table1") CATCH_REQUIRE(table.find(p0) != table.end()); } - - -typedef std::unordered_set vectord_table; +using vectord_table = std::unordered_set; CATCH_TEST_CASE("dynamic, table1") { - cml::vectord p0(1.,2.,3.); + cml::vectord p0(1., 2., 3.); vectord_table table; CATCH_REQUIRE(table.insert(p0).second); CATCH_REQUIRE(table.size() == 1); CATCH_REQUIRE(table.find(p0) != table.end()); } - - -typedef std::unordered_set externalnd_table; +using externalnd_table = std::unordered_set; CATCH_TEST_CASE("dynamic external, table1") { - double av0[] = { 1., 2., 3. }; + double av0[] = {1., 2., 3.}; cml::externalnd p0(av0, 3); externalnd_table table; CATCH_REQUIRE(table.insert(p0).second); CATCH_REQUIRE(table.size() == 1); CATCH_REQUIRE(table.find(p0) != table.end()); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/CMakeLists.txt b/tests/vector/CMakeLists.txt index 35ccbe5..86c83a4 100644 --- a/tests/vector/CMakeLists.txt +++ b/tests/vector/CMakeLists.txt @@ -1,9 +1,8 @@ -# -*- cmake -*- ----------------------------------------------------------- +# *------------------------------------------------------------------------- # @@COPYRIGHT@@ -#*------------------------------------------------------------------------- +# *------------------------------------------------------------------------- -project(CML_Testing_Vector) -set(CML_CURRENT_TEST_GROUP "Vector") +set(CML_TEST_GROUP "vector") cml_add_test(fixed_compiled_vector1) cml_add_test(fixed_external_vector1) diff --git a/tests/vector/cross1.cpp b/tests/vector/cross1.cpp index ccc2405..75168f1 100644 --- a/tests/vector/cross1.cpp +++ b/tests/vector/cross1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -17,15 +15,14 @@ CATCH_TEST_CASE("cross1") { - cml::vector3d v1 = { 1., 1., 1. }; - cml::vector3d v2 = { 2., 2., 2. }; + cml::vector3d v1 = {1., 1., 1.}; + cml::vector3d v2 = {2., 2., 2.}; - typedef decltype(cml::cross(v1,v2)) cross_type; - static_assert( - std::is_same::value, + using cross_type = decltype(cml::cross(v1, v2)); + static_assert(std::is_same::value, "got wrong size_tag from cross()"); - auto v = cml::cross(v1,v2); + auto v = cml::cross(v1, v2); CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v[0] == 0.); CATCH_CHECK(v[1] == 0.); @@ -35,39 +32,35 @@ CATCH_TEST_CASE("cross1") CATCH_TEST_CASE("cross2") { cml::vectord v1(1., 2., 3.); - cml::vector3d v2 (3., 2., 1.); + cml::vector3d v2(3., 2., 1.); - typedef decltype(cml::cross(v1,v2)) cross_type; - static_assert( - std::is_same::value, + using cross_type = decltype(cml::cross(v1, v2)); + static_assert(std::is_same::value, "got wrong size_tag from cross()"); - auto v = cml::cross(v1,v2); + auto v = cml::cross(v1, v2); CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v[0] == -4.); - CATCH_CHECK(v[1] == 8.); + CATCH_CHECK(v[1] == 8.); CATCH_CHECK(v[2] == -4.); } CATCH_TEST_CASE("size_check1") { cml::vectord v1(2); - CATCH_CHECK_THROWS_AS(cml::cross(v1,v1), cml::vector_size_error); + CATCH_CHECK_THROWS_AS(cml::cross(v1, v1), cml::vector_size_error); } CATCH_TEST_CASE("size_check2") { - cml::vectord v1(2,3); - cml::vector3d v2(2,3,3); - CATCH_CHECK_THROWS_AS(cml::cross(v1,v2), cml::vector_size_error); + cml::vectord v1(2, 3); + cml::vector3d v2(2, 3, 3); + CATCH_CHECK_THROWS_AS(cml::cross(v1, v2), cml::vector_size_error); } CATCH_TEST_CASE("size_check3") { - cml::vector3d v1(2,3,3); - cml::vectord v2(2,3); - CATCH_CHECK_THROWS_AS(cml::cross(v1,v2), cml::vector_size_error); + cml::vector3d v1(2, 3, 3); + cml::vectord v2(2, 3); + CATCH_CHECK_THROWS_AS(cml::cross(v1, v2), cml::vector_size_error); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/dynamic_allocated_vector1.cpp b/tests/vector/dynamic_allocated_vector1.cpp index 7f2db03..a635516 100644 --- a/tests/vector/dynamic_allocated_vector1.cpp +++ b/tests/vector/dynamic_allocated_vector1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include @@ -46,7 +44,7 @@ CATCH_TEST_CASE("resize1") CATCH_TEST_CASE("array_construct") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::vectord v(data); CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); @@ -55,7 +53,7 @@ CATCH_TEST_CASE("array_construct") CATCH_TEST_CASE("array_temp_construct") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::vectord v = data; CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); @@ -64,7 +62,7 @@ CATCH_TEST_CASE("array_temp_construct") CATCH_TEST_CASE("array_assign") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::vectord v; v = data; CATCH_REQUIRE(v.size() == 3); @@ -101,7 +99,7 @@ CATCH_TEST_CASE("element_construct3") CATCH_TEST_CASE("element_construct4") { - cml::vectord v(1.,2.f,3,4U); + cml::vectord v(1., 2.f, 3, 4U); CATCH_REQUIRE(v.size() == 4); CATCH_CHECK(v.data()[0] == 1.); CATCH_CHECK(v[0] == 1.); @@ -132,7 +130,7 @@ CATCH_TEST_CASE("combine_construct2") CATCH_TEST_CASE("pointer_construct1") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::vectord v(3, &data[0]); CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); @@ -141,7 +139,7 @@ CATCH_TEST_CASE("pointer_construct1") CATCH_TEST_CASE("pointer_construct2") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::vectord v(&data[0], 3); CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); @@ -150,7 +148,7 @@ CATCH_TEST_CASE("pointer_construct2") CATCH_TEST_CASE("list_construct") { - cml::vectord v { 1., 2., 3. }; + cml::vectord v{1., 2., 3.}; CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); CATCH_CHECK(v[0] == 1.); @@ -158,7 +156,7 @@ CATCH_TEST_CASE("list_construct") CATCH_TEST_CASE("list_temp_construct") { - cml::vectord v = { 1., 2., 3. }; + cml::vectord v = {1., 2., 3.}; CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); CATCH_CHECK(v[0] == 1.); @@ -186,8 +184,5 @@ CATCH_TEST_CASE("size_check1") { cml::vectord v; CATCH_REQUIRE(v.size() == 0); - CATCH_CHECK_NOTHROW((v = { 1., 2., 3., 4. })); + CATCH_CHECK_NOTHROW((v = {1., 2., 3., 4.})); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/dynamic_external_vector1.cpp b/tests/vector/dynamic_external_vector1.cpp index 5523597..c6e7b6e 100644 --- a/tests/vector/dynamic_external_vector1.cpp +++ b/tests/vector/dynamic_external_vector1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -13,7 +11,7 @@ CATCH_TEST_CASE("array_construct") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::externalnd v(data, 3); CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data() == &data[0]); @@ -24,7 +22,7 @@ CATCH_TEST_CASE("array_construct") CATCH_TEST_CASE("array_assign") { double av[3]; - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::externalnd v(av, 3); v = data; CATCH_REQUIRE(v.size() == 3); @@ -36,13 +34,14 @@ CATCH_TEST_CASE("list_assign") { double av[3]; cml::externalnd v(av, 3); - v = { 1., 2., 3. }; + v = {1., 2., 3.}; CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); CATCH_CHECK(v[0] == 1.); } -CATCH_TEST_CASE("fill1") { +CATCH_TEST_CASE("fill1") +{ double av[5]; cml::externalnd v(av, 5); v.fill(1.); @@ -53,7 +52,7 @@ CATCH_TEST_CASE("fill1") { CATCH_TEST_CASE("write1") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::externalnd v(data, 3); CATCH_REQUIRE(v.size() == 3); v[0] = 1.; @@ -66,16 +65,13 @@ CATCH_TEST_CASE("size_check1") double av[3]; cml::externalnd v(av, 3); CATCH_REQUIRE(v.size() == 3); - CATCH_CHECK_THROWS_AS( - (v = { 1., 2., 3., 4. }), cml::incompatible_vector_size_error); + CATCH_CHECK_THROWS_AS((v = {1., 2., 3., 4.}), + cml::incompatible_vector_size_error); } CATCH_TEST_CASE("const1") { - const double av[] = { 1., 2., 3. }; + const double av[] = {1., 2., 3.}; cml::externalncd v(av, 3); CATCH_REQUIRE(v.size() == 3); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/fixed_compiled_vector1.cpp b/tests/vector/fixed_compiled_vector1.cpp index f54b6e8..54455ae 100644 --- a/tests/vector/fixed_compiled_vector1.cpp +++ b/tests/vector/fixed_compiled_vector1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -12,7 +10,7 @@ CATCH_TEST_CASE("array_construct") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::vector3d v(data); CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); @@ -21,7 +19,7 @@ CATCH_TEST_CASE("array_construct") CATCH_TEST_CASE("array_temp_construct") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::vector3d v = data; CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); @@ -57,7 +55,7 @@ CATCH_TEST_CASE("element_construct3") CATCH_TEST_CASE("element_construct4") { - cml::vector4d v(1.,2.f,3,4U); + cml::vector4d v(1., 2.f, 3, 4U); CATCH_REQUIRE(v.size() == 4); CATCH_CHECK(v.data()[0] == 1.); CATCH_CHECK(v[0] == 1.); @@ -120,7 +118,7 @@ CATCH_TEST_CASE("element_set4") { cml::vector4d v; CATCH_REQUIRE(v.size() == 4); - v.set(1.,2.f,3,4U); + v.set(1., 2.f, 3, 4U); CATCH_CHECK(v.data()[0] == 1.); CATCH_CHECK(v[0] == 1.); CATCH_CHECK(v[1] == 2.); @@ -130,7 +128,7 @@ CATCH_TEST_CASE("element_set4") CATCH_TEST_CASE("array_assign") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::vector3d v; v = data; CATCH_REQUIRE(v.size() == 3); @@ -140,7 +138,7 @@ CATCH_TEST_CASE("array_assign") CATCH_TEST_CASE("pointer_construct") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::vector3d v(&data[0]); CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); @@ -149,7 +147,7 @@ CATCH_TEST_CASE("pointer_construct") CATCH_TEST_CASE("list_construct") { - cml::vector3d v { 1., 2., 3. }; + cml::vector3d v{1., 2., 3.}; CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); CATCH_CHECK(v[0] == 1.); @@ -157,7 +155,7 @@ CATCH_TEST_CASE("list_construct") CATCH_TEST_CASE("list_temp_construct") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); CATCH_CHECK(v[0] == 1.); @@ -166,13 +164,14 @@ CATCH_TEST_CASE("list_temp_construct") CATCH_TEST_CASE("list_assign") { cml::vector3d v; - v = { 1., 2., 3. }; + v = {1., 2., 3.}; CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); CATCH_CHECK(v[0] == 1.); } -CATCH_TEST_CASE("fill1") { +CATCH_TEST_CASE("fill1") +{ cml::vector3d v; v.fill(1.); CATCH_REQUIRE(v.size() == 3); @@ -193,19 +192,16 @@ CATCH_TEST_CASE("size_check1") { cml::vector3d v; CATCH_REQUIRE(v.size() == 3); - CATCH_REQUIRE_THROWS_AS( - (v = { 1., 2., 3., 4. }), cml::incompatible_vector_size_error); + CATCH_REQUIRE_THROWS_AS((v = {1., 2., 3., 4.}), + cml::incompatible_vector_size_error); } #ifdef CML_HAS_STRUCTURED_BINDINGS CATCH_TEST_CASE("structured_binding1") { - auto [x,y,z] = cml::vector3d(1., 2., 3. ); + auto [x, y, z] = cml::vector3d(1., 2., 3.); CATCH_CHECK(x == 1.); CATCH_CHECK(y == 2.); CATCH_CHECK(z == 3.); } #endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/fixed_external_vector1.cpp b/tests/vector/fixed_external_vector1.cpp index f32345e..3023154 100644 --- a/tests/vector/fixed_external_vector1.cpp +++ b/tests/vector/fixed_external_vector1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -13,7 +11,7 @@ CATCH_TEST_CASE("array_construct") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::external3d v(data); CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data() == &data[0]); @@ -24,7 +22,7 @@ CATCH_TEST_CASE("array_construct") CATCH_TEST_CASE("array_assign") { double av[3]; - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::external3d v(av); v = data; CATCH_REQUIRE(v.size() == 3); @@ -36,13 +34,14 @@ CATCH_TEST_CASE("list_assign") { double av[3]; cml::external3d v(av); - v = { 1., 2., 3. }; + v = {1., 2., 3.}; CATCH_REQUIRE(v.size() == 3); CATCH_CHECK(v.data()[0] == 1.); CATCH_CHECK(v[0] == 1.); } -CATCH_TEST_CASE("fill1") { +CATCH_TEST_CASE("fill1") +{ double av[3]; cml::external3d v(av); v.fill(1.); @@ -53,7 +52,7 @@ CATCH_TEST_CASE("fill1") { CATCH_TEST_CASE("write1") { - double data[] = { 1., 2., 3. }; + double data[] = {1., 2., 3.}; cml::external3d v(data); CATCH_REQUIRE(v.size() == 3); v[0] = 1.; @@ -66,13 +65,13 @@ CATCH_TEST_CASE("size_check1") double av[3]; cml::external3d v(av); CATCH_REQUIRE(v.size() == 3); - CATCH_CHECK_THROWS_AS( - (v = { 1., 2., 3., 4. }), cml::incompatible_vector_size_error); + CATCH_CHECK_THROWS_AS((v = {1., 2., 3., 4.}), + cml::incompatible_vector_size_error); } CATCH_TEST_CASE("const1") { - const double av[] = { 1., 2., 3. }; + const double av[] = {1., 2., 3.}; cml::external3cd v(av); CATCH_REQUIRE(v.size() == 3); } @@ -80,13 +79,10 @@ CATCH_TEST_CASE("const1") #ifdef CML_HAS_STRUCTURED_BINDINGS CATCH_TEST_CASE("structured_binding1") { - double data[] = { 1., 2., 3. }; - auto [x,y,z] = cml::external3d(data); + double data[] = {1., 2., 3.}; + auto [x, y, z] = cml::external3d(data); CATCH_CHECK(x == 1.); CATCH_CHECK(y == 2.); CATCH_CHECK(z == 3.); } #endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/outer_product1.cpp b/tests/vector/outer_product1.cpp index 6d37e90..3df44bf 100644 --- a/tests/vector/outer_product1.cpp +++ b/tests/vector/outer_product1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -15,90 +13,60 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, outer1") { auto v = cml::vector3d(1., 2., 3.); - auto C = cml::outer(v,v); + auto C = cml::outer(v, v); CATCH_REQUIRE(C.rows() == 3); CATCH_REQUIRE(C.cols() == 3); - auto expected = cml::matrix33d( - 1., 2., 3., - 2., 4., 6., - 3., 6., 9. - ); + auto expected = cml::matrix33d(1., 2., 3., 2., 4., 6., 3., 6., 9.); - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(C(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) + CATCH_CHECK(C(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } - - - CATCH_TEST_CASE("fixed external, outer1") { - double av[] = { 1., 2., 3. }; + double av[] = {1., 2., 3.}; auto v = cml::external3d(av); - auto C = cml::outer(v,v); + auto C = cml::outer(v, v); CATCH_REQUIRE(C.rows() == 3); CATCH_REQUIRE(C.cols() == 3); - auto expected = cml::matrix33d( - 1., 2., 3., - 2., 4., 6., - 3., 6., 9. - ); + auto expected = cml::matrix33d(1., 2., 3., 2., 4., 6., 3., 6., 9.); - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(C(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) + CATCH_CHECK(C(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } - - - CATCH_TEST_CASE("dynamic external, outer1") { - double av[] = { 1., 2., 3. }; + double av[] = {1., 2., 3.}; auto v = cml::externalnd(3, av); - auto C = cml::outer(v,v); + auto C = cml::outer(v, v); CATCH_REQUIRE(C.rows() == 3); CATCH_REQUIRE(C.cols() == 3); - auto expected = cml::matrix33d( - 1., 2., 3., - 2., 4., 6., - 3., 6., 9. - ); + auto expected = cml::matrix33d(1., 2., 3., 2., 4., 6., 3., 6., 9.); - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(C(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) + CATCH_CHECK(C(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } - - - CATCH_TEST_CASE("dynamic, outer1") { auto v = cml::vectord(1., 2., 3.); - auto C = cml::outer(v,v); + auto C = cml::outer(v, v); CATCH_REQUIRE(C.rows() == 3); CATCH_REQUIRE(C.cols() == 3); - auto expected = cml::matrix33d( - 1., 2., 3., - 2., 4., 6., - 3., 6., 9. - ); + auto expected = cml::matrix33d(1., 2., 3., 2., 4., 6., 3., 6., 9.); - for(int i = 0; i < 3; ++ i) - for(int j = 0; j < 3; ++ j) - CATCH_CHECK(C(i,j) == Approx(expected(i,j)).epsilon(1e-12)); + for(int i = 0; i < 3; ++i) + for(int j = 0; j < 3; ++j) + CATCH_CHECK(C(i, j) == Approx(expected(i, j)).epsilon(1e-12)); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/perp_dot1.cpp b/tests/vector/perp_dot1.cpp index 5700c67..d775f34 100644 --- a/tests/vector/perp_dot1.cpp +++ b/tests/vector/perp_dot1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -16,9 +14,9 @@ CATCH_TEST_CASE("perp_dot1") { - cml::vector2d v1 = { 1., 0. }; - cml::vector2d v2 = { 0., 1. }; - double pd = cml::perp_dot(v1,v2); + cml::vector2d v1 = {1., 0.}; + cml::vector2d v2 = {0., 1.}; + double pd = cml::perp_dot(v1, v2); CATCH_CHECK(pd == 1.); } @@ -26,23 +24,20 @@ CATCH_TEST_CASE("perp_dot2") { cml::vectord v1(2., 8.); cml::vector2d v2(3., 7.); - double pd = cml::perp_dot(v1,v2); + double pd = cml::perp_dot(v1, v2); CATCH_CHECK(pd == -10.); } CATCH_TEST_CASE("size_check1") { - cml::vectord v1(2,3,3); - cml::vector2d v2(2,3); - CATCH_CHECK_THROWS_AS(cml::perp_dot(v1,v2), cml::vector_size_error); + cml::vectord v1(2, 3, 3); + cml::vector2d v2(2, 3); + CATCH_CHECK_THROWS_AS(cml::perp_dot(v1, v2), cml::vector_size_error); } CATCH_TEST_CASE("size_check2") { - cml::vector2d v1(2,3); - cml::vectord v2(2,3,3); - CATCH_CHECK_THROWS_AS(cml::perp_dot(v1,v2), cml::vector_size_error); + cml::vector2d v1(2, 3); + cml::vectord v2(2, 3, 3); + CATCH_CHECK_THROWS_AS(cml::perp_dot(v1, v2), cml::vector_size_error); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/subvector1.cpp b/tests/vector/subvector1.cpp index 7755fb8..dfdd982 100644 --- a/tests/vector/subvector1.cpp +++ b/tests/vector/subvector1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include @@ -18,11 +16,10 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, sub1") { - cml::vector3d v1 = { 1., 2., 3. }; - auto xpr = cml::subvector(v1,0); + cml::vector3d v1 = {1., 2., 3.}; + auto xpr = cml::subvector(v1, 0); CATCH_REQUIRE(cml::int_c::value == 2); CATCH_REQUIRE(xpr.size() == 2); CATCH_CHECK(xpr[0] == 2.); @@ -31,7 +28,7 @@ CATCH_TEST_CASE("fixed, sub1") CATCH_TEST_CASE("fixed, sub2") { - cml::vector3d v1 = { 1., 2., 3. }; + cml::vector3d v1 = {1., 2., 3.}; auto xpr = v1.subvector(0); CATCH_REQUIRE(cml::int_c::value == 2); CATCH_REQUIRE(xpr.size() == 2); @@ -48,14 +45,11 @@ CATCH_TEST_CASE("fixed, sub3") CATCH_CHECK(xpr[1] == 3.); } - - - CATCH_TEST_CASE("fixed external, sub1") { - double av1[] = { 1., 2., 3. }; + double av1[] = {1., 2., 3.}; cml::external3d v1(av1); - auto xpr = cml::subvector(v1,0); + auto xpr = cml::subvector(v1, 0); CATCH_REQUIRE(cml::int_c::value == 2); CATCH_REQUIRE(xpr.size() == 2); CATCH_CHECK(xpr[0] == 2.); @@ -64,7 +58,7 @@ CATCH_TEST_CASE("fixed external, sub1") CATCH_TEST_CASE("fixed external, sub2") { - double av1[] = { 1., 2., 3. }; + double av1[] = {1., 2., 3.}; cml::external3d v1(av1); auto xpr = v1.subvector(0); CATCH_REQUIRE(cml::int_c::value == 2); @@ -75,7 +69,7 @@ CATCH_TEST_CASE("fixed external, sub2") CATCH_TEST_CASE("fixed external, sub3") { - double av1[] = { 1., 2., 3. }; + double av1[] = {1., 2., 3.}; auto xpr = cml::subvector(cml::external3d(av1), 0); CATCH_REQUIRE(cml::int_c::value == 2); CATCH_REQUIRE(xpr.size() == 2); @@ -83,14 +77,11 @@ CATCH_TEST_CASE("fixed external, sub3") CATCH_CHECK(xpr[1] == 3.); } - - - CATCH_TEST_CASE("fixed const external, sub1") { - const double av1[] = { 1., 2., 3. }; + const double av1[] = {1., 2., 3.}; cml::external3cd v1(av1); - auto xpr = cml::subvector(v1,0); + auto xpr = cml::subvector(v1, 0); CATCH_REQUIRE(cml::int_c::value == 2); CATCH_REQUIRE(xpr.size() == 2); CATCH_CHECK(xpr[0] == 2.); @@ -99,7 +90,7 @@ CATCH_TEST_CASE("fixed const external, sub1") CATCH_TEST_CASE("fixed const external, sub2") { - const double av1[] = { 1., 2., 3. }; + const double av1[] = {1., 2., 3.}; cml::external3cd v1(av1); auto xpr = v1.subvector(0); CATCH_REQUIRE(cml::int_c::value == 2); @@ -110,7 +101,7 @@ CATCH_TEST_CASE("fixed const external, sub2") CATCH_TEST_CASE("fixed const external, sub3") { - const double av1[] = { 1., 2., 3. }; + const double av1[] = {1., 2., 3.}; auto xpr = cml::subvector(cml::external3cd(av1), 0); CATCH_REQUIRE(cml::int_c::value == 2); CATCH_REQUIRE(xpr.size() == 2); @@ -118,13 +109,10 @@ CATCH_TEST_CASE("fixed const external, sub3") CATCH_CHECK(xpr[1] == 3.); } - - - CATCH_TEST_CASE("dynamic, sub1") { - cml::vectord v1 = { 1., 2., 3. }; - auto xpr = cml::subvector(v1,0); + cml::vectord v1 = {1., 2., 3.}; + auto xpr = cml::subvector(v1, 0); CATCH_REQUIRE(cml::int_c::value == -1); CATCH_REQUIRE(xpr.size() == 2); CATCH_CHECK(xpr[0] == 2.); @@ -133,7 +121,7 @@ CATCH_TEST_CASE("dynamic, sub1") CATCH_TEST_CASE("dynamic, sub2") { - cml::vectord v1 = { 1., 2., 3. }; + cml::vectord v1 = {1., 2., 3.}; auto xpr = v1.subvector(0); CATCH_REQUIRE(v1.size() == 3); CATCH_REQUIRE(cml::int_c::value == -1); @@ -151,14 +139,11 @@ CATCH_TEST_CASE("dynamic, sub3") CATCH_CHECK(xpr[1] == 3.); } - - - CATCH_TEST_CASE("dynamic external, sub1") { - double av1[] = { 1., 2., 3. }; + double av1[] = {1., 2., 3.}; cml::externalnd v1(av1, 3); - auto xpr = cml::subvector(v1,0); + auto xpr = cml::subvector(v1, 0); CATCH_REQUIRE(cml::int_c::value == -1); CATCH_REQUIRE(xpr.size() == 2); CATCH_CHECK(xpr[0] == 2.); @@ -167,7 +152,7 @@ CATCH_TEST_CASE("dynamic external, sub1") CATCH_TEST_CASE("dynamic external, sub2") { - double av1[] = { 1., 2., 3. }; + double av1[] = {1., 2., 3.}; cml::externalnd v1(av1, 3); auto xpr = v1.subvector(0); CATCH_REQUIRE(cml::int_c::value == -1); @@ -178,7 +163,7 @@ CATCH_TEST_CASE("dynamic external, sub2") CATCH_TEST_CASE("dynamic external, sub3") { - double av1[] = { 1., 2., 3. }; + double av1[] = {1., 2., 3.}; auto xpr = cml::subvector(cml::externalnd(av1, 3), 0); CATCH_REQUIRE(cml::int_c::value == -1); CATCH_REQUIRE(xpr.size() == 2); @@ -186,14 +171,11 @@ CATCH_TEST_CASE("dynamic external, sub3") CATCH_CHECK(xpr[1] == 3.); } - - - CATCH_TEST_CASE("dynamic const external, sub1") { - const double av1[] = { 1., 2., 3. }; + const double av1[] = {1., 2., 3.}; cml::externalncd v1(av1, 3); - auto xpr = cml::subvector(v1,0); + auto xpr = cml::subvector(v1, 0); CATCH_REQUIRE(cml::int_c::value == -1); CATCH_REQUIRE(xpr.size() == 2); CATCH_CHECK(xpr[0] == 2.); @@ -202,7 +184,7 @@ CATCH_TEST_CASE("dynamic const external, sub1") CATCH_TEST_CASE("dynamic const external, sub2") { - const double av1[] = { 1., 2., 3. }; + const double av1[] = {1., 2., 3.}; cml::externalncd v1(av1, 3); auto xpr = v1.subvector(0); CATCH_REQUIRE(cml::int_c::value == -1); @@ -213,7 +195,7 @@ CATCH_TEST_CASE("dynamic const external, sub2") CATCH_TEST_CASE("dynamic const external, sub3") { - const double av1[] = { 1., 2., 3. }; + const double av1[] = {1., 2., 3.}; auto xpr = cml::subvector(cml::externalncd(av1, 3), 0); CATCH_REQUIRE(cml::int_c::value == -1); CATCH_REQUIRE(xpr.size() == 2); @@ -222,13 +204,13 @@ CATCH_TEST_CASE("dynamic const external, sub3") } - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS CATCH_TEST_CASE("rv from this1, sub1") { - typedef decltype(cml::vector3d().subvector(0)) node_type; - CATCH_CHECK((std::is_rvalue_reference::value)); + using node_type = decltype(cml::vector3d().subvector(0)); + CATCH_CHECK( + (std::is_rvalue_reference::value)); auto xpr = cml::vector3d(1., 2., 3.).subvector(0); CATCH_REQUIRE(cml::int_c::value == 2); CATCH_REQUIRE(xpr.size() == 2); @@ -238,9 +220,10 @@ CATCH_TEST_CASE("rv from this1, sub1") CATCH_TEST_CASE("rv from this1, sub2") { - cml::vector3d v1 = { 1., 2., 3. }; - typedef decltype(v1.subvector(0)) node_type; - CATCH_CHECK((std::is_lvalue_reference::value)); + cml::vector3d v1 = {1., 2., 3.}; + using node_type = decltype(v1.subvector(0)); + CATCH_CHECK( + (std::is_lvalue_reference::value)); auto xpr = v1.subvector(0); CATCH_REQUIRE(cml::int_c::value == 2); CATCH_REQUIRE(xpr.size() == 2); @@ -267,7 +250,7 @@ CATCH_TEST_CASE("rv from this1, sub1") CATCH_TEST_CASE("rv from this1, sub2") { typedef cml::vector3d vector3_t; - vector3_t v1 = { 1., 2., 3. }; + vector3_t v1 = {1., 2., 3.}; typedef decltype(v1.subvector(0)) node_type; CATCH_CHECK((std::is_same::value)); @@ -280,6 +263,3 @@ CATCH_TEST_CASE("rv from this1, sub2") } #endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/triple_product1.cpp b/tests/vector/triple_product1.cpp index 99b0742..46ff39f 100644 --- a/tests/vector/triple_product1.cpp +++ b/tests/vector/triple_product1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -17,22 +15,20 @@ CATCH_TEST_CASE("triple_product1") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; - double a3[3] = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; + double a3[3] = {7., 8., 9.}; cml::external3d v3(a3); - double tp = cml::triple_product(v1,v2,v3); + double tp = cml::triple_product(v1, v2, v3); CATCH_CHECK(tp == 0.); } CATCH_TEST_CASE("size_check1") { - cml::vectord v1 = { 1., 2. }; - cml::vectord v2 = { 4., 5., 6. }; - double a3[3] = { 7., 8., 9. }; + cml::vectord v1 = {1., 2.}; + cml::vectord v2 = {4., 5., 6.}; + double a3[3] = {7., 8., 9.}; cml::external3d v3(a3); - CATCH_CHECK_THROWS_AS(cml::triple_product(v1,v2,v3), cml::vector_size_error); + CATCH_CHECK_THROWS_AS(cml::triple_product(v1, v2, v3), + cml::vector_size_error); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/vector_binary_node1.cpp b/tests/vector/vector_binary_node1.cpp index 2b197f9..d36f1cd 100644 --- a/tests/vector/vector_binary_node1.cpp +++ b/tests/vector/vector_binary_node1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -18,103 +16,86 @@ CATCH_TEST_CASE("binary_types1") { - typedef cml::vector3d vector_type; + using vector_type = cml::vector3d; { CATCH_CHECK(cml::is_statically_polymorphic::value); } { auto xpr = vector_type() + vector_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { auto xpr = vector_type() - vector_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { vector_type M; auto xpr = vector_type() + M; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { vector_type M; auto xpr = M + vector_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { vector_type M; auto xpr = vector_type() - M; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { vector_type M; auto xpr = M - vector_type(); - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { vector_type M1, M2; auto xpr = M1 + M2; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { vector_type M1, M2; auto xpr = M1 - M2; - typedef decltype(xpr) xpr_type; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } } - CATCH_TEST_CASE("fixed, binary_minus1") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; cml::vector3d w; w = v1 - v2; CATCH_REQUIRE(w.size() == 3); @@ -125,8 +106,8 @@ CATCH_TEST_CASE("fixed, binary_minus1") CATCH_TEST_CASE("fixed, binary_minus2") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; cml::vector3d w = v1 - v2; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -3.); @@ -136,8 +117,8 @@ CATCH_TEST_CASE("fixed, binary_minus2") CATCH_TEST_CASE("fixed, binary_plus1") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; cml::vector3d w; w = v1 + v2; CATCH_REQUIRE(w.size() == 3); @@ -148,8 +129,8 @@ CATCH_TEST_CASE("fixed, binary_plus1") CATCH_TEST_CASE("fixed, binary_plus2") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; cml::vector3d w = v1 + v2; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 5.); @@ -159,9 +140,9 @@ CATCH_TEST_CASE("fixed, binary_plus2") CATCH_TEST_CASE("fixed, multiple_plus1") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; - cml::vector3d v3 = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; + cml::vector3d v3 = {7., 8., 9.}; cml::vector3d w; w = v1 + (v2 + v3); CATCH_REQUIRE(w.size() == 3); @@ -172,9 +153,9 @@ CATCH_TEST_CASE("fixed, multiple_plus1") CATCH_TEST_CASE("fixed, multiple_plus2") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; - cml::vector3d v3 = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; + cml::vector3d v3 = {7., 8., 9.}; cml::vector3d w = v1 + (v2 + v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 12.); @@ -184,9 +165,9 @@ CATCH_TEST_CASE("fixed, multiple_plus2") CATCH_TEST_CASE("fixed, mixed_op1") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; - cml::vector3d v3 = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; + cml::vector3d v3 = {7., 8., 9.}; cml::vector3d w; w = v2 - (v1 + v3); CATCH_REQUIRE(w.size() == 3); @@ -197,9 +178,9 @@ CATCH_TEST_CASE("fixed, mixed_op1") CATCH_TEST_CASE("fixed, mixed_op2") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; - cml::vector3d v3 = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; + cml::vector3d v3 = {7., 8., 9.}; cml::vector3d w = v2 - (v1 + v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -4.); @@ -209,8 +190,8 @@ CATCH_TEST_CASE("fixed, mixed_op2") CATCH_TEST_CASE("fixed, assign_minus1") { - cml::vector3d w = { 1., 2., 3. }; - cml::vector3d v = { 4., 5., 6. }; + cml::vector3d w = {1., 2., 3.}; + cml::vector3d v = {4., 5., 6.}; w -= v; CATCH_CHECK(w[0] == -3.); CATCH_CHECK(w[1] == -3.); @@ -219,21 +200,18 @@ CATCH_TEST_CASE("fixed, assign_minus1") CATCH_TEST_CASE("fixed, assign_plus1") { - cml::vector3d w = { 1., 2., 3. }; - cml::vector3d v = { 4., 5., 6. }; + cml::vector3d w = {1., 2., 3.}; + cml::vector3d v = {4., 5., 6.}; w += v; CATCH_CHECK(w[0] == 5.); CATCH_CHECK(w[1] == 7.); CATCH_CHECK(w[2] == 9.); } - - - CATCH_TEST_CASE("fixed external, binary_minus1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; double aw[3]; cml::external3d v1(av1); cml::external3d v2(av2); @@ -247,8 +225,8 @@ CATCH_TEST_CASE("fixed external, binary_minus1") CATCH_TEST_CASE("fixed external, binary_plus1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; double aw[3]; cml::external3d v1(av1); cml::external3d v2(av2); @@ -262,9 +240,9 @@ CATCH_TEST_CASE("fixed external, binary_plus1") CATCH_TEST_CASE("fixed external, multiple_plus1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; - double av3[] = { 7., 8., 9. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; + double av3[] = {7., 8., 9.}; double aw[3]; cml::external3d v1(av1); cml::external3d v2(av2); @@ -279,9 +257,9 @@ CATCH_TEST_CASE("fixed external, multiple_plus1") CATCH_TEST_CASE("fixed external, mixed_op1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; - double av3[] = { 7., 8., 9. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; + double av3[] = {7., 8., 9.}; double aw[3]; cml::external3d v1(av1); cml::external3d v2(av2); @@ -294,17 +272,14 @@ CATCH_TEST_CASE("fixed external, mixed_op1") CATCH_CHECK(w[2] == -6.); } - - - CATCH_TEST_CASE("dynamic external, binary_minus1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; double aw[3]; - cml::externalnd v1(av1,3); - cml::externalnd v2(av2,3); - cml::externalnd w(aw,3); + cml::externalnd v1(av1, 3); + cml::externalnd v2(av2, 3); + cml::externalnd w(aw, 3); w = v1 - v2; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -3.); @@ -314,12 +289,12 @@ CATCH_TEST_CASE("dynamic external, binary_minus1") CATCH_TEST_CASE("dynamic external, binary_plus1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; double aw[3]; - cml::externalnd v1(av1,3); - cml::externalnd v2(av2,3); - cml::externalnd w(aw,3); + cml::externalnd v1(av1, 3); + cml::externalnd v2(av2, 3); + cml::externalnd w(aw, 3); w = v1 + v2; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 5.); @@ -329,14 +304,14 @@ CATCH_TEST_CASE("dynamic external, binary_plus1") CATCH_TEST_CASE("dynamic external, multiple_plus1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; - double av3[] = { 7., 8., 9. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; + double av3[] = {7., 8., 9.}; double aw[3]; - cml::externalnd v1(av1,3); - cml::externalnd v2(av2,3); - cml::externalnd v3(av3,3); - cml::externalnd w(aw,3); + cml::externalnd v1(av1, 3); + cml::externalnd v2(av2, 3); + cml::externalnd v3(av3, 3); + cml::externalnd w(aw, 3); w = v1 + (v2 + v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 12.); @@ -346,14 +321,14 @@ CATCH_TEST_CASE("dynamic external, multiple_plus1") CATCH_TEST_CASE("dynamic external, mixed_op1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; - double av3[] = { 7., 8., 9. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; + double av3[] = {7., 8., 9.}; double aw[3]; - cml::externalnd v1(av1,3); - cml::externalnd v2(av2,3); - cml::externalnd v3(av3,3); - cml::externalnd w(aw,3); + cml::externalnd v1(av1, 3); + cml::externalnd v2(av2, 3); + cml::externalnd v3(av3, 3); + cml::externalnd w(aw, 3); w = v2 - (v1 + v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -4.); @@ -361,17 +336,14 @@ CATCH_TEST_CASE("dynamic external, mixed_op1") CATCH_CHECK(w[2] == -6.); } - - - CATCH_TEST_CASE("dynamic const external, binary_minus1") { - const double av1[] = { 1., 2., 3. }; - const double av2[] = { 4., 5., 6. }; + const double av1[] = {1., 2., 3.}; + const double av2[] = {4., 5., 6.}; double aw[3]; - cml::externalncd v1(av1,3); - cml::externalncd v2(av2,3); - cml::externalnd w(aw,3); + cml::externalncd v1(av1, 3); + cml::externalncd v2(av2, 3); + cml::externalnd w(aw, 3); w = v1 - v2; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -3.); @@ -381,12 +353,12 @@ CATCH_TEST_CASE("dynamic const external, binary_minus1") CATCH_TEST_CASE("dynamic const external, binary_plus1") { - const double av1[] = { 1., 2., 3. }; - const double av2[] = { 4., 5., 6. }; + const double av1[] = {1., 2., 3.}; + const double av2[] = {4., 5., 6.}; double aw[3]; - cml::externalncd v1(av1,3); - cml::externalncd v2(av2,3); - cml::externalnd w(aw,3); + cml::externalncd v1(av1, 3); + cml::externalncd v2(av2, 3); + cml::externalnd w(aw, 3); w = v1 + v2; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 5.); @@ -396,14 +368,14 @@ CATCH_TEST_CASE("dynamic const external, binary_plus1") CATCH_TEST_CASE("dynamic const external, multiple_plus1") { - const double av1[] = { 1., 2., 3. }; - const double av2[] = { 4., 5., 6. }; - double av3[] = { 7., 8., 9. }; + const double av1[] = {1., 2., 3.}; + const double av2[] = {4., 5., 6.}; + double av3[] = {7., 8., 9.}; double aw[3]; - cml::externalncd v1(av1,3); - cml::externalncd v2(av2,3); - cml::externalnd v3(av3,3); - cml::externalnd w(aw,3); + cml::externalncd v1(av1, 3); + cml::externalncd v2(av2, 3); + cml::externalnd v3(av3, 3); + cml::externalnd w(aw, 3); w = v1 + (v2 + v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 12.); @@ -413,14 +385,14 @@ CATCH_TEST_CASE("dynamic const external, multiple_plus1") CATCH_TEST_CASE("dynamic const external, mixed_op1") { - const double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; - const double av3[] = { 7., 8., 9. }; + const double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; + const double av3[] = {7., 8., 9.}; double aw[3]; - cml::externalncd v1(av1,3); - cml::externalnd v2(av2,3); - cml::externalncd v3(av3,3); - cml::externalnd w(aw,3); + cml::externalncd v1(av1, 3); + cml::externalnd v2(av2, 3); + cml::externalncd v3(av3, 3); + cml::externalnd w(aw, 3); w = v2 - (v1 + v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -4.); @@ -428,13 +400,10 @@ CATCH_TEST_CASE("dynamic const external, mixed_op1") CATCH_CHECK(w[2] == -6.); } - - - CATCH_TEST_CASE("dynamic, binary_minus1") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; cml::vectord w; w = v1 - v2; CATCH_REQUIRE(w.size() == 3); @@ -445,8 +414,8 @@ CATCH_TEST_CASE("dynamic, binary_minus1") CATCH_TEST_CASE("dynamic, binary_minus2") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; cml::vectord w = v1 - v2; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -3.); @@ -456,8 +425,8 @@ CATCH_TEST_CASE("dynamic, binary_minus2") CATCH_TEST_CASE("dynamic, binary_plus1") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; cml::vectord w; w = v1 + v2; CATCH_REQUIRE(w.size() == 3); @@ -468,8 +437,8 @@ CATCH_TEST_CASE("dynamic, binary_plus1") CATCH_TEST_CASE("dynamic, binary_plus2") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; cml::vectord w = v1 + v2; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 5.); @@ -479,9 +448,9 @@ CATCH_TEST_CASE("dynamic, binary_plus2") CATCH_TEST_CASE("dynamic, multiple_plus1") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; - cml::vectord v3 = { 7., 8., 9. }; + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; + cml::vectord v3 = {7., 8., 9.}; cml::vectord w; w = v1 + (v2 + v3); CATCH_REQUIRE(w.size() == 3); @@ -492,9 +461,9 @@ CATCH_TEST_CASE("dynamic, multiple_plus1") CATCH_TEST_CASE("dynamic, multiple_plus2") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; - cml::vectord v3 = { 7., 8., 9. }; + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; + cml::vectord v3 = {7., 8., 9.}; cml::vectord w = v1 + (v2 + v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 12.); @@ -504,9 +473,9 @@ CATCH_TEST_CASE("dynamic, multiple_plus2") CATCH_TEST_CASE("dynamic, mixed_op1") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; - cml::vectord v3 = { 7., 8., 9. }; + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; + cml::vectord v3 = {7., 8., 9.}; cml::vectord w; w = v2 - (v1 + v3); CATCH_REQUIRE(w.size() == 3); @@ -517,9 +486,9 @@ CATCH_TEST_CASE("dynamic, mixed_op1") CATCH_TEST_CASE("dynamic, mixed_op2") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; - cml::vectord v3 = { 7., 8., 9. }; + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; + cml::vectord v3 = {7., 8., 9.}; cml::vectord w = v2 - (v1 + v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -4.); @@ -529,8 +498,8 @@ CATCH_TEST_CASE("dynamic, mixed_op2") CATCH_TEST_CASE("dynamic, assign_minus1") { - cml::vectord w = { 1., 2., 3. }; - cml::vectord v = { 4., 5., 6. }; + cml::vectord w = {1., 2., 3.}; + cml::vectord v = {4., 5., 6.}; w -= v; CATCH_CHECK(w[0] == -3.); CATCH_CHECK(w[1] == -3.); @@ -539,25 +508,22 @@ CATCH_TEST_CASE("dynamic, assign_minus1") CATCH_TEST_CASE("dynamic, assign_plus1") { - cml::vectord w = { 1., 2., 3. }; - cml::vectord v = { 4., 5., 6. }; + cml::vectord w = {1., 2., 3.}; + cml::vectord v = {4., 5., 6.}; w += v; CATCH_CHECK(w[0] == 5.); CATCH_CHECK(w[1] == 7.); CATCH_CHECK(w[2] == 9.); } - - - CATCH_TEST_CASE("mixed fixed storage, construct_xpr") { - cml::vector3d v1 = { 1., 2., 3. }; - double av2[] = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + double av2[] = {7., 8., 9.}; cml::external3d v2(av2); - cml::vector3d v3 = { 4., 5., 6. }; - double av4[] = { 10., 11., 12. }; + cml::vector3d v3 = {4., 5., 6.}; + double av4[] = {10., 11., 12.}; cml::external3d v4(av4); cml::vector3d w = v1 + v2 - v3 + v4; @@ -569,12 +535,12 @@ CATCH_TEST_CASE("mixed fixed storage, construct_xpr") CATCH_TEST_CASE("mixed fixed storage, assign_xpr") { - cml::vector3d v1 = { 1., 2., 3. }; - double av2[] = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + double av2[] = {7., 8., 9.}; cml::external3d v2(av2); - cml::vector3d v3 = { 4., 5., 6. }; - double av4[] = { 10., 11., 12. }; + cml::vector3d v3 = {4., 5., 6.}; + double av4[] = {10., 11., 12.}; cml::external3d v4(av4); cml::vector3d w; @@ -587,12 +553,12 @@ CATCH_TEST_CASE("mixed fixed storage, assign_xpr") CATCH_TEST_CASE("mixed fixed storage, assign_temp_xpr") { - cml::vector3d v1 = { 1., 2., 3. }; - double av2[] = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + double av2[] = {7., 8., 9.}; cml::external3d v2(av2); - cml::vector3d v3 = { 4., 5., 6. }; - double av4[] = { 10., 11., 12. }; + cml::vector3d v3 = {4., 5., 6.}; + double av4[] = {10., 11., 12.}; cml::external3d v4(av4); auto xpr = v1 + v2 - v3 + v4; @@ -606,17 +572,14 @@ CATCH_TEST_CASE("mixed fixed storage, assign_temp_xpr") CATCH_CHECK(w[2] == 18.); } - - - CATCH_TEST_CASE("mixed storage, construct_xpr") { - cml::vector3d v1 = { 1., 2., 3. }; - double av2[] = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + double av2[] = {7., 8., 9.}; cml::external3d v2(av2); - cml::vectord v3 = { 4., 5., 6. }; - double av4[] = { 10., 11., 12. }; + cml::vectord v3 = {4., 5., 6.}; + double av4[] = {10., 11., 12.}; cml::externalnd v4(av4, 3); cml::vector3d w = v1 + v2 - v3 + v4; @@ -628,12 +591,12 @@ CATCH_TEST_CASE("mixed storage, construct_xpr") CATCH_TEST_CASE("mixed storage, assign_xpr") { - cml::vector3d v1 = { 1., 2., 3. }; - double av2[] = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + double av2[] = {7., 8., 9.}; cml::external3d v2(av2); - cml::vectord v3 = { 4., 5., 6. }; - double av4[] = { 10., 11., 12. }; + cml::vectord v3 = {4., 5., 6.}; + double av4[] = {10., 11., 12.}; cml::externalnd v4(av4, 3); cml::vectord w; @@ -646,12 +609,12 @@ CATCH_TEST_CASE("mixed storage, assign_xpr") CATCH_TEST_CASE("mixed storage, assign_temp_xpr") { - cml::vector3d v1 = { 1., 2., 3. }; - double av2[] = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + double av2[] = {7., 8., 9.}; cml::external3d v2(av2); - cml::vectord v3 = { 4., 5., 6. }; - double av4[] = { 10., 11., 12. }; + cml::vectord v3 = {4., 5., 6.}; + double av4[] = {10., 11., 12.}; cml::externalnd v4(av4, 3); auto xpr = v1 + v2 - v3 + v4; @@ -665,7 +628,3 @@ CATCH_TEST_CASE("mixed storage, assign_temp_xpr") CATCH_CHECK(w[1] == 16.); CATCH_CHECK(w[2] == 18.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/vector_comparison1.cpp b/tests/vector/vector_comparison1.cpp index 0f87c4f..5d4bbfd 100644 --- a/tests/vector/vector_comparison1.cpp +++ b/tests/vector/vector_comparison1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -15,66 +13,63 @@ CATCH_TEST_CASE("less_greater1") { - cml::vector3d v = { 1., 2., 3. }; - cml::vector3d w = { 2., 2., 2. }; + cml::vector3d v = {1., 2., 3.}; + cml::vector3d w = {2., 2., 2.}; CATCH_REQUIRE(v < w); CATCH_REQUIRE(w > v); } CATCH_TEST_CASE("less_greater2") { - cml::vector3d v = { 1., 2., 3. }; - cml::vector3d w = { 1., 2., 2. }; + cml::vector3d v = {1., 2., 3.}; + cml::vector3d w = {1., 2., 2.}; CATCH_REQUIRE(w < v); CATCH_REQUIRE(v > w); } CATCH_TEST_CASE("less_greater3") { - cml::vector3d v = { 1., 2., 3. }; - cml::vector3d w = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; + cml::vector3d w = {1., 2., 3.}; CATCH_REQUIRE(!(w < v)); CATCH_REQUIRE(!(v < w)); } CATCH_TEST_CASE("less_equal1") { - cml::vector3d v = { 1., 2., 3. }; - cml::vector3d w = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; + cml::vector3d w = {1., 2., 3.}; CATCH_REQUIRE(v <= w); CATCH_REQUIRE(w <= v); } CATCH_TEST_CASE("less_equal2") { - cml::vector3d v = { 1., 2., 3. }; - cml::vector3d w = { 1., 2., 4. }; + cml::vector3d v = {1., 2., 3.}; + cml::vector3d w = {1., 2., 4.}; CATCH_REQUIRE(v <= w); CATCH_REQUIRE(!(w <= v)); } CATCH_TEST_CASE("greater_equal1") { - cml::vector3d v = { 1., 2., 3. }; - cml::vector3d w = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; + cml::vector3d w = {1., 2., 3.}; CATCH_REQUIRE(v >= w); CATCH_REQUIRE(w >= v); } CATCH_TEST_CASE("greater_equal2") { - cml::vector3d v = { 1., 2., 3. }; - cml::vector3d w = { 1., 2., 4. }; + cml::vector3d v = {1., 2., 3.}; + cml::vector3d w = {1., 2., 4.}; CATCH_REQUIRE(w >= v); CATCH_REQUIRE(!(v >= w)); } CATCH_TEST_CASE("equal1") { - cml::vector3d v = { 1., 2., 3. }; - cml::vector3d w = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; + cml::vector3d w = {1., 2., 3.}; CATCH_REQUIRE(w == v); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/vector_copy1.cpp b/tests/vector/vector_copy1.cpp index 1f8e04c..b565855 100644 --- a/tests/vector/vector_copy1.cpp +++ b/tests/vector/vector_copy1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include #include @@ -13,17 +11,16 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, copy_temp_fixed") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; cml::vector3d w = v; CATCH_CHECK(v == w); } CATCH_TEST_CASE("fixed, copy_temp_fixed_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::external3d v(av); cml::vector3d w = v; CATCH_CHECK(v == w); @@ -31,7 +28,7 @@ CATCH_TEST_CASE("fixed, copy_temp_fixed_external") CATCH_TEST_CASE("fixed, copy_temp_dynamic_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::externalnd v(av, 3); cml::vector3d w = v; CATCH_CHECK(v == w); @@ -39,14 +36,14 @@ CATCH_TEST_CASE("fixed, copy_temp_dynamic_external") CATCH_TEST_CASE("fixed, copy_temp_dynamic") { - cml::vectord v = { 1., 2., 3. }; - cml::vector3d w = v; + cml::vectord v = {1., 2., 3.}; + cml::vector3d w = v; CATCH_CHECK(v == w); } CATCH_TEST_CASE("fixed, copy_assign_fixed") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; cml::vector3d w; w = v; CATCH_CHECK(v == w); @@ -54,7 +51,7 @@ CATCH_TEST_CASE("fixed, copy_assign_fixed") CATCH_TEST_CASE("fixed, copy_assign_fixed_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::external3d v(av); cml::vector3d w; w = v; @@ -63,7 +60,7 @@ CATCH_TEST_CASE("fixed, copy_assign_fixed_external") CATCH_TEST_CASE("fixed, copy_assign_dynamic_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::externalnd v(av, 3); cml::vector3d w; w = v; @@ -72,26 +69,23 @@ CATCH_TEST_CASE("fixed, copy_assign_dynamic_external") CATCH_TEST_CASE("fixed, copy_assign_dynamic") { - cml::vectord v = { 1., 2., 3. }; + cml::vectord v = {1., 2., 3.}; cml::vector3d w; - w = v; + w = v; CATCH_CHECK(v == w); } CATCH_TEST_CASE("fixed, move_assign") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; cml::vector3d w; w = cml::vector3d(1., 2., 3.); CATCH_CHECK(v == w); } - - - CATCH_TEST_CASE("fixed external, copy_assign_fixed") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; double aw[3]; cml::external3d w(aw); w = v; @@ -100,7 +94,7 @@ CATCH_TEST_CASE("fixed external, copy_assign_fixed") CATCH_TEST_CASE("fixed external, copy_assign_fixed_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::external3d v(av); double aw[3]; cml::external3d w(aw); @@ -110,7 +104,7 @@ CATCH_TEST_CASE("fixed external, copy_assign_fixed_external") CATCH_TEST_CASE("fixed external, copy_assign_dynamic_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::externalnd v(av, 3); double aw[3]; cml::external3d w(aw); @@ -120,16 +114,16 @@ CATCH_TEST_CASE("fixed external, copy_assign_dynamic_external") CATCH_TEST_CASE("fixed external, copy_assign_dynamic") { - cml::vectord v = { 1., 2., 3. }; + cml::vectord v = {1., 2., 3.}; double aw[3]; cml::external3d w(aw); - w = v; + w = v; CATCH_CHECK(v == w); } CATCH_TEST_CASE("fixed external, move_assign") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS cml::external3d w; #else @@ -138,18 +132,15 @@ CATCH_TEST_CASE("fixed external, move_assign") // user code on compilers that do not support rvalue references from // this. #endif - double at[3] = { 1., 2., 3. }; + double at[3] = {1., 2., 3.}; w = cml::external3d(at); CATCH_REQUIRE(w.data() == &at[0]); CATCH_CHECK(v == w); } - - - CATCH_TEST_CASE("dynamic external, copy_assign_fixed") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; double aw[3]; cml::externalnd w(aw, 3); w = v; @@ -158,7 +149,7 @@ CATCH_TEST_CASE("dynamic external, copy_assign_fixed") CATCH_TEST_CASE("dynamic external, copy_assign_fixed_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::external3d v(av); double aw[3]; cml::externalnd w(aw, 3); @@ -168,7 +159,7 @@ CATCH_TEST_CASE("dynamic external, copy_assign_fixed_external") CATCH_TEST_CASE("dynamic external, copy_assign_dynamic_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::externalnd v(av, 3); double aw[3]; cml::externalnd w(aw, 3); @@ -178,16 +169,16 @@ CATCH_TEST_CASE("dynamic external, copy_assign_dynamic_external") CATCH_TEST_CASE("dynamic external, copy_assign_dynamic") { - cml::vectord v = { 1., 2., 3. }; + cml::vectord v = {1., 2., 3.}; double aw[3]; cml::externalnd w(aw, 3); - w = v; + w = v; CATCH_CHECK(v == w); } CATCH_TEST_CASE("dynamic external, move_assign") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS cml::externalnd w; #else @@ -196,18 +187,15 @@ CATCH_TEST_CASE("dynamic external, move_assign") // user code on compilers that do not support rvalue references from // this. #endif - double at[3] = { 1., 2., 3. }; + double at[3] = {1., 2., 3.}; w = cml::externalnd(at, 3); CATCH_REQUIRE(w.data() == &at[0]); CATCH_CHECK(v == w); } - - - CATCH_TEST_CASE("dynamic, copy_temp_fixed") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; cml::vectord w = v; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(v == w); @@ -215,7 +203,7 @@ CATCH_TEST_CASE("dynamic, copy_temp_fixed") CATCH_TEST_CASE("dynamic, copy_temp_fixed_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::external3d v(av); cml::vectord w = v; CATCH_REQUIRE(w.size() == 3); @@ -224,7 +212,7 @@ CATCH_TEST_CASE("dynamic, copy_temp_fixed_external") CATCH_TEST_CASE("dynamic, copy_temp_dynamic_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::externalnd v(av, 3); cml::vectord w = v; CATCH_REQUIRE(w.size() == 3); @@ -233,15 +221,15 @@ CATCH_TEST_CASE("dynamic, copy_temp_dynamic_external") CATCH_TEST_CASE("dynamic, copy_temp_dynamic") { - cml::vectord v = { 1., 2., 3. }; - cml::vectord w = v; + cml::vectord v = {1., 2., 3.}; + cml::vectord w = v; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(v == w); } CATCH_TEST_CASE("dynamic, copy_assign_fixed") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; cml::vectord w; w = v; CATCH_REQUIRE(w.size() == 3); @@ -250,7 +238,7 @@ CATCH_TEST_CASE("dynamic, copy_assign_fixed") CATCH_TEST_CASE("dynamic, copy_assign_fixed_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::external3d v(av); cml::vectord w; w = v; @@ -260,7 +248,7 @@ CATCH_TEST_CASE("dynamic, copy_assign_fixed_external") CATCH_TEST_CASE("dynamic, copy_assign_dynamic_external") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::externalnd v(av, 3); cml::vectord w; w = v; @@ -270,22 +258,18 @@ CATCH_TEST_CASE("dynamic, copy_assign_dynamic_external") CATCH_TEST_CASE("dynamic, copy_assign_dynamic") { - cml::vectord v = { 1., 2., 3. }; + cml::vectord v = {1., 2., 3.}; cml::vectord w; - w = v; + w = v; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(v == w); } CATCH_TEST_CASE("dynamic, move_assign") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; cml::vectord w; w = cml::vectord(1., 2., 3.); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(v == w); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/vector_dot1.cpp b/tests/vector/vector_dot1.cpp index 2a342c8..ba46014 100644 --- a/tests/vector/vector_dot1.cpp +++ b/tests/vector/vector_dot1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -16,31 +14,28 @@ CATCH_TEST_CASE("dot1") { - cml::vector3d v1 = { 1., 1., 1. }; - cml::vector3d v2 = { 2., 2., 2. }; - double dp = cml::dot(v1,v2); + cml::vector3d v1 = {1., 1., 1.}; + cml::vector3d v2 = {2., 2., 2.}; + double dp = cml::dot(v1, v2); CATCH_CHECK(dp == 6.); } CATCH_TEST_CASE("size_check1") { cml::vectord v1; - CATCH_CHECK_THROWS_AS(cml::dot(v1,v1), cml::minimum_vector_size_error); + CATCH_CHECK_THROWS_AS(cml::dot(v1, v1), cml::minimum_vector_size_error); } CATCH_TEST_CASE("size_check2") { - cml::vectord v1(2,3); - cml::vector3d v2(2,3,3); - CATCH_CHECK_THROWS_AS(cml::dot(v1,v2), cml::incompatible_vector_size_error); + cml::vectord v1(2, 3); + cml::vector3d v2(2, 3, 3); + CATCH_CHECK_THROWS_AS(cml::dot(v1, v2), cml::incompatible_vector_size_error); } CATCH_TEST_CASE("size_check3") { - cml::vector3d v1(2,3,3); - cml::vectord v2(2,3); - CATCH_CHECK_THROWS_AS(cml::dot(v1,v2), cml::incompatible_vector_size_error); + cml::vector3d v1(2, 3, 3); + cml::vectord v2(2, 3); + CATCH_CHECK_THROWS_AS(cml::dot(v1, v2), cml::incompatible_vector_size_error); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/vector_functions1.cpp b/tests/vector/vector_functions1.cpp index da09e70..6a53b7d 100644 --- a/tests/vector/vector_functions1.cpp +++ b/tests/vector/vector_functions1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include @@ -14,38 +12,37 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, length_squared1") { - cml::vector3d v1 = { 1., 1., 1. }; + cml::vector3d v1 = {1., 1., 1.}; double l2 = v1.length_squared(); CATCH_CHECK(l2 == 3.); } CATCH_TEST_CASE("fixed, length_squared2") { - cml::vector3d v1 = { 1., 1., 1. }; + cml::vector3d v1 = {1., 1., 1.}; double l2 = cml::length_squared(v1); CATCH_CHECK(l2 == 3.); } CATCH_TEST_CASE("fixed, length1") { - cml::vector3d v1 = { 1., 1., 1. }; + cml::vector3d v1 = {1., 1., 1.}; double l = v1.length(); CATCH_CHECK(l == Approx(std::sqrt(3.)).epsilon(1e-4)); } CATCH_TEST_CASE("fixed, length2") { - cml::vector3d v1 = { 1., 1., 1. }; + cml::vector3d v1 = {1., 1., 1.}; double l = cml::length(v1); CATCH_CHECK(l == Approx(std::sqrt(3.)).epsilon(1e-4)); } CATCH_TEST_CASE("fixed, normalize1") { - cml::vector3d v1 = { 1., 1., 1. }; + cml::vector3d v1 = {1., 1., 1.}; v1.normalize(); double l2 = v1.length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); @@ -53,33 +50,32 @@ CATCH_TEST_CASE("fixed, normalize1") CATCH_TEST_CASE("fixed, normalize2") { - cml::vector3d v1 = { 1., 1., 1. }; + cml::vector3d v1 = {1., 1., 1.}; double l2 = cml::normalize(v1).length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, normalize3") { - CATCH_CHECK((std::is_same::value)); - double l2 = cml::normalize( - cml::vector3d(1., 1., 1.)).length_squared(); + CATCH_CHECK((std::is_same::value)); + double l2 = cml::normalize(cml::vector3d(1., 1., 1.)).length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, normalize4") { - cml::vector3d v1 = { 1., 1., 1. }; - cml::vector3d v2 = { 1., 1., 1. }; - cml::vector3d v3 = { 1., 1., 1. }; - auto xpr = cml::normalize(v1 + 2.*v2); + cml::vector3d v1 = {1., 1., 1.}; + cml::vector3d v2 = {1., 1., 1.}; + cml::vector3d v3 = {1., 1., 1.}; + auto xpr = cml::normalize(v1 + 2. * v2); CATCH_CHECK((std::is_same::value)); CATCH_CHECK(xpr.length_squared() == Approx(1.0).epsilon(1e-12)); } CATCH_TEST_CASE("fixed, zero1") { - cml::vector3d v1 = { 1., 1., 1. }; + cml::vector3d v1 = {1., 1., 1.}; v1.zero(); CATCH_CHECK(v1[0] == 0.); CATCH_CHECK(v1[1] == 0.); @@ -89,8 +85,8 @@ CATCH_TEST_CASE("fixed, zero1") CATCH_TEST_CASE("fixed, minimize1") { - cml::vector3d v1 = { 1., 1., 1. }; - cml::vector3d v2 = { 2., 0., 3. }; + cml::vector3d v1 = {1., 1., 1.}; + cml::vector3d v2 = {2., 0., 3.}; v1.minimize(v2); CATCH_CHECK(v1[0] == 1.); CATCH_CHECK(v1[1] == 0.); @@ -99,8 +95,8 @@ CATCH_TEST_CASE("fixed, minimize1") CATCH_TEST_CASE("fixed, maximize1") { - cml::vector3d v1 = { 1., 1., 1. }; - cml::vector3d v2 = { 2., 0., 3. }; + cml::vector3d v1 = {1., 1., 1.}; + cml::vector3d v2 = {2., 0., 3.}; v1.maximize(v2); CATCH_CHECK(v1[0] == 2.); CATCH_CHECK(v1[1] == 1.); @@ -119,19 +115,16 @@ CATCH_TEST_CASE("fixed, cardinal1") CATCH_TEST_CASE("fixed, random1") { cml::vector4d v1; - v1.random(0.,1.); + v1.random(0., 1.); for(const auto& e : v1) { CATCH_CHECK(e >= 0.); CATCH_CHECK(e < 1.); } } - - - CATCH_TEST_CASE("fixed external, length_squared1") { - double av1[] = { 1., 1., 1. }; + double av1[] = {1., 1., 1.}; cml::external3d v1(av1); double l2 = v1.length_squared(); CATCH_CHECK(l2 == 3.); @@ -139,7 +132,7 @@ CATCH_TEST_CASE("fixed external, length_squared1") CATCH_TEST_CASE("fixed external, length1") { - double av1[] = { 1., 1., 1. }; + double av1[] = {1., 1., 1.}; cml::external3d v1(av1); double l = v1.length(); CATCH_CHECK(l == Approx(std::sqrt(3.)).epsilon(1e-4)); @@ -147,7 +140,7 @@ CATCH_TEST_CASE("fixed external, length1") CATCH_TEST_CASE("fixed external, normalize1") { - double av1[] = { 1., 1., 1. }; + double av1[] = {1., 1., 1.}; cml::external3d v1(av1); double l2 = v1.normalize().length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); @@ -155,7 +148,7 @@ CATCH_TEST_CASE("fixed external, normalize1") CATCH_TEST_CASE("fixed external, normalize2") { - double av1[] = { 1., 1., 1. }; + double av1[] = {1., 1., 1.}; cml::external3d v1(av1); double l2 = cml::normalize(v1).length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); @@ -163,7 +156,7 @@ CATCH_TEST_CASE("fixed external, normalize2") CATCH_TEST_CASE("fixed external, zero1") { - double av1[] = { 1., 1., 1. }; + double av1[] = {1., 1., 1.}; cml::external3d v1(av1); v1.zero(); CATCH_CHECK(v1[0] == 0.); @@ -174,8 +167,8 @@ CATCH_TEST_CASE("fixed external, zero1") CATCH_TEST_CASE("fixed external, minimize1") { - double av1[] = { 1., 1., 1. }; - double av2[] = { 2., 0., 3. }; + double av1[] = {1., 1., 1.}; + double av2[] = {2., 0., 3.}; cml::external3d v1(av1); cml::external3d v2(av2); v1.minimize(v2); @@ -186,8 +179,8 @@ CATCH_TEST_CASE("fixed external, minimize1") CATCH_TEST_CASE("fixed external, maximize1") { - double av1[] = { 1., 1., 1. }; - double av2[] = { 2., 0., 3. }; + double av1[] = {1., 1., 1.}; + double av2[] = {2., 0., 3.}; cml::external3d v1(av1); cml::external3d v2(av2); v1.maximize(v2); @@ -210,19 +203,16 @@ CATCH_TEST_CASE("fixed external, random1") { double av1[4]; cml::external3d v1(av1); - v1.random(0.,1.); + v1.random(0., 1.); for(const auto& e : v1) { CATCH_CHECK(e >= 0.); CATCH_CHECK(e < 1.); } } - - - CATCH_TEST_CASE("fixed const external, length_squared1") { - const double av1[] = { 1., 1., 1. }; + const double av1[] = {1., 1., 1.}; cml::external3cd v1(av1); double l2 = v1.length_squared(); CATCH_CHECK(l2 == 3.); @@ -230,7 +220,7 @@ CATCH_TEST_CASE("fixed const external, length_squared1") CATCH_TEST_CASE("fixed const external, length1") { - const double av1[] = { 1., 1., 1. }; + const double av1[] = {1., 1., 1.}; cml::external3cd v1(av1); double l = v1.length(); CATCH_CHECK(l == Approx(std::sqrt(3.)).epsilon(1e-4)); @@ -238,7 +228,7 @@ CATCH_TEST_CASE("fixed const external, length1") CATCH_TEST_CASE("fixed const external, normalize1") { - const double av1[] = { 1., 1., 1. }; + const double av1[] = {1., 1., 1.}; cml::external3cd v1(av1); double l2 = v1.normalize().length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); @@ -246,32 +236,29 @@ CATCH_TEST_CASE("fixed const external, normalize1") CATCH_TEST_CASE("fixed const external, normalize2") { - const double av1[] = { 1., 1., 1. }; + const double av1[] = {1., 1., 1.}; cml::external3cd v1(av1); double l2 = cml::normalize(v1).length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); } - - - CATCH_TEST_CASE("dynamic, length_squared1") { - cml::vectord v1 = { 1., 1., 1. }; + cml::vectord v1 = {1., 1., 1.}; double l2 = v1.length_squared(); CATCH_CHECK(l2 == 3.); } CATCH_TEST_CASE("dynamic, length1") { - cml::vectord v1 = { 1., 1., 1. }; + cml::vectord v1 = {1., 1., 1.}; double l = v1.length(); CATCH_CHECK(l == Approx(std::sqrt(3.)).epsilon(1e-4)); } CATCH_TEST_CASE("dynamic, normalize1") { - cml::vectord v1 = { 1., 1., 1. }; + cml::vectord v1 = {1., 1., 1.}; v1.normalize(); double l2 = v1.length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); @@ -279,14 +266,14 @@ CATCH_TEST_CASE("dynamic, normalize1") CATCH_TEST_CASE("dynamic, normalize2") { - cml::vectord v1 = { 1., 1., 1. }; + cml::vectord v1 = {1., 1., 1.}; double l2 = cml::normalize(v1).length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); } CATCH_TEST_CASE("dynamic, normalize3") { - const cml::vectord v1 = { 1., 1., 1. }; + const cml::vectord v1 = {1., 1., 1.}; auto xpr = v1.normalize(); double l2 = xpr.length_squared(); CATCH_REQUIRE(v1.size() == 3); @@ -295,7 +282,7 @@ CATCH_TEST_CASE("dynamic, normalize3") CATCH_TEST_CASE("dynamic, zero1") { - cml::vectord v1 = { 1., 1., 1. }; + cml::vectord v1 = {1., 1., 1.}; v1.zero(); CATCH_CHECK(v1[0] == 0.); CATCH_CHECK(v1[1] == 0.); @@ -305,8 +292,8 @@ CATCH_TEST_CASE("dynamic, zero1") CATCH_TEST_CASE("dynamic, minimize1") { - cml::vectord v1 = { 1., 1., 1. }; - cml::vectord v2 = { 2., 0., 3. }; + cml::vectord v1 = {1., 1., 1.}; + cml::vectord v2 = {2., 0., 3.}; v1.minimize(v2); CATCH_CHECK(v1[0] == 1.); CATCH_CHECK(v1[1] == 0.); @@ -315,8 +302,8 @@ CATCH_TEST_CASE("dynamic, minimize1") CATCH_TEST_CASE("dynamic, maximize1") { - cml::vectord v1 = { 1., 1., 1. }; - cml::vectord v2 = { 2., 0., 3. }; + cml::vectord v1 = {1., 1., 1.}; + cml::vectord v2 = {2., 0., 3.}; v1.maximize(v2); CATCH_CHECK(v1[0] == 2.); CATCH_CHECK(v1[1] == 1.); @@ -335,19 +322,16 @@ CATCH_TEST_CASE("dynamic, cardinal1") CATCH_TEST_CASE("dynamic, random1") { cml::vectord v1(4); - v1.random(0.,1.); + v1.random(0., 1.); for(const auto& e : v1) { CATCH_CHECK(e >= 0.); CATCH_CHECK(e < 1.); } } - - - CATCH_TEST_CASE("dynamic external, length_squared1") { - double av1[] = { 1., 1., 1. }; + double av1[] = {1., 1., 1.}; cml::externalnd v1(av1, 3); double l2 = v1.length_squared(); CATCH_CHECK(l2 == 3.); @@ -355,7 +339,7 @@ CATCH_TEST_CASE("dynamic external, length_squared1") CATCH_TEST_CASE("dynamic external, length1") { - double av1[] = { 1., 1., 1. }; + double av1[] = {1., 1., 1.}; cml::externalnd v1(av1, 3); double l = v1.length(); CATCH_CHECK(l == Approx(std::sqrt(3.)).epsilon(1e-4)); @@ -363,7 +347,7 @@ CATCH_TEST_CASE("dynamic external, length1") CATCH_TEST_CASE("dynamic external, normalize1") { - double av1[] = { 1., 1., 1. }; + double av1[] = {1., 1., 1.}; cml::externalnd v1(av1, 3); double l2 = v1.normalize().length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); @@ -371,7 +355,7 @@ CATCH_TEST_CASE("dynamic external, normalize1") CATCH_TEST_CASE("dynamic external, normalize2") { - double av1[] = { 1., 1., 1. }; + double av1[] = {1., 1., 1.}; cml::externalnd v1(av1, 3); double l2 = cml::normalize(v1).length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); @@ -379,7 +363,7 @@ CATCH_TEST_CASE("dynamic external, normalize2") CATCH_TEST_CASE("dynamic external, zero1") { - double av1[] = { 1., 1., 1. }; + double av1[] = {1., 1., 1.}; cml::externalnd v1(av1, 3); v1.zero(); CATCH_CHECK(v1[0] == 0.); @@ -390,8 +374,8 @@ CATCH_TEST_CASE("dynamic external, zero1") CATCH_TEST_CASE("dynamic external, minimize1") { - double av1[] = { 1., 1., 1. }; - double av2[] = { 2., 0., 3. }; + double av1[] = {1., 1., 1.}; + double av2[] = {2., 0., 3.}; cml::externalnd v1(av1, 3); cml::externalnd v2(av2, 3); v1.minimize(v2); @@ -402,8 +386,8 @@ CATCH_TEST_CASE("dynamic external, minimize1") CATCH_TEST_CASE("dynamic external, maximize1") { - double av1[] = { 1., 1., 1. }; - double av2[] = { 2., 0., 3. }; + double av1[] = {1., 1., 1.}; + double av2[] = {2., 0., 3.}; cml::externalnd v1(av1, 3); cml::externalnd v2(av2, 3); v1.maximize(v2); @@ -426,19 +410,16 @@ CATCH_TEST_CASE("dynamic external, random1") { double av1[4]; cml::externalnd v1(av1, 4); - v1.random(0.,1.); + v1.random(0., 1.); for(const auto& e : v1) { CATCH_CHECK(e >= 0.); CATCH_CHECK(e < 1.); } } - - - CATCH_TEST_CASE("dynamic const external, length_squared1") { - const double av1[] = { 1., 1., 1. }; + const double av1[] = {1., 1., 1.}; cml::externalncd v1(av1, 3); double l2 = v1.length_squared(); CATCH_CHECK(l2 == 3.); @@ -446,7 +427,7 @@ CATCH_TEST_CASE("dynamic const external, length_squared1") CATCH_TEST_CASE("dynamic const external, length1") { - const double av1[] = { 1., 1., 1. }; + const double av1[] = {1., 1., 1.}; cml::externalncd v1(av1, 3); double l = v1.length(); CATCH_CHECK(l == Approx(std::sqrt(3.)).epsilon(1e-4)); @@ -454,7 +435,7 @@ CATCH_TEST_CASE("dynamic const external, length1") CATCH_TEST_CASE("dynamic const external, normalize1") { - const double av1[] = { 1., 1., 1. }; + const double av1[] = {1., 1., 1.}; cml::externalncd v1(av1, 3); double l2 = v1.normalize().length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); @@ -462,20 +443,19 @@ CATCH_TEST_CASE("dynamic const external, normalize1") CATCH_TEST_CASE("dynamic const external, normalize2") { - const double av1[] = { 1., 1., 1. }; + const double av1[] = {1., 1., 1.}; cml::externalncd v1(av1, 3); double l2 = cml::normalize(v1).length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); } - #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS CATCH_TEST_CASE("rv from this1, normalize1") { - CATCH_CHECK((std::is_rvalue_reference::value)); + CATCH_CHECK((std::is_rvalue_reference< + decltype(cml::vector3d(1., 1., 1.).normalize())>::value)); auto xpr = cml::vector3d(1., 1., 1.).normalize(); double l2 = xpr.length_squared(); CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); @@ -483,8 +463,8 @@ CATCH_TEST_CASE("rv from this1, normalize1") CATCH_TEST_CASE("rv from this1, zero1") { - CATCH_CHECK((std::is_rvalue_reference::value)); + CATCH_CHECK((std::is_rvalue_reference< + decltype(cml::vector3d(1., 1., 1.).zero())>::value)); auto xpr = cml::vector3d(1., 1., 1.).zero(); CATCH_CHECK(xpr[0] == 0.); CATCH_CHECK(xpr[1] == 0.); @@ -494,10 +474,10 @@ CATCH_TEST_CASE("rv from this1, zero1") CATCH_TEST_CASE("rv from this1, minimize1") { - CATCH_CHECK((std::is_rvalue_reference::value)); - auto xpr = cml::vector3d(1., 1., 1.) - .minimize(cml::vector3d(2., 0., 3.)); + CATCH_CHECK((std::is_rvalue_reference< + decltype(cml::vector3d(1., 1., 1.).minimize(cml::vector3d(2., 0., 3.)))>:: + value)); + auto xpr = cml::vector3d(1., 1., 1.).minimize(cml::vector3d(2., 0., 3.)); CATCH_CHECK(xpr[0] == 1.); CATCH_CHECK(xpr[1] == 0.); CATCH_CHECK(xpr[2] == 1.); @@ -505,10 +485,10 @@ CATCH_TEST_CASE("rv from this1, minimize1") CATCH_TEST_CASE("rv from this1, maximize1") { - CATCH_CHECK((std::is_rvalue_reference::value)); - auto xpr = cml::vector3d(1., 1., 1.) - .maximize(cml::vector3d(2., 0., 3.)); + CATCH_CHECK((std::is_rvalue_reference< + decltype(cml::vector3d(1., 1., 1.).maximize(cml::vector3d(2., 0., 3.)))>:: + value)); + auto xpr = cml::vector3d(1., 1., 1.).maximize(cml::vector3d(2., 0., 3.)); CATCH_CHECK(xpr[0] == 2.); CATCH_CHECK(xpr[1] == 1.); CATCH_CHECK(xpr[2] == 3.); @@ -516,8 +496,8 @@ CATCH_TEST_CASE("rv from this1, maximize1") CATCH_TEST_CASE("rv from this1, cardinal1") { - CATCH_CHECK((std::is_rvalue_reference< - decltype(cml::vector3d().cardinal(0))>::value)); + CATCH_CHECK( + (std::is_rvalue_reference::value)); auto xpr = cml::vector3d().cardinal(0); CATCH_CHECK(xpr[0] == 1.); CATCH_CHECK(xpr[1] == 0.); @@ -551,10 +531,10 @@ CATCH_TEST_CASE("rv from this1, zero1") CATCH_TEST_CASE("rv from this1, minimize1") { - CATCH_CHECK((std::is_lvalue_reference::value)); - auto xpr = cml::vector3d(1., 1., 1.) - .minimize(cml::vector3d(2., 0., 3.)); + CATCH_CHECK((std::is_lvalue_reference< + decltype(cml::vector3d(1., 1., 1.).minimize(cml::vector3d(2., 0., 3.)))>:: + value)); + auto xpr = cml::vector3d(1., 1., 1.).minimize(cml::vector3d(2., 0., 3.)); CATCH_CHECK((std::is_reference::value) == false); CATCH_CHECK(xpr[0] == 1.); CATCH_CHECK(xpr[1] == 0.); @@ -563,10 +543,10 @@ CATCH_TEST_CASE("rv from this1, minimize1") CATCH_TEST_CASE("rv from this1, maximize1") { - CATCH_CHECK((std::is_lvalue_reference::value)); - auto xpr = cml::vector3d(1., 1., 1.) - .maximize(cml::vector3d(2., 0., 3.)); + CATCH_CHECK((std::is_lvalue_reference< + decltype(cml::vector3d(1., 1., 1.).maximize(cml::vector3d(2., 0., 3.)))>:: + value)); + auto xpr = cml::vector3d(1., 1., 1.).maximize(cml::vector3d(2., 0., 3.)); CATCH_CHECK((std::is_reference::value) == false); CATCH_CHECK(xpr[0] == 2.); CATCH_CHECK(xpr[1] == 1.); @@ -575,8 +555,8 @@ CATCH_TEST_CASE("rv from this1, maximize1") CATCH_TEST_CASE("rv from this1, cardinal1") { - CATCH_CHECK((std::is_lvalue_reference< - decltype(cml::vector3d().cardinal(0))>::value)); + CATCH_CHECK( + (std::is_lvalue_reference::value)); auto xpr = cml::vector3d().cardinal(0); CATCH_CHECK((std::is_reference::value) == false); CATCH_CHECK(xpr[0] == 1.); @@ -585,6 +565,3 @@ CATCH_TEST_CASE("rv from this1, cardinal1") } #endif - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/vector_hadamard_product1.cpp b/tests/vector/vector_hadamard_product1.cpp index 1de0d12..63e5a33 100644 --- a/tests/vector/vector_hadamard_product1.cpp +++ b/tests/vector/vector_hadamard_product1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -15,13 +13,12 @@ /* Testing headers: */ #include "catch_runner.h" - CATCH_TEST_CASE("fixed, hadamard1") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; cml::vector3d w; - w = cml::hadamard(v1,v2); + w = cml::hadamard(v1, v2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 4.); CATCH_CHECK(w[1] == 10.); @@ -30,9 +27,9 @@ CATCH_TEST_CASE("fixed, hadamard1") CATCH_TEST_CASE("fixed, hadamard2") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; - cml::vector3d w = cml::hadamard(v1,v2); + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; + cml::vector3d w = cml::hadamard(v1, v2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 4.); CATCH_CHECK(w[1] == 10.); @@ -41,11 +38,11 @@ CATCH_TEST_CASE("fixed, hadamard2") CATCH_TEST_CASE("fixed, mixed_op1") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; - cml::vector3d v3 = { 7., 8., 9. }; + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; + cml::vector3d v3 = {7., 8., 9.}; cml::vector3d w; - w = v2 - cml::hadamard(v1,v3); + w = v2 - cml::hadamard(v1, v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -3.); CATCH_CHECK(w[1] == -11.); @@ -54,28 +51,25 @@ CATCH_TEST_CASE("fixed, mixed_op1") CATCH_TEST_CASE("fixed, mixed_op2") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d v2 = { 4., 5., 6. }; - cml::vector3d v3 = { 7., 8., 9. }; - cml::vector3d w = v2 - cml::hadamard(v1,v3); + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d v2 = {4., 5., 6.}; + cml::vector3d v3 = {7., 8., 9.}; + cml::vector3d w = v2 - cml::hadamard(v1, v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -3.); CATCH_CHECK(w[1] == -11.); CATCH_CHECK(w[2] == -21.); } - - - CATCH_TEST_CASE("fixed external, hadamard1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; double aw[3]; cml::external3d v1(av1); cml::external3d v2(av2); cml::external3d w(aw); - w = cml::hadamard(v1,v2); + w = cml::hadamard(v1, v2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 4.); CATCH_CHECK(w[1] == 10.); @@ -84,33 +78,30 @@ CATCH_TEST_CASE("fixed external, hadamard1") CATCH_TEST_CASE("fixed external, mixed_op1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; - double av3[] = { 7., 8., 9. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; + double av3[] = {7., 8., 9.}; double aw[3]; cml::external3d v1(av1); cml::external3d v2(av2); cml::external3d v3(av3); cml::external3d w(aw); - w = v2 - cml::hadamard(v1,v3); + w = v2 - cml::hadamard(v1, v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -3.); CATCH_CHECK(w[1] == -11.); CATCH_CHECK(w[2] == -21.); } - - - CATCH_TEST_CASE("dynamic external, hadamard1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; double aw[3]; - cml::externalnd v1(av1,3); - cml::externalnd v2(av2,3); - cml::externalnd w(aw,3); - w = cml::hadamard(v1,v2); + cml::externalnd v1(av1, 3); + cml::externalnd v2(av2, 3); + cml::externalnd w(aw, 3); + w = cml::hadamard(v1, v2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 4.); CATCH_CHECK(w[1] == 10.); @@ -119,30 +110,27 @@ CATCH_TEST_CASE("dynamic external, hadamard1") CATCH_TEST_CASE("dynamic external, mixed_op1") { - double av1[] = { 1., 2., 3. }; - double av2[] = { 4., 5., 6. }; - double av3[] = { 7., 8., 9. }; + double av1[] = {1., 2., 3.}; + double av2[] = {4., 5., 6.}; + double av3[] = {7., 8., 9.}; double aw[3]; - cml::externalnd v1(av1,3); - cml::externalnd v2(av2,3); - cml::externalnd v3(av3,3); - cml::externalnd w(aw,3); - w = v2 - cml::hadamard(v1,v3); + cml::externalnd v1(av1, 3); + cml::externalnd v2(av2, 3); + cml::externalnd v3(av3, 3); + cml::externalnd w(aw, 3); + w = v2 - cml::hadamard(v1, v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -3.); CATCH_CHECK(w[1] == -11.); CATCH_CHECK(w[2] == -21.); } - - - CATCH_TEST_CASE("dynamic, hadamard1") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; cml::vectord w; - w = cml::hadamard(v1,v2); + w = cml::hadamard(v1, v2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 4.); CATCH_CHECK(w[1] == 10.); @@ -151,9 +139,9 @@ CATCH_TEST_CASE("dynamic, hadamard1") CATCH_TEST_CASE("dynamic, hadamard2") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; - cml::vectord w = cml::hadamard(v1,v2); + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; + cml::vectord w = cml::hadamard(v1, v2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 4.); CATCH_CHECK(w[1] == 10.); @@ -162,11 +150,11 @@ CATCH_TEST_CASE("dynamic, hadamard2") CATCH_TEST_CASE("dynamic, mixed_op1") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; - cml::vectord v3 = { 7., 8., 9. }; + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; + cml::vectord v3 = {7., 8., 9.}; cml::vectord w; - w = v2 - cml::hadamard(v1,v3); + w = v2 - cml::hadamard(v1, v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -3.); CATCH_CHECK(w[1] == -11.); @@ -175,15 +163,12 @@ CATCH_TEST_CASE("dynamic, mixed_op1") CATCH_TEST_CASE("dynamic, mixed_op2") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord v2 = { 4., 5., 6. }; - cml::vectord v3 = { 7., 8., 9. }; - cml::vectord w = v2 - cml::hadamard(v1,v3); + cml::vectord v1 = {1., 2., 3.}; + cml::vectord v2 = {4., 5., 6.}; + cml::vectord v3 = {7., 8., 9.}; + cml::vectord w = v2 - cml::hadamard(v1, v3); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == -3.); CATCH_CHECK(w[1] == -11.); CATCH_CHECK(w[2] == -21.); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/vector_scalar_node1.cpp b/tests/vector/vector_scalar_node1.cpp index 253d15b..2d086ac 100644 --- a/tests/vector/vector_scalar_node1.cpp +++ b/tests/vector/vector_scalar_node1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -18,96 +16,71 @@ CATCH_TEST_CASE("scalar_types1") { - typedef cml::vector3d vector_type; + using vector_type = cml::vector3d; { - auto xpr = vector_type()*int(); - typedef decltype(xpr) xpr_type; + auto xpr = vector_type() * int(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); - CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { - auto xpr = int()*vector_type(); - typedef decltype(xpr) xpr_type; - CATCH_CHECK( - std::is_rvalue_reference::value - ); + auto xpr = int() * vector_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { - auto xpr = vector_type()/int(); - typedef decltype(xpr) xpr_type; + auto xpr = vector_type() / int(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); - CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { double v = 0.; - auto xpr = vector_type()*v; - typedef decltype(xpr) xpr_type; - CATCH_CHECK( - std::is_rvalue_reference::value - ); + auto xpr = vector_type() * v; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_lvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { double v = 0.; - auto xpr = v*vector_type(); - typedef decltype(xpr) xpr_type; + auto xpr = v * vector_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); CATCH_CHECK( - std::is_rvalue_reference::value - ); - CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_rvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } { double v = 0.; - auto xpr = vector_type()/v; - typedef decltype(xpr) xpr_type; - CATCH_CHECK( - std::is_rvalue_reference::value - ); + auto xpr = vector_type() / v; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_rvalue_reference::value); CATCH_CHECK( - std::is_arithmetic::value - ); + std::is_lvalue_reference::value); + CATCH_CHECK(std::is_arithmetic::value); } } - CATCH_TEST_CASE("fixed, scalar_multiply1") { - cml::vector3d v1 = { 1., 2., 3. }; + cml::vector3d v1 = {1., 2., 3.}; cml::vector3d w; - w = 2.*v1; + w = 2. * v1; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 2.); CATCH_CHECK(w[1] == 4.); @@ -116,8 +89,8 @@ CATCH_TEST_CASE("fixed, scalar_multiply1") CATCH_TEST_CASE("fixed, scalar_multiply2") { - cml::vector3d v1 = { 1., 2., 3. }; - cml::vector3d w = 2.*v1; + cml::vector3d v1 = {1., 2., 3.}; + cml::vector3d w = 2. * v1; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 2.); CATCH_CHECK(w[1] == 4.); @@ -126,9 +99,9 @@ CATCH_TEST_CASE("fixed, scalar_multiply2") CATCH_TEST_CASE("fixed, scalar_divide1") { - cml::vector3d v1 = { 2., 4., 6. }; + cml::vector3d v1 = {2., 4., 6.}; cml::vector3d w; - w = v1/2.; + w = v1 / 2.; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); CATCH_CHECK(w[1] == 2.); @@ -137,8 +110,8 @@ CATCH_TEST_CASE("fixed, scalar_divide1") CATCH_TEST_CASE("fixed, scalar_divide2") { - cml::vector3d v1 = { 2., 4., 6. }; - cml::vector3d w = v1/2.; + cml::vector3d v1 = {2., 4., 6.}; + cml::vector3d w = v1 / 2.; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); CATCH_CHECK(w[1] == 2.); @@ -147,7 +120,7 @@ CATCH_TEST_CASE("fixed, scalar_divide2") CATCH_TEST_CASE("fixed, scalar_multiply_assign1") { - cml::vector3d v1 = { 1., 2., 3. }; + cml::vector3d v1 = {1., 2., 3.}; v1 *= 2; CATCH_REQUIRE(v1.size() == 3); CATCH_CHECK(v1[0] == 2.); @@ -158,7 +131,7 @@ CATCH_TEST_CASE("fixed, scalar_multiply_assign1") CATCH_TEST_CASE("fixed, scalar_multiply_assign2") { cml::vector3d w; - w = (cml::vector3d(1.,2.,3.) *= 2); + w = (cml::vector3d(1., 2., 3.) *= 2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 2.); CATCH_CHECK(w[1] == 4.); @@ -167,7 +140,7 @@ CATCH_TEST_CASE("fixed, scalar_multiply_assign2") CATCH_TEST_CASE("fixed, scalar_divide_assign1") { - cml::vector3d v1 = { 2., 4., 6. }; + cml::vector3d v1 = {2., 4., 6.}; v1 /= 2; CATCH_REQUIRE(v1.size() == 3); CATCH_CHECK(v1[0] == 1.); @@ -178,23 +151,20 @@ CATCH_TEST_CASE("fixed, scalar_divide_assign1") CATCH_TEST_CASE("fixed, scalar_divide_assign2") { cml::vector3d w; - w = (cml::vector3d(2.,4.,6.) /= 2); + w = (cml::vector3d(2., 4., 6.) /= 2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); CATCH_CHECK(w[1] == 2.); CATCH_CHECK(w[2] == 3.); } - - - CATCH_TEST_CASE("fixed external, scalar_multiply1") { - double av1[] = { 1., 2., 3. }; + double av1[] = {1., 2., 3.}; double aw[3]; cml::external3d v1(av1); cml::external3d w(aw); - w = 2.*v1; + w = 2. * v1; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 2.); CATCH_CHECK(w[1] == 4.); @@ -203,11 +173,11 @@ CATCH_TEST_CASE("fixed external, scalar_multiply1") CATCH_TEST_CASE("fixed external, scalar_divide1") { - double av1[] = { 2., 4., 6. }; + double av1[] = {2., 4., 6.}; double aw[3]; cml::external3d v1(av1); cml::external3d w(aw); - w = v1/2.; + w = v1 / 2.; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); CATCH_CHECK(w[1] == 2.); @@ -216,7 +186,7 @@ CATCH_TEST_CASE("fixed external, scalar_divide1") CATCH_TEST_CASE("fixed external, scalar_multiply_assign1") { - double av1[] = { 1., 2., 3. }; + double av1[] = {1., 2., 3.}; cml::external3d v1(av1); v1 *= 2; CATCH_REQUIRE(v1.size() == 3); @@ -228,7 +198,7 @@ CATCH_TEST_CASE("fixed external, scalar_multiply_assign1") CATCH_TEST_CASE("fixed external, scalar_multiply_assign2") { #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - double av1[] = { 1., 2., 3. }; + double av1[] = {1., 2., 3.}; cml::external3d w; w = (cml::external3d(av1) *= 2); CATCH_REQUIRE(w.size() == 3); @@ -243,7 +213,7 @@ CATCH_TEST_CASE("fixed external, scalar_multiply_assign2") CATCH_TEST_CASE("fixed external, scalar_divide_assign1") { - double av1[] = { 2., 4., 6. }; + double av1[] = {2., 4., 6.}; cml::external3d v1(av1); v1 /= 2; CATCH_REQUIRE(v1.size() == 3); @@ -255,7 +225,7 @@ CATCH_TEST_CASE("fixed external, scalar_divide_assign1") CATCH_TEST_CASE("fixed external, scalar_divide_assign2") { #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - double av1[] = { 2., 4., 6. }; + double av1[] = {2., 4., 6.}; cml::external3d w; w = (cml::external3d(av1) /= 2); CATCH_REQUIRE(w.size() == 3); @@ -268,16 +238,13 @@ CATCH_TEST_CASE("fixed external, scalar_divide_assign2") #endif } - - - CATCH_TEST_CASE("dynamic external, scalar_multiply1") { - double av1[] = { 1., 2., 3. }; + double av1[] = {1., 2., 3.}; double aw[3]; - cml::externalnd v1(av1,3); - cml::externalnd w(aw,3); - w = 2.*v1; + cml::externalnd v1(av1, 3); + cml::externalnd w(aw, 3); + w = 2. * v1; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 2.); CATCH_CHECK(w[1] == 4.); @@ -286,11 +253,11 @@ CATCH_TEST_CASE("dynamic external, scalar_multiply1") CATCH_TEST_CASE("dynamic external, scalar_divide1") { - double av1[] = { 2., 4., 6. }; + double av1[] = {2., 4., 6.}; double aw[3]; - cml::externalnd v1(av1,3); - cml::externalnd w(aw,3); - w = v1/2.; + cml::externalnd v1(av1, 3); + cml::externalnd w(aw, 3); + w = v1 / 2.; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); CATCH_CHECK(w[1] == 2.); @@ -299,8 +266,8 @@ CATCH_TEST_CASE("dynamic external, scalar_divide1") CATCH_TEST_CASE("dynamic external, scalar_multiply_assign1") { - double av1[] = { 1., 2., 3. }; - cml::externalnd v1(av1,3); + double av1[] = {1., 2., 3.}; + cml::externalnd v1(av1, 3); v1 *= 2; CATCH_REQUIRE(v1.size() == 3); CATCH_CHECK(v1[0] == 2.); @@ -311,9 +278,9 @@ CATCH_TEST_CASE("dynamic external, scalar_multiply_assign1") CATCH_TEST_CASE("dynamic external, scalar_multiply_assign2") { #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - double av1[] = { 1., 2., 3. }; + double av1[] = {1., 2., 3.}; cml::externalnd w; - w = (cml::externalnd(av1,3) *= 2); + w = (cml::externalnd(av1, 3) *= 2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w.data() == &av1[0]); CATCH_CHECK(w[0] == 2.); @@ -326,8 +293,8 @@ CATCH_TEST_CASE("dynamic external, scalar_multiply_assign2") CATCH_TEST_CASE("dynamic external, scalar_divide_assign1") { - double av1[] = { 2., 4., 6. }; - cml::externalnd v1(av1,3); + double av1[] = {2., 4., 6.}; + cml::externalnd v1(av1, 3); v1 /= 2; CATCH_REQUIRE(v1.size() == 3); CATCH_CHECK(v1[0] == 1.); @@ -338,9 +305,9 @@ CATCH_TEST_CASE("dynamic external, scalar_divide_assign1") CATCH_TEST_CASE("dynamic external, scalar_divide_assign2") { #ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - double av1[] = { 2., 4., 6. }; + double av1[] = {2., 4., 6.}; cml::externalnd w; - w = (cml::externalnd(av1,3) /= 2); + w = (cml::externalnd(av1, 3) /= 2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w.data() == &av1[0]); CATCH_CHECK(w[0] == 1.); @@ -351,12 +318,11 @@ CATCH_TEST_CASE("dynamic external, scalar_divide_assign2") #endif } - CATCH_TEST_CASE("dynamic, scalar_multiply1") { - cml::vectord v1 = { 1., 2., 3. }; + cml::vectord v1 = {1., 2., 3.}; cml::vectord w; - w = 2.*v1; + w = 2. * v1; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 2.); CATCH_CHECK(w[1] == 4.); @@ -365,8 +331,8 @@ CATCH_TEST_CASE("dynamic, scalar_multiply1") CATCH_TEST_CASE("dynamic, scalar_multiply2") { - cml::vectord v1 = { 1., 2., 3. }; - cml::vectord w = 2.*v1; + cml::vectord v1 = {1., 2., 3.}; + cml::vectord w = 2. * v1; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 2.); CATCH_CHECK(w[1] == 4.); @@ -375,9 +341,9 @@ CATCH_TEST_CASE("dynamic, scalar_multiply2") CATCH_TEST_CASE("dynamic, scalar_divide1") { - cml::vectord v1 = { 2., 4., 6. }; + cml::vectord v1 = {2., 4., 6.}; cml::vectord w; - w = v1/2.; + w = v1 / 2.; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); CATCH_CHECK(w[1] == 2.); @@ -386,8 +352,8 @@ CATCH_TEST_CASE("dynamic, scalar_divide1") CATCH_TEST_CASE("dynamic, scalar_divide2") { - cml::vectord v1 = { 2., 4., 6. }; - cml::vectord w = v1/2.; + cml::vectord v1 = {2., 4., 6.}; + cml::vectord w = v1 / 2.; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); CATCH_CHECK(w[1] == 2.); @@ -396,7 +362,7 @@ CATCH_TEST_CASE("dynamic, scalar_divide2") CATCH_TEST_CASE("dynamic, scalar_multiply_assign1") { - cml::vectord v1 = { 1., 2., 3. }; + cml::vectord v1 = {1., 2., 3.}; v1 *= 2; CATCH_REQUIRE(v1.size() == 3); CATCH_CHECK(v1[0] == 2.); @@ -407,7 +373,7 @@ CATCH_TEST_CASE("dynamic, scalar_multiply_assign1") CATCH_TEST_CASE("dynamic, scalar_multiply_assign2") { cml::vectord w; - w = (cml::vector>(1.,2.,3.) *= 2); + w = (cml::vector>(1., 2., 3.) *= 2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 2.); CATCH_CHECK(w[1] == 4.); @@ -416,7 +382,7 @@ CATCH_TEST_CASE("dynamic, scalar_multiply_assign2") CATCH_TEST_CASE("dynamic, scalar_divide_assign1") { - cml::vectord v1 = { 2., 4., 6. }; + cml::vectord v1 = {2., 4., 6.}; v1 /= 2; CATCH_REQUIRE(v1.size() == 3); CATCH_CHECK(v1[0] == 1.); @@ -427,12 +393,9 @@ CATCH_TEST_CASE("dynamic, scalar_divide_assign1") CATCH_TEST_CASE("dynamic, scalar_divide_assign2") { cml::vectord w; - w = (cml::vectord(2.,4.,6.) /= 2); + w = (cml::vectord(2., 4., 6.) /= 2); CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); CATCH_CHECK(w[1] == 2.); CATCH_CHECK(w[2] == 3.); } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/vector_temporary1.cpp b/tests/vector/vector_temporary1.cpp index ea3a89d..cc3bc61 100644 --- a/tests/vector/vector_temporary1.cpp +++ b/tests/vector/vector_temporary1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ #include @@ -16,8 +14,5 @@ */ CATCH_TEST_CASE("const_temporary1") { - typedef cml::temporary_of_t const_type; + using const_type = cml::temporary_of_t; } - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 diff --git a/tests/vector/vector_unary_node1.cpp b/tests/vector/vector_unary_node1.cpp index 396f6ce..6c1f058 100644 --- a/tests/vector/vector_unary_node1.cpp +++ b/tests/vector/vector_unary_node1.cpp @@ -1,8 +1,6 @@ -/* -*- C++ -*- ------------------------------------------------------------ +/*------------------------------------------------------------------------- @@COPYRIGHT@@ *-----------------------------------------------------------------------*/ -/** @file - */ // Make sure the main header compiles cleanly: #include @@ -18,122 +16,113 @@ CATCH_TEST_CASE("unary_types1") { - typedef cml::vector3d vector_type; + using vector_type = cml::vector3d; { CATCH_CHECK(cml::is_statically_polymorphic::value); } { - auto xpr = - vector_type(); - typedef decltype(xpr) xpr_type; + auto xpr = -vector_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { - auto xpr = + vector_type(); - typedef decltype(xpr) xpr_type; + auto xpr = +vector_type(); + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_rvalue_reference::value - ); + std::is_rvalue_reference::value); } { vector_type M; - auto xpr = - M; - typedef decltype(xpr) xpr_type; + auto xpr = -M; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } { vector_type M; - auto xpr = + M; - typedef decltype(xpr) xpr_type; + auto xpr = +M; + using xpr_type = decltype(xpr); CATCH_CHECK( - std::is_lvalue_reference::value - ); + std::is_lvalue_reference::value); } } - - CATCH_TEST_CASE("fixed, unary_minus1") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; cml::vector3d w; - w = - v; + w = -v; CATCH_REQUIRE(w.size() == 3); - CATCH_CHECK(w[0] == - 1.); + CATCH_CHECK(w[0] == -1.); } CATCH_TEST_CASE("fixed, unary_minus2") { - cml::vector3d v = { 1., 2., 3. }; - cml::vector3d w = - v; + cml::vector3d v = {1., 2., 3.}; + cml::vector3d w = -v; CATCH_REQUIRE(w.size() == 3); - CATCH_CHECK(w[0] == - 1.); + CATCH_CHECK(w[0] == -1.); } CATCH_TEST_CASE("fixed, unary_plus1") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; cml::vector3d w; - w = + v; + w = +v; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); } CATCH_TEST_CASE("fixed, unary_plus2") { - cml::vector3d v = { 1., 2., 3. }; - cml::vector3d w = + v; + cml::vector3d v = {1., 2., 3.}; + cml::vector3d w = +v; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); } CATCH_TEST_CASE("fixed, double_negate1") { - cml::vector3d v = { 1., 2., 3. }; + cml::vector3d v = {1., 2., 3.}; CATCH_REQUIRE(v.size() == 3); cml::vector3d w; CATCH_REQUIRE(w.size() == 3); - auto xpr = - (-v); + auto xpr = -(-v); w = xpr; CATCH_CHECK(w[0] == 1.); } - - - CATCH_TEST_CASE("fixed external, unary_minus1") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::external3d v(av); double aw[3]; cml::external3d w(aw); - w = - v; + w = -v; CATCH_REQUIRE(w.size() == 3); - CATCH_CHECK(w[0] == - 1.); + CATCH_CHECK(w[0] == -1.); } CATCH_TEST_CASE("fixed external, unary_plus1") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::external3d v(av); double aw[3]; cml::external3d w(aw); - w = + v; + w = +v; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); } CATCH_TEST_CASE("fixed external, double_negate1") { - double av[3] = { 1., 2., 3. }; + double av[3] = {1., 2., 3.}; cml::external3d v(av); CATCH_REQUIRE(v.size() == 3); @@ -141,146 +130,133 @@ CATCH_TEST_CASE("fixed external, double_negate1") cml::external3d w(aw); CATCH_REQUIRE(w.size() == 3); - auto xpr = - (-v); + auto xpr = -(-v); w = xpr; CATCH_CHECK(w[0] == 1.); } - - - CATCH_TEST_CASE("dynamic external, unary_minus1") { - double av[3] = { 1., 2., 3. }; - cml::externalnd v(av,3); + double av[3] = {1., 2., 3.}; + cml::externalnd v(av, 3); double aw[3]; - cml::externalnd w(aw,3); + cml::externalnd w(aw, 3); - w = - v; + w = -v; CATCH_REQUIRE(w.size() == 3); - CATCH_CHECK(w[0] == - 1.); + CATCH_CHECK(w[0] == -1.); } CATCH_TEST_CASE("dynamic external, unary_plus1") { - double av[3] = { 1., 2., 3. }; - cml::externalnd v(av,3); + double av[3] = {1., 2., 3.}; + cml::externalnd v(av, 3); double aw[3]; - cml::externalnd w(aw,3); + cml::externalnd w(aw, 3); - w = + v; + w = +v; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); } CATCH_TEST_CASE("dynamic external, double_negate1") { - double av[3] = { 1., 2., 3. }; - cml::externalnd v(av,3); + double av[3] = {1., 2., 3.}; + cml::externalnd v(av, 3); CATCH_REQUIRE(v.size() == 3); double aw[3]; - cml::externalnd w(aw,3); + cml::externalnd w(aw, 3); CATCH_REQUIRE(w.size() == 3); - auto xpr = - (-v); + auto xpr = -(-v); w = xpr; CATCH_CHECK(w[0] == 1.); } - - - CATCH_TEST_CASE("dynamic, unary_minus1") { - cml::vectord v = { 1., 2., 3. }; + cml::vectord v = {1., 2., 3.}; cml::vectord w; - w = - v; + w = -v; CATCH_REQUIRE(w.size() == 3); - CATCH_CHECK(w[0] == - 1.); + CATCH_CHECK(w[0] == -1.); } CATCH_TEST_CASE("dynamic, unary_minus2") { - cml::vectord v = { 1., 2., 3. }; - cml::vectord w = - v; + cml::vectord v = {1., 2., 3.}; + cml::vectord w = -v; CATCH_REQUIRE(w.size() == 3); - CATCH_CHECK(w[0] == - 1.); + CATCH_CHECK(w[0] == -1.); } CATCH_TEST_CASE("dynamic, unary_plus1") { - cml::vectord v = { 1., 2., 3. }; + cml::vectord v = {1., 2., 3.}; cml::vectord w; - w = + v; + w = +v; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); } CATCH_TEST_CASE("dynamic, unary_plus2") { - cml::vectord v = { 1., 2., 3. }; - cml::vectord w = + v; + cml::vectord v = {1., 2., 3.}; + cml::vectord w = +v; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); } CATCH_TEST_CASE("dynamic, double_negate1") { - cml::vectord v = { 1., 2., 3. }; + cml::vectord v = {1., 2., 3.}; cml::vectord w; CATCH_REQUIRE(v.size() == 3); - auto xpr = - (-v); + auto xpr = -(-v); w = xpr; CATCH_CHECK(w[0] == 1.); } - - - CATCH_TEST_CASE("dynamic const external, unary_minus1") { - const double av[3] = { 1., 2., 3. }; - cml::externalncd v(av,3); + const double av[3] = {1., 2., 3.}; + cml::externalncd v(av, 3); double aw[3]; - cml::externalnd w(aw,3); + cml::externalnd w(aw, 3); - w = - v; + w = -v; CATCH_REQUIRE(w.size() == 3); - CATCH_CHECK(w[0] == - 1.); + CATCH_CHECK(w[0] == -1.); } CATCH_TEST_CASE("dynamic const external, unary_plus1") { - const double av[3] = { 1., 2., 3. }; - cml::externalncd v(av,3); + const double av[3] = {1., 2., 3.}; + cml::externalncd v(av, 3); double aw[3]; - cml::externalnd w(aw,3); + cml::externalnd w(aw, 3); - w = + v; + w = +v; CATCH_REQUIRE(w.size() == 3); CATCH_CHECK(w[0] == 1.); } CATCH_TEST_CASE("dynamic const external, double_negate1") { - const double av[3] = { 1., 2., 3. }; - cml::externalncd v(av,3); + const double av[3] = {1., 2., 3.}; + cml::externalncd v(av, 3); CATCH_REQUIRE(v.size() == 3); double aw[3]; - cml::externalnd w(aw,3); + cml::externalnd w(aw, 3); CATCH_REQUIRE(w.size() == 3); - auto xpr = - (-v); + auto xpr = -(-v); w = xpr; CATCH_CHECK(w[0] == 1.); } - - -// ------------------------------------------------------------------------- -// vim:ft=cpp:sw=2 From f01a0767c6f98365d47cf8547dd22262500ee0a3 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 18:28:32 -0500 Subject: [PATCH 08/38] Update to Catch2 v3.7.1 via FetchContent --- CMakeLists.txt | 12 +++++++----- tests/CMakeLists.txt | 1 - tests/main/CMakeLists.txt | 20 ++++++++++++++++---- tests/main/catch_runner.h | 12 +++++------- 4 files changed, 28 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71beba4..cd464bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,11 +40,13 @@ if(NOT DEFINED BUILD_STATIC_RUNTIME) endif() # Determine the default runtime library for MSVC-like compilers: -if(NOT DEFINED MSVC_RUNTIME_LIBRARY) - if(BUILD_STATIC_RUNTIME) - set(MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") - else() - set(MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") +if(MSVC) + if(NOT DEFINED MSVC_RUNTIME_LIBRARY) + if(BUILD_STATIC_RUNTIME) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + else() + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>DLL") + endif() endif() endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8c9a4db..823599e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -60,7 +60,6 @@ function(cml_add_test _name) set_target_properties(${ExecName} PROPERTIES FOLDER "cml-tests/${CML_TEST_GROUP}" - MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY} ) get_target_property(_path ${_name} SOURCE_DIR) diff --git a/tests/main/CMakeLists.txt b/tests/main/CMakeLists.txt index cf23242..cb4565f 100644 --- a/tests/main/CMakeLists.txt +++ b/tests/main/CMakeLists.txt @@ -2,15 +2,27 @@ # @@COPYRIGHT@@ # -------------------------------------------------------------------------- -add_library(cml_test_main STATIC catch_main.cpp catch.hpp catch_runner.h) +# Pull Catch2 at v3.7.1 +include(FetchContent) + +FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.7.1 +) + +FetchContent_MakeAvailable(Catch2) + +add_library(cml_test_main INTERFACE catch_runner.h) target_include_directories(cml_test_main - PUBLIC ${CMAKE_CURRENT_LIST_DIR} - PRIVATE ${CML_ROOT} + INTERFACE ${CMAKE_CURRENT_LIST_DIR} ${CML_ROOT} +) +target_link_libraries(cml_test_main + INTERFACE Catch2::Catch2WithMain ) set_target_properties(cml_test_main PROPERTIES FOLDER "cml-tests/main" - MSVC_RUNTIME_LIBRARY ${MSVC_RUNTIME_LIBRARY} ) get_target_property(_path cml_test_main SOURCE_DIR) diff --git a/tests/main/catch_runner.h b/tests/main/catch_runner.h index 21580b5..f263dd0 100644 --- a/tests/main/catch_runner.h +++ b/tests/main/catch_runner.h @@ -4,10 +4,8 @@ #pragma once -#ifndef cml_tests_main_catch_runner_h -# define cml_tests_main_catch_runner_h - -# define CATCH_CONFIG_PREFIX_ALL -# include "catch.hpp" - -#endif +#define CATCH_CONFIG_PREFIX_ALL +#define CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS +#include +#include // Note: Approx() is deprecated in Catch2 v3 +using Catch::Approx; From 0ff345ff73d793f136d7b467c64a393dfe77c72e Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 18:30:07 -0500 Subject: [PATCH 09/38] Fix warning in inverse_pivot --- cml/matrix/detail/inverse.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cml/matrix/detail/inverse.h b/cml/matrix/detail/inverse.h index 315dec5..78a651d 100644 --- a/cml/matrix/detail/inverse.h +++ b/cml/matrix/detail/inverse.h @@ -196,8 +196,8 @@ inverse_pivot(writable_matrix& M, RowIndexArray& row_index, pivoted[col] = true; pivot = M(col, col); M(col, col) = value_type(1); - value_type k = value_type(1) / pivot; - for(int j = 0; j < N; ++j) M(col, j) *= k; + value_type s = value_type(1) / pivot; + for(int j = 0; j < N; ++j) M(col, j) *= s; /* Process other rows */ for(int j = 0; j < N; ++j) { From eeda67e06ec31b7da71decfb9a3e9c4f60106078 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 18:32:29 -0500 Subject: [PATCH 10/38] Remove unneeded files --- .appveyor.yml | 72 -------------------------------------------------- .gitattributes | 26 ------------------ 2 files changed, 98 deletions(-) delete mode 100644 .appveyor.yml delete mode 100644 .gitattributes diff --git a/.appveyor.yml b/.appveyor.yml deleted file mode 100644 index e96288a..0000000 --- a/.appveyor.yml +++ /dev/null @@ -1,72 +0,0 @@ -version: build-{branch}-#{build} - -branches: - only: - - master - - develop - -environment: - matrix: - - # Visual Studio builds: - - appveyor_build_worker_image: Visual Studio 2017 - CMAKE_GENERATOR: Visual Studio 15 2017 - CMAKE_ARCH: -Ax64 - CMAKE_TOOLSET: -Thost=x64 - CMAKE_CONCURRENT: /m - # WARNING: do not add a space after -T here. - - - appveyor_build_worker_image: Visual Studio 2019 - CMAKE_GENERATOR: Visual Studio 16 2019 - CMAKE_ARCH: -Ax64 - CMAKE_TOOLSET: -Thost=x64 - CMAKE_CONCURRENT: /m - # WARNING: do not add a space after -A or -T here. - - - # Clang builds: - - appveyor_build_worker_image: Ubuntu - CMAKE_GENERATOR: Ninja - CC: clang-11 - CXX: clang++-11 - CMAKE_BUILD_TYPE: -DCMAKE_BUILD_TYPE=Release - - - appveyor_build_worker_image: Ubuntu - CMAKE_GENERATOR: Ninja - CC: clang-10 - CXX: clang++-10 - CMAKE_BUILD_TYPE: -DCMAKE_BUILD_TYPE=Release - - - # GCC builds: - - appveyor_build_worker_image: Ubuntu - CMAKE_GENERATOR: Ninja - CC: gcc-9 - CXX: g++-9 - CMAKE_BUILD_TYPE: -DCMAKE_BUILD_TYPE=Release - - - appveyor_build_worker_image: Ubuntu - CMAKE_GENERATOR: Ninja - CC: gcc-8 - CXX: g++-8 - CMAKE_BUILD_TYPE: -DCMAKE_BUILD_TYPE=Release - -build_script: - - pwsh: | - New-Item -Path .\build -ItemType Directory - Set-Location -Path .\build - cmake .. -DCML_BUILD_TESTING=ON "-G${env:CMAKE_GENERATOR}" ${env:CMAKE_ARCH} ${env:CMAKE_TOOLSET} ${env:CMAKE_BUILD_TYPE} - cmake --build . --config Release -- ${env:CMAKE_CONCURRENT} - -test_script: - - pwsh: | - if((Split-Path -Leaf -Path ${pwd}) -ne 'build') { - Set-Location -Path .\build - } - ctest -V -C Release - -# init: -# - ps: iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) - -# on_finish: -# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1')) diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 879d48b..0000000 --- a/.gitattributes +++ /dev/null @@ -1,26 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# Custom for Visual Studio -*.cs diff=csharp - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain - -# Other: -*.h diff=cpp -*.tpp diff=cpp -*.hpp diff=cpp -*.ipp diff=cpp -*.cpp diff=cpp -*.cmake diff=astextplain -*.txt diff=astextplain \ No newline at end of file From 7637c88afe225885968854aafc2d66a3cd041390 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 20:30:59 -0500 Subject: [PATCH 11/38] Only pull Catch2 if it is not found locally --- tests/main/CMakeLists.txt | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/tests/main/CMakeLists.txt b/tests/main/CMakeLists.txt index cb4565f..91db1a7 100644 --- a/tests/main/CMakeLists.txt +++ b/tests/main/CMakeLists.txt @@ -2,16 +2,21 @@ # @@COPYRIGHT@@ # -------------------------------------------------------------------------- -# Pull Catch2 at v3.7.1 -include(FetchContent) +# Allow finding Catch2 locally first: +find_package(Catch2 3.7.1 CONFIG QUIET) -FetchContent_Declare( - Catch2 - GIT_REPOSITORY https://github.com/catchorg/Catch2.git - GIT_TAG v3.7.1 -) +# If not found or already pulled, pull Catch2 at v3.7.1 +if(NOT Catch2_FOUND) + include(FetchContent) + + FetchContent_Declare( + Catch2 + GIT_REPOSITORY https://github.com/catchorg/Catch2.git + GIT_TAG v3.7.1 + ) -FetchContent_MakeAvailable(Catch2) + FetchContent_MakeAvailable(Catch2) +endif() add_library(cml_test_main INTERFACE catch_runner.h) target_include_directories(cml_test_main From d1a204c7f8f0d908ad40ac0d63e59f97fbf20948 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 20:31:30 -0500 Subject: [PATCH 12/38] Update README.md to reflect current instructions --- README.md | 50 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 55fa949..6ae0bc9 100644 --- a/README.md +++ b/README.md @@ -7,10 +7,6 @@ For CML version 1, please see https://github.com/demianmnave/CML1. The Configurable Math Library (CML) is released under the [Boost Software License, Version 1.0.](http://www.boost.org/LICENSE_1_0.txt). -## Status - -[![Build status](https://ci.appveyor.com/api/projects/status/r3l3xnhxe8djjimg/branch/master?svg=true)](https://ci.appveyor.com/project/demianmnave/cml/branch/master) - ## Using the CML As it is header-only, it is simple enough to copy the `cml` header directory into your project and setup your build to reference it. Users of CMake 3.15+ can also leverage [`cmake --install ...`](make.org/cmake/help/v3.15/manual/cmake.1.html#install-a-project) and [`find_package(CML CONFIG)`](https://cmake.org/cmake/help/v3.15/command/find_package.html) to integrate CML into a CMake project. @@ -23,24 +19,42 @@ At the moment, the CML requires the following compiler features (listed as CMake - [cxx_constexpr](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf) - [cxx_defaulted_functions](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm) -## Running Tests - +## Building and Running Tests +### With plain CMake To run the test suite from a command prompt using a Makefile-like generator, start in your build directory and execute: - -`cmake . -G -DCML_BUILD_TESTING=On -DCML_BUILD_TYPE=RELEASE` +```bash +cmake -S \ -G{generator name} -DBUILD_TESTING=On -DCMAKE_BUILD_TYPE=Release +``` Then, to build the tests (again from your build directory): - -`cmake --build . --config Release` +```bash +cmake --build . --config Release +``` You can run the full test suite from your build directory by executing: - -`ctest -C Release` +```bash +ctest -C Release +``` If you have multiple CPUs (e.g. 4 in this case), you can speed things up a bit using, for example: - -`cmake --build . --config Release -- -j4` - -`ctest -C Release -j4` - -See .travis.yml for supported XCode, Clang, and GCC versions, and .appveyor.yml for supported Visual Studio versions. +```bash +cmake --build . --config Release -- -j4 +ctest -C Release -j4 +``` +### With CMake presets +See _CMakePresets.json_ for the default base presets, as well as the predefined configure and build presets. Note that all of the predefined configure presets generate a build system under _\/.build_/\. + +To see the available configure presets, execute: +```bash +cmake --list-presets +``` + +To see the available build presets, execute: +```bash +cmake --build --list-presets +``` + +To use one of the predefined configure presets, for example _cml-dev-msvc17-clangcl-mt-s_ to use the Visual Studio 2022 IDE with ClangCL: +```bash +cmake --preset=cml-dev-msvc17-clangcl-mt-s +``` \ No newline at end of file From 6bafd43b0f91839903214bee279de94ada2b7980 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 21:19:14 -0500 Subject: [PATCH 13/38] Remove non-unnecessary macros and gated code --- CML.cmake | 1 - cml/common/compiler.h | 21 -- cml/common/mpl/rebind.h | 18 -- cml/common/type_util.h | 1 - cml/matrix/basis_node.h | 21 +- cml/matrix/basis_node.tpp | 2 - cml/matrix/binary_node.h | 37 +-- cml/matrix/binary_node.tpp | 2 - cml/matrix/col_node.h | 21 +- cml/matrix/col_node.tpp | 2 - cml/matrix/dynamic_allocated.h | 81 ++--- cml/matrix/dynamic_allocated.tpp | 17 +- cml/matrix/dynamic_external.h | 88 ++---- cml/matrix/dynamic_external.tpp | 9 +- cml/matrix/fixed_compiled.h | 48 +-- cml/matrix/fixed_compiled.tpp | 4 +- cml/matrix/fixed_external.h | 60 +--- cml/matrix/fixed_external.tpp | 7 +- cml/matrix/readable_matrix.h | 34 +- cml/matrix/row_node.h | 21 +- cml/matrix/row_node.tpp | 2 - cml/matrix/scalar_node.h | 21 +- cml/matrix/scalar_node.tpp | 5 +- cml/matrix/transpose_node.h | 17 +- cml/matrix/transpose_node.tpp | 5 +- cml/matrix/unary_node.h | 21 +- cml/matrix/unary_node.tpp | 5 +- cml/matrix/writable_matrix.h | 402 +++++++++++------------- cml/matrix/writable_matrix.tpp | 72 ++--- cml/quaternion/binary_node.h | 37 +-- cml/quaternion/binary_node.tpp | 2 - cml/quaternion/conjugate_node.h | 17 +- cml/quaternion/conjugate_node.tpp | 2 - cml/quaternion/fixed_compiled.h | 86 ++--- cml/quaternion/fixed_compiled.tpp | 4 +- cml/quaternion/imaginary_node.h | 21 +- cml/quaternion/imaginary_node.tpp | 5 +- cml/quaternion/inverse_node.h | 21 +- cml/quaternion/inverse_node.tpp | 5 +- cml/quaternion/readable_quaternion.h | 25 -- cml/quaternion/readable_quaternion.tpp | 41 +-- cml/quaternion/scalar_node.h | 21 +- cml/quaternion/scalar_node.tpp | 2 - cml/quaternion/unary_node.h | 21 +- cml/quaternion/unary_node.tpp | 2 - cml/quaternion/writable_quaternion.h | 275 +++++++--------- cml/quaternion/writable_quaternion.tpp | 110 ++----- cml/scalar/traits.h | 1 - cml/vector/binary_node.h | 37 +-- cml/vector/binary_node.tpp | 2 - cml/vector/cross_node.h | 37 +-- cml/vector/dynamic_allocated.h | 88 ++---- cml/vector/dynamic_allocated.tpp | 4 +- cml/vector/dynamic_const_external.tpp | 2 - cml/vector/dynamic_external.h | 54 +--- cml/vector/dynamic_external.tpp | 7 +- cml/vector/fixed_compiled.h | 54 +--- cml/vector/fixed_compiled.tpp | 4 +- cml/vector/fixed_const_external.tpp | 2 - cml/vector/fixed_external.h | 44 +-- cml/vector/fixed_external.tpp | 4 +- cml/vector/outer_product_node.h | 37 +-- cml/vector/outer_product_node.tpp | 2 - cml/vector/readable_vector.h | 17 - cml/vector/readable_vector.tpp | 23 -- cml/vector/scalar_node.h | 21 +- cml/vector/scalar_node.tpp | 2 - cml/vector/subvector_node.h | 17 +- cml/vector/subvector_node.tpp | 2 - cml/vector/unary_node.h | 17 +- cml/vector/unary_node.tpp | 2 - cml/vector/writable_vector.h | 347 +++++++++----------- cml/vector/writable_vector.tpp | 69 +--- cml/version.h | 4 +- tests/common/rv_from_this1.cpp | 11 +- tests/matrix/matrix_scalar_node1.cpp | 16 - tests/vector/fixed_compiled_vector1.cpp | 2 - tests/vector/fixed_external_vector1.cpp | 2 - tests/vector/subvector1.cpp | 35 --- tests/vector/vector_copy1.cpp | 14 - tests/vector/vector_functions1.cpp | 65 ---- tests/vector/vector_scalar_node1.cpp | 16 - 82 files changed, 879 insertions(+), 1924 deletions(-) delete mode 100644 cml/common/compiler.h diff --git a/CML.cmake b/CML.cmake index 612e985..21eef13 100644 --- a/CML.cmake +++ b/CML.cmake @@ -15,7 +15,6 @@ set(main_HEADERS set(common_HEADERS cml/common/array_size_of.h cml/common/basis_tags.h - cml/common/compiler.h cml/common/exception.h cml/common/hash.h cml/common/layout_tags.h diff --git a/cml/common/compiler.h b/cml/common/compiler.h deleted file mode 100644 index d1aa82a..0000000 --- a/cml/common/compiler.h +++ /dev/null @@ -1,21 +0,0 @@ -/*------------------------------------------------------------------------- - @@COPYRIGHT@@ - *-----------------------------------------------------------------------*/ - -#pragma once - -/* N2439 move semantics for *this, used, for example, to efficiently return - * an expression node from a class method. Without this, a temporary is - * returned instead: - */ -#ifdef __cpp_ref_qualifiers -# define CML_HAS_RVALUE_REFERENCE_FROM_THIS -# define __CML_REF & -#else -# error "Compiler does not support __cpp_ref_qualifiers." -#endif - -/* Compiler (optionally) supports C++17 structured bindings: */ -#ifdef __cpp_structured_bindings -# define CML_HAS_STRUCTURED_BINDINGS -#endif diff --git a/cml/common/mpl/rebind.h b/cml/common/mpl/rebind.h index b12a61f..2c412aa 100644 --- a/cml/common/mpl/rebind.h +++ b/cml/common/mpl/rebind.h @@ -5,7 +5,6 @@ #pragma once #include -#include namespace cml { @@ -22,22 +21,6 @@ template struct rebind template using rebind_t = typename rebind::other; - -#ifdef CML_HAS_MSVC_WONKY_PARAMETER_PACK -/** Helper to rebind allocator @c T. - * - * @note Only typed parameters are supported. - */ -template struct rebind_alloc -{ - using traits = std::allocator_traits; - using other = typename traits::template rebind_alloc; -}; - -/** Convenience alias for rebind_alloc. */ -template -using rebind_alloc_t = typename rebind_alloc::other; -#else /** Helper to rebind allocator @c T. * * @note Only typed parameters are supported. @@ -51,6 +34,5 @@ template struct rebind_alloc /** Convenience alias for rebind_alloc. */ template using rebind_alloc_t = typename rebind_alloc::other; -#endif } // namespace cml diff --git a/cml/common/type_util.h b/cml/common/type_util.h index 72b5084..b4888cd 100644 --- a/cml/common/type_util.h +++ b/cml/common/type_util.h @@ -5,7 +5,6 @@ #pragma once #include -#include #include namespace cml { diff --git a/cml/matrix/basis_node.h b/cml/matrix/basis_node.h index 4962736..1016f4c 100644 --- a/cml/matrix/basis_node.h +++ b/cml/matrix/basis_node.h @@ -63,19 +63,17 @@ class matrix_basis_node public: /** Construct from the wrapped sub-expression and the basis index. @c - * sub must be an lvalue reference or rvalue reference type. - * - * @throws std::invalid_argument if @c i < 0. - */ + * sub must be an lvalue reference or rvalue reference type. + * + * @throws std::invalid_argument if @c i < 0. + */ explicit matrix_basis_node(Sub sub, int i); /** Move constructor. */ matrix_basis_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ matrix_basis_node(const node_type& other); -#endif protected: @@ -95,9 +93,9 @@ class matrix_basis_node protected: /** The type used to store the subexpression. The expression is stored - * as a copy if Sub is an rvalue reference (temporary), or by const - * reference if Sub is an lvalue reference. - */ + * as a copy if Sub is an rvalue reference (temporary), or by const + * reference if Sub is an lvalue reference. + */ using sub_wrap_type = cml::if_t::value, const sub_type&, sub_type>; @@ -111,11 +109,6 @@ class matrix_basis_node private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_basis_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/matrix/basis_node.tpp b/cml/matrix/basis_node.tpp index 8c392b6..f42a5d4 100644 --- a/cml/matrix/basis_node.tpp +++ b/cml/matrix/basis_node.tpp @@ -24,13 +24,11 @@ matrix_basis_node::matrix_basis_node(node_type&& other) , m_i(other.m_i) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template matrix_basis_node::matrix_basis_node(const node_type& other) : m_sub(other.m_sub) , m_i(other.m_i) {} -#endif /* Internal methods: */ diff --git a/cml/matrix/binary_node.h b/cml/matrix/binary_node.h index 4fd7d1d..4f6bce5 100644 --- a/cml/matrix/binary_node.h +++ b/cml/matrix/binary_node.h @@ -94,22 +94,20 @@ class matrix_binary_node public: /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be - * lvalue reference or rvalue reference types. - * - * @throws incompatible_matrix_sizes at run-time if either Sub1 or Sub2 - * is a dynamically-sized matrix, and sub1.size() != sub2.size(). If - * both Sub1 and Sub2 are fixed-size expressions, then the sizes are - * checked at compile time. - */ + * lvalue reference or rvalue reference types. + * + * @throws incompatible_matrix_sizes at run-time if either Sub1 or Sub2 + * is a dynamically-sized matrix, and sub1.size() != sub2.size(). If + * both Sub1 and Sub2 are fixed-size expressions, then the sizes are + * checked at compile time. + */ matrix_binary_node(Sub1 left, Sub2 right); /** Move constructor. */ matrix_binary_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ matrix_binary_node(const node_type& other); -#endif protected: @@ -125,8 +123,8 @@ class matrix_binary_node int i_cols() const; /** Apply the operator to element @c (i,j) of the subexpressions and - * return the result. - */ + * return the result. + */ immutable_value i_get(int i, int j) const; /*@}*/ @@ -134,16 +132,16 @@ class matrix_binary_node protected: /** The type used to store the left subexpression. The expression is - * stored as a copy if Sub1 is an rvalue reference (temporary), or by - * const reference if Sub1 is an lvalue reference. - */ + * stored as a copy if Sub1 is an rvalue reference (temporary), or by + * const reference if Sub1 is an lvalue reference. + */ using left_wrap_type = cml::if_t::value, const left_type&, left_type>; /** The type used to store the right subexpression. The expression is - * stored as a copy if Sub2 is an rvalue reference (temporary), or by - * const reference if Sub2 is an lvalue reference. - */ + * stored as a copy if Sub2 is an rvalue reference (temporary), or by + * const reference if Sub2 is an lvalue reference. + */ using right_wrap_type = cml::if_t::value, const right_type&, right_type>; @@ -157,11 +155,6 @@ class matrix_binary_node private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_binary_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/matrix/binary_node.tpp b/cml/matrix/binary_node.tpp index bdb24ed..0acb65d 100644 --- a/cml/matrix/binary_node.tpp +++ b/cml/matrix/binary_node.tpp @@ -29,13 +29,11 @@ matrix_binary_node::matrix_binary_node(node_type&& other) , m_right(std::move(other.m_right)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template matrix_binary_node::matrix_binary_node(const node_type& other) : m_left(other.m_left) , m_right(other.m_right) {} -#endif /* Internal methods: */ diff --git a/cml/matrix/col_node.h b/cml/matrix/col_node.h index 5de21f2..0266fb7 100644 --- a/cml/matrix/col_node.h +++ b/cml/matrix/col_node.h @@ -63,19 +63,17 @@ class matrix_col_node public: /** Construct from the wrapped sub-expression and the column index. @c - * sub must be an lvalue reference or rvalue reference type. - * - * @throws std::invalid_argument if @c col < 0. - */ + * sub must be an lvalue reference or rvalue reference type. + * + * @throws std::invalid_argument if @c col < 0. + */ explicit matrix_col_node(Sub sub, int col); /** Move constructor. */ matrix_col_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ matrix_col_node(const node_type& other); -#endif protected: @@ -95,9 +93,9 @@ class matrix_col_node protected: /** The type used to store the subexpression. The expression is stored - * as a copy if Sub is an rvalue reference (temporary), or by const - * reference if Sub is an lvalue reference. - */ + * as a copy if Sub is an rvalue reference (temporary), or by const + * reference if Sub is an lvalue reference. + */ using sub_wrap_type = cml::if_t::value, const sub_type&, sub_type>; @@ -111,11 +109,6 @@ class matrix_col_node private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_col_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/matrix/col_node.tpp b/cml/matrix/col_node.tpp index 7feff5d..a82db82 100644 --- a/cml/matrix/col_node.tpp +++ b/cml/matrix/col_node.tpp @@ -24,13 +24,11 @@ matrix_col_node::matrix_col_node(node_type&& other) , m_col(other.m_col) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template matrix_col_node::matrix_col_node(const node_type& other) : m_sub(other.m_sub) , m_col(other.m_col) {} -#endif /* Internal methods: */ diff --git a/cml/matrix/dynamic_allocated.h b/cml/matrix/dynamic_allocated.h index 3552738..931a95d 100644 --- a/cml/matrix/dynamic_allocated.h +++ b/cml/matrix/dynamic_allocated.h @@ -98,9 +98,7 @@ class matrix, BasisOrient, Layout> public: /* Include methods from writable_type: */ using writable_type::operator(); -#ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS using writable_type::operator=; -#endif public: @@ -119,15 +117,15 @@ class matrix, BasisOrient, Layout> public: /** Default constructor. - * - * @note The matrix has no elements. - */ + * + * @note The matrix has no elements. + */ matrix(); /** Construct given a size. - * - * @throws std::invalid_argument if @c rows < 0 or @c cols < 0. - */ + * + * @throws std::invalid_argument if @c rows < 0 or @c cols < 0. + */ matrix(int rows, int cols); /** Copy constructor. */ @@ -140,10 +138,10 @@ class matrix, BasisOrient, Layout> template matrix(const readable_matrix& sub); /** Construct from at least 1 value. - * - * @note This overload is enabled only if all of the arguments are - * convertible to value_type. - */ + * + * @note This overload is enabled only if all of the arguments are + * convertible to value_type. + */ template, BasisOrient, Layout> const_pointer end() const; /** Resize the matrix to the specified size. - * - * @note This will reallocate the array and copy existing elements, if - * any. - * - * @throws std::invalid_argument if @c rows or @c cols is negative. - */ + * + * @note This will reallocate the array and copy existing elements, if + * any. + * + * @throws std::invalid_argument if @c rows or @c cols is negative. + */ void resize(int rows, int cols); /** Resize the matrix to the specified size without copying the old - * elements. - * - * @throws std::invalid_argument if @c rows or @c cols is negative. - */ + * elements. + * + * @throws std::invalid_argument if @c rows or @c cols is negative. + */ void resize_fast(int rows, int cols); @@ -222,42 +220,16 @@ class matrix, BasisOrient, Layout> /** Move assignment. */ matrix_type& operator=(matrix_type&& other); -#ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline matrix_type& operator=(const readable_matrix& other) - { - return this->assign(other); - } - - template* = nullptr> - inline matrix_type& operator=(const Array& array) - { - return this->assign(array); - } - - template - inline matrix_type& operator=(Other const (&array)[Rows][Cols]) - { - return this->assign(array); - } - - template - inline matrix_type& operator=(std::initializer_list l) - { - return this->assign(l); - } -#endif - protected: /** No-op for trivially destructible elements - * (is_trivially_destructible). - */ + * (is_trivially_destructible). + */ void destruct(pointer, int, std::true_type); /** Invoke non-trivial destructors for @c n elements starting at @c - * data. - */ + * data. + */ void destruct(pointer data, int n, std::false_type); @@ -289,13 +261,10 @@ class matrix, BasisOrient, Layout> mutable_value i_get(int i, int j); /** Set element @c i. */ - template - matrix_type& i_put(int i, int j, const Other& v) __CML_REF; + template matrix_type& i_put(int i, int j, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i on a temporary. */ template matrix_type&& i_put(int i, int j, const Other& v) &&; -#endif /*@}*/ diff --git a/cml/matrix/dynamic_allocated.tpp b/cml/matrix/dynamic_allocated.tpp index 6e0b2db..ac3a5fb 100644 --- a/cml/matrix/dynamic_allocated.tpp +++ b/cml/matrix/dynamic_allocated.tpp @@ -4,14 +4,11 @@ #pragma once -#ifndef cml_matrix_dynamic_allocated_tpp -# define cml_matrix_dynamic_allocated_tpp +#ifndef __CML_MATRIX_DYNAMIC_ALLOCATED_TPP +# error "matrix/dynamic_allocated.tpp not included correctly" +#endif -# ifndef __CML_MATRIX_DYNAMIC_ALLOCATED_TPP -# error "matrix/dynamic_allocated.tpp not included correctly" -# endif - -# include +#include namespace cml { @@ -317,13 +314,12 @@ template template auto matrix, BO, L>::i_put(int i, int j, - const Other& v) __CML_REF->matrix_type& + const Other& v) & -> matrix_type& { s_access(*this, i, j, layout_tag()) = value_type(v); return *this; } -# ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template auto @@ -333,8 +329,5 @@ matrix, BO, L>::i_put(int i, int j, s_access(*this, i, j, layout_tag()) = value_type(v); return (matrix_type&&) *this; } -# endif } // namespace cml - -#endif \ No newline at end of file diff --git a/cml/matrix/dynamic_external.h b/cml/matrix/dynamic_external.h index 60fb655..f7b3e06 100644 --- a/cml/matrix/dynamic_external.h +++ b/cml/matrix/dynamic_external.h @@ -92,9 +92,7 @@ class matrix, BasisOrient, Layout> public: /* Include methods from writable_type: */ using writable_type::operator(); -#ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS using writable_type::operator=; -#endif public: @@ -113,35 +111,35 @@ class matrix, BasisOrient, Layout> public: /** Default construct with a null pointer and 0 size (rows, cols). - * - * @warning The default constructor is enabled only if the compiler - * supports rvalue references from *this. - */ + * + * @warning The default constructor is enabled only if the compiler + * supports rvalue references from *this. + */ matrix(); /** Construct from the wrapped pointer and the dimensions. - * - * @note @c data will be referenced using the assigned matrix layout. - * - * @note This is for compatibility with CML1. - */ + * + * @note @c data will be referenced using the assigned matrix layout. + * + * @note This is for compatibility with CML1. + */ matrix(pointer data, int rows, int cols); /** Construct from the wrapped pointer and the dimensions. - * - * @note @c data will be referenced using the assigned matrix layout. - */ + * + * @note @c data will be referenced using the assigned matrix layout. + */ matrix(int rows, int cols, pointer data); /** Construct from a wrapped pointer to a 2D array of values with - * dimensions N1xN2. - * - * @note The dimensions of @c array must take the matrix layout into - * account. For example, the C-array initializer for a 3x2 external - * matrix in row-major layout will have dimensions N1xN2 = [3][2], but - * the initializer for a column-major matrix will have dimensions N1xN2 - * = [2][3]. - */ + * dimensions N1xN2. + * + * @note The dimensions of @c array must take the matrix layout into + * account. For example, the C-array initializer for a 3x2 external + * matrix in row-major layout will have dimensions N1xN2 = [3][2], but + * the initializer for a column-major matrix will have dimensions N1xN2 + * = [2][3]. + */ template matrix(Other (&array)[N1][N2]); /** Move constructor. */ @@ -162,14 +160,14 @@ class matrix, BasisOrient, Layout> const_pointer end() const; /** Resize (reshape) the matrix to the specified size. - * - * @note The existing elements are not changed. - * - * @throws std::invalid_argument if @c rows or @c cols is negative. - * - * @throws matrix_size_error if the number of elements in the resized - * matrix would be different from the original. - */ + * + * @note The existing elements are not changed. + * + * @throws std::invalid_argument if @c rows or @c cols is negative. + * + * @throws matrix_size_error if the number of elements in the resized + * matrix would be different from the original. + */ void resize(int rows, int cols); /** Reset the matrix to have no elements and no external pointer. */ @@ -183,32 +181,6 @@ class matrix, BasisOrient, Layout> /** Move assignment. */ matrix_type& operator=(matrix_type&& other); -#ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline matrix_type& operator=(const readable_matrix& other) - { - return this->assign(other); - } - - template* = nullptr> - inline matrix_type& operator=(const Array& array) - { - return this->assign(array); - } - - template - inline matrix_type& operator=(Other const (&array)[Rows][Cols]) - { - return this->assign(array); - } - - template - inline matrix_type& operator=(std::initializer_list l) - { - return this->assign(l); - } -#endif - protected: /** @name readable_matrix Interface */ @@ -239,12 +211,10 @@ class matrix, BasisOrient, Layout> /** Set element @c i. */ template - matrix_type& i_put(int i, int j, const Other& v) __CML_REF; + matrix_type& i_put(int i, int j, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i on a temporary. */ template matrix_type&& i_put(int i, int j, const Other& v) &&; -#endif /*@}*/ diff --git a/cml/matrix/dynamic_external.tpp b/cml/matrix/dynamic_external.tpp index 027b2a5..b9ce319 100644 --- a/cml/matrix/dynamic_external.tpp +++ b/cml/matrix/dynamic_external.tpp @@ -16,9 +16,6 @@ matrix, BO, L>::matrix() , m_rows(0) , m_cols(0) { -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - static_assert(false, "external matrix default constructor not supported"); -#endif } template @@ -163,13 +160,12 @@ template template auto matrix, BO, L>::i_put(int i, int j, - const Other& v) __CML_REF->matrix_type& + const Other& v) & -> matrix_type& { s_access(*this, i, j, layout_tag()) = value_type(v); return *this; } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template auto @@ -179,6 +175,5 @@ matrix, BO, L>::i_put(int i, int j, s_access(*this, i, j, layout_tag()) = value_type(v); return (matrix_type&&) *this; } -#endif -} // namespace cml \ No newline at end of file +} // namespace cml diff --git a/cml/matrix/fixed_compiled.h b/cml/matrix/fixed_compiled.h index 59b3f82..43f36fe 100644 --- a/cml/matrix/fixed_compiled.h +++ b/cml/matrix/fixed_compiled.h @@ -85,9 +85,7 @@ class matrix, BasisOrient, Layout> public: /* Include methods from writable_matrix: */ using writable_type::operator(); -#ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS using writable_type::operator=; -#endif public: @@ -106,9 +104,9 @@ class matrix, BasisOrient, Layout> public: /** Compiler-default constructor. - * - * @note The matrix elements are uninitialized. - */ + * + * @note The matrix elements are uninitialized. + */ matrix() = default; /** Compiler-default destructor. */ @@ -117,19 +115,17 @@ class matrix, BasisOrient, Layout> /** Compiler-default copy constructor. */ matrix(const matrix_type& other) = default; -#ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR /** Compiler-default move constructor. */ matrix(matrix_type&& other) = default; -#endif /** Construct from a readable_matrix. */ template matrix(const readable_matrix& sub); /** Construct from at least 1 value. - * - * @note This overload is enabled only if all of the arguments are - * convertible to value_type. - */ + * + * @note This overload is enabled only if all of the arguments are + * convertible to value_type. + */ template::type* = @@ -178,32 +174,6 @@ class matrix, BasisOrient, Layout> /** Move assignment. */ matrix_type& operator=(matrix_type&& other); -#ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline matrix_type& operator=(const readable_matrix& other) - { - return this->assign(other); - } - - template* = nullptr> - inline matrix_type& operator=(const Array& array) - { - return this->assign(array); - } - - template - inline matrix_type& operator=(Other const (&array)[Rows][Cols]) - { - return this->assign(array); - } - - template - inline matrix_type& operator=(std::initializer_list l) - { - return this->assign(l); - } -#endif - protected: /** @name readable_matrix Interface */ @@ -234,12 +204,10 @@ class matrix, BasisOrient, Layout> /** Set element @c i. */ template - matrix_type& i_put(int i, int j, const Other& v) __CML_REF; + matrix_type& i_put(int i, int j, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i on a temporary. */ template matrix_type&& i_put(int i, int j, const Other& v) &&; -#endif /*@}*/ diff --git a/cml/matrix/fixed_compiled.tpp b/cml/matrix/fixed_compiled.tpp index 99e8342..a6ff21a 100644 --- a/cml/matrix/fixed_compiled.tpp +++ b/cml/matrix/fixed_compiled.tpp @@ -132,13 +132,12 @@ template template auto matrix, BO, L>::i_put(int i, int j, - const Other& v) __CML_REF->matrix_type& + const Other& v) &->matrix_type& { s_access(*this, i, j, layout_tag()) = value_type(v); return *this; } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template auto @@ -148,6 +147,5 @@ matrix, BO, L>::i_put(int i, int j, s_access(*this, i, j, layout_tag()) = value_type(v); return (matrix_type&&) *this; } -#endif } // namespace cml \ No newline at end of file diff --git a/cml/matrix/fixed_external.h b/cml/matrix/fixed_external.h index a444b06..cba9a40 100644 --- a/cml/matrix/fixed_external.h +++ b/cml/matrix/fixed_external.h @@ -91,9 +91,7 @@ class matrix, BasisOrient, Layout> public: /* Include methods from writable_type: */ using writable_type::operator(); -#ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS using writable_type::operator=; -#endif public: @@ -112,26 +110,26 @@ class matrix, BasisOrient, Layout> public: /** Default construct with a null pointer. - * - * @warning The default constructor is enabled only if the compiler - * supports rvalue references from *this. - */ + * + * @warning The default constructor is enabled only if the compiler + * supports rvalue references from *this. + */ matrix(); /** Construct from the wrapped pointer. - * - * @note @c data will be referenced using the assigned matrix layout. - */ + * + * @note @c data will be referenced using the assigned matrix layout. + */ explicit matrix(pointer data); /** Construct from a wrapped pointer to a 2D array of values. - * - * @note The dimensions of @c array must match those of the matrix, - * taking the matrix layout into account. For example, the C-array - * initializer for a 3x2 external matrix in row-major layout will have - * dimensions [3][2], but the initializer for a column-major matrix - * will have dimensions [2][3]. - */ + * + * @note The dimensions of @c array must match those of the matrix, + * taking the matrix layout into account. For example, the C-array + * initializer for a 3x2 external matrix in row-major layout will have + * dimensions [3][2], but the initializer for a column-major matrix + * will have dimensions [2][3]. + */ matrix(matrix_data_type& array); /** Move constructor. */ @@ -159,32 +157,6 @@ class matrix, BasisOrient, Layout> /** Move assignment. */ matrix_type& operator=(matrix_type&& other); -#ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline matrix_type& operator=(const readable_matrix& other) - { - return this->assign(other); - } - - template* = nullptr> - inline matrix_type& operator=(const Array& array) - { - return this->assign(array); - } - - template - inline matrix_type& operator=(Other const (&array)[Rows][Cols]) - { - return this->assign(array); - } - - template - inline matrix_type& operator=(std::initializer_list l) - { - return this->assign(l); - } -#endif - protected: /** @name readable_matrix Interface */ @@ -215,12 +187,10 @@ class matrix, BasisOrient, Layout> /** Set element @c i. */ template - matrix_type& i_put(int i, int j, const Other& v) __CML_REF; + matrix_type& i_put(int i, int j, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i on a temporary. */ template matrix_type&& i_put(int i, int j, const Other& v) &&; -#endif /*@}*/ diff --git a/cml/matrix/fixed_external.tpp b/cml/matrix/fixed_external.tpp index 5023940..9c020d0 100644 --- a/cml/matrix/fixed_external.tpp +++ b/cml/matrix/fixed_external.tpp @@ -14,9 +14,6 @@ template matrix, BO, L>::matrix() : m_data(0) { -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - static_assert(false, "external matrix default constructor not supported"); -#endif } template @@ -120,13 +117,12 @@ template template auto matrix, BO, L>::i_put(int i, int j, - const Other& v) __CML_REF->matrix_type& + const Other& v) &->matrix_type& { s_access(*this, i, j, layout_tag()) = value_type(v); return *this; } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template auto @@ -136,6 +132,5 @@ matrix, BO, L>::i_put(int i, int j, s_access(*this, i, j, layout_tag()) = value_type(v); return (matrix_type&&) *this; } -#endif } // namespace cml \ No newline at end of file diff --git a/cml/matrix/readable_matrix.h b/cml/matrix/readable_matrix.h index 83b80fb..cf9a8ac 100644 --- a/cml/matrix/readable_matrix.h +++ b/cml/matrix/readable_matrix.h @@ -64,8 +64,8 @@ template class readable_matrix immutable_value operator()(int i, int j) const; /** Returns element @c j of basis vector @c i. The returned value - * depends upon the basis orientation. - */ + * depends upon the basis orientation. + */ immutable_value basis_element(int i, int j) const; /** Returns the number of basis vectors. */ @@ -75,19 +75,19 @@ template class readable_matrix int basis_size() const; /** Compute the determinant of the matrix. - * - * @throws non_square_matrix_error at run-time if the matrix is - * dynamically-sized and not square. Fixed-size matrices are checked - * at compile-time. - */ + * + * @throws non_square_matrix_error at run-time if the matrix is + * dynamically-sized and not square. Fixed-size matrices are checked + * at compile-time. + */ value_type determinant() const; /** Compute the trace of the matrix. - * - * @throws non_square_matrix_error at run-time if the matrix is - * dynamically-sized and not square. Fixed-size matrices are checked - * at compile-time. - */ + * + * @throws non_square_matrix_error at run-time if the matrix is + * dynamically-sized and not square. Fixed-size matrices are checked + * at compile-time. + */ value_type trace() const; @@ -105,13 +105,13 @@ template class readable_matrix int basis_count(col_basis) const; /** Return the number of elements in a basis vector for a row_basis - * matrix. - */ + * matrix. + */ int basis_size(row_basis) const; /** Return the number of elements in a basis vectors for a col_basis - * matrix. - */ + * matrix. + */ int basis_size(col_basis) const; @@ -122,10 +122,8 @@ template class readable_matrix // Use the compiler-generated copy constructor: readable_matrix(const readable_matrix&) = default; -#ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR // Use the compiler-generated move constructor: readable_matrix(readable_matrix&&) = default; -#endif }; } // namespace cml diff --git a/cml/matrix/row_node.h b/cml/matrix/row_node.h index 0fab085..245f8d3 100644 --- a/cml/matrix/row_node.h +++ b/cml/matrix/row_node.h @@ -63,19 +63,17 @@ class matrix_row_node public: /** Construct from the wrapped sub-expression and the row index. @c - * sub must be an lvalue reference or rvalue reference type. - * - * @throws std::invalid_argument if @c row < 0. - */ + * sub must be an lvalue reference or rvalue reference type. + * + * @throws std::invalid_argument if @c row < 0. + */ explicit matrix_row_node(Sub sub, int row); /** Move constructor. */ matrix_row_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ matrix_row_node(const node_type& other); -#endif protected: @@ -95,9 +93,9 @@ class matrix_row_node protected: /** The type used to store the subexpression. The expression is stored - * as a copy if Sub is an rvalue reference (temporary), or by const - * reference if Sub is an lvalue reference. - */ + * as a copy if Sub is an rvalue reference (temporary), or by const + * reference if Sub is an lvalue reference. + */ using sub_wrap_type = cml::if_t::value, const sub_type&, sub_type>; @@ -111,11 +109,6 @@ class matrix_row_node private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_row_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/matrix/row_node.tpp b/cml/matrix/row_node.tpp index 960ee5e..fd0efdc 100644 --- a/cml/matrix/row_node.tpp +++ b/cml/matrix/row_node.tpp @@ -24,13 +24,11 @@ matrix_row_node::matrix_row_node(node_type&& other) , m_row(other.m_row) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template matrix_row_node::matrix_row_node(const node_type& other) : m_sub(other.m_sub) , m_row(other.m_row) {} -#endif /* Internal methods: */ diff --git a/cml/matrix/scalar_node.h b/cml/matrix/scalar_node.h index 70b6e61..31923a9 100644 --- a/cml/matrix/scalar_node.h +++ b/cml/matrix/scalar_node.h @@ -82,17 +82,15 @@ class matrix_scalar_node public: /** Construct from the wrapped sub-expression and the scalar to apply. - * @c left and @c right must be lvalue or rvalue references. - */ + * @c left and @c right must be lvalue or rvalue references. + */ matrix_scalar_node(Sub left, Scalar right); /** Move constructor. */ matrix_scalar_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ matrix_scalar_node(const node_type& other); -#endif protected: @@ -108,8 +106,8 @@ class matrix_scalar_node int i_cols() const; /** Apply the operator to element @c (i,j) of the subexpressions and - * return the result. - */ + * return the result. + */ immutable_value i_get(int i, int j) const; /*@}*/ @@ -117,9 +115,9 @@ class matrix_scalar_node protected: /** The type used to store the left subexpression. The expression is - * stored as a copy if Sub is an rvalue reference (temporary), or by - * const reference if Sub is an lvalue reference. - */ + * stored as a copy if Sub is an rvalue reference (temporary), or by + * const reference if Sub is an lvalue reference. + */ using left_wrap_type = cml::if_t::value, const left_type&, left_type>; @@ -133,11 +131,6 @@ class matrix_scalar_node private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_scalar_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/matrix/scalar_node.tpp b/cml/matrix/scalar_node.tpp index da67925..67595a2 100644 --- a/cml/matrix/scalar_node.tpp +++ b/cml/matrix/scalar_node.tpp @@ -22,14 +22,11 @@ matrix_scalar_node::matrix_scalar_node(node_type&& other) , m_right(std::move(other.m_right)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template matrix_scalar_node::matrix_scalar_node(const node_type& other) : m_left(other.m_left) , m_right(other.m_right) {} -#endif - /* Internal methods: */ @@ -57,4 +54,4 @@ matrix_scalar_node::i_get(int i, int j) const return Op().apply(this->m_left.get(i, j), this->m_right); } -} // namespace cml \ No newline at end of file +} // namespace cml diff --git a/cml/matrix/transpose_node.h b/cml/matrix/transpose_node.h index 58a03b8..3ea2351 100644 --- a/cml/matrix/transpose_node.h +++ b/cml/matrix/transpose_node.h @@ -80,17 +80,15 @@ class matrix_transpose_node : public readable_matrix> public: /** Construct from the wrapped sub-expression. @c sub must be an - * lvalue reference or rvalue reference type. - */ + * lvalue reference or rvalue reference type. + */ matrix_transpose_node(Sub sub); /** Move constructor. */ matrix_transpose_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ matrix_transpose_node(const node_type& other); -#endif protected: @@ -113,9 +111,9 @@ class matrix_transpose_node : public readable_matrix> protected: /** The type used to store the subexpression. The expression is stored - * as a copy if Sub is an rvalue reference (temporary), or by const - * reference if Sub is an lvalue reference. - */ + * as a copy if Sub is an rvalue reference (temporary), or by const + * reference if Sub is an lvalue reference. + */ using sub_wrap_type = cml::if_t::value, const sub_type&, sub_type>; @@ -126,11 +124,6 @@ class matrix_transpose_node : public readable_matrix> private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_transpose_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/matrix/transpose_node.tpp b/cml/matrix/transpose_node.tpp index 73de3a5..56c4f07 100644 --- a/cml/matrix/transpose_node.tpp +++ b/cml/matrix/transpose_node.tpp @@ -20,13 +20,10 @@ matrix_transpose_node::matrix_transpose_node(node_type&& other) : m_sub(std::move(other.m_sub)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template matrix_transpose_node::matrix_transpose_node(const node_type& other) : m_sub(other.m_sub) {} -#endif - /* Internal methods: */ @@ -53,4 +50,4 @@ matrix_transpose_node::i_get(int i, int j) const -> immutable_value return this->m_sub.get(j, i); } -} // namespace cml \ No newline at end of file +} // namespace cml diff --git a/cml/matrix/unary_node.h b/cml/matrix/unary_node.h index 49e194e..855c624 100644 --- a/cml/matrix/unary_node.h +++ b/cml/matrix/unary_node.h @@ -74,17 +74,15 @@ class matrix_unary_node : public readable_matrix> public: /** Construct from the wrapped sub-expression. @c sub must be an - * lvalue reference or rvalue reference type. - */ + * lvalue reference or rvalue reference type. + */ explicit matrix_unary_node(Sub sub); /** Move constructor. */ matrix_unary_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ matrix_unary_node(const node_type& other); -#endif protected: @@ -100,8 +98,8 @@ class matrix_unary_node : public readable_matrix> int i_cols() const; /** Apply the operator to element @c (i,j) of the subexpressions and - * return the result. - */ + * return the result. + */ immutable_value i_get(int i, int j) const; /*@}*/ @@ -109,9 +107,9 @@ class matrix_unary_node : public readable_matrix> protected: /** The type used to store the subexpression. The expression is stored - * as a copy if Sub is an rvalue reference (temporary), or by const - * reference if Sub is an lvalue reference. - */ + * as a copy if Sub is an rvalue reference (temporary), or by const + * reference if Sub is an lvalue reference. + */ using sub_wrap_type = cml::if_t::value, const sub_type&, sub_type>; @@ -122,11 +120,6 @@ class matrix_unary_node : public readable_matrix> private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - matrix_unary_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/matrix/unary_node.tpp b/cml/matrix/unary_node.tpp index e32a9ec..4bb98cf 100644 --- a/cml/matrix/unary_node.tpp +++ b/cml/matrix/unary_node.tpp @@ -20,13 +20,10 @@ matrix_unary_node::matrix_unary_node(node_type&& other) : m_sub(std::move(other.m_sub)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template matrix_unary_node::matrix_unary_node(const node_type& other) : m_sub(other.m_sub) {} -#endif - /* Internal methods: */ @@ -53,4 +50,4 @@ matrix_unary_node::i_get(int i, int j) const -> immutable_value return Op().apply(this->m_sub.get(i, j)); } -} // namespace cml \ No newline at end of file +} // namespace cml diff --git a/cml/matrix/writable_matrix.h b/cml/matrix/writable_matrix.h index bb83bf9..631dc77 100644 --- a/cml/matrix/writable_matrix.h +++ b/cml/matrix/writable_matrix.h @@ -60,12 +60,10 @@ class writable_matrix : public readable_matrix DerivedT& actual(); /** Set element @c (i,j). */ - template DerivedT& put(int i, int j, const Other& v) __CML_REF; + template DerivedT& put(int i, int j, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c (i,j) on a temporary. */ template DerivedT&& put(int i, int j, const Other& v) &&; -#endif /** Return mutable element @c (i,j). */ mutable_value get(int i, int j); @@ -77,352 +75,312 @@ class writable_matrix : public readable_matrix public: /** Set element @c j of basis vector @c i. */ template - DerivedT& set_basis_element(int i, int j, const Other& v) __CML_REF; + DerivedT& set_basis_element(int i, int j, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c j of basis vector @c i on a temporary. */ template DerivedT&& set_basis_element(int i, int j, const Other& v) &&; -#endif /** Copy @c v to row @c i of the matrix. - * - * @throws cml::incompatible_matrix_col_size_error if the matrix is - * dynamic and the number of columns does not match the size of - * @c v. The sizes are checked at compile time otherwise. - */ - template - DerivedT& set_row(int i, const readable_vector& v) __CML_REF; + * + * @throws cml::incompatible_matrix_col_size_error if the matrix is + * dynamic and the number of columns does not match the size of + * @c v. The sizes are checked at compile time otherwise. + */ + template DerivedT& set_row(int i, const readable_vector& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy @c v to row @c i of a temporary matrix. - * - * @throws cml::incompatible_matrix_col_size_error if the matrix is - * dynamic and the number of columns does not match the size of - * @c v. The sizes are checked at compile time otherwise. - */ + * + * @throws cml::incompatible_matrix_col_size_error if the matrix is + * dynamic and the number of columns does not match the size of + * @c v. The sizes are checked at compile time otherwise. + */ template DerivedT&& set_row(int i, const readable_vector& v) &&; -#endif /** Copy @c v to column @c j of the matrix. - * - * @throws cml::incompatible_matrix_row_size_error if the matrix is - * dynamic and the number of rows does not match the size of @c v. The - * sizes are checked at compile time otherwise. - */ - template - DerivedT& set_col(int j, const readable_vector& v) __CML_REF; + * + * @throws cml::incompatible_matrix_row_size_error if the matrix is + * dynamic and the number of rows does not match the size of @c v. The + * sizes are checked at compile time otherwise. + */ + template DerivedT& set_col(int j, const readable_vector& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy @c v to column @c j of a temporary matrix. - * - * @throws cml::incompatible_matrix_row_size_error if the matrix is - * dynamic and the number of rows does not match the size of @c v. The - * sizes are checked at compile time otherwise. - */ + * + * @throws cml::incompatible_matrix_row_size_error if the matrix is + * dynamic and the number of rows does not match the size of @c v. The + * sizes are checked at compile time otherwise. + */ template DerivedT&& set_col(int j, const readable_vector& v) &&; -#endif /** Zero the matrix elements. */ - DerivedT& zero() __CML_REF; + DerivedT& zero() &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Zero the matrix elements of a temporary. */ DerivedT&& zero() &&; -#endif /** Set the matrix to the identity. */ - DerivedT& identity() __CML_REF; + DerivedT& identity() &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set a temporary matrix to the identity. */ DerivedT&& identity() &&; -#endif /** Set elements to random values in the range @c[low,high]. */ - DerivedT& random(const_reference low, const_reference high) __CML_REF; + DerivedT& random(const_reference low, const_reference high) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set elements of a temporary to random values in the range - * @c[low,high]. - */ + * @c[low,high]. + */ DerivedT&& random(const_reference low, const_reference high) &&; -#endif /** Set all elements to a specific value. */ - DerivedT& fill(const_reference v) __CML_REF; + DerivedT& fill(const_reference v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set all elements of a temporary to a specific value. */ DerivedT&& fill(const_reference v) &&; -#endif /** Set the matrix to its inverse. - * - * @throws non_square_matrix_error at run-time if the matrix is - * dynamically sized and not square. - */ - DerivedT& inverse() __CML_REF; + * + * @throws non_square_matrix_error at run-time if the matrix is + * dynamically sized and not square. + */ + DerivedT& inverse() &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set a temporary matrix to its inverse. - * - * @throws non_square_matrix_error at run-time if the matrix is - * dynamically sized and not square. - */ + * + * @throws non_square_matrix_error at run-time if the matrix is + * dynamically sized and not square. + */ DerivedT&& inverse() &&; -#endif /** Set the matrix to its transpose. - * - * @note This will raise a compile time error if the matrix is - * fixed-size and non-square. Dynamic-size matrices will be assigned - * from a temporary. - */ - DerivedT& transpose() __CML_REF; - -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS + * + * @note This will raise a compile time error if the matrix is + * fixed-size and non-square. Dynamic-size matrices will be assigned + * from a temporary. + */ + DerivedT& transpose() &; + /** Set a temporary matrix to its inverse. - * - * @note This will raise a compile time error if the matrix is - * fixed-size and non-square. Dynamic-size matrices will be assigned - * from a temporary. - */ + * + * @note This will raise a compile time error if the matrix is + * fixed-size and non-square. Dynamic-size matrices will be assigned + * from a temporary. + */ DerivedT&& transpose() &&; -#endif public: /** Assign from a readable_matrix. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is not - * resizable, and if @c other.size() != this->size(). If both are - * fixed-size, then the size is checked at compile time. - */ + * + * @throws incompatible_matrix_size_error at run-time if the matrix is not + * resizable, and if @c other.size() != this->size(). If both are + * fixed-size, then the size is checked at compile time. + */ template - DerivedT& operator=(const readable_matrix& other) __CML_REF; + DerivedT& operator=(const readable_matrix& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Assign a temporary from a readable_matrix. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is not - * resizable, and if @c other.size() != this->size(). If both are - * fixed-size, then the size is checked at compile time. - */ + * + * @throws incompatible_matrix_size_error at run-time if the matrix is not + * resizable, and if @c other.size() != this->size(). If both are + * fixed-size, then the size is checked at compile time. + */ template DerivedT&& operator=(const readable_matrix& other) &&; -#endif /** Assign from a fixed-length array type. - * - * @throws incompatible_matrix_size_error at run-time if @c - * array_size_of_c::value != this->rows()*this->cols(). If both - * are fixed-size, then the size is checked at compile time. - */ + * + * @throws incompatible_matrix_size_error at run-time if @c + * array_size_of_c::value != this->rows()*this->cols(). If both + * are fixed-size, then the size is checked at compile time. + */ template* = nullptr> - DerivedT& operator=(const Array& array) __CML_REF; + DerivedT& operator=(const Array& array) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Assign a temporary from a fixed-length array type. - * - * @throws incompatible_matrix_size_error at run-time if @c - * array_size_of_c::value != this->rows()*this->cols(). If both - * are fixed-size, then the size is checked at compile time. - */ + * + * @throws incompatible_matrix_size_error at run-time if @c + * array_size_of_c::value != this->rows()*this->cols(). If both + * are fixed-size, then the size is checked at compile time. + */ template* = nullptr> DerivedT&& operator=(const Array& array) &&; -#endif /** Assign from a 2D C-array. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is - * not resizable and does not have the same size as @c array. If both - * are fixed-size, then the size is checked at compile time. - */ + * + * @throws incompatible_matrix_size_error at run-time if the matrix is + * not resizable and does not have the same size as @c array. If both + * are fixed-size, then the size is checked at compile time. + */ template - DerivedT& operator=(Other const (&array)[Rows][Cols]) __CML_REF; + DerivedT& operator=(Other const (&array)[Rows][Cols]) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Assign a temporary from a fixed-length array type. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is - * not resizable and does not have the same size as @c array. If both - * are fixed-size, then the size is checked at compile time. - */ + * + * @throws incompatible_matrix_size_error at run-time if the matrix is + * not resizable and does not have the same size as @c array. If both + * are fixed-size, then the size is checked at compile time. + */ template DerivedT& operator=(Other const (&array)[Rows][Cols]) &&; -#endif /** Assign from initializer list. - * - * @throws incompatible_matrix_size_error if the matrix is not - * resizable, and if @c l.size() != this->size(). - */ - template - DerivedT& operator=(std::initializer_list l) __CML_REF; + * + * @throws incompatible_matrix_size_error if the matrix is not + * resizable, and if @c l.size() != this->size(). + */ + template DerivedT& operator=(std::initializer_list l) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Assign a temporary from initializer list. - * - * @throws incompatible_matrix_size_error if the matrix is not - * resizable, and if @c l.size() != this->size(). - */ + * + * @throws incompatible_matrix_size_error if the matrix is not + * resizable, and if @c l.size() != this->size(). + */ template DerivedT&& operator=(std::initializer_list l) &&; -#endif /** Modify the matrix by addition of another matrix. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is - * dynamically-sized, and if @c other.size() != this->size(). If both - * are fixed-size expressions, then the size is checked at compile - * time. - */ + * + * @throws incompatible_matrix_size_error at run-time if the matrix is + * dynamically-sized, and if @c other.size() != this->size(). If both + * are fixed-size expressions, then the size is checked at compile + * time. + */ template - DerivedT& operator+=(const readable_matrix& other) __CML_REF; + DerivedT& operator+=(const readable_matrix& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Modify a temporary matrix by addition of another matrix. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is - * dynamically-sized, and if @c other.size() != this->size(). If both - * are fixed-size expressions, then the size is checked at compile - * time. - */ + * + * @throws incompatible_matrix_size_error at run-time if the matrix is + * dynamically-sized, and if @c other.size() != this->size(). If both + * are fixed-size expressions, then the size is checked at compile + * time. + */ template DerivedT&& operator+=(const readable_matrix& other) &&; -#endif /** Modify the matrix by subtraction of another matrix. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is - * dynamically-sized, and if @c other.size() != this->size(). If both - * are fixed-size expressions, then the size is checked at compile - * time. - */ + * + * @throws incompatible_matrix_size_error at run-time if the matrix is + * dynamically-sized, and if @c other.size() != this->size(). If both + * are fixed-size expressions, then the size is checked at compile + * time. + */ template - DerivedT& operator-=(const readable_matrix& other) __CML_REF; + DerivedT& operator-=(const readable_matrix& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Modify a temporary matrix by subtraction of another matrix. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is - * dynamically-sized, and if @c other.size() != this->size(). If both - * are fixed-size expressions, then the size is checked at compile - * time. - */ + * + * @throws incompatible_matrix_size_error at run-time if the matrix is + * dynamically-sized, and if @c other.size() != this->size(). If both + * are fixed-size expressions, then the size is checked at compile + * time. + */ template DerivedT&& operator-=(const readable_matrix& other) &&; -#endif /** Multiply the matrix by a scalar convertible to its value_type. */ template::type* = nullptr> - DerivedT& operator*=(const ScalarT& v) __CML_REF; + DerivedT& operator*=(const ScalarT& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Multiply the matrix temporary by a scalar convertible to its - * value_type. - */ + * value_type. + */ template::type* = nullptr> DerivedT&& operator*=(const ScalarT& v) &&; -#endif /** Divide the matrix by a scalar convertible to its value_type. */ template::type* = nullptr> - DerivedT& operator/=(const ScalarT& v) __CML_REF; + DerivedT& operator/=(const ScalarT& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Divide a temporary matrix by a scalar. - * - * @note This depends upon implicit conversion of @c v to the - * matrix value_type. - */ - /** Divide the matrix temporary by a scalar convertible to its - * value_type. - */ + * + * @note This depends upon implicit conversion of @c v to the + * matrix value_type. + */ template::type* = nullptr> DerivedT&& operator/=(const ScalarT& v) &&; -#endif protected: /** Assign from a readable_matrix. - * - * @note This depends upon implicit conversion of the source matrix - * elements to the matrix value_type. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is not - * resizable, and if @c other.size() != this->size(). If both are - * fixed-size expressions, then the size is checked at compile time. - */ + * + * @note This depends upon implicit conversion of the source matrix + * elements to the matrix value_type. + * + * @throws incompatible_matrix_size_error at run-time if the matrix is not + * resizable, and if @c other.size() != this->size(). If both are + * fixed-size expressions, then the size is checked at compile time. + */ template DerivedT& assign(const readable_matrix& other); /** Assign from an array type. - * - * @note This depends upon implicit conversion of the array elements to - * the matrix value_type. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is - * not resizable, and if @c array_size_of_c::value != - * this->rows()*this->cols(). If both are fixed-size, then the size is - * checked at compile time. - */ + * + * @note This depends upon implicit conversion of the array elements to + * the matrix value_type. + * + * @throws incompatible_matrix_size_error at run-time if the matrix is + * not resizable, and if @c array_size_of_c::value != + * this->rows()*this->cols(). If both are fixed-size, then the size is + * checked at compile time. + */ template* = nullptr> DerivedT& assign(const Array& array); /** Assign from a 2D C-array type. - * - * @note This depends upon implicit conversion of the array elements to - * the matrix value_type. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is - * not resizable and does not have the same size as @c array. If both - * are fixed-size, then the size is checked at compile time. - */ + * + * @note This depends upon implicit conversion of the array elements to + * the matrix value_type. + * + * @throws incompatible_matrix_size_error at run-time if the matrix is + * not resizable and does not have the same size as @c array. If both + * are fixed-size, then the size is checked at compile time. + */ template DerivedT& assign(Other const (&array)[Rows][Cols]); /** Assign from a pointer to an array. - * - * @note This depends upon implicit conversion of the array elements to - * the matrix value_type. - * - * @note The number of elements read from @c array depends upon the - * current size of the matrix. - */ + * + * @note This depends upon implicit conversion of the array elements to + * the matrix value_type. + * + * @note The number of elements read from @c array depends upon the + * current size of the matrix. + */ template* = nullptr> DerivedT& assign(const Pointer& array); /** Assign from an initializer_list. - * - * @note This depends upon implicit conversion of @c Other to the - * matrix value_type. - * - * @throws incompatible_matrix_size_error if the matrix is not resizable, - * and if @c l.size() != this->rows()*this->cols(). - */ + * + * @note This depends upon implicit conversion of @c Other to the + * matrix value_type. + * + * @throws incompatible_matrix_size_error if the matrix is not resizable, + * and if @c l.size() != this->rows()*this->cols(). + */ template DerivedT& assign(const std::initializer_list& l); /** Construct from a variable list of values. If the matrix has more - * elements than the variable argument list, the remaining elements are - * set to value_type(0). - * - * @note For fixed-size matrices, the number of arguments is checked - * against the number of matrix elements at compile time. - * - * @note This depends upon implicit conversions of the elements to the - * matrix value_type. - * - * @throws incompatible_matrix_size_error at run-time if the matrix is - * not fixed-sized, and if @c sizeof...(eN) > @c (rows()*cols()). If - * the matrix is fixed-size, then the size is checked at compile time. - */ + * elements than the variable argument list, the remaining elements are + * set to value_type(0). + * + * @note For fixed-size matrices, the number of arguments is checked + * against the number of matrix elements at compile time. + * + * @note This depends upon implicit conversions of the elements to the + * matrix value_type. + * + * @throws incompatible_matrix_size_error at run-time if the matrix is + * not fixed-sized, and if @c sizeof...(eN) > @c (rows()*cols()). If + * the matrix is fixed-size, then the size is checked at compile time. + */ template DerivedT& assign_elements(const Elements&... eN); @@ -443,10 +401,8 @@ class writable_matrix : public readable_matrix // Use the compiler-generated copy constructor: writable_matrix(const writable_matrix&) = default; -#ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR // Use the compiler-generated move constructor: writable_matrix(writable_matrix&&) = default; -#endif // Force assignment through operator=(readable_matrix<>): writable_matrix& operator=(const writable_matrix&) = delete; diff --git a/cml/matrix/writable_matrix.tpp b/cml/matrix/writable_matrix.tpp index ff4c9c6..078f119 100644 --- a/cml/matrix/writable_matrix.tpp +++ b/cml/matrix/writable_matrix.tpp @@ -69,12 +69,11 @@ writable_matrix

::get(int i, int j) -> mutable_value template template DT& -writable_matrix
::put(int i, int j, const Other& v) __CML_REF +writable_matrix
::put(int i, int j, const Other& v) & { return this->actual().i_put(i, j, v); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -83,7 +82,6 @@ writable_matrix
::put(int i, int j, const Other& v) && this->put(i, j, v); // Forward to put(...) & return (DT&&) *this; } -#endif template auto @@ -95,13 +93,12 @@ writable_matrix
::operator()(int i, int j) -> mutable_value template template DT& -writable_matrix
::set_basis_element(int i, int j, const Other& v) __CML_REF +writable_matrix
::set_basis_element(int i, int j, const Other& v) & { this->set_basis_element(i, j, v, basis_tag()); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -110,20 +107,18 @@ writable_matrix
::set_basis_element(int i, int j, const Other& v) && this->set_basis_element(i, j, v); // Forward to set_basis_element(...) & return (DT&&) *this; } -#endif template template DT& -writable_matrix
::set_row(int i, const readable_vector& v) __CML_REF +writable_matrix
::set_row(int i, const readable_vector& v) & { cml::check_same_col_size(*this, v); for(int j = 0; j < this->cols(); ++j) this->put(i, j, v.get(j)); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -132,19 +127,17 @@ writable_matrix
::set_row(int i, const readable_vector& v) && this->set_row(i, v); return (DT&&) *this; } -#endif template template DT& -writable_matrix
::set_col(int j, const readable_vector& v) __CML_REF +writable_matrix
::set_col(int j, const readable_vector& v) & { cml::check_same_row_size(*this, v); for(int i = 0; i < this->rows(); ++i) this->put(i, j, v.get(i)); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -153,19 +146,17 @@ writable_matrix
::set_col(int j, const readable_vector& v) && this->set_col(j, v); return (DT&&) *this; } -#endif template DT& -writable_matrix
::zero() __CML_REF +writable_matrix
::zero() & { auto zero_f = [](int, int) { return value_type(0); }; detail::generate(*this, zero_f, layout_tag()); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_matrix
::zero() && @@ -173,19 +164,17 @@ writable_matrix
::zero() && this->zero(); // Forward to zero & return (DT&&) *this; } -#endif template DT& -writable_matrix
::identity() __CML_REF +writable_matrix
::identity() & { auto identity_f = [](int i, int j) { return value_type(i == j); }; detail::generate(*this, identity_f, layout_tag()); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_matrix
::identity() && @@ -193,11 +182,10 @@ writable_matrix
::identity() && this->identity(); // Forward to zero & return (DT&&) *this; } -#endif template DT& -writable_matrix
::random(const_reference low, const_reference high) __CML_REF +writable_matrix
::random(const_reference low, const_reference high) & { using distribution_type = if_t::value, std::uniform_int_distribution, @@ -211,7 +199,6 @@ writable_matrix
::random(const_reference low, const_reference high) __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_matrix
::random(const_reference low, const_reference high) && @@ -219,18 +206,16 @@ writable_matrix
::random(const_reference low, const_reference high) && this->random(low, high); return (DT&&) *this; } -#endif template DT& -writable_matrix
::fill(const_reference v) __CML_REF +writable_matrix
::fill(const_reference v) & { detail::generate( *this, [&v](int, int) { return v; }, layout_tag()); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_matrix
::fill(const_reference v) && @@ -238,18 +223,16 @@ writable_matrix
::fill(const_reference v) && this->fill(v); return (DT&&) *this; } -#endif template DT& -writable_matrix
::inverse() __CML_REF +writable_matrix
::inverse() & { cml::check_square(*this); detail::inverse(*this, cml::int_c()); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_matrix
::inverse() && @@ -257,18 +240,16 @@ writable_matrix
::inverse() && this->inverse(); return (DT&&) *this; } -#endif template DT& -writable_matrix
::transpose() __CML_REF +writable_matrix
::transpose() & { using tag = size_tag_of_t; detail::transpose(*this, tag()); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_matrix
::transpose() && @@ -276,18 +257,16 @@ writable_matrix
::transpose() && this->transpose(); return (DT&&) *this; } -#endif template template DT& -writable_matrix
::operator=(const readable_matrix& other) __CML_REF +writable_matrix
::operator=(const readable_matrix& other) & { return this->assign(other); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -296,17 +275,15 @@ writable_matrix
::operator=(const readable_matrix& other) && this->operator=(other); return (DT&&) *this; } -#endif template template*> DT& -writable_matrix
::operator=(const Array& array) __CML_REF +writable_matrix
::operator=(const Array& array) & { return this->assign(array); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template*> DT&& @@ -315,17 +292,15 @@ writable_matrix
::operator=(const Array& array) && this->operator=(array); return (DT&&) *this; } -#endif template template DT& -writable_matrix
::operator=(Other const (&array)[Rows][Cols]) __CML_REF +writable_matrix
::operator=(Other const (&array)[Rows][Cols]) & { return this->assign(array); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT& @@ -334,17 +309,15 @@ writable_matrix
::operator=(Other const (&array)[Rows][Cols]) && this->operator=(array); return (DT&&) *this; } -#endif template template DT& -writable_matrix
::operator=(std::initializer_list l) __CML_REF +writable_matrix
::operator=(std::initializer_list l) & { return this->assign(l); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -352,19 +325,17 @@ writable_matrix
::operator=(std::initializer_list l) && { return this->assign(l); } -#endif template template DT& -writable_matrix
::operator+=(const readable_matrix& other) __CML_REF +writable_matrix
::operator+=(const readable_matrix& other) & { detail::check_or_resize(*this, other); detail::apply>(*this, other, layout_tag()); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -373,19 +344,17 @@ writable_matrix
::operator+=(const readable_matrix& other) && this->operator+=(other); return (DT&&) *this; } -#endif template template DT& -writable_matrix
::operator-=(const readable_matrix& other) __CML_REF +writable_matrix
::operator-=(const readable_matrix& other) & { detail::check_or_resize(*this, other); detail::apply>(*this, other, layout_tag()); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -394,7 +363,6 @@ writable_matrix
::operator-=(const readable_matrix& other) && this->operator-=(other); return (DT&&) *this; } -#endif template @@ -402,13 +370,12 @@ template::value_type, ScalarT>::type*> DT& -writable_matrix
::operator*=(const ScalarT& v) __CML_REF +writable_matrix
::operator*=(const ScalarT& v) & { detail::apply>(*this, v, layout_tag()); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template::value_type, @@ -419,20 +386,18 @@ writable_matrix
::operator*=(const ScalarT& v) && this->operator*=(v); return (DT&&) *this; } -#endif template template::value_type, ScalarT>::type*> DT& -writable_matrix
::operator/=(const ScalarT& v) __CML_REF +writable_matrix
::operator/=(const ScalarT& v) & { detail::apply>(*this, v, layout_tag()); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template::value_type, @@ -443,7 +408,6 @@ writable_matrix
::operator/=(const ScalarT& v) && this->operator/=(v); return (DT&&) *this; } -#endif /* Internal methods: */ diff --git a/cml/quaternion/binary_node.h b/cml/quaternion/binary_node.h index 486fd1f..91c6dd0 100644 --- a/cml/quaternion/binary_node.h +++ b/cml/quaternion/binary_node.h @@ -76,22 +76,20 @@ class quaternion_binary_node public: /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be - * lvalue reference or rvalue reference types. - * - * @throws incompatible_quaternion_size_error at run-time if either Sub1 or - * Sub2 is a dynamically-sized quaternion, and sub1.size() != sub2.size(). - * If both Sub1 and Sub2 are fixed-size expressions, then the sizes are - * checked at compile time. - */ + * lvalue reference or rvalue reference types. + * + * @throws incompatible_quaternion_size_error at run-time if either Sub1 or + * Sub2 is a dynamically-sized quaternion, and sub1.size() != sub2.size(). + * If both Sub1 and Sub2 are fixed-size expressions, then the sizes are + * checked at compile time. + */ quaternion_binary_node(Sub1 left, Sub2 right); /** Move constructor. */ quaternion_binary_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ quaternion_binary_node(const node_type& other); -#endif protected: @@ -101,8 +99,8 @@ class quaternion_binary_node friend readable_type; /** Apply the operator to element @c i of the subexpressions and return - * the result. - */ + * the result. + */ immutable_value i_get(int i) const; /*@}*/ @@ -110,16 +108,16 @@ class quaternion_binary_node protected: /** The type used to store the left subexpression. The expression is - * stored as a copy if Sub1 is an rvalue reference (temporary), or by - * const reference if Sub1 is an lvalue reference. - */ + * stored as a copy if Sub1 is an rvalue reference (temporary), or by + * const reference if Sub1 is an lvalue reference. + */ using left_wrap_type = cml::if_t::value, const left_type&, left_type>; /** The type used to store the right subexpression. The expression is - * stored as a copy if Sub2 is an rvalue reference (temporary), or by - * const reference if Sub2 is an lvalue reference. - */ + * stored as a copy if Sub2 is an rvalue reference (temporary), or by + * const reference if Sub2 is an lvalue reference. + */ using right_wrap_type = cml::if_t::value, const right_type&, right_type>; @@ -133,11 +131,6 @@ class quaternion_binary_node private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - quaternion_binary_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/quaternion/binary_node.tpp b/cml/quaternion/binary_node.tpp index 46551bc..096e4ff 100644 --- a/cml/quaternion/binary_node.tpp +++ b/cml/quaternion/binary_node.tpp @@ -24,14 +24,12 @@ quaternion_binary_node::quaternion_binary_node( , m_right(std::move(other.m_right)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template quaternion_binary_node::quaternion_binary_node( const node_type& other) : m_left(other.m_left) , m_right(other.m_right) {} -#endif /* Internal methods: */ diff --git a/cml/quaternion/conjugate_node.h b/cml/quaternion/conjugate_node.h index adb5e50..909096d 100644 --- a/cml/quaternion/conjugate_node.h +++ b/cml/quaternion/conjugate_node.h @@ -59,17 +59,15 @@ class conjugate_node : public readable_quaternion> public: /** Construct from the wrapped quaternion expression. @c sub must be - * an lvalue reference or rvalue reference. - */ + * an lvalue reference or rvalue reference. + */ explicit conjugate_node(Sub sub); /** Move constructor. */ conjugate_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ conjugate_node(const node_type& other); -#endif protected: @@ -86,9 +84,9 @@ class conjugate_node : public readable_quaternion> protected: /** The type used to store the subexpression. The expression is stored - * as a copy if Sub is an rvalue reference (temporary), or by const - * reference if Sub is an lvalue reference. - */ + * as a copy if Sub is an rvalue reference (temporary), or by const + * reference if Sub is an lvalue reference. + */ using wrap_type = cml::if_t::value, const sub_type&, sub_type>; @@ -97,11 +95,6 @@ class conjugate_node : public readable_quaternion> private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - conjugate_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/quaternion/conjugate_node.tpp b/cml/quaternion/conjugate_node.tpp index 7615d66..9c72241 100644 --- a/cml/quaternion/conjugate_node.tpp +++ b/cml/quaternion/conjugate_node.tpp @@ -22,12 +22,10 @@ conjugate_node::conjugate_node(node_type&& other) : m_sub(std::move(other.m_sub)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template conjugate_node::conjugate_node(const node_type& other) : m_sub(other.m_sub) {} -#endif /* Internal methods: */ diff --git a/cml/quaternion/fixed_compiled.h b/cml/quaternion/fixed_compiled.h index 174a690..c8a3eb4 100644 --- a/cml/quaternion/fixed_compiled.h +++ b/cml/quaternion/fixed_compiled.h @@ -70,9 +70,7 @@ class quaternion, Order, Cross> using writable_type::X; using writable_type::Y; using writable_type::Z; -#ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS using writable_type::operator=; -#endif public: @@ -85,9 +83,9 @@ class quaternion, Order, Cross> public: /** Compiler-default constructor. - * - * @note The quaternion elements are uninitialized. - */ + * + * @note The quaternion elements are uninitialized. + */ quaternion() = default; /** Compiler-default destructor. */ @@ -96,19 +94,17 @@ class quaternion, Order, Cross> /** Compiler-default copy constructor. */ quaternion(const quaternion_type& other) = default; -#ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR /** Compiler-default move constructor. */ quaternion(quaternion_type&& other) = default; -#endif /** Construct from a readable_quaternion. */ template quaternion(const readable_quaternion& sub); /** Construct from 4 values. - * - * @note This overload is enabled only if all of the arguments are - * convertible to value_type. - */ + * + * @note This overload is enabled only if all of the arguments are + * convertible to value_type. + */ template* = nullptr> quaternion(const E0& e0, const E1& e1, const E2& e2, const E3& e3) @@ -119,13 +115,13 @@ class quaternion, Order, Cross> } /** Construct from a 3D readable_vector and one additional element. - * - * @note Although the imaginary part is specified first, the proper - * coefficient order is maintained. - * - * @note This overload is enabled only if the value_type of @c sub and - * the scalar argument are convertible to value_type. - */ + * + * @note Although the imaginary part is specified first, the proper + * coefficient order is maintained. + * + * @note This overload is enabled only if the value_type of @c sub and + * the scalar argument are convertible to value_type. + */ template, E0>* = nullptr> @@ -137,13 +133,13 @@ class quaternion, Order, Cross> } /** Construct from one additional element and a 3D readable_vector. - * - * @note Although the imaginary part is specified second, the proper - * coefficient order is maintained. - * - * @note This overload is enabled only if the value_type of @c sub and - * the scalar argument are convertible to value_type. - */ + * + * @note Although the imaginary part is specified second, the proper + * coefficient order is maintained. + * + * @note This overload is enabled only if the value_type of @c sub and + * the scalar argument are convertible to value_type. + */ template, E0>* = nullptr> @@ -155,18 +151,18 @@ class quaternion, Order, Cross> } /** Construct from a 3-element array and one additional element. - * - * @note Although the imaginary part is specified first, the proper - * coefficient order is maintained. - */ + * + * @note Although the imaginary part is specified first, the proper + * coefficient order is maintained. + */ template* = nullptr> quaternion(const Array& array, const E1& e1); /** Construct from one additional element and a 3-element array. - * - * @note Although the imaginary part is specified second, the proper - * coefficient order is maintained. - */ + * + * @note Although the imaginary part is specified second, the proper + * coefficient order is maintained. + */ template* = nullptr> quaternion(const E0& e0, const Array& array); @@ -206,26 +202,6 @@ class quaternion, Order, Cross> /** Move assignment. */ quaternion_type& operator=(quaternion_type&& other); -#ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - quaternion_type& operator=(const readable_quaternion& other) - { - return this->assign(other); - } - - template* = nullptr> - quaternion_type& operator=(const Array& array) - { - return this->assign(array); - } - - template - quaternion_type& operator=(std::initializer_list l) - { - return this->assign(l); - } -#endif - protected: /** @name readable_quaternion Interface */ @@ -249,12 +225,10 @@ class quaternion, Order, Cross> mutable_value i_get(int i); /** Set element @c i. */ - template quaternion_type& i_put(int i, const Other& v) __CML_REF; + template quaternion_type& i_put(int i, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i on a temporary. */ template quaternion_type&& i_put(int i, const Other& v) &&; -#endif /*@}*/ diff --git a/cml/quaternion/fixed_compiled.tpp b/cml/quaternion/fixed_compiled.tpp index fdd91e3..119e7ec 100644 --- a/cml/quaternion/fixed_compiled.tpp +++ b/cml/quaternion/fixed_compiled.tpp @@ -133,13 +133,12 @@ template template auto quaternion, O, C>::i_put(int i, - const Other& v) __CML_REF->quaternion_type& + const Other& v) &->quaternion_type& { this->m_data[i] = value_type(v); return *this; } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template auto @@ -149,6 +148,5 @@ quaternion, O, C>::i_put(int i, this->m_data[i] = value_type(v); return (quaternion_type&&) *this; } -#endif } // namespace cml \ No newline at end of file diff --git a/cml/quaternion/imaginary_node.h b/cml/quaternion/imaginary_node.h index 9b3edfe..824e1f3 100644 --- a/cml/quaternion/imaginary_node.h +++ b/cml/quaternion/imaginary_node.h @@ -68,17 +68,15 @@ class imaginary_node : public readable_vector> public: /** Construct from the wrapped quaternion expression. @c sub must be - * an lvalue reference or rvalue reference. - */ + * an lvalue reference or rvalue reference. + */ explicit imaginary_node(Sub sub); /** Move constructor. */ imaginary_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ imaginary_node(const node_type& other); -#endif protected: @@ -98,22 +96,17 @@ class imaginary_node : public readable_vector> protected: /** The type used to store the subexpression. The expression is stored - * as a copy if Sub is an rvalue reference (temporary), or by const - * reference if Sub is an lvalue reference. - */ - using wrap_type = cml::if_t::value, const sub_type&, - sub_type>; + * as a copy if Sub is an rvalue reference (temporary), or by const + * reference if Sub is an lvalue reference. + */ + using wrap_type = + cml::if_t::value, const sub_type&, sub_type>; /** The wrapped subexpression. */ wrap_type m_sub; private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - imaginary_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/quaternion/imaginary_node.tpp b/cml/quaternion/imaginary_node.tpp index d6d8880..b385bb9 100644 --- a/cml/quaternion/imaginary_node.tpp +++ b/cml/quaternion/imaginary_node.tpp @@ -22,13 +22,10 @@ imaginary_node::imaginary_node(node_type&& other) : m_sub(std::move(other.m_sub)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template imaginary_node::imaginary_node(const node_type& other) : m_sub(other.m_sub) {} -#endif - /* Internal methods: */ @@ -50,4 +47,4 @@ imaginary_node::i_get(int i) const -> immutable_value /* Note: X is either 0 (imaginary_first) or 1 (real_first). */ } -} // namespace cml \ No newline at end of file +} // namespace cml diff --git a/cml/quaternion/inverse_node.h b/cml/quaternion/inverse_node.h index 47d292a..eaced90 100644 --- a/cml/quaternion/inverse_node.h +++ b/cml/quaternion/inverse_node.h @@ -59,17 +59,15 @@ class inverse_node : public readable_quaternion> public: /** Construct from the wrapped quaternion expression. @c sub must be - * an lvalue reference or rvalue reference. - */ + * an lvalue reference or rvalue reference. + */ explicit inverse_node(Sub sub); /** Move constructor. */ inverse_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ inverse_node(const node_type& other); -#endif protected: @@ -86,11 +84,11 @@ class inverse_node : public readable_quaternion> protected: /** The type used to store the subexpression. The expression is stored - * as a copy if Sub is an rvalue reference (temporary), or by const - * reference if Sub is an lvalue reference. - */ - using wrap_type = cml::if_t::value, const sub_type&, - sub_type>; + * as a copy if Sub is an rvalue reference (temporary), or by const + * reference if Sub is an lvalue reference. + */ + using wrap_type = + cml::if_t::value, const sub_type&, sub_type>; /** The wrapped subexpression. */ wrap_type m_sub; @@ -100,11 +98,6 @@ class inverse_node : public readable_quaternion> private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - inverse_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/quaternion/inverse_node.tpp b/cml/quaternion/inverse_node.tpp index b09ccf7..7ec0884 100644 --- a/cml/quaternion/inverse_node.tpp +++ b/cml/quaternion/inverse_node.tpp @@ -24,14 +24,11 @@ inverse_node::inverse_node(node_type&& other) , m_inv_norm(std::move(other.m_inv_norm)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template inverse_node::inverse_node(const node_type& other) : m_sub(other.m_sub) , m_inv_norm(other.m_inv_norm) {} -#endif - /* Internal methods: */ @@ -47,4 +44,4 @@ inverse_node::i_get(int i) const -> immutable_value /* Note: W is either 0 (inverse_first) or 3 (real_first). */ } -} // namespace cml \ No newline at end of file +} // namespace cml diff --git a/cml/quaternion/readable_quaternion.h b/cml/quaternion/readable_quaternion.h index caa6675..15c8d62 100644 --- a/cml/quaternion/readable_quaternion.h +++ b/cml/quaternion/readable_quaternion.h @@ -4,7 +4,6 @@ #pragma once -#include #include #include @@ -78,7 +77,6 @@ template class readable_quaternion /** Return the real part of the quaternion. */ immutable_value real() const; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Return the imaginary part of the quaternion as a vector expression. */ imaginary_node imaginary() const&; @@ -87,10 +85,6 @@ template class readable_quaternion * moving the source into the node. */ imaginary_node imaginary() const&&; -#else - /** Return the imaginary part of the quaternion as a vector expression. */ - imaginary_node imaginary() const; -#endif /** Return the squared length of the quaternion. */ value_type length_squared() const; @@ -101,7 +95,6 @@ template class readable_quaternion /** Return the Cayley norm of the quaternion. */ value_type norm() const; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Return the normalized quaternion as an expression node. */ quaternion_scalar_node> @@ -113,14 +106,7 @@ template class readable_quaternion quaternion_scalar_node> normalize() const&&; -#else - /** Return the normalized quaternion as an expression node. */ - quaternion_scalar_node> - normalize() const; -#endif -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Return the conjugate as an expression node. */ conjugate_node conjugate() const&; @@ -128,12 +114,7 @@ template class readable_quaternion * the node. */ conjugate_node conjugate() const&&; -#else - /** Return the conjugate as an expression node. */ - conjugate_node conjugate() const; -#endif -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Return the inverse as an expression node. */ inverse_node inverse() const&; @@ -141,10 +122,6 @@ template class readable_quaternion * the node. */ inverse_node inverse() const&&; -#else - /** Return the inverse as an expression node. */ - inverse_node inverse() const; -#endif protected: @@ -154,10 +131,8 @@ template class readable_quaternion // Use the compiler-generated copy constructor: readable_quaternion(const readable_quaternion&) = default; -#ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR // Use the compiler-generated move constructor: readable_quaternion(readable_quaternion&&) = default; -#endif }; } // namespace cml diff --git a/cml/quaternion/readable_quaternion.tpp b/cml/quaternion/readable_quaternion.tpp index be6badf..47ec69e 100644 --- a/cml/quaternion/readable_quaternion.tpp +++ b/cml/quaternion/readable_quaternion.tpp @@ -78,7 +78,6 @@ readable_quaternion
::real() const -> immutable_value return this->get(order_type::W); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template auto readable_quaternion
::imaginary() const& -> imaginary_node @@ -92,14 +91,6 @@ readable_quaternion
::imaginary() const&& -> imaginary_node { return imaginary_node((DT&&) *this); } -#else -template -auto -readable_quaternion
::imaginary() const -> imaginary_node
-{ - return imaginary_node
((const DT&) *this); -} -#endif template auto @@ -124,7 +115,6 @@ readable_quaternion
::norm() const -> value_type return this->length_squared(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template auto readable_quaternion
::normalize() const& -> quaternion_scalar_node::normalize() const&& -> quaternion_scalar_node>((DT&&) *this, this->length()); } -#else -template -auto -readable_quaternion
::normalize() const -> quaternion_scalar_node> -{ - return quaternion_scalar_node>((const DT&) *this, - this->length()); -} -#endif -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template auto readable_quaternion
::conjugate() const& -> conjugate_node @@ -169,16 +147,7 @@ readable_quaternion
::conjugate() const&& -> conjugate_node { return conjugate_node((DT&&) *this); } -#else -template -auto -readable_quaternion
::conjugate() const -> conjugate_node
-{ - return conjugate_node
((const DT&) *this); -} -#endif -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template auto readable_quaternion
::inverse() const& -> inverse_node @@ -192,13 +161,5 @@ readable_quaternion
::inverse() const&& -> inverse_node { return inverse_node((DT&&) *this); } -#else -template -auto -readable_quaternion
::inverse() const -> inverse_node
-{ - return inverse_node
((const DT&) *this); -} -#endif -} // namespace cml \ No newline at end of file +} // namespace cml diff --git a/cml/quaternion/scalar_node.h b/cml/quaternion/scalar_node.h index 021baf1..fd8fc53 100644 --- a/cml/quaternion/scalar_node.h +++ b/cml/quaternion/scalar_node.h @@ -70,17 +70,15 @@ class quaternion_scalar_node public: /** Construct from the wrapped sub-expression and the scalar to apply. - * @c left must be an lvalue reference or rvalue reference. - */ + * @c left must be an lvalue reference or rvalue reference. + */ quaternion_scalar_node(Sub left, const right_type& right); /** Move constructor. */ quaternion_scalar_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ quaternion_scalar_node(const node_type& other); -#endif protected: @@ -90,8 +88,8 @@ class quaternion_scalar_node friend readable_type; /** Apply the scalar operator to element @c i of the subexpression and - * return the result. - */ + * return the result. + */ immutable_value i_get(int i) const; /*@}*/ @@ -99,9 +97,9 @@ class quaternion_scalar_node protected: /** The type used to store the left subexpression. The expression is - * stored as a copy if Sub is an rvalue reference (temporary), or by - * const reference if Sub is an lvalue reference. - */ + * stored as a copy if Sub is an rvalue reference (temporary), or by + * const reference if Sub is an lvalue reference. + */ using left_wrap_type = cml::if_t::value, const left_type&, left_type>; @@ -115,11 +113,6 @@ class quaternion_scalar_node private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - quaternion_scalar_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/quaternion/scalar_node.tpp b/cml/quaternion/scalar_node.tpp index 3bd988d..32a2269 100644 --- a/cml/quaternion/scalar_node.tpp +++ b/cml/quaternion/scalar_node.tpp @@ -24,14 +24,12 @@ quaternion_scalar_node::quaternion_scalar_node( , m_right(std::move(other.m_right)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template quaternion_scalar_node::quaternion_scalar_node( const node_type& other) : m_left(other.m_left) , m_right(other.m_right) {} -#endif /* Internal methods: */ diff --git a/cml/quaternion/unary_node.h b/cml/quaternion/unary_node.h index 8daa228..acedd45 100644 --- a/cml/quaternion/unary_node.h +++ b/cml/quaternion/unary_node.h @@ -64,17 +64,15 @@ class quaternion_unary_node public: /** Construct from the wrapped sub-expression. @c sub must be an - * lvalue reference or rvalue reference. - */ + * lvalue reference or rvalue reference. + */ quaternion_unary_node(Sub sub); /** Move constructor. */ quaternion_unary_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ quaternion_unary_node(const node_type& other); -#endif protected: @@ -84,8 +82,8 @@ class quaternion_unary_node friend readable_type; /** Apply the unary operator to element @c i of the subexpression and - * return the result. - */ + * return the result. + */ immutable_value i_get(int i) const; /*@}*/ @@ -93,9 +91,9 @@ class quaternion_unary_node protected: /** The type used to store the subexpression. The expression is stored - * as a copy if Sub is an rvalue reference (temporary), or by const - * reference if Sub is an lvalue reference. - */ + * as a copy if Sub is an rvalue reference (temporary), or by const + * reference if Sub is an lvalue reference. + */ using sub_wrap_type = cml::if_t::value, const sub_type&, sub_type>; @@ -106,11 +104,6 @@ class quaternion_unary_node private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - quaternion_unary_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/quaternion/unary_node.tpp b/cml/quaternion/unary_node.tpp index 0edf294..4872cf8 100644 --- a/cml/quaternion/unary_node.tpp +++ b/cml/quaternion/unary_node.tpp @@ -20,12 +20,10 @@ quaternion_unary_node::quaternion_unary_node(node_type&& other) : m_sub(std::move(other.m_sub)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template quaternion_unary_node::quaternion_unary_node(const node_type& other) : m_sub(other.m_sub) {} -#endif /* Internal methods: */ diff --git a/cml/quaternion/writable_quaternion.h b/cml/quaternion/writable_quaternion.h index 41f443a..1330ba5 100644 --- a/cml/quaternion/writable_quaternion.h +++ b/cml/quaternion/writable_quaternion.h @@ -71,12 +71,10 @@ class writable_quaternion : public readable_quaternion DerivedT& actual(); /** Set element @c i. */ - template DerivedT& put(int i, const Other& v) __CML_REF; + template DerivedT& put(int i, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i on a temporary. */ template DerivedT&& put(int i, const Other& v) &&; -#endif /** Return mutable element @c i. */ mutable_value get(int i); @@ -99,265 +97,212 @@ class writable_quaternion : public readable_quaternion public: /** Set the scalar of the quaternion to @c s, and the imaginary - * vector to @c v. - * - * @note This functin is enabled only if the value_type of @c v and @c - * E are convertible to value_type. - */ + * vector to @c v. + * + * @note This functin is enabled only if the value_type of @c v and @c + * E are convertible to value_type. + */ template* = nullptr> - auto set(const readable_vector& v, const E& s) __CML_REF->enable_if_t< + auto set(const readable_vector& v, const E& s) & -> enable_if_t< are_convertible, E>::value, DerivedT&>; /** Set the scalar of the quaternion to @c s, and the imaginary - * vector to @c v. - * - * @note This functin is enabled only if the value_type of @c v and @c - * E are convertible to value_type. - */ + * vector to @c v. + * + * @note This functin is enabled only if the value_type of @c v and @c + * E are convertible to value_type. + */ template* = nullptr> - auto set(const E& s, const readable_vector& v) __CML_REF->enable_if_t< + auto set(const E& s, const readable_vector& v) & -> enable_if_t< are_convertible, E>::value, DerivedT&>; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set the scalar of the temporary quaternion to @c s, and the - * imaginary vector to @c v. - * - * @note This functin is enabled only if the value_type of @c v and @c - * E are convertible to value_type. - */ + * imaginary vector to @c v. + * + * @note This functin is enabled only if the value_type of @c v and @c + * E are convertible to value_type. + */ template* = nullptr> auto set(const readable_vector& v, const E& s) && -> enable_if_t< are_convertible, E>::value, DerivedT&&>; /** Set the scalar of the temporary quaternion to @c s, and the - * imaginary vector to @c v. - * - * @note This functin is enabled only if the value_type of @c v and @c - * E are convertible to value_type. - */ + * imaginary vector to @c v. + * + * @note This functin is enabled only if the value_type of @c v and @c + * E are convertible to value_type. + */ template* = nullptr> auto set(const E& s, const readable_vector& v) && -> enable_if_t< are_convertible, E>::value, DerivedT&&>; -#endif public: /** Divide the quaternion elements by the length of the quaternion. */ - DerivedT& normalize() __CML_REF; + DerivedT& normalize() &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Divide the quaternion elements of a temporary by the length of the - * quaternion. - */ + * quaternion. + */ DerivedT&& normalize() &&; -#endif /** Zero the quaternion elements. */ - DerivedT& zero() __CML_REF; + DerivedT& zero() &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Zero the quaternion elements of a temporary. */ DerivedT&& zero() &&; -#endif /** Set the quaternion to the identity. */ - DerivedT& identity() __CML_REF; + DerivedT& identity() &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set a temporary to the identity. */ DerivedT&& identity() &&; -#endif /** Set the quaternion to its conjugate. */ - DerivedT& conjugate() __CML_REF; + DerivedT& conjugate() &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set a temporary to its conjugate. */ DerivedT&& conjugate() &&; -#endif /** Set the quaternion to its inverse. */ - DerivedT& inverse() __CML_REF; + DerivedT& inverse() &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set a temporary to its inverse. */ DerivedT&& inverse() &&; -#endif /** Set the quaternion to its natural logarithm. - * - * @note It is up to the caller to ensure the quaternion has a usable - * non-zero length. - * - * @breaking In CML1, this function returns a temporary. Use cml::log() - * as a replacement. - */ - DerivedT& log() __CML_REF; - -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS + * + * @note It is up to the caller to ensure the quaternion has a usable + * non-zero length. + * + * @breaking In CML1, this function returns a temporary. Use cml::log() as a + * replacement. + */ + DerivedT& log() &; + /** Set a temporary to its natural logarithm. - * - * @note It is up to the caller to ensure the quaternion has a usable - * non-zero length. - * - * @breaking In CML1, this function returns a temporary. Use cml::log() - * as a replacement. - */ + * + * @note It is up to the caller to ensure the quaternion has a usable + * non-zero length. + * + * @breaking In CML1, this function returns a temporary. Use cml::log() + * as a replacement. + */ DerivedT&& log() &&; -#endif /** Set the quaternion to its exponential. - * - * @breaking In CML1, this function returns a temporary. Use cml::exp() - * as a replacement. - */ - DerivedT& exp() __CML_REF; + * + * @breaking In CML1, this function returns a temporary. Use cml::exp() + * as a replacement. + */ + DerivedT& exp() &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set a temporary to its exponential. - * - * @breaking In CML1, this function returns a temporary. Use cml::exp() - * as a replacement. - */ + * + * @breaking In CML1, this function returns a temporary. Use cml::exp() + * as a replacement. + */ DerivedT&& exp() &&; -#endif - - -#if 0 - /** Set elements to random values in the range @c[low,high]. - * - * @note Use std::srand() to seed the random number generator. - */ - DerivedT& random(const_reference low, const_reference high) __CML_REF; - -# ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - /** Set elements of a temporary to random values in the range - * @c[low,high]. - */ - DerivedT&& random(const_reference low, const_reference high) &&; -# endif -#endif public: /** Assign from a readable_quaternion. */ template - DerivedT& operator=( - const readable_quaternion& other) __CML_REF; + DerivedT& operator=(const readable_quaternion& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Assign a temporary from a readable_quaternion. */ template DerivedT&& operator=(const readable_quaternion& other) &&; -#endif /** Assign from a fixed-length array type. - * - * @throws incompatible_quaternion_size_error if @c - * array_size_of_c::value != 4. - */ + * + * @throws incompatible_quaternion_size_error if @c + * array_size_of_c::value != 4. + */ template* = nullptr> - DerivedT& operator=(const Array& array) __CML_REF; + DerivedT& operator=(const Array& array) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Assign a temporary from a fixed-length array type. - * - * @throws incompatible_quaternion_size_error if @c - * array_size_of_c::value != 4. - */ + * + * @throws incompatible_quaternion_size_error if @c + * array_size_of_c::value != 4. + */ template* = nullptr> DerivedT&& operator=(const Array& array) &&; -#endif /** Assign from initializer list. - * - * @throws incompatible_quaternion_size_error if if @c l.size() != 4. - */ - template - DerivedT& operator=(std::initializer_list l) __CML_REF; + * + * @throws incompatible_quaternion_size_error if if @c l.size() != 4. + */ + template DerivedT& operator=(std::initializer_list l) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Assign a temporary from initializer list. - * - * @throws incompatible_quaternion_size_error if if @c l.size() != 4. - */ + * + * @throws incompatible_quaternion_size_error if if @c l.size() != 4. + */ template DerivedT&& operator=(std::initializer_list l) &&; -#endif /** Modify the quaternion by addition of another quaternion. */ template - DerivedT& operator+=( - const readable_quaternion& other) __CML_REF; + DerivedT& operator+=(const readable_quaternion& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Modify a temporary quaternion by addition of another quaternion. */ template DerivedT&& operator+=(const readable_quaternion& other) &&; -#endif /** Modify the quaternion by subtraction of another quaternion. */ template - DerivedT& operator-=( - const readable_quaternion& other) __CML_REF; + DerivedT& operator-=(const readable_quaternion& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Modify a temporary quaternion by subtraction of another quaternion. */ template DerivedT&& operator-=(const readable_quaternion& other) &&; -#endif /** Modify the quaternion by multiplication of another quaternion. */ template - DerivedT& operator*=( - const readable_quaternion& other) __CML_REF; + DerivedT& operator*=(const readable_quaternion& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Modify a temporary quaternion by multiplication of another - * quaternion. - */ + * quaternion. + */ template DerivedT&& operator*=(const readable_quaternion& other) &&; -#endif /** Multiply the quaternion by a scalar convertible to its value_type. */ template::type* = nullptr> - DerivedT& operator*=(const ScalarT& v) __CML_REF; + DerivedT& operator*=(const ScalarT& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Multiply the temporary quaternion by a scalar convertible to its - * value_type. - */ + * value_type. + */ template::type* = nullptr> DerivedT&& operator*=(const ScalarT& v) &&; -#endif /** Divide the quaternion by a scalar convertible to its value_type. */ template::type* = nullptr> - DerivedT& operator/=(const ScalarT& v) __CML_REF; + DerivedT& operator/=(const ScalarT& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Divide the quaternion temporary by a scalar convertible to its - * value_type. - */ + * value_type. + */ template::type* = nullptr> DerivedT&& operator/=(const ScalarT& v) &&; -#endif protected: /** Assign from a readable_quaternion. - * - * @note This depends upon implicit conversion of the source quaternion - * elements to the quaternion value_type. - */ + * + * @note This depends upon implicit conversion of the source quaternion + * elements to the quaternion value_type. + */ template DerivedT& assign(const readable_quaternion& other); @@ -366,43 +311,43 @@ class writable_quaternion : public readable_quaternion DerivedT& assign(const readable_vector& other, const E0& e0); /** Construct from a fixed-length array of values. The assignment - * order is determined by the quaternion order. - * - * @note This depends upon implicit conversions of the elements to the - * quaternion value_type. - */ + * order is determined by the quaternion order. + * + * @note This depends upon implicit conversions of the elements to the + * quaternion value_type. + */ template* = nullptr> DerivedT& assign(const Array& array); /** Assign from a pointer to an array. - * - * @note This depends upon implicit conversion of the array elements to - * the quaternion value_type. - */ + * + * @note This depends upon implicit conversion of the array elements to + * the quaternion value_type. + */ template* = nullptr> DerivedT& assign(const Pointer& array); /** Construct from an array of 3 values and one additional element. - * The assignment order is determined by the quaternion order. - * - * @note This depends upon implicit conversions of the elements to the - * quaternion value_type. - */ + * The assignment order is determined by the quaternion order. + * + * @note This depends upon implicit conversions of the elements to the + * quaternion value_type. + */ template* = nullptr> DerivedT& assign(const Array& array, const E0& e0); /** Construct from an initializer_list. - * - * @note This depends upon implicit conversions of the elements to the - * quaternion value_type. - */ + * + * @note This depends upon implicit conversions of the elements to the + * quaternion value_type. + */ template DerivedT& assign(const std::initializer_list& l); /** Construct from a list of 4 values. - * - * @note This depends upon implicit conversions of the elements to the - * quaternion value_type. - */ + * + * @note This depends upon implicit conversions of the elements to the + * quaternion value_type. + */ template DerivedT& assign_elements(const E0& e0, const E1& e1, const E2& e2, const E3& e3); @@ -415,10 +360,8 @@ class writable_quaternion : public readable_quaternion // Use the compiler-generated copy constructor: writable_quaternion(const writable_quaternion&) = default; -#ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR // Use the compiler-generated move constructor: writable_quaternion(writable_quaternion&&) = default; -#endif // Force assignment through operator=(readable_quaternion<>): writable_quaternion& operator=(const writable_quaternion&) = delete; diff --git a/cml/quaternion/writable_quaternion.tpp b/cml/quaternion/writable_quaternion.tpp index 3dc115c..05cf0a5 100644 --- a/cml/quaternion/writable_quaternion.tpp +++ b/cml/quaternion/writable_quaternion.tpp @@ -32,12 +32,11 @@ writable_quaternion
::get(int i) -> mutable_value template template DT& -writable_quaternion
::put(int i, const Other& v) __CML_REF +writable_quaternion
::put(int i, const Other& v) & { return this->actual().i_put(i, v); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -46,7 +45,6 @@ writable_quaternion
::put(int i, const Other& v) && this->put(i, v); return (DT&&) *this; } -#endif template auto @@ -85,12 +83,11 @@ writable_quaternion
::z() -> mutable_value template DT& -writable_quaternion
::normalize() __CML_REF +writable_quaternion
::normalize() & { return this->operator/=(this->length()); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_quaternion
::normalize() && @@ -98,17 +95,15 @@ writable_quaternion
::normalize() && this->normalize(); // Forward to normalize & return (DT&&) *this; } -#endif template DT& -writable_quaternion
::zero() __CML_REF +writable_quaternion
::zero() & { for(int i = 0; i < 4; ++i) this->put(i, value_type(0)); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_quaternion
::zero() && @@ -116,11 +111,10 @@ writable_quaternion
::zero() && this->zero(); // Forward to zero & return (DT&&) *this; } -#endif template DT& -writable_quaternion
::identity() __CML_REF +writable_quaternion
::identity() & { this->put(W, value_type(1)); this->put(X, value_type(0)); @@ -129,7 +123,6 @@ writable_quaternion
::identity() __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_quaternion
::identity() && @@ -137,11 +130,10 @@ writable_quaternion
::identity() && this->identity(); // Forward to identity & return (DT&&) *this; } -#endif template DT& -writable_quaternion
::conjugate() __CML_REF +writable_quaternion
::conjugate() & { this->put(W, this->get(W)); this->put(X, -this->get(X)); @@ -150,7 +142,6 @@ writable_quaternion
::conjugate() __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_quaternion
::conjugate() && @@ -158,11 +149,10 @@ writable_quaternion
::conjugate() && this->conjugate(); // Forward to conjugate & return (DT&&) *this; } -#endif template DT& -writable_quaternion
::inverse() __CML_REF +writable_quaternion
::inverse() & { /* Cayley norm (squared length). */ auto n = this->norm(); @@ -175,7 +165,6 @@ writable_quaternion
::inverse() __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_quaternion
::inverse() && @@ -183,11 +172,10 @@ writable_quaternion
::inverse() && this->inverse(); // Forward to inverse & return (DT&&) *this; } -#endif template DT& -writable_quaternion
::log() __CML_REF +writable_quaternion
::log() & { /* Shorthand: */ using element_traits = typename traits_type::element_traits; @@ -206,7 +194,6 @@ writable_quaternion
::log() __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_quaternion
::log() && @@ -214,11 +201,10 @@ writable_quaternion
::log() && this->log(); // Forward to log & return (DT&&) *this; } -#endif template DT& -writable_quaternion
::exp() __CML_REF +writable_quaternion
::exp() & { /* Shorthand: */ using element_traits = typename traits_type::element_traits; @@ -237,7 +223,6 @@ writable_quaternion
::exp() __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_quaternion
::exp() && @@ -245,40 +230,12 @@ writable_quaternion
::exp() && this->exp(); // Forward to exp & return (DT&&) *this; } -#endif - - -#if 0 -template DT& -writable_quaternion
::random( - const_reference low, const_reference high - ) __CML_REF -{ - typedef if_t::value - , std::uniform_int_distribution - , std::uniform_real_distribution> distribution_type; - - std::default_random_engine gen(std::rand()); - distribution_type d(low, high); - for(int i = 0; i < this->size(); ++ i) this->put(i, d(gen)); - return this->actual(); -} - -# ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS -template DT&& -writable_quaternion
::random(const_reference low, const_reference high) && -{ - this->random(low, high); - return (DT&&) *this; -} -# endif -#endif template template*> auto -writable_quaternion
::set(const readable_vector& v, const E& s) - __CML_REF->enable_if_t< +writable_quaternion
:: + set(const readable_vector& v, const E& s) & -> enable_if_t< are_convertible, E>::value, DT&> { return this->assign(v, s); @@ -287,15 +244,13 @@ writable_quaternion
::set(const readable_vector& v, const E& s) template template*> auto -writable_quaternion
::set(const E& s, const readable_vector& v) - __CML_REF->enable_if_t< +writable_quaternion
:: + set(const E& s, const readable_vector& v) & -> enable_if_t< are_convertible, E>::value, DT&> { return this->assign(v, s); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - template template*> auto @@ -318,18 +273,14 @@ writable_quaternion
:: return (DT&&) *this; } -#endif - template template DT& -writable_quaternion
::operator=( - const readable_quaternion& other) __CML_REF +writable_quaternion
::operator=(const readable_quaternion& other) & { return this->assign(other); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -338,17 +289,15 @@ writable_quaternion
::operator=(const readable_quaternion& other) && this->operator=(other); return (DT&&) *this; } -#endif template template*> DT& -writable_quaternion
::operator=(const Array& array) __CML_REF +writable_quaternion
::operator=(const Array& array) & { return this->assign(array); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template*> DT&& @@ -357,17 +306,15 @@ writable_quaternion
::operator=(const Array& array) && this->operator=(array); return (DT&&) *this; } -#endif template template DT& -writable_quaternion
::operator=(std::initializer_list l) __CML_REF +writable_quaternion
::operator=(std::initializer_list l) & { return this->assign(l); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -375,13 +322,11 @@ writable_quaternion
::operator=(std::initializer_list l) && { return this->assign(l); } -#endif template template DT& -writable_quaternion
::operator+=( - const readable_quaternion& other) __CML_REF +writable_quaternion
::operator+=(const readable_quaternion& other) & { using op_type = binary_plus_t; for(int i = 0; i < 4; ++i) @@ -389,7 +334,6 @@ writable_quaternion
::operator+=( return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -398,13 +342,11 @@ writable_quaternion
::operator+=(const readable_quaternion& other) && this->operator+=(other); return (DT&&) *this; } -#endif template template DT& -writable_quaternion
::operator-=( - const readable_quaternion& other) __CML_REF +writable_quaternion
::operator-=(const readable_quaternion& other) & { using op_type = binary_minus_t; for(int i = 0; i < 4; ++i) @@ -412,7 +354,6 @@ writable_quaternion
::operator-=( return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -421,19 +362,16 @@ writable_quaternion
::operator-=(const readable_quaternion& other) && this->operator-=(other); return (DT&&) *this; } -#endif template template DT& -writable_quaternion
::operator*=( - const readable_quaternion& other) __CML_REF +writable_quaternion
::operator*=(const readable_quaternion& other) & { return this->assign((*this) * other); /* Note: operator*() returns a temporary here. */ } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -442,21 +380,19 @@ writable_quaternion
::operator*=(const readable_quaternion& other) && this->operator*=(other); return (DT&&) *this; } -#endif template template::value_type, ScalarT>::type*> DT& -writable_quaternion
::operator*=(const ScalarT& v) __CML_REF +writable_quaternion
::operator*=(const ScalarT& v) & { using op_type = binary_multiply_t; for(int i = 0; i < 4; ++i) this->put(i, op_type().apply(this->get(i), v)); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template::value_type, @@ -467,21 +403,19 @@ writable_quaternion
::operator*=(const ScalarT& v) && this->operator*=(v); return (DT&&) *this; } -#endif template template::value_type, ScalarT>::type*> DT& -writable_quaternion
::operator/=(const ScalarT& v) __CML_REF +writable_quaternion
::operator/=(const ScalarT& v) & { using op_type = binary_divide_t; for(int i = 0; i < 4; ++i) this->put(i, op_type().apply(this->get(i), v)); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template::value_type, @@ -492,8 +426,6 @@ writable_quaternion
::operator/=(const ScalarT& v) && this->operator/=(v); return (DT&&) *this; } -#endif - /* Internal methods: */ @@ -591,4 +523,4 @@ writable_quaternion
::assign_elements(const E0& e0, const E1& e1, return this->actual(); } -} // namespace cml \ No newline at end of file +} // namespace cml diff --git a/cml/scalar/traits.h b/cml/scalar/traits.h index 0df0d26..6cf6ad3 100644 --- a/cml/scalar/traits.h +++ b/cml/scalar/traits.h @@ -6,7 +6,6 @@ #include #include -#include #include #include #include diff --git a/cml/vector/binary_node.h b/cml/vector/binary_node.h index 69a85d7..03c4767 100644 --- a/cml/vector/binary_node.h +++ b/cml/vector/binary_node.h @@ -66,22 +66,20 @@ class vector_binary_node public: /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be - * lvalue reference or rvalue reference types. - * - * @throws incompatible_vector_size_error at run-time if either Sub1 or - * Sub2 is a dynamically-sized vector, and sub1.size() != sub2.size(). - * If both Sub1 and Sub2 are fixed-size expressions, then the sizes are - * checked at compile time. - */ + * lvalue reference or rvalue reference types. + * + * @throws incompatible_vector_size_error at run-time if either Sub1 or + * Sub2 is a dynamically-sized vector, and sub1.size() != sub2.size(). + * If both Sub1 and Sub2 are fixed-size expressions, then the sizes are + * checked at compile time. + */ vector_binary_node(Sub1 left, Sub2 right); /** Move constructor. */ vector_binary_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ vector_binary_node(const node_type& other); -#endif protected: @@ -94,8 +92,8 @@ class vector_binary_node int i_size() const; /** Apply the operator to element @c i of the subexpressions and return - * the result. - */ + * the result. + */ immutable_value i_get(int i) const; /*@}*/ @@ -103,16 +101,16 @@ class vector_binary_node protected: /** The type used to store the left subexpression. The expression is - * stored as a copy if Sub1 is an rvalue reference (temporary), or by - * const reference if Sub1 is an lvalue reference. - */ + * stored as a copy if Sub1 is an rvalue reference (temporary), or by + * const reference if Sub1 is an lvalue reference. + */ using left_wrap_type = cml::if_t::value, const left_type&, left_type>; /** The type used to store the right subexpression. The expression is - * stored as a copy if Sub2 is an rvalue reference (temporary), or by - * const reference if Sub2 is an lvalue reference. - */ + * stored as a copy if Sub2 is an rvalue reference (temporary), or by + * const reference if Sub2 is an lvalue reference. + */ using right_wrap_type = cml::if_t::value, const right_type&, right_type>; @@ -126,11 +124,6 @@ class vector_binary_node private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - vector_binary_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/vector/binary_node.tpp b/cml/vector/binary_node.tpp index 952eb1d..8667290 100644 --- a/cml/vector/binary_node.tpp +++ b/cml/vector/binary_node.tpp @@ -29,13 +29,11 @@ vector_binary_node::vector_binary_node(node_type&& other) , m_right(std::move(other.m_right)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template vector_binary_node::vector_binary_node(const node_type& other) : m_left(other.m_left) , m_right(other.m_right) {} -#endif /* Internal methods: */ diff --git a/cml/vector/cross_node.h b/cml/vector/cross_node.h index 1f28bd1..3baeecf 100644 --- a/cml/vector/cross_node.h +++ b/cml/vector/cross_node.h @@ -67,22 +67,20 @@ class vector_cross_node : public readable_vector> public: /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be - * lvalue reference or rvalue reference types. - * - * @throws vector_size_error at run-time if either Sub1 or Sub2 is a - * dynamically-sized vector, and sub1.size() != sub2.size() != 3. If - * both Sub1 and Sub2 are fixed-size expressions, then the sizes are - * checked at compile time. - */ + * lvalue reference or rvalue reference types. + * + * @throws vector_size_error at run-time if either Sub1 or Sub2 is a + * dynamically-sized vector, and sub1.size() != sub2.size() != 3. If + * both Sub1 and Sub2 are fixed-size expressions, then the sizes are + * checked at compile time. + */ vector_cross_node(Sub1 left, Sub2 right); /** Move constructor. */ vector_cross_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ vector_cross_node(const node_type& other); -#endif protected: @@ -95,8 +93,8 @@ class vector_cross_node : public readable_vector> int i_size() const; /** Apply the operator to element @c i of the subexpressions and return - * the result. - */ + * the result. + */ immutable_value i_get(int i) const; /*@}*/ @@ -104,16 +102,16 @@ class vector_cross_node : public readable_vector> protected: /** The type used to store the left subexpression. The expression is - * stored as a copy if Sub1 is an rvalue reference (temporary), or by - * const reference if Sub1 is an lvalue reference. - */ + * stored as a copy if Sub1 is an rvalue reference (temporary), or by + * const reference if Sub1 is an lvalue reference. + */ using left_wrap_type = cml::if_t::value, const left_type&, left_type>; /** The type used to store the right subexpression. The expression is - * stored as a copy if Sub2 is an rvalue reference (temporary), or by - * const reference if Sub2 is an lvalue reference. - */ + * stored as a copy if Sub2 is an rvalue reference (temporary), or by + * const reference if Sub2 is an lvalue reference. + */ using right_wrap_type = cml::if_t::value, const right_type&, right_type>; @@ -127,11 +125,6 @@ class vector_cross_node : public readable_vector> private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - vector_cross_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/vector/dynamic_allocated.h b/cml/vector/dynamic_allocated.h index cb184c3..efc9775 100644 --- a/cml/vector/dynamic_allocated.h +++ b/cml/vector/dynamic_allocated.h @@ -73,9 +73,7 @@ class vector> public: /* Include methods from writable_type: */ using writable_type::operator[]; -#ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS using writable_type::operator=; -#endif public: @@ -85,15 +83,15 @@ class vector> public: /** Default constructor. - * - * @note The vector has no elements. - */ + * + * @note The vector has no elements. + */ vector(); /** Construct given a size. - * - * @throws std::invalid_argument if @c size < 0. - */ + * + * @throws std::invalid_argument if @c size < 0. + */ template::value>* = nullptr> explicit vector(Int size); @@ -107,11 +105,11 @@ class vector> template vector(const readable_vector& sub); /** Construct from at least 1 value. The vector is resized to - * accomodate the number of elements passed. - * - * @note This overload is enabled only if all of the arguments are - * convertible to value_type. - */ + * accomodate the number of elements passed. + * + * @note This overload is enabled only if all of the arguments are + * convertible to value_type. + */ template* = nullptr> vector(const E0& e0, const Elements&... eN) @@ -124,12 +122,12 @@ class vector> } /** Construct from a readable_vector and at least one - * additional element. The vector is resized to accomodate the total - * number of elements passed. - * - * @note This overload is enabled only if the value_type of @c sub and - * all of the scalar arguments are convertible to value_type. - */ + * additional element. The vector is resized to accomodate the total + * number of elements passed. + * + * @note This overload is enabled only if the value_type of @c sub and + * all of the scalar arguments are convertible to value_type. + */ template, E0, Elements...>* = nullptr> @@ -175,19 +173,19 @@ class vector> const_pointer end() const; /** Resize the vector to the specified size. - * - * @note This will reallocate the array and copy existing elements, if - * any. - * - * @throws std::invalid_argument if @c n is negative. - */ + * + * @note This will reallocate the array and copy existing elements, if + * any. + * + * @throws std::invalid_argument if @c n is negative. + */ void resize(int n); /** Resize the vector to the specified size without copying the old - * elements. - * - * @throws std::invalid_argument if @c n is negative. - */ + * elements. + * + * @throws std::invalid_argument if @c n is negative. + */ void resize_fast(int n); @@ -198,36 +196,16 @@ class vector> /** Move assignment. */ vector_type& operator=(vector_type&& other); -#ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline vector_type& operator=(const readable_vector& other) - { - return this->assign(other); - } - - template* = nullptr> - inline vector_type& operator=(const Array& array) - { - return this->assign(array); - } - - template - inline vector_type& operator=(std::initializer_list l) - { - return this->assign(l); - } -#endif - protected: /** No-op for trivially destructible elements - * (is_trivially_destructible). - */ + * (is_trivially_destructible). + */ void destruct(pointer, int, std::true_type); /** Invoke non-trivial destructors for @c n elements starting at @c - * data. - */ + * data. + */ void destruct(pointer data, int n, std::false_type); @@ -256,12 +234,10 @@ class vector> mutable_value i_get(int i); /** Set element @c i. */ - template vector_type& i_put(int i, const Other& v) __CML_REF; + template vector_type& i_put(int i, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i on a temporary. */ template vector_type&& i_put(int i, const Other& v) &&; -#endif /*@}*/ diff --git a/cml/vector/dynamic_allocated.tpp b/cml/vector/dynamic_allocated.tpp index 3beb6f0..3bd5c6f 100644 --- a/cml/vector/dynamic_allocated.tpp +++ b/cml/vector/dynamic_allocated.tpp @@ -276,13 +276,12 @@ vector>::i_get(int i) -> mutable_value template template auto -vector>::i_put(int i, const Other& v) __CML_REF->vector_type& +vector>::i_put(int i, const Other& v) &->vector_type& { this->m_data[i] = value_type(v); return *this; } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template auto @@ -291,6 +290,5 @@ vector>::i_put(int i, const Other& v) && -> vector_type&& this->m_data[i] = value_type(v); return (vector_type&&) *this; } -#endif } // namespace cml \ No newline at end of file diff --git a/cml/vector/dynamic_const_external.tpp b/cml/vector/dynamic_const_external.tpp index 71dd778..2691c17 100644 --- a/cml/vector/dynamic_const_external.tpp +++ b/cml/vector/dynamic_const_external.tpp @@ -12,13 +12,11 @@ namespace cml { /* dynamic_const_external 'structors: */ -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template vector>::vector() : m_data(0) , m_size(0) {} -#endif template vector>::vector(const_pointer data, int size) diff --git a/cml/vector/dynamic_external.h b/cml/vector/dynamic_external.h index 7952c1f..66215ce 100644 --- a/cml/vector/dynamic_external.h +++ b/cml/vector/dynamic_external.h @@ -63,9 +63,7 @@ class vector> public: /* Include methods from writable_type: */ using writable_type::operator[]; -#ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS using writable_type::operator=; -#endif public: @@ -75,26 +73,26 @@ class vector> public: /** Default construct with a null pointer and 0 size. - * - * @warning The default constructor is enabled only if the compiler - * supports rvalue references from *this. - */ + * + * @warning The default constructor is enabled only if the compiler + * supports rvalue references from *this. + */ vector(); /** Construct from the wrapped pointer and size. - * - * @note This is for CML1 compatibility. - */ + * + * @note This is for CML1 compatibility. + */ vector(pointer data, int size); /** Construct from the wrapped pointer and size. */ vector(int size, pointer data); /** Copy constructor. - * - * @warning This copy has the semantics of a raw pointer, and can lead - * to memory leaks if not used correctly. - */ + * + * @warning This copy has the semantics of a raw pointer, and can lead + * to memory leaks if not used correctly. + */ vector(const vector_type& other); /** Move constructor. */ @@ -120,34 +118,14 @@ class vector> public: /** Copy assignment. - * - * @note This copies element-by-element from @c other. - */ + * + * @note This copies element-by-element from @c other. + */ vector_type& operator=(const vector_type& other); /** Move assignment. */ vector_type& operator=(vector_type&& other); -#ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline vector_type& operator=(const readable_vector& other) - { - return this->assign(other); - } - - template* = nullptr> - inline vector_type& operator=(const Array& array) - { - return this->assign(array); - } - - template - inline vector_type& operator=(std::initializer_list l) - { - return this->assign(l); - } -#endif - protected: /** @name readable_vector Interface */ @@ -174,12 +152,10 @@ class vector> mutable_value i_get(int i); /** Set element @c i. */ - template vector_type& i_put(int i, const Other& v) __CML_REF; + template vector_type& i_put(int i, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i on a temporary. */ template vector_type&& i_put(int i, const Other& v) &&; -#endif /*@}*/ diff --git a/cml/vector/dynamic_external.tpp b/cml/vector/dynamic_external.tpp index c6d1a4e..1d75bd7 100644 --- a/cml/vector/dynamic_external.tpp +++ b/cml/vector/dynamic_external.tpp @@ -17,9 +17,6 @@ vector>::vector() : m_data(0) , m_size(0) { -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS - static_assert(false, "external vector default constructor not supported"); -#endif } template @@ -138,13 +135,12 @@ vector>::i_get(int i) -> mutable_value template template auto -vector>::i_put(int i, const Other& v) __CML_REF->vector_type& +vector>::i_put(int i, const Other& v) &->vector_type& { this->m_data[i] = value_type(v); return *this; } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template auto @@ -153,6 +149,5 @@ vector>::i_put(int i, const Other& v) && -> vector_type&& this->m_data[i] = value_type(v); return (vector_type&&) *this; } -#endif } // namespace cml \ No newline at end of file diff --git a/cml/vector/fixed_compiled.h b/cml/vector/fixed_compiled.h index d8efd4e..2e0acdd 100644 --- a/cml/vector/fixed_compiled.h +++ b/cml/vector/fixed_compiled.h @@ -59,9 +59,7 @@ class vector> public: /* Include methods from writable_type: */ using writable_type::operator[]; -#ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS using writable_type::operator=; -#endif public: @@ -74,9 +72,9 @@ class vector> public: /** Compiler-default constructor. - * - * @note The vector elements are uninitialized. - */ + * + * @note The vector elements are uninitialized. + */ vector() = default; /** Compiler-default destructor. */ @@ -85,19 +83,17 @@ class vector> /** Compiler-default copy constructor. */ vector(const vector_type& other) = default; -#ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR /** Compiler-default move constructor. */ vector(vector_type&& other) = default; -#endif /** Construct from a readable_vector. */ template vector(const readable_vector& sub); /** Construct from at least 1 value. - * - * @note This overload is enabled only if all of the arguments are - * convertible to value_type. - */ + * + * @note This overload is enabled only if all of the arguments are + * convertible to value_type. + */ template* = nullptr> vector(const E0& e0, const Elements&... eN) @@ -108,11 +104,11 @@ class vector> } /** Construct from a readable_vector and at least one - * additional element. - * - * @note This overload is enabled only if the value_type of @c sub and - * all of the scalar arguments are convertible to value_type. - */ + * additional element. + * + * @note This overload is enabled only if the value_type of @c sub and + * all of the scalar arguments are convertible to value_type. + */ template, E0, Elements...>* = nullptr> @@ -156,26 +152,6 @@ class vector> /** Move assignment. */ vector_type& operator=(vector_type&& other); -#ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline vector_type& operator=(const readable_vector& other) - { - return this->assign(other); - } - - template* = nullptr> - inline vector_type& operator=(const Array& array) - { - return this->assign(array); - } - - template - inline vector_type& operator=(std::initializer_list l) - { - return this->assign(l); - } -#endif - protected: /** @name readable_vector Interface */ @@ -202,12 +178,10 @@ class vector> mutable_value i_get(int i); /** Set element @c i. */ - template vector_type& i_put(int i, const Other& v) __CML_REF; + template vector_type& i_put(int i, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i on a temporary. */ template vector_type&& i_put(int i, const Other& v) &&; -#endif /*@}*/ @@ -219,7 +193,6 @@ class vector> } // namespace cml -#ifdef CML_HAS_STRUCTURED_BINDINGS template struct std::tuple_size>> { @@ -231,7 +204,6 @@ struct std::tuple_element>> { using type = cml::value_type_of_t>>; }; -#endif #define __CML_VECTOR_FIXED_COMPILED_TPP #include diff --git a/cml/vector/fixed_compiled.tpp b/cml/vector/fixed_compiled.tpp index 04c6f8d..ea42f23 100644 --- a/cml/vector/fixed_compiled.tpp +++ b/cml/vector/fixed_compiled.tpp @@ -113,13 +113,12 @@ vector>::i_get(int i) -> mutable_value template template auto -vector>::i_put(int i, const Other& v) __CML_REF->vector_type& +vector>::i_put(int i, const Other& v) &->vector_type& { this->m_data[i] = value_type(v); return *this; } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template auto @@ -128,6 +127,5 @@ vector>::i_put(int i, const Other& v) && -> vector_type&& this->m_data[i] = value_type(v); return (vector_type&&) *this; } -#endif } // namespace cml \ No newline at end of file diff --git a/cml/vector/fixed_const_external.tpp b/cml/vector/fixed_const_external.tpp index 89ab611..7fe787b 100644 --- a/cml/vector/fixed_const_external.tpp +++ b/cml/vector/fixed_const_external.tpp @@ -10,12 +10,10 @@ namespace cml { /* fixed_external 'structors: */ -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template vector>::vector() : m_data(0) {} -#endif template vector>::vector(const_pointer data) diff --git a/cml/vector/fixed_external.h b/cml/vector/fixed_external.h index 0dec1e0..b26cf01 100644 --- a/cml/vector/fixed_external.h +++ b/cml/vector/fixed_external.h @@ -64,9 +64,7 @@ class vector> public: /* Include methods from writable_type: */ using writable_type::operator[]; -#ifndef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS using writable_type::operator=; -#endif public: @@ -85,10 +83,10 @@ class vector> explicit vector(pointer data); /** Copy constructor. - * - * @warning This copy has the semantics of a raw pointer, and can lead - * to memory leaks if not used correctly. - */ + * + * @warning This copy has the semantics of a raw pointer, and can lead + * to memory leaks if not used correctly. + */ vector(const vector_type& other); /** Move constructor. */ @@ -111,35 +109,15 @@ class vector> public: /** Copy assignment. - * - * @warning This assignment has the semantics of a raw pointer, and can - * lead to memory leaks if not used correctly. - */ + * + * @warning This assignment has the semantics of a raw pointer, and can + * lead to memory leaks if not used correctly. + */ vector_type& operator=(const vector_type& other); /** Move assignment. */ vector_type& operator=(vector_type&& other); -#ifdef CML_HAS_MSVC_BRAIN_DEAD_ASSIGNMENT_OVERLOADS - template - inline vector_type& operator=(const readable_vector& other) - { - return this->assign(other); - } - - template* = nullptr> - inline vector_type& operator=(const Array& array) - { - return this->assign(array); - } - - template - inline vector_type& operator=(std::initializer_list l) - { - return this->assign(l); - } -#endif - protected: /** @name readable_vector Interface */ @@ -166,12 +144,10 @@ class vector> mutable_value i_get(int i); /** Set element @c i. */ - template vector_type& i_put(int i, const Other& v) __CML_REF; + template vector_type& i_put(int i, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i on a temporary. */ template vector_type&& i_put(int i, const Other& v) &&; -#endif /*@}*/ @@ -183,7 +159,6 @@ class vector> } // namespace cml -#ifdef CML_HAS_STRUCTURED_BINDINGS template struct std::tuple_size>> { @@ -195,7 +170,6 @@ struct std::tuple_element>> { using type = cml::value_type_of_t>>; }; -#endif #define __CML_VECTOR_FIXED_EXTERNAL_TPP #include diff --git a/cml/vector/fixed_external.tpp b/cml/vector/fixed_external.tpp index 8a3a351..eaba87f 100644 --- a/cml/vector/fixed_external.tpp +++ b/cml/vector/fixed_external.tpp @@ -108,13 +108,12 @@ vector>::i_get(int i) -> mutable_value template template auto -vector>::i_put(int i, const Other& v) __CML_REF->vector_type& +vector>::i_put(int i, const Other& v) &->vector_type& { this->m_data[i] = value_type(v); return *this; } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template auto @@ -123,6 +122,5 @@ vector>::i_put(int i, const Other& v) && -> vector_type&& this->m_data[i] = value_type(v); return (vector_type&&) *this; } -#endif } // namespace cml \ No newline at end of file diff --git a/cml/vector/outer_product_node.h b/cml/vector/outer_product_node.h index 88b49a0..15abd77 100644 --- a/cml/vector/outer_product_node.h +++ b/cml/vector/outer_product_node.h @@ -97,22 +97,20 @@ class outer_product_node public: /** Construct from the wrapped sub-expressions. Sub1 and Sub2 must be - * lvalue reference or rvalue reference types. - * - * @throws incompatible_matrix_sizes at run-time if either Sub1 or Sub2 - * is a dynamically-sized matrix, and sub1.size() != sub2.size(). If - * both Sub1 and Sub2 are fixed-size expressions, then the sizes are - * checked at compile time. - */ + * lvalue reference or rvalue reference types. + * + * @throws incompatible_matrix_sizes at run-time if either Sub1 or Sub2 + * is a dynamically-sized matrix, and sub1.size() != sub2.size(). If + * both Sub1 and Sub2 are fixed-size expressions, then the sizes are + * checked at compile time. + */ outer_product_node(Sub1 left, Sub2 right); /** Move constructor. */ outer_product_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ outer_product_node(const node_type& other); -#endif protected: /** @name readable_matrix Interface */ @@ -127,8 +125,8 @@ class outer_product_node int i_cols() const; /** Apply the operator to element @c (i,j) of the subexpressions and - * return the result. - */ + * return the result. + */ immutable_value i_get(int i, int j) const; /*@}*/ @@ -136,16 +134,16 @@ class outer_product_node protected: /** The type used to store the left subexpression. The expression is - * stored as a copy if Sub1 is an rvalue reference (temporary), or by - * const reference if Sub1 is an lvalue reference. - */ + * stored as a copy if Sub1 is an rvalue reference (temporary), or by + * const reference if Sub1 is an lvalue reference. + */ using left_wrap_type = cml::if_t::value, const left_type&, left_type>; /** The type used to store the right subexpression. The expression is - * stored as a copy if Sub2 is an rvalue reference (temporary), or by - * const reference if Sub2 is an lvalue reference. - */ + * stored as a copy if Sub2 is an rvalue reference (temporary), or by + * const reference if Sub2 is an lvalue reference. + */ using right_wrap_type = cml::if_t::value, const right_type&, right_type>; @@ -159,11 +157,6 @@ class outer_product_node private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - outer_product_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/vector/outer_product_node.tpp b/cml/vector/outer_product_node.tpp index 5efe53b..04c2aac 100644 --- a/cml/vector/outer_product_node.tpp +++ b/cml/vector/outer_product_node.tpp @@ -22,13 +22,11 @@ outer_product_node::outer_product_node(node_type&& other) , m_right(std::move(other.m_right)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template outer_product_node::outer_product_node(const node_type& other) : m_left(other.m_left) , m_right(other.m_right) {} -#endif /* Internal methods: */ diff --git a/cml/vector/readable_vector.h b/cml/vector/readable_vector.h index 45b4a75..5148f22 100644 --- a/cml/vector/readable_vector.h +++ b/cml/vector/readable_vector.h @@ -4,7 +4,6 @@ #pragma once -#include #include #include @@ -57,12 +56,10 @@ template class readable_vector /** Return const element @c i. */ immutable_value get(int i) const; -#ifdef CML_HAS_STRUCTURED_BINDINGS /** Return const element @c i. */ template>* = nullptr> immutable_value get() const; -#endif /** Return const element @c i. */ immutable_value operator[](int i) const; @@ -75,7 +72,6 @@ template class readable_vector /** Return the length of the vector. */ value_type length() const; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Return the normalized vector as an expression node. */ vector_scalar_node> @@ -87,14 +83,7 @@ template class readable_vector vector_scalar_node> normalize() const&&; -#else - /** Return the normalized vector as an expression node. */ - vector_scalar_node> - normalize() const; -#endif -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Return subvector @c i as an expression node. */ subvector_node subvector(int i) const&; @@ -102,10 +91,6 @@ template class readable_vector * into the node. */ subvector_node subvector(int i) const&&; -#else - /** Return subvector @c i as an expression node. */ - subvector_node subvector(int i) const; -#endif protected: @@ -115,10 +100,8 @@ template class readable_vector // Use the compiler-generated copy constructor: readable_vector(const readable_vector&) = default; -#ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR // Use the compiler-generated move constructor: readable_vector(readable_vector&&) = default; -#endif }; } // namespace cml diff --git a/cml/vector/readable_vector.tpp b/cml/vector/readable_vector.tpp index c93ba80..38edcd9 100644 --- a/cml/vector/readable_vector.tpp +++ b/cml/vector/readable_vector.tpp @@ -37,7 +37,6 @@ readable_vector
::get(int i) const -> immutable_value return this->actual().i_get(i); } -#ifdef CML_HAS_STRUCTURED_BINDINGS template template>*> auto @@ -45,7 +44,6 @@ readable_vector
::get() const -> immutable_value { return this->actual().i_get(I); } -#endif template auto @@ -71,7 +69,6 @@ readable_vector
::length() const -> value_type return element_traits::sqrt(this->length_squared()); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template auto readable_vector
::normalize() const& -> vector_scalar_node::normalize() const&& -> vector_scalar_node>((DT&&) *this, this->length()); } -#else -template -auto -readable_vector
::normalize() const -> vector_scalar_node> -{ - return vector_scalar_node>((const DT&) *this, - this->length()); -} -#endif -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template auto readable_vector
::subvector(int i) const& -> subvector_node @@ -116,13 +101,5 @@ readable_vector
::subvector(int i) const&& -> subvector_node { return subvector_node((DT&&) *this, i); } -#else -template -auto -readable_vector
::subvector(int i) const -> subvector_node
-{ - return subvector_node
((const DT&) *this, i); -} -#endif } // namespace cml \ No newline at end of file diff --git a/cml/vector/scalar_node.h b/cml/vector/scalar_node.h index 2599b25..9d8854d 100644 --- a/cml/vector/scalar_node.h +++ b/cml/vector/scalar_node.h @@ -60,17 +60,15 @@ class vector_scalar_node public: /** Construct from the wrapped sub-expression and the scalar to apply. - * @c left must be an lvalue reference or rvalue reference. - */ + * @c left must be an lvalue reference or rvalue reference. + */ vector_scalar_node(Sub left, const right_type& right); /** Move constructor. */ vector_scalar_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ vector_scalar_node(const node_type& other); -#endif protected: @@ -83,8 +81,8 @@ class vector_scalar_node int i_size() const; /** Apply the scalar operator to element @c i of the subexpression and - * return the result. - */ + * return the result. + */ immutable_value i_get(int i) const; /*@}*/ @@ -92,9 +90,9 @@ class vector_scalar_node protected: /** The type used to store the left subexpression. The expression is - * stored as a copy if Sub is an rvalue reference (temporary), or by - * const reference if Sub is an lvalue reference. - */ + * stored as a copy if Sub is an rvalue reference (temporary), or by + * const reference if Sub is an lvalue reference. + */ using left_wrap_type = cml::if_t::value, const left_type&, left_type>; @@ -108,11 +106,6 @@ class vector_scalar_node private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - vector_scalar_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/vector/scalar_node.tpp b/cml/vector/scalar_node.tpp index ca718ff..3259c3d 100644 --- a/cml/vector/scalar_node.tpp +++ b/cml/vector/scalar_node.tpp @@ -23,13 +23,11 @@ vector_scalar_node::vector_scalar_node(node_type&& other) , m_right(std::move(other.m_right)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template vector_scalar_node::vector_scalar_node(const node_type& other) : m_left(other.m_left) , m_right(other.m_right) {} -#endif /* Internal methods: */ diff --git a/cml/vector/subvector_node.h b/cml/vector/subvector_node.h index 78847db..6c7d297 100644 --- a/cml/vector/subvector_node.h +++ b/cml/vector/subvector_node.h @@ -69,17 +69,15 @@ class subvector_node : public readable_vector> public: /** Construct from the wrapped sub-expression and the element to drop. - * @c sub must be an lvalue reference or rvalue reference. - */ + * @c sub must be an lvalue reference or rvalue reference. + */ subvector_node(Sub sub, int skip); /** Move constructor. */ subvector_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ subvector_node(const node_type& other); -#endif protected: @@ -99,9 +97,9 @@ class subvector_node : public readable_vector> protected: /** The type used to store the subexpression. The expression is stored - * as a copy if Sub is an rvalue reference (temporary), or by const - * reference if Sub is an lvalue reference. - */ + * as a copy if Sub is an rvalue reference (temporary), or by const + * reference if Sub is an lvalue reference. + */ using wrap_type = cml::if_t::value, const sub_type&, sub_type>; @@ -113,11 +111,6 @@ class subvector_node : public readable_vector> private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - subvector_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/vector/subvector_node.tpp b/cml/vector/subvector_node.tpp index 740a28e..c4e7cb1 100644 --- a/cml/vector/subvector_node.tpp +++ b/cml/vector/subvector_node.tpp @@ -22,13 +22,11 @@ subvector_node::subvector_node(node_type&& other) , m_skip(other.m_skip) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template subvector_node::subvector_node(const node_type& other) : m_sub(other.m_sub) , m_skip(other.m_skip) {} -#endif /* Internal methods: */ diff --git a/cml/vector/unary_node.h b/cml/vector/unary_node.h index 79f0aa0..c8ea758 100644 --- a/cml/vector/unary_node.h +++ b/cml/vector/unary_node.h @@ -51,17 +51,15 @@ class vector_unary_node : public readable_vector> public: /** Construct from the wrapped sub-expression. @c sub must be an - * lvalue reference or rvalue reference. - */ + * lvalue reference or rvalue reference. + */ explicit vector_unary_node(Sub sub); /** Move constructor. */ vector_unary_node(node_type&& other); -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Copy constructor. */ vector_unary_node(const node_type& other); -#endif protected: @@ -81,9 +79,9 @@ class vector_unary_node : public readable_vector> protected: /** The type used to store the subexpression. The expression is stored - * as a copy if Sub is an rvalue reference (temporary), or by const - * reference if Sub is an lvalue reference. - */ + * as a copy if Sub is an rvalue reference (temporary), or by const + * reference if Sub is an lvalue reference. + */ using sub_wrap_type = cml::if_t::value, const sub_type&, sub_type>; @@ -92,11 +90,6 @@ class vector_unary_node : public readable_vector> private: -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - // Not copy constructible. - vector_unary_node(const node_type&); -#endif - // Not assignable. node_type& operator=(const node_type&); }; diff --git a/cml/vector/unary_node.tpp b/cml/vector/unary_node.tpp index f4ae780..340bc20 100644 --- a/cml/vector/unary_node.tpp +++ b/cml/vector/unary_node.tpp @@ -20,12 +20,10 @@ vector_unary_node::vector_unary_node(node_type&& other) : m_sub(std::move(other.m_sub)) {} -#ifndef CML_HAS_RVALUE_REFERENCE_FROM_THIS template vector_unary_node::vector_unary_node(const node_type& other) : m_sub(other.m_sub) {} -#endif /* Internal methods: */ diff --git a/cml/vector/writable_vector.h b/cml/vector/writable_vector.h index aedf2b4..9f6a531 100644 --- a/cml/vector/writable_vector.h +++ b/cml/vector/writable_vector.h @@ -59,22 +59,18 @@ class writable_vector : public readable_vector DerivedT& actual(); /** Set element @c i. */ - template DerivedT& put(int i, const Other& v) __CML_REF; + template DerivedT& put(int i, const Other& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i on a temporary. */ template DerivedT&& put(int i, const Other& v) &&; -#endif /** Return mutable element @c i. */ mutable_value get(int i); -#ifdef CML_HAS_STRUCTURED_BINDINGS /** Return const element @c i. */ template>* = nullptr> mutable_value get(); -#endif /** Return a mutable reference to element @c i. */ mutable_value operator[](int i); @@ -82,317 +78,286 @@ class writable_vector : public readable_vector public: /** Divide the vector elements by the length of the vector. */ - DerivedT& normalize() __CML_REF; + DerivedT& normalize() &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Divide the vector elements of a temporary by the length of the - * vector. - */ + * vector. + */ DerivedT&& normalize() &&; -#endif /** Zero the vector elements. */ - DerivedT& zero() __CML_REF; + DerivedT& zero() &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Zero the vector elements of a temporary. */ DerivedT&& zero() &&; -#endif /** Set element @c i to value_type(1), and the other elements to 0. */ - DerivedT& cardinal(int i) __CML_REF; + DerivedT& cardinal(int i) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set element @c i of a temporary to value_type(1), and the other - * elements to 0. - */ + * elements to 0. + */ DerivedT&& cardinal(int i) &&; -#endif /** Set the vector to the pairwise minimum elements with @c other. - * - * @throws incompatible_vector_size_error at run-time if either vector is - * dynamically-sized, and @c other.size() != this->size(). If both are - * fixed-size expressions, then the size is checked at compile time. - */ + * + * @throws incompatible_vector_size_error at run-time if either vector is + * dynamically-sized, and @c other.size() != this->size(). If both are + * fixed-size expressions, then the size is checked at compile time. + */ template - DerivedT& minimize(const readable_vector& other) __CML_REF; + DerivedT& minimize(const readable_vector& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set the temporary vector to the pairwise minimum elements with @c - * other. - * - * @throws incompatible_vector_size_error at run-time if either vector is - * dynamically-sized, and @c other.size() != this->size(). If both are - * fixed-size expressions, then the size is checked at compile time. - */ + * other. + * + * @throws incompatible_vector_size_error at run-time if either vector is + * dynamically-sized, and @c other.size() != this->size(). If both are + * fixed-size expressions, then the size is checked at compile time. + */ template DerivedT&& minimize(const readable_vector& other) &&; -#endif /** Set the vector to the pairwise minimum elements with @c other. - * - * @throws incompatible_vector_size_error at run-time if either vector is - * dynamically-sized, and @c other.size() != this->size(). If both are - * fixed-size expressions, then the size is checked at compile time. - */ + * + * @throws incompatible_vector_size_error at run-time if either vector is + * dynamically-sized, and @c other.size() != this->size(). If both are + * fixed-size expressions, then the size is checked at compile time. + */ template - DerivedT& maximize(const readable_vector& other) __CML_REF; + DerivedT& maximize(const readable_vector& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set the vector to the pairwise minimum elements with @c other. - * - * @throws incompatible_vector_size_error at run-time if either vector is - * dynamically-sized, and @c other.size() != this->size(). If both are - * fixed-size expressions, then the size is checked at compile time. - */ + * + * @throws incompatible_vector_size_error at run-time if either vector is + * dynamically-sized, and @c other.size() != this->size(). If both are + * fixed-size expressions, then the size is checked at compile time. + */ template DerivedT&& maximize(const readable_vector& other) &&; -#endif /** Set elements to random values in the range @c[low,high]. - * - * @note Use std::srand() to seed the random number generator. - */ - DerivedT& random(const_reference low, const_reference high) __CML_REF; + * + * @note Use std::srand() to seed the random number generator. + */ + DerivedT& random(const_reference low, const_reference high) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set elements of a temporary to random values in the range - * @c[low,high]. - */ + * @c[low,high]. + */ DerivedT&& random(const_reference low, const_reference high) &&; -#endif /** Set all elements to a specific value. */ - DerivedT& fill(const_reference v) __CML_REF; + DerivedT& fill(const_reference v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Set all elements of a temporary to a specific value. */ DerivedT&& fill(const_reference v) &&; -#endif public: /** Assign from a variable list of at least one value. If the vector is - * resizable, it is resized to exactly accomodate the elements of @c - * eN. If the vector is fixed-size, it must have the same length as @c - * eN. - * - * @note This overload is enabled only if all of the arguments are - * convertible to value_type. - */ + * resizable, it is resized to exactly accomodate the elements of @c + * eN. If the vector is fixed-size, it must have the same length as @c + * eN. + * + * @note This overload is enabled only if all of the arguments are + * convertible to value_type. + */ template - auto set(const E0& e0, const Elements&... eN) __CML_REF->enable_if_t< + auto set(const E0& e0, const Elements&... eN) &->enable_if_t< are_convertible::value, DerivedT&>; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Assign a temporary from a variable list of at least one value. If - * the vector is resizable, it is resized to exactly accomodate the - * elements of @c eN. If the vector is fixed-size, it must have the - * same length as @c eN. - * - * @note This overload is enabled only if all of the arguments are - * convertible to value_type. - */ + * the vector is resizable, it is resized to exactly accomodate the + * elements of @c eN. If the vector is fixed-size, it must have the + * same length as @c eN. + * + * @note This overload is enabled only if all of the arguments are + * convertible to value_type. + */ template auto set(const E0& e0, const Elements&... eN) && -> enable_if_t< are_convertible::value, DerivedT&&>; -#endif - /** Copy assignment. */ - DerivedT& operator=(const writable_vector& other) __CML_REF; + DerivedT& operator=(const writable_vector& other) &; /** Assign from a readable_vector. - * - * @throws incompatible_vector_size_error at run-time if the vector is not - * resizable, and if @c other.size() != this->size(). If both are - * fixed-size, then the size is checked at compile time. - */ + * + * @throws incompatible_vector_size_error at run-time if the vector is not + * resizable, and if @c other.size() != this->size(). If both are + * fixed-size, then the size is checked at compile time. + */ template - DerivedT& operator=(const readable_vector& other) __CML_REF; + DerivedT& operator=(const readable_vector& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Assign a temporary from a readable_vector. - * - * @throws incompatible_vector_size_error at run-time if the vector is not - * resizable, and if @c other.size() != this->size(). If both are - * fixed-size, then the size is checked at compile time. - */ + * + * @throws incompatible_vector_size_error at run-time if the vector is not + * resizable, and if @c other.size() != this->size(). If both are + * fixed-size, then the size is checked at compile time. + */ template DerivedT&& operator=(const readable_vector& other) &&; -#endif /** Assign from a fixed-length array type. - * - * @throws incompatible_vector_size_error at run-time if the vector is not - * resizable, and if @c array_size_of_c::value != - * this->size(). If both are fixed-size, then the size is checked at - * compile time. - */ + * + * @throws incompatible_vector_size_error at run-time if the vector is not + * resizable, and if @c array_size_of_c::value != + * this->size(). If both are fixed-size, then the size is checked at + * compile time. + */ template* = nullptr> - DerivedT& operator=(const Array& array) __CML_REF; + DerivedT& operator=(const Array& array) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Assign a temporary from a fixed-length array type. - * - * @throws incompatible_vector_size_error at run-time if the vector is not - * resizable, and if @c array_size_of_c::value != - * this->size(). If both are fixed-size, then the size is checked at - * compile time. - */ + * + * @throws incompatible_vector_size_error at run-time if the vector is not + * resizable, and if @c array_size_of_c::value != + * this->size(). If both are fixed-size, then the size is checked at + * compile time. + */ template* = nullptr> DerivedT&& operator=(const Array& array) &&; -#endif /** Assign from initializer list. - * - * @throws incompatible_vector_size_error if the vector is not resizable, - * and if @c l.size() != this->size(). - */ + * + * @throws incompatible_vector_size_error if the vector is not resizable, + * and if @c l.size() != this->size(). + */ template - DerivedT& operator=(std::initializer_list l) __CML_REF; + DerivedT& operator=(std::initializer_list l) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Assign a temporary from initializer list. - * - * @throws incompatible_vector_size_error if the vector is not resizable, - * and if @c l.size() != this->size(). - */ + * + * @throws incompatible_vector_size_error if the vector is not resizable, + * and if @c l.size() != this->size(). + */ template DerivedT&& operator=(std::initializer_list l) &&; -#endif /** Modify the vector by addition of another vector. - * - * @throws incompatible_vector_size_error at run-time if the vector is - * dynamically-sized, and if @c other.size() != this->size(). If both - * are fixed-size expressions, then the size is checked at compile - * time. - */ + * + * @throws incompatible_vector_size_error at run-time if the vector is + * dynamically-sized, and if @c other.size() != this->size(). If both + * are fixed-size expressions, then the size is checked at compile + * time. + */ template - DerivedT& operator+=(const readable_vector& other) __CML_REF; + DerivedT& operator+=(const readable_vector& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Modify a temporary vector by addition of another vector. - * - * @throws incompatible_vector_size_error at run-time if the vector is - * dynamically-sized, and if @c other.size() != this->size(). If both - * are fixed-size expressions, then the size is checked at compile - * time. - */ + * + * @throws incompatible_vector_size_error at run-time if the vector is + * dynamically-sized, and if @c other.size() != this->size(). If both + * are fixed-size expressions, then the size is checked at compile + * time. + */ template DerivedT&& operator+=(const readable_vector& other) &&; -#endif /** Modify the vector by subtraction of another vector. - * - * @throws incompatible_vector_size_error at run-time if the vector is - * dynamically-sized, and if @c other.size() != this->size(). If both - * are fixed-size expressions, then the size is checked at compile - * time. - */ + * + * @throws incompatible_vector_size_error at run-time if the vector is + * dynamically-sized, and if @c other.size() != this->size(). If both + * are fixed-size expressions, then the size is checked at compile + * time. + */ template - DerivedT& operator-=(const readable_vector& other) __CML_REF; + DerivedT& operator-=(const readable_vector& other) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Modify a temporary vector by subtraction of another vector. - * - * @throws incompatible_vector_size_error at run-time if the vector is - * dynamically-sized, and if @c other.size() != this->size(). If both - * are fixed-size expressions, then the size is checked at compile - * time. - */ + * + * @throws incompatible_vector_size_error at run-time if the vector is + * dynamically-sized, and if @c other.size() != this->size(). If both + * are fixed-size expressions, then the size is checked at compile + * time. + */ template DerivedT&& operator-=(const readable_vector& other) &&; -#endif /** Multiply the vector by a scalar convertible to its value_type. */ template* = nullptr> - DerivedT& operator*=(const ScalarT& v) __CML_REF; + DerivedT& operator*=(const ScalarT& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Multiply the temporary vector by a scalar convertible to its - * value_type. - */ + * value_type. + */ template* = nullptr> DerivedT&& operator*=(const ScalarT& v) &&; -#endif /** Divide the vector by a scalar convertible to its value_type. */ template* = nullptr> - DerivedT& operator/=(const ScalarT& v) __CML_REF; + DerivedT& operator/=(const ScalarT& v) &; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS /** Divide the vector temporary by a scalar convertible to its - * value_type. - */ + * value_type. + */ template* = nullptr> DerivedT&& operator/=(const ScalarT& v) &&; -#endif protected: /** Assign from a readable_vector. - * - * @note This depends upon implicit conversion of the source vector - * elements to the vector value_type. - * - * @throws incompatible_vector_size_error at run-time if the vector is not - * resizable, and if @c other.size() != this->size(). If both are - * fixed-size expressions, then the size is checked at compile time. - */ + * + * @note This depends upon implicit conversion of the source vector + * elements to the vector value_type. + * + * @throws incompatible_vector_size_error at run-time if the vector is not + * resizable, and if @c other.size() != this->size(). If both are + * fixed-size expressions, then the size is checked at compile time. + */ template DerivedT& assign(const readable_vector& other); /** Construct from a fixed-length array of values. If the vector is - * resizable, it is resized to exactly accomodate the array. If the - * vector is fixed-size, it must have the same length as @c array. - * - * @note This depends upon implicit conversions of the elements to the - * vector value_type. - */ + * resizable, it is resized to exactly accomodate the array. If the + * vector is fixed-size, it must have the same length as @c array. + * + * @note This depends upon implicit conversions of the elements to the + * vector value_type. + */ template* = nullptr> DerivedT& assign(const Array& array); /** Assign from a pointer to an array. - * - * @note This depends upon implicit conversion of the array elements to - * the vector value_type. - * - * @note The number of elements read from @c array depends upon the - * current size of the vector. - */ + * + * @note This depends upon implicit conversion of the array elements to + * the vector value_type. + * + * @note The number of elements read from @c array depends upon the + * current size of the vector. + */ template* = nullptr> DerivedT& assign(const Pointer& array); /** Construct from an initializer_list. If the vector is resizable, it - * is resized to exactly accomodate the elements of @c l. If the vector - * is fixed-size, it must have the same length as @c array. - * - * @note This depends upon implicit conversions of the elements to the - * vector value_type. - */ + * is resized to exactly accomodate the elements of @c l. If the vector + * is fixed-size, it must have the same length as @c array. + * + * @note This depends upon implicit conversions of the elements to the + * vector value_type. + */ template DerivedT& assign(const std::initializer_list& l); /** Assign from a subvector and 1 or more additional elements to - * append. - */ + * append. + */ template DerivedT& assign(const readable_vector& other, const Elements&... eN); /** Construct from a variable list of values. If the vector is - * resizable, it is resized to exactly accomodate the elements of @c - * eN. If the vector is fixed-size, it must have the same length as @c - * eN. - * - * @note This depends upon implicit conversions of the elements to the - * vector value_type. - */ + * resizable, it is resized to exactly accomodate the elements of @c + * eN. If the vector is fixed-size, it must have the same length as @c + * eN. + * + * @note This depends upon implicit conversions of the elements to the + * vector value_type. + */ template DerivedT& assign_elements(const Elements&... eN); @@ -403,10 +368,8 @@ class writable_vector : public readable_vector // Use the compiler-generated copy constructor: writable_vector(const writable_vector&) = default; -#ifdef CML_HAS_DEFAULTED_MOVE_CONSTRUCTOR // Use the compiler-generated move constructor: writable_vector(writable_vector&&) = default; -#endif }; } // namespace cml diff --git a/cml/vector/writable_vector.tpp b/cml/vector/writable_vector.tpp index 32c830c..7781a4f 100644 --- a/cml/vector/writable_vector.tpp +++ b/cml/vector/writable_vector.tpp @@ -68,7 +68,6 @@ writable_vector
::get(int i) -> mutable_value return this->actual().i_get(i); } -#ifdef CML_HAS_STRUCTURED_BINDINGS template template>*> auto @@ -76,7 +75,6 @@ writable_vector
::get() -> mutable_value { return this->actual().i_get(I); } -#endif template auto @@ -88,12 +86,11 @@ writable_vector
::operator[](int i) -> mutable_value template template DT& -writable_vector
::put(int i, const Other& v) __CML_REF +writable_vector
::put(int i, const Other& v) & { return this->actual().i_put(i, v); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -102,17 +99,15 @@ writable_vector
::put(int i, const Other& v) && this->put(i, v); // Forward to put(...) & return (DT&&) *this; } -#endif template DT& -writable_vector
::normalize() __CML_REF +writable_vector
::normalize() & { return this->operator/=(this->length()); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_vector
::normalize() && @@ -120,17 +115,15 @@ writable_vector
::normalize() && this->normalize(); // Forward to normalize & return (DT&&) *this; } -#endif template DT& -writable_vector
::zero() __CML_REF +writable_vector
::zero() & { for(int i = 0; i < this->size(); ++i) this->put(i, 0); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_vector
::zero() && @@ -138,16 +131,14 @@ writable_vector
::zero() && this->zero(); // Forward to zero & return (DT&&) *this; } -#endif template DT& -writable_vector
::cardinal(int i) __CML_REF +writable_vector
::cardinal(int i) & { return this->zero().put(i, 1); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_vector
::cardinal(int i) && @@ -155,12 +146,11 @@ writable_vector
::cardinal(int i) && this->cardinal(i); // Forward to cardinal & return (DT&&) *this; } -#endif template template DT& -writable_vector
::minimize(const readable_vector& other) __CML_REF +writable_vector
::minimize(const readable_vector& other) & { cml::check_same_size(*this, other); for(int i = 0; i < this->size(); ++i) { @@ -169,7 +159,6 @@ writable_vector
::minimize(const readable_vector& other) __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -178,12 +167,11 @@ writable_vector
::minimize(const readable_vector& other) && this->minimize(other); // Forward to minimize & return (DT&&) *this; } -#endif template template DT& -writable_vector
::maximize(const readable_vector& other) __CML_REF +writable_vector
::maximize(const readable_vector& other) & { cml::check_same_size(*this, other); for(int i = 0; i < this->size(); ++i) { @@ -192,7 +180,6 @@ writable_vector
::maximize(const readable_vector& other) __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -201,11 +188,10 @@ writable_vector
::maximize(const readable_vector& other) && this->maximize(other); // Forward to maximize & return (DT&&) *this; } -#endif template DT& -writable_vector
::random(const_reference low, const_reference high) __CML_REF +writable_vector
::random(const_reference low, const_reference high) & { using distribution_type = if_t::value, std::uniform_int_distribution, @@ -217,7 +203,6 @@ writable_vector
::random(const_reference low, const_reference high) __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_vector
::random(const_reference low, const_reference high) && @@ -225,17 +210,15 @@ writable_vector
::random(const_reference low, const_reference high) && this->random(low, high); return (DT&&) *this; } -#endif template DT& -writable_vector
::fill(const_reference v) __CML_REF +writable_vector
::fill(const_reference v) & { for(int i = 0; i < this->size(); ++i) this->put(i, v); return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template DT&& writable_vector
::fill(const_reference v) && @@ -243,18 +226,16 @@ writable_vector
::fill(const_reference v) && this->fill(v); return (DT&&) *this; } -#endif template template auto -writable_vector
::set(const E0& e0, const Es&... eN) __CML_REF +writable_vector
::set(const E0& e0, const Es&... eN) & ->enable_if_t::value, DT&> { return this->assign_elements(e0, eN...); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template auto @@ -264,11 +245,10 @@ writable_vector
::set(const E0& e0, const Es&... eN) && -> enable_if_t< this->assign_elements(e0, eN...); return (DT&&) *this; } -#endif template DT& -writable_vector
::operator=(const writable_vector& other) __CML_REF +writable_vector
::operator=(const writable_vector& other) & { return this->assign(other); } @@ -276,12 +256,11 @@ writable_vector
::operator=(const writable_vector& other) __CML_REF template template DT& -writable_vector
::operator=(const readable_vector& other) __CML_REF +writable_vector
::operator=(const readable_vector& other) & { return this->assign(other); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -290,17 +269,15 @@ writable_vector
::operator=(const readable_vector& other) && this->operator=(other); return (DT&&) *this; } -#endif template template*> DT& -writable_vector
::operator=(const Array& array) __CML_REF +writable_vector
::operator=(const Array& array) & { return this->assign(array); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template*> DT&& @@ -309,17 +286,15 @@ writable_vector
::operator=(const Array& array) && this->operator=(array); return (DT&&) *this; } -#endif template template DT& -writable_vector
::operator=(std::initializer_list l) __CML_REF +writable_vector
::operator=(std::initializer_list l) & { return this->assign(l); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -327,12 +302,11 @@ writable_vector
::operator=(std::initializer_list l) && { return this->assign(l); } -#endif template template DT& -writable_vector
::operator+=(const readable_vector& other) __CML_REF +writable_vector
::operator+=(const readable_vector& other) & { using op_type = binary_plus_t; detail::check_or_resize(*this, other); @@ -341,7 +315,6 @@ writable_vector
::operator+=(const readable_vector& other) __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -350,12 +323,11 @@ writable_vector
::operator+=(const readable_vector& other) && this->operator+=(other); return (DT&&) *this; } -#endif template template DT& -writable_vector
::operator-=(const readable_vector& other) __CML_REF +writable_vector
::operator-=(const readable_vector& other) & { using op_type = binary_minus_t; detail::check_or_resize(*this, other); @@ -364,7 +336,6 @@ writable_vector
::operator-=(const readable_vector& other) __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template DT&& @@ -373,13 +344,12 @@ writable_vector
::operator-=(const readable_vector& other) && this->operator-=(other); return (DT&&) *this; } -#endif template template::value_type, ScalarT>*> DT& -writable_vector
::operator*=(const ScalarT& v) __CML_REF +writable_vector
::operator*=(const ScalarT& v) & { using op_type = binary_multiply_t; for(int i = 0; i < this->size(); ++i) @@ -387,7 +357,6 @@ writable_vector
::operator*=(const ScalarT& v) __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template::value_type, ScalarT>*> @@ -397,13 +366,12 @@ writable_vector
::operator*=(const ScalarT& v) && this->operator*=(v); return (DT&&) *this; } -#endif template template::value_type, ScalarT>*> DT& -writable_vector
::operator/=(const ScalarT& v) __CML_REF +writable_vector
::operator/=(const ScalarT& v) & { using op_type = binary_divide_t; for(int i = 0; i < this->size(); ++i) @@ -411,7 +379,6 @@ writable_vector
::operator/=(const ScalarT& v) __CML_REF return this->actual(); } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS template template::value_type, ScalarT>*> @@ -421,8 +388,6 @@ writable_vector
::operator/=(const ScalarT& v) && this->operator/=(v); return (DT&&) *this; } -#endif - /* Internal methods: */ diff --git a/cml/version.h b/cml/version.h index 1acebab..5a4a47e 100644 --- a/cml/version.h +++ b/cml/version.h @@ -5,7 +5,7 @@ #pragma once /* Current CML version: */ -#define CML_VERSION 200202U +#define CML_VERSION 200300U /* Current CML version as a string: */ -#define CML_VERSION_STRING "2.2.2" +#define CML_VERSION_STRING "2.3.0" diff --git a/tests/common/rv_from_this1.cpp b/tests/common/rv_from_this1.cpp index e7851a9..a7a764a 100644 --- a/tests/common/rv_from_this1.cpp +++ b/tests/common/rv_from_this1.cpp @@ -4,30 +4,21 @@ #include #include -#include /* Testing headers: */ #include "catch_runner.h" struct rv_from_this { -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS rv_from_this&& mover() &&; -#endif - rv_from_this& refer() __CML_REF; + rv_from_this& refer() &; }; CATCH_TEST_CASE("rv_from_this1") { -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS CATCH_CHECK(true == (std::is_same::value)); CATCH_REQUIRE(true == (std::is_same().refer()), rv_from_this&>::value)); -#else - CATCH_REQUIRE(true - == (std::is_same().refer()), - rv_from_this&>::value)); -#endif } diff --git a/tests/matrix/matrix_scalar_node1.cpp b/tests/matrix/matrix_scalar_node1.cpp index b090d28..985999d 100644 --- a/tests/matrix/matrix_scalar_node1.cpp +++ b/tests/matrix/matrix_scalar_node1.cpp @@ -223,7 +223,6 @@ CATCH_TEST_CASE("fixed external scalar_multiply_assign1") CATCH_TEST_CASE("fixed external scalar_multiply_assign2") { -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS double aM[] = {1., 2., 3., 4.}; cml::external22d M; M = (cml::external22d(aM) *= 2.); @@ -233,9 +232,6 @@ CATCH_TEST_CASE("fixed external scalar_multiply_assign2") CATCH_CHECK(M(0, 1) == 4.); CATCH_CHECK(M(1, 0) == 6.); CATCH_CHECK(M(1, 1) == 8.); -#else - CATCH_WARN("Assignment to temporary external vectors not supported"); -#endif } CATCH_TEST_CASE("fixed external scalar_divide_assign1") @@ -254,7 +250,6 @@ CATCH_TEST_CASE("fixed external scalar_divide_assign1") CATCH_TEST_CASE("fixed external scalar_divide_assign2") { -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS double aM[] = {2., 4., 6., 8.}; cml::external22d M; M = (cml::external22d(aM) /= 2.); @@ -264,9 +259,6 @@ CATCH_TEST_CASE("fixed external scalar_divide_assign2") CATCH_CHECK(M(0, 1) == 2.); CATCH_CHECK(M(1, 0) == 3.); CATCH_CHECK(M(1, 1) == 4.); -#else - CATCH_WARN("Assignment to temporary external vectors not supported"); -#endif } CATCH_TEST_CASE("dynamic external scalar_multiply1") @@ -319,7 +311,6 @@ CATCH_TEST_CASE("dynamic external scalar_multiply_assign1") CATCH_TEST_CASE("dynamic external scalar_multiply_assign2") { -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS double aM[] = {1., 2., 3., 4.}; cml::externalmnd M; M = (cml::externalmnd(aM, 2, 2) *= 2.); @@ -329,9 +320,6 @@ CATCH_TEST_CASE("dynamic external scalar_multiply_assign2") CATCH_CHECK(M(0, 1) == 4.); CATCH_CHECK(M(1, 0) == 6.); CATCH_CHECK(M(1, 1) == 8.); -#else - CATCH_WARN("Assignment to temporary external vectors not supported"); -#endif } CATCH_TEST_CASE("dynamic external scalar_divide_assign1") @@ -350,7 +338,6 @@ CATCH_TEST_CASE("dynamic external scalar_divide_assign1") CATCH_TEST_CASE("dynamic external scalar_divide_assign2") { -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS double aM[] = {2., 4., 6., 8.}; cml::externalmnd M; M = (cml::externalmnd(2, 2, aM) /= 2.); @@ -360,9 +347,6 @@ CATCH_TEST_CASE("dynamic external scalar_divide_assign2") CATCH_CHECK(M(0, 1) == 2.); CATCH_CHECK(M(1, 0) == 3.); CATCH_CHECK(M(1, 1) == 4.); -#else - CATCH_WARN("Assignment to temporary external vectors not supported"); -#endif } CATCH_TEST_CASE("dynamic scalar_multiply1") diff --git a/tests/vector/fixed_compiled_vector1.cpp b/tests/vector/fixed_compiled_vector1.cpp index 54455ae..c7077e2 100644 --- a/tests/vector/fixed_compiled_vector1.cpp +++ b/tests/vector/fixed_compiled_vector1.cpp @@ -196,7 +196,6 @@ CATCH_TEST_CASE("size_check1") cml::incompatible_vector_size_error); } -#ifdef CML_HAS_STRUCTURED_BINDINGS CATCH_TEST_CASE("structured_binding1") { auto [x, y, z] = cml::vector3d(1., 2., 3.); @@ -204,4 +203,3 @@ CATCH_TEST_CASE("structured_binding1") CATCH_CHECK(y == 2.); CATCH_CHECK(z == 3.); } -#endif diff --git a/tests/vector/fixed_external_vector1.cpp b/tests/vector/fixed_external_vector1.cpp index 3023154..4ad3409 100644 --- a/tests/vector/fixed_external_vector1.cpp +++ b/tests/vector/fixed_external_vector1.cpp @@ -76,7 +76,6 @@ CATCH_TEST_CASE("const1") CATCH_REQUIRE(v.size() == 3); } -#ifdef CML_HAS_STRUCTURED_BINDINGS CATCH_TEST_CASE("structured_binding1") { double data[] = {1., 2., 3.}; @@ -85,4 +84,3 @@ CATCH_TEST_CASE("structured_binding1") CATCH_CHECK(y == 2.); CATCH_CHECK(z == 3.); } -#endif diff --git a/tests/vector/subvector1.cpp b/tests/vector/subvector1.cpp index dfdd982..04c954f 100644 --- a/tests/vector/subvector1.cpp +++ b/tests/vector/subvector1.cpp @@ -204,8 +204,6 @@ CATCH_TEST_CASE("dynamic const external, sub3") } -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - CATCH_TEST_CASE("rv from this1, sub1") { using node_type = decltype(cml::vector3d().subvector(0)); @@ -230,36 +228,3 @@ CATCH_TEST_CASE("rv from this1, sub2") CATCH_CHECK(xpr[0] == 2.); CATCH_CHECK(xpr[1] == 3.); } - -#else - -CATCH_TEST_CASE("rv from this1, sub1") -{ - typedef cml::vector3d vector3_t; - typedef decltype(vector3_t().subvector(0)) node_type; - - CATCH_CHECK((std::is_same::value)); - - auto xpr = vector3_t(1., 2., 3.).subvector(0); - CATCH_REQUIRE(cml::int_c::value == 2); - CATCH_REQUIRE(xpr.size() == 2); - CATCH_CHECK(xpr[0] == 2.); - CATCH_CHECK(xpr[1] == 3.); -} - -CATCH_TEST_CASE("rv from this1, sub2") -{ - typedef cml::vector3d vector3_t; - vector3_t v1 = {1., 2., 3.}; - typedef decltype(v1.subvector(0)) node_type; - - CATCH_CHECK((std::is_same::value)); - - auto xpr = v1.subvector(0); - CATCH_REQUIRE(cml::int_c::value == 2); - CATCH_REQUIRE(xpr.size() == 2); - CATCH_CHECK(xpr[0] == 2.); - CATCH_CHECK(xpr[1] == 3.); -} - -#endif diff --git a/tests/vector/vector_copy1.cpp b/tests/vector/vector_copy1.cpp index b565855..51f01c0 100644 --- a/tests/vector/vector_copy1.cpp +++ b/tests/vector/vector_copy1.cpp @@ -124,14 +124,7 @@ CATCH_TEST_CASE("fixed external, copy_assign_dynamic") CATCH_TEST_CASE("fixed external, move_assign") { cml::vector3d v = {1., 2., 3.}; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS cml::external3d w; -#else - cml::external3d w(nullptr); - // Note: this allows the test to go through, but is not recommended for - // user code on compilers that do not support rvalue references from - // this. -#endif double at[3] = {1., 2., 3.}; w = cml::external3d(at); CATCH_REQUIRE(w.data() == &at[0]); @@ -179,14 +172,7 @@ CATCH_TEST_CASE("dynamic external, copy_assign_dynamic") CATCH_TEST_CASE("dynamic external, move_assign") { cml::vector3d v = {1., 2., 3.}; -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS cml::externalnd w; -#else - cml::externalnd w(nullptr, 0); - // Note: this allows the test to go through, but is not recommended for - // user code on compilers that do not support rvalue references from - // this. -#endif double at[3] = {1., 2., 3.}; w = cml::externalnd(at, 3); CATCH_REQUIRE(w.data() == &at[0]); diff --git a/tests/vector/vector_functions1.cpp b/tests/vector/vector_functions1.cpp index 6a53b7d..4da64c6 100644 --- a/tests/vector/vector_functions1.cpp +++ b/tests/vector/vector_functions1.cpp @@ -449,9 +449,6 @@ CATCH_TEST_CASE("dynamic const external, normalize2") CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); } - -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS - CATCH_TEST_CASE("rv from this1, normalize1") { CATCH_CHECK((std::is_rvalue_reference< @@ -503,65 +500,3 @@ CATCH_TEST_CASE("rv from this1, cardinal1") CATCH_CHECK(xpr[1] == 0.); CATCH_CHECK(xpr[2] == 0.); } - -#else - -CATCH_TEST_CASE("rv from this1, normalize1") -{ - CATCH_CHECK((std::is_lvalue_reference< - decltype(cml::vector3d(1., 1., 1.).normalize())>::value)); - auto xpr = cml::vector3d(1., 1., 1.).normalize(); - CATCH_CHECK((std::is_reference::value) == false); - - double l2 = xpr.length_squared(); - CATCH_CHECK(l2 == Approx(1.0).epsilon(1e-12)); -} - -CATCH_TEST_CASE("rv from this1, zero1") -{ - CATCH_CHECK((std::is_lvalue_reference< - decltype(cml::vector3d(1., 1., 1.).zero())>::value)); - auto xpr = cml::vector3d(1., 1., 1.).zero(); - CATCH_CHECK((std::is_reference::value) == false); - CATCH_CHECK(xpr[0] == 0.); - CATCH_CHECK(xpr[1] == 0.); - CATCH_CHECK(xpr[2] == 0.); - CATCH_CHECK(xpr.length() == 0.); -} - -CATCH_TEST_CASE("rv from this1, minimize1") -{ - CATCH_CHECK((std::is_lvalue_reference< - decltype(cml::vector3d(1., 1., 1.).minimize(cml::vector3d(2., 0., 3.)))>:: - value)); - auto xpr = cml::vector3d(1., 1., 1.).minimize(cml::vector3d(2., 0., 3.)); - CATCH_CHECK((std::is_reference::value) == false); - CATCH_CHECK(xpr[0] == 1.); - CATCH_CHECK(xpr[1] == 0.); - CATCH_CHECK(xpr[2] == 1.); -} - -CATCH_TEST_CASE("rv from this1, maximize1") -{ - CATCH_CHECK((std::is_lvalue_reference< - decltype(cml::vector3d(1., 1., 1.).maximize(cml::vector3d(2., 0., 3.)))>:: - value)); - auto xpr = cml::vector3d(1., 1., 1.).maximize(cml::vector3d(2., 0., 3.)); - CATCH_CHECK((std::is_reference::value) == false); - CATCH_CHECK(xpr[0] == 2.); - CATCH_CHECK(xpr[1] == 1.); - CATCH_CHECK(xpr[2] == 3.); -} - -CATCH_TEST_CASE("rv from this1, cardinal1") -{ - CATCH_CHECK( - (std::is_lvalue_reference::value)); - auto xpr = cml::vector3d().cardinal(0); - CATCH_CHECK((std::is_reference::value) == false); - CATCH_CHECK(xpr[0] == 1.); - CATCH_CHECK(xpr[1] == 0.); - CATCH_CHECK(xpr[2] == 0.); -} - -#endif diff --git a/tests/vector/vector_scalar_node1.cpp b/tests/vector/vector_scalar_node1.cpp index 2d086ac..9dd2868 100644 --- a/tests/vector/vector_scalar_node1.cpp +++ b/tests/vector/vector_scalar_node1.cpp @@ -197,7 +197,6 @@ CATCH_TEST_CASE("fixed external, scalar_multiply_assign1") CATCH_TEST_CASE("fixed external, scalar_multiply_assign2") { -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS double av1[] = {1., 2., 3.}; cml::external3d w; w = (cml::external3d(av1) *= 2); @@ -206,9 +205,6 @@ CATCH_TEST_CASE("fixed external, scalar_multiply_assign2") CATCH_CHECK(w[0] == 2.); CATCH_CHECK(w[1] == 4.); CATCH_CHECK(w[2] == 6.); -#else - CATCH_WARN("Assignment to temporary external vectors not supported"); -#endif } CATCH_TEST_CASE("fixed external, scalar_divide_assign1") @@ -224,7 +220,6 @@ CATCH_TEST_CASE("fixed external, scalar_divide_assign1") CATCH_TEST_CASE("fixed external, scalar_divide_assign2") { -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS double av1[] = {2., 4., 6.}; cml::external3d w; w = (cml::external3d(av1) /= 2); @@ -233,9 +228,6 @@ CATCH_TEST_CASE("fixed external, scalar_divide_assign2") CATCH_CHECK(w[0] == 1.); CATCH_CHECK(w[1] == 2.); CATCH_CHECK(w[2] == 3.); -#else - CATCH_WARN("Assignment to temporary external vectors not supported"); -#endif } CATCH_TEST_CASE("dynamic external, scalar_multiply1") @@ -277,7 +269,6 @@ CATCH_TEST_CASE("dynamic external, scalar_multiply_assign1") CATCH_TEST_CASE("dynamic external, scalar_multiply_assign2") { -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS double av1[] = {1., 2., 3.}; cml::externalnd w; w = (cml::externalnd(av1, 3) *= 2); @@ -286,9 +277,6 @@ CATCH_TEST_CASE("dynamic external, scalar_multiply_assign2") CATCH_CHECK(w[0] == 2.); CATCH_CHECK(w[1] == 4.); CATCH_CHECK(w[2] == 6.); -#else - CATCH_WARN("Assignment to temporary external vectors not supported"); -#endif } CATCH_TEST_CASE("dynamic external, scalar_divide_assign1") @@ -304,7 +292,6 @@ CATCH_TEST_CASE("dynamic external, scalar_divide_assign1") CATCH_TEST_CASE("dynamic external, scalar_divide_assign2") { -#ifdef CML_HAS_RVALUE_REFERENCE_FROM_THIS double av1[] = {2., 4., 6.}; cml::externalnd w; w = (cml::externalnd(av1, 3) /= 2); @@ -313,9 +300,6 @@ CATCH_TEST_CASE("dynamic external, scalar_divide_assign2") CATCH_CHECK(w[0] == 1.); CATCH_CHECK(w[1] == 2.); CATCH_CHECK(w[2] == 3.); -#else - CATCH_WARN("Assignment to temporary external vectors not supported"); -#endif } CATCH_TEST_CASE("dynamic, scalar_multiply1") From 66eee9e0ac69d32cb81472725eb2c94de32b7f66 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 21:19:27 -0500 Subject: [PATCH 14/38] Tidy up README.md --- README.md | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/README.md b/README.md index 6ae0bc9..dee1218 100644 --- a/README.md +++ b/README.md @@ -1,41 +1,26 @@ ## Configurable Math Library - For CML version 1, please see https://github.com/demianmnave/CML1. - ## License - The Configurable Math Library (CML) is released under the [Boost Software License, Version 1.0.](http://www.boost.org/LICENSE_1_0.txt). - ## Using the CML - As it is header-only, it is simple enough to copy the `cml` header directory into your project and setup your build to reference it. Users of CMake 3.15+ can also leverage [`cmake --install ...`](make.org/cmake/help/v3.15/manual/cmake.1.html#install-a-project) and [`find_package(CML CONFIG)`](https://cmake.org/cmake/help/v3.15/command/find_package.html) to integrate CML into a CMake project. - ## Compiler requirements - -At the moment, the CML requires the following compiler features (listed as CMake [`target_compile_features(...)`](https://cmake.org/cmake/help/v3.15/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html) flags here): - -- [cxx_reference_qualified_functions](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2439.htm) -- [cxx_constexpr](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2235.pdf) -- [cxx_defaulted_functions](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2346.htm) - +The CML requires a compiler with C++17 support. ## Building and Running Tests ### With plain CMake To run the test suite from a command prompt using a Makefile-like generator, start in your build directory and execute: ```bash cmake -S \ -G{generator name} -DBUILD_TESTING=On -DCMAKE_BUILD_TYPE=Release ``` - Then, to build the tests (again from your build directory): ```bash cmake --build . --config Release ``` - You can run the full test suite from your build directory by executing: ```bash ctest -C Release ``` - If you have multiple CPUs (e.g. 4 in this case), you can speed things up a bit using, for example: ```bash cmake --build . --config Release -- -j4 @@ -48,12 +33,10 @@ To see the available configure presets, execute: ```bash cmake --list-presets ``` - To see the available build presets, execute: ```bash cmake --build --list-presets ``` - To use one of the predefined configure presets, for example _cml-dev-msvc17-clangcl-mt-s_ to use the Visual Studio 2022 IDE with ClangCL: ```bash cmake --preset=cml-dev-msvc17-clangcl-mt-s From e811aea0c6a0e24a72ba46520804deca438b1e7f Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 21:28:37 -0500 Subject: [PATCH 15/38] Tidy up the CMake directory and CMakeLists.txt --- CMakeLists.txt | 39 ++++------ {CMake => cmake}/CMLBuildMacros.cmake | 101 +++++++++++++------------- {CMake => cmake}/cml-config.cmake | 0 3 files changed, 67 insertions(+), 73 deletions(-) rename {CMake => cmake}/CMLBuildMacros.cmake (67%) rename {CMake => cmake}/cml-config.cmake (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd464bc..5c7ab03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,11 @@ # @@COPYRIGHT@@ # -------------------------------------------------------------------------- +set(CML_ROOT "${CMAKE_CURRENT_LIST_DIR}") +list(APPEND CMAKE_MODULE_PATH ${CML_ROOT}/cmake) +include(CMakeDependentOption) +include(CMLBuildMacros) + # Set the minimum CMake version: cmake_minimum_required(VERSION 3.15) @@ -14,17 +19,16 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Just enable Debug and Release for multi-config generators: set(CMAKE_CONFIGURATION_TYPES "Debug;Release") -# The project name: -project(CML) - -# Path to the project source tree: -set(CML_ROOT "${CML_SOURCE_DIR}") - -# Path to project-specific configuration files: -list(APPEND CMAKE_MODULE_PATH ${CML_ROOT}/CMake) -include(CMLBuildMacros) - -include(CMakeDependentOption) +# Set the project version: +cml_version_from_file( + ${CML_ROOT}/cml/version.h # Path to version.h + "CML_VERSION" # The macro name to find + _CML_VERSION_MAJOR # Parsed major version + _CML_VERSION_MINOR # Parsed minor version + _CML_VERSION_PATCH # Parsed patch version + _CML_VERSION # String MM.mm.pp +) +project(CML VERSION ${_CML_VERSION}) if(NOT DEFINED BUILD_SHARED_LIBS) option(BUILD_SHARED_LIBS "Build shared libraries" OFF) @@ -83,17 +87,6 @@ if(NOT DEFINED CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}/lib) endif() endif() - -# Figure out which version of CML is being built by parsing CML/version.h (this -# is from the root Boost.CMake CMakeLists.txt file): -cml_version_from_file( - ${CML_ROOT}/cml/version.h # Path to version.h - "CML_VERSION" # The macro name to find - CML_VERSION_MAJOR # Parsed major version - CML_VERSION_MINOR # Parsed minor version - CML_VERSION_PATCH # Parsed patch version - CML_VERSION # String MM.mm.pp -) message(STATUS "Building CML ${CML_VERSION}") # Create the CML interface library: @@ -118,7 +111,7 @@ install(EXPORT cml-targets DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cml FILE cm install(DIRECTORY cml DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN "*") install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cml-config-version.cmake - CMake/cml-config.cmake + cmake/cml-config.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/cml ) diff --git a/CMake/CMLBuildMacros.cmake b/cmake/CMLBuildMacros.cmake similarity index 67% rename from CMake/CMLBuildMacros.cmake rename to cmake/CMLBuildMacros.cmake index 45bb066..ddbaafa 100644 --- a/CMake/CMLBuildMacros.cmake +++ b/cmake/CMLBuildMacros.cmake @@ -1,51 +1,52 @@ -# -*- cmake -*- ----------------------------------------------------------- -# @@COPYRIGHT@@ -#*------------------------------------------------------------------------- - -# Find and parse a version string from a file. The version should have the -# format: -# -# #define MMmmmpp -# or -# #define Mmmmpp -# -# The major, minor, and patch versions are stored to , -# , and . -macro(cml_version_from_file - version_file - version_macro_name - version_major - version_minor - version_patch - version_string - ) - - # Parse ${version_file} to find #define ${version_macro_name} (this is from - # the root Boost.CMake CMakeLists.txt file). The recognized version - # pattern is - # - # #define [space] Mmp[U] - # - # e.g. - # - # #define APP_VERSION_STRING 010103U - # #define APP_VERSION_STRING 10103U - # #define APP_VERSION_STRING 010103 - file(STRINGS ${version_file} _version_string REGEX - "#define[ \t]+${version_macro_name}[ \t]+[0-9]+U?$") - - # Make sure it's a real version number: - string(REGEX MATCH "[ \t]+[0-9]+" _version_string ${_version_string}) - - # Calculate the version parts: - if(_version_string) - math(EXPR ${version_major} "${_version_string} / 100000") - math(EXPR ${version_minor} "${_version_string} / 100 % 1000") - math(EXPR ${version_patch} "${_version_string} % 100") - set(${version_string} - "${${version_major}}.${${version_minor}}.${${version_patch}}") - else() - message(FATAL_ERROR - "Unable to parse the version from ${version_file}") - endif() +# *------------------------------------------------------------------------- +# @@COPYRIGHT@@ +# *------------------------------------------------------------------------- + +# Find and parse a version string from a file. The version should have the +# format: +# +# #define MMmmmpp +# or +# #define Mmmmpp +# +# The major, minor, and patch versions are stored to , +# , and . +# +# Note: this was copied from the root Boost.CMake CMakeLists.txt file. +macro(cml_version_from_file + version_file + version_macro_name + version_major + version_minor + version_patch + version_string +) + # Parse ${version_file} to find #define ${version_macro_name} (this is from + # the root Boost.CMake CMakeLists.txt file). The recognized version + # pattern is + # + # #define [space] Mmp[U] + # + # e.g. + # + # #define APP_VERSION_STRING 010103U + # #define APP_VERSION_STRING 10103U + # #define APP_VERSION_STRING 010103 + file(STRINGS ${version_file} _version_string REGEX + "#define[ \t]+${version_macro_name}[ \t]+[0-9]+U?$") + + # Make sure it's a real version number: + string(REGEX MATCH "[ \t]+[0-9]+" _version_string ${_version_string}) + + # Calculate the version parts: + if(_version_string) + math(EXPR ${version_major} "${_version_string} / 100000") + math(EXPR ${version_minor} "${_version_string} / 100 % 1000") + math(EXPR ${version_patch} "${_version_string} % 100") + set(${version_string} + "${${version_major}}.${${version_minor}}.${${version_patch}}") + else() + message(FATAL_ERROR + "Unable to parse the version from ${version_file}") + endif() endmacro() \ No newline at end of file diff --git a/CMake/cml-config.cmake b/cmake/cml-config.cmake similarity index 100% rename from CMake/cml-config.cmake rename to cmake/cml-config.cmake From 1e2da7aa6d30566bbcee26d0678dc20c7e18c64e Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 22:17:08 -0500 Subject: [PATCH 16/38] Make a workflow to test adding the v17.10 build tools --- .github/workflows/ninja-msvc17.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/ninja-msvc17.yml diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml new file mode 100644 index 0000000..4866ab7 --- /dev/null +++ b/.github/workflows/ninja-msvc17.yml @@ -0,0 +1,16 @@ +# SPDX short identifier: BSL-1.0 + +name: ninja-msvc17 +on: push + +jobs: + job: + name: VS 2022 update test + runs-on: windows-2022 + steps: + - name: Run vs_installer.exe + shell: pwsh + run: | + $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' + Test-Path -Path $vsinstaller | Should -Be $true + & $vsinstaller modify --add 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' \ No newline at end of file From f3a01cdf1270bc3a79df4acd4748f380be314185 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 22:31:54 -0500 Subject: [PATCH 17/38] Check for cl.exe --- .github/workflows/ninja-msvc17.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index 4866ab7..c38dc26 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -13,4 +13,8 @@ jobs: run: | $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' Test-Path -Path $vsinstaller | Should -Be $true - & $vsinstaller modify --add 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' \ No newline at end of file + & $vsinstaller modify --add 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' + $vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' + $clexe = Join-Path $vsbin 'cl.exe' + Test-Path -Path $clexe | Should -Be $true + & $clexe /? \ No newline at end of file From e2caf3c131f9717eb5ca14516a06f087222ac7a3 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 22:38:37 -0500 Subject: [PATCH 18/38] Need to wait for the install to complete --- .github/workflows/ninja-msvc17.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index c38dc26..1e25ead 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -13,7 +13,17 @@ jobs: run: | $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' Test-Path -Path $vsinstaller | Should -Be $true - & $vsinstaller modify --add 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' + + $mod_args = @( + 'modify' + '--add' + 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' + '--quiet' + '--wait' + ) + $modify = Start-Process -FilePath $vsinstaller -ArgumentList @mod_args -Wait -PassThru + Write-Host $modify.ExitCode + $vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' $clexe = Join-Path $vsbin 'cl.exe' Test-Path -Path $clexe | Should -Be $true From 1f1dd092834b1486c9c685bcd3bd5a5710b5c61d Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 22:44:35 -0500 Subject: [PATCH 19/38] Can't splat ArgumentList --- .github/workflows/ninja-msvc17.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index 1e25ead..886b126 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -14,14 +14,8 @@ jobs: $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' Test-Path -Path $vsinstaller | Should -Be $true - $mod_args = @( - 'modify' - '--add' - 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' - '--quiet' - '--wait' - ) - $modify = Start-Process -FilePath $vsinstaller -ArgumentList @mod_args -Wait -PassThru + $modify = Start-Process -Wait -PassThru -FilePath $vsinstaller ` + -ArgumentList 'modify', '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64', '--quiet', '--wait' Write-Host $modify.ExitCode $vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' From 39c2a08fdddaadba421e28015fc0e4f18a0ca871 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 22:45:54 -0500 Subject: [PATCH 20/38] Enterprise, not Community... duh. --- .github/workflows/ninja-msvc17.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index 886b126..023e121 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -18,7 +18,7 @@ jobs: -ArgumentList 'modify', '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64', '--quiet', '--wait' Write-Host $modify.ExitCode - $vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' + $vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' $clexe = Join-Path $vsbin 'cl.exe' Test-Path -Path $clexe | Should -Be $true & $clexe /? \ No newline at end of file From 6aa3dcd48bef135bf4e6ca006d31c7494c17b011 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 22:47:41 -0500 Subject: [PATCH 21/38] List contents of the expected path --- .github/workflows/ninja-msvc17.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index 023e121..9db9030 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -18,7 +18,9 @@ jobs: -ArgumentList 'modify', '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64', '--quiet', '--wait' Write-Host $modify.ExitCode - $vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' - $clexe = Join-Path $vsbin 'cl.exe' - Test-Path -Path $clexe | Should -Be $true - & $clexe /? \ No newline at end of file + Get-ChildItem -Recurse 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC' + + #$vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' + #$clexe = Join-Path $vsbin 'cl.exe' + #Test-Path -Path $clexe | Should -Be $true + #& $clexe /? \ No newline at end of file From f1170c4c0ff7ec52e2e7f51196ca8a8a800357a9 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 22:57:37 -0500 Subject: [PATCH 22/38] Add '--installPath' --- .github/workflows/ninja-msvc17.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index 9db9030..0bf7075 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -11,16 +11,21 @@ jobs: - name: Run vs_installer.exe shell: pwsh run: | + $vspath = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise' + Test-Path -Path $vspath | Should -Be $true + $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' Test-Path -Path $vsinstaller | Should -Be $true $modify = Start-Process -Wait -PassThru -FilePath $vsinstaller ` - -ArgumentList 'modify', '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64', '--quiet', '--wait' + -ArgumentList 'modify', '--installPath', "$vspath", '--quiet', '--norestart', '--nocache' ` + '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' Write-Host $modify.ExitCode - Get-ChildItem -Recurse 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC' + $vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' + Test-Path -Path $vsbin | Should -Be $true + + $clexe = Join-Path $vsbin 'cl.exe' + Test-Path -Path $clexe | Should -Be $true - #$vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' - #$clexe = Join-Path $vsbin 'cl.exe' - #Test-Path -Path $clexe | Should -Be $true - #& $clexe /? \ No newline at end of file + & $clexe /? \ No newline at end of file From 808179e4cd22ac1a4861316fb91f36900c00ea3b Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 23:02:51 -0500 Subject: [PATCH 23/38] Fix typo --- .github/workflows/ninja-msvc17.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index 0bf7075..7d5a606 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -17,9 +17,9 @@ jobs: $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' Test-Path -Path $vsinstaller | Should -Be $true - $modify = Start-Process -Wait -PassThru -FilePath $vsinstaller ` - -ArgumentList 'modify', '--installPath', "$vspath", '--quiet', '--norestart', '--nocache' ` - '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' + $modify = Start-Process -Wait -FilePath $vsinstaller -ArgumentList ` + 'modify', '--installPath', "$vspath", '--quiet', '--norestart', '--nocache', ` + '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' Write-Host $modify.ExitCode $vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' From 60bc50d5e05556456cb45ef11fea2fc93dabe665 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 23:07:45 -0500 Subject: [PATCH 24/38] See if the tools actually got installed --- .github/workflows/ninja-msvc17.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index 7d5a606..bcf7b6e 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -22,10 +22,12 @@ jobs: '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' Write-Host $modify.ExitCode - $vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' - Test-Path -Path $vsbin | Should -Be $true + Get-ChildItem -Path (Join-Path $vspath 'VC\Tools\MSVC') - $clexe = Join-Path $vsbin 'cl.exe' - Test-Path -Path $clexe | Should -Be $true + #$vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' + #Test-Path -Path $vsbin | Should -Be $true - & $clexe /? \ No newline at end of file + #$clexe = Join-Path $vsbin 'cl.exe' + #Test-Path -Path $clexe | Should -Be $true + + #& $clexe /? \ No newline at end of file From ab3734c2897bb1366b96ffb6bb946f840a48fac8 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 23:12:39 -0500 Subject: [PATCH 25/38] Do not capture the Start-Process return value --- .github/workflows/ninja-msvc17.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index bcf7b6e..4b17601 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -17,10 +17,9 @@ jobs: $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' Test-Path -Path $vsinstaller | Should -Be $true - $modify = Start-Process -Wait -FilePath $vsinstaller -ArgumentList ` + Start-Process -Wait -FilePath $vsinstaller -ArgumentList ` 'modify', '--installPath', "$vspath", '--quiet', '--norestart', '--nocache', ` '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' - Write-Host $modify.ExitCode Get-ChildItem -Path (Join-Path $vspath 'VC\Tools\MSVC') From d30c74fd0bbebeb0675753235b3c0e1bf09ff3c5 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 23:42:38 -0500 Subject: [PATCH 26/38] Output installer logs to see what is failing --- .github/workflows/ninja-msvc17.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index 4b17601..c4eb8ae 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -17,11 +17,16 @@ jobs: $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' Test-Path -Path $vsinstaller | Should -Be $true - Start-Process -Wait -FilePath $vsinstaller -ArgumentList ` - 'modify', '--installPath', "$vspath", '--quiet', '--norestart', '--nocache', ` + Start-Process -NoNewWindow -Wait -FilePath $vsinstaller ` + -RedirectStandardOutput stdout.txt ` + -RedirectStandardError stderr.txt ` + -ArgumentList ` + 'modify', '--installPath', "$vspath", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' - Get-ChildItem -Path (Join-Path $vspath 'VC\Tools\MSVC') + Get-ChildItem $env:LOCALAPPDATA\Temp\dd_installer_* | Get-Content + + # Get-ChildItem -Path (Join-Path $vspath 'VC\Tools\MSVC') #$vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' #Test-Path -Path $vsbin | Should -Be $true From fad880cfb2be3cd8472b562477871f34cc0965e9 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Mon, 18 Nov 2024 23:48:24 -0500 Subject: [PATCH 27/38] Missing double-escaped quotes for installPath --- .github/workflows/ninja-msvc17.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index c4eb8ae..7c64f95 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -17,11 +17,8 @@ jobs: $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' Test-Path -Path $vsinstaller | Should -Be $true - Start-Process -NoNewWindow -Wait -FilePath $vsinstaller ` - -RedirectStandardOutput stdout.txt ` - -RedirectStandardError stderr.txt ` - -ArgumentList ` - 'modify', '--installPath', "$vspath", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` + Start-Process -NoNewWindow -Wait -FilePath $vsinstaller -ArgumentList ` + 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' Get-ChildItem $env:LOCALAPPDATA\Temp\dd_installer_* | Get-Content From 871ea2ccebc32ff6242247cef95db24db2911a1d Mon Sep 17 00:00:00 2001 From: demianmnave Date: Tue, 19 Nov 2024 00:02:34 -0500 Subject: [PATCH 28/38] Check installed build tools --- .github/workflows/ninja-msvc17.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index 7c64f95..9654936 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -21,9 +21,9 @@ jobs: 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' - Get-ChildItem $env:LOCALAPPDATA\Temp\dd_installer_* | Get-Content + # Get-ChildItem $env:LOCALAPPDATA\Temp\dd_installer_* | Get-Content - # Get-ChildItem -Path (Join-Path $vspath 'VC\Tools\MSVC') + Get-ChildItem -Path (Join-Path $vspath 'VC\Tools\MSVC') #$vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' #Test-Path -Path $vsbin | Should -Be $true From 98ed95a6a418a523af481095b8716d850e1dfb88 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Tue, 19 Nov 2024 12:33:43 -0500 Subject: [PATCH 29/38] Add build and test steps --- .github/workflows/ninja-msvc17.yml | 31 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/ninja-msvc17.yml index 9654936..447e588 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/ninja-msvc17.yml @@ -5,10 +5,10 @@ on: push jobs: job: - name: VS 2022 update test + name: MSVC 17.10, CMake 3.27 runs-on: windows-2022 steps: - - name: Run vs_installer.exe + - name: Install MSVC 17.10 shell: pwsh run: | $vspath = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise' @@ -21,14 +21,19 @@ jobs: 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' - # Get-ChildItem $env:LOCALAPPDATA\Temp\dd_installer_* | Get-Content - - Get-ChildItem -Path (Join-Path $vspath 'VC\Tools\MSVC') - - #$vsbin = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64' - #Test-Path -Path $vsbin | Should -Be $true - - #$clexe = Join-Path $vsbin 'cl.exe' - #Test-Path -Path $clexe | Should -Be $true - - #& $clexe /? \ No newline at end of file + - name: Pull cmake 3.27 + uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.27.0" + useCloudCache: true + + - name: Checkout CML + uses: actions/checkout@v4 + + - name: Build and test with MSVC 17.10 + uses: lukka/run-cmake@v10 + with: + configurePreset: "cml-ci-msvc17-mt-s", + configurePresetAdditionalArgs: "['-T version=14.40']" + buildPreset: "cml-ci-msvc17-mt-s-release", + testPreset: "cml-ci-msvc17-mt-s-release-test" \ No newline at end of file From d64d3390ed01b835711b0ef3b11fc7c87fa57158 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Tue, 19 Nov 2024 12:40:39 -0500 Subject: [PATCH 30/38] Configure, build, and test with MSVC 17.10 --- .../{ninja-msvc17.yml => msvc17.yml} | 12 +- CMakePresets.json | 147 ++++++++++++------ tests/CMakeLists.txt | 2 +- tests/vector/vector_temporary1.cpp | 3 +- 4 files changed, 106 insertions(+), 58 deletions(-) rename .github/workflows/{ninja-msvc17.yml => msvc17.yml} (82%) diff --git a/.github/workflows/ninja-msvc17.yml b/.github/workflows/msvc17.yml similarity index 82% rename from .github/workflows/ninja-msvc17.yml rename to .github/workflows/msvc17.yml index 447e588..93a01b3 100644 --- a/.github/workflows/ninja-msvc17.yml +++ b/.github/workflows/msvc17.yml @@ -1,11 +1,11 @@ # SPDX short identifier: BSL-1.0 -name: ninja-msvc17 +name: msvc17 on: push jobs: job: - name: MSVC 17.10, CMake 3.27 + name: MSVC 17.10 runs-on: windows-2022 steps: - name: Install MSVC 17.10 @@ -21,16 +21,14 @@ jobs: 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' - - name: Pull cmake 3.27 - uses: lukka/get-cmake@latest + - uses: lukka/get-cmake@latest with: cmakeVersion: "~3.27.0" useCloudCache: true - - name: Checkout CML - uses: actions/checkout@v4 + - uses: actions/checkout@v4 - - name: Build and test with MSVC 17.10 + - name: CMake configure-build-test uses: lukka/run-cmake@v10 with: configurePreset: "cml-ci-msvc17-mt-s", diff --git a/CMakePresets.json b/CMakePresets.json index 80ed5d8..50f3bc1 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -2,38 +2,6 @@ // Core configuration presets: "version": 7, "configurePresets": [ - { - // Standard build directory, and always target x64: - "name": ".cml-configure-defaults", - "hidden": true, - "binaryDir": "${sourceDir}/.build/${presetName}", - "architecture": { - "value": "x64", - "strategy": "external" - }, - "cacheVariables": { - "BUILD_SHARED_LIBS": { - "type": "BOOL", - "value": false - }, - "BUILD_STATIC_RUNTIME": { - "type": "BOOL", - "value": true - } - } - }, - { - // Inheritable preset to enable testing: - "name": ".cml-configure-testing", - "hidden": true, - "cacheVariables": { - "BUILD_TESTING": { - "type": "BOOL", - "value": true - } - } - }, - { // Inheritable conditional to enable a configuration preset on Windows only: "name": ".cml-windows-only", @@ -80,21 +48,49 @@ } }, + { - // Inheritable configuration to use ClangCL and the Ninja generator: - "name": ".cml-ninja-clangcl", + // Standard build directory, and always target x64: + "name": ".cml-configure-defaults", + "hidden": true, + "binaryDir": "${sourceDir}/.build/${presetName}", + "architecture": { + "value": "x64", + "strategy": "external" + }, + "cacheVariables": { + "BUILD_SHARED_LIBS": { + "type": "BOOL", + "value": false + }, + "BUILD_STATIC_RUNTIME": { + "type": "BOOL", + "value": true + }, + "BUILD_TESTING": { + "type": "BOOL", + "value": true + } + } + }, + + { + // Inheritable configuration to use the system default MSVC ClangCL and the Ninja generator: + "name": ".cml-ninja-msvc-clangcl", "hidden": true, - "generator": "Ninja", + "inherits": [ ".cml-windows-only" ], + "generator": "Ninja Multi-Config", "cacheVariables": { "CMAKE_C_COMPILER": "clang-cl.exe", "CMAKE_CXX_COMPILER": "clang-cl.exe" } }, { - // Inheritable configuration to use MSVC and the Ninja generator: + // Inheritable configuration to use the system default MSVC and the Ninja generator: "name": ".cml-ninja-msvc", "hidden": true, - "generator": "Ninja", + "inherits": [ ".cml-windows-only" ], + "generator": "Ninja Multi-Config", "cacheVariables": { "CMAKE_C_COMPILER": "cl.exe", "CMAKE_CXX_COMPILER": "cl.exe" @@ -108,7 +104,7 @@ "generator": "Visual Studio 17 2022" }, { - // Inheritable configuration to use MSVC17+ClangCL and MSBuild: + // Inheritable configuration to use the system default MSVC17 with ClangCL and MSBuild: "name": ".cml-msvc17-clangcl", "hidden": true, "inherits": [ ".cml-windows-only" ], @@ -117,27 +113,30 @@ }, { - // Preset to configure a static dev-test (IDE) build with MSVC17: + // Preset to configure a static dev-test (IDE) build with the system default MSVC17: "name": "cml-dev-msvc17-mt-s", - "inherits": [ ".cml-configure-defaults", ".cml-msvc17", ".cml-configure-testing" ] + "inherits": [ ".cml-configure-defaults", ".cml-msvc17" ] }, - { - // Preset to configure a static dev-test build (IDE) with MSVC17+ClangCL: + // Preset to configure a static dev-test build (IDE) with the system default MSVC17 ClangCL: "name": "cml-dev-msvc17-clangcl-mt-s", - "inherits": [ ".cml-configure-defaults", ".cml-msvc17-clangcl", ".cml-configure-testing" ] + "inherits": [ ".cml-configure-defaults", ".cml-msvc17-clangcl" ] }, { - // Preset to configure a CI test build with Ninja+ClangCL: - "name": "cml-ci-ninja-clangcl-mt-s", - "inherits": [ ".cml-configure-defaults", ".cml-ninja-clangcl", ".cml-configure-testing" ] + // Preset to configure a CI test build with Ninja Multi-Config and the system default MSVC ClangCL: + "name": "cml-ci-ninja-msvc-clangcl-mt-s", + "inherits": [ ".cml-configure-defaults", ".cml-ninja-msvc-clangcl" ] }, - { - // Preset to configure a CI test build with Ninja+MSVC: + // Preset to configure a CI test build with Ninja Multi-Config and the system default MSVC: "name": "cml-ci-ninja-msvc-mt-s", - "inherits": [ ".cml-configure-defaults", ".cml-ninja-msvc", ".cml-configure-testing" ] + "inherits": [ ".cml-configure-defaults", ".cml-ninja-msvc" ] + }, + { + // Preset to configure a CI test build with MSVC17: + "name": "cml-ci-msvc17-mt-s", + "inherits": [ ".cml-configure-defaults", ".cml-msvc17" ] } ], @@ -186,6 +185,56 @@ } ] } + }, + + { + // Static Ninja+ClangCl release build: + "name": "cml-ci-ninja-msvc-clangcl-mt-s-release", + "inherits": [ ".cml-windows-build-only" ], + "configurePreset": "cml-ci-ninja-msvc-clangcl-mt-s", + "inheritConfigureEnvironment": true, + "configuration": "Release" + }, + { + // Static MSVC release build: + "name": "cml-ci-msvc17-mt-s-release", + "inherits": [ ".cml-windows-build-only" ], + "configurePreset": "cml-ci-msvc17-mt-s", + "inheritConfigureEnvironment": true, + "configuration": "Release" + } + ], + + "testPresets": [ + { + // Inheritable conditional to enable a test preset on Windows only: + "name": ".cml-windows-test-only", + "hidden": true, + "condition": { + "type": "allOf", + "conditions": [ + { + "lhs": "${hostSystemName}", + "type": "equals", + "rhs": "Windows" + } + ] + } + }, + + { + "name": "cml-ci-ninja-msvc-clangcl-mt-s-release-test", + "inherits": [ ".cml-windows-test-only" ], + "configurePreset": "cml-ci-ninja-msvc-clangcl-mt-s", + "inheritConfigureEnvironment": true, + "configuration": "Release" + }, + { + "name": "cml-ci-msvc17-mt-s-release-test", + "inherits": [ ".cml-windows-test-only" ], + "configurePreset": "cml-ci-msvc17-mt-s", + "inheritConfigureEnvironment": true, + "configuration": "Release" } ] } \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 823599e..fa53c21 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,7 +22,6 @@ function(cml_add_test _name) if(MSVC) set(_msvc_common_options /permissive- - /MP /EHsc /W4 # Enable strict warnings. ) @@ -36,6 +35,7 @@ function(cml_add_test _name) /Zc:rvalueCast /diagnostics:caret /WL + /MP ) set(_msvc_link_options diff --git a/tests/vector/vector_temporary1.cpp b/tests/vector/vector_temporary1.cpp index cc3bc61..43ae013 100644 --- a/tests/vector/vector_temporary1.cpp +++ b/tests/vector/vector_temporary1.cpp @@ -15,4 +15,5 @@ CATCH_TEST_CASE("const_temporary1") { using const_type = cml::temporary_of_t; -} + CATCH_CHECK(std::is_same_v); +} \ No newline at end of file From 2bb6c08b8ab5637a75767e068215990487cf1091 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Tue, 19 Nov 2024 12:42:05 -0500 Subject: [PATCH 31/38] Fix workflow typos --- .github/workflows/msvc17.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/msvc17.yml b/.github/workflows/msvc17.yml index 93a01b3..78d4e0a 100644 --- a/.github/workflows/msvc17.yml +++ b/.github/workflows/msvc17.yml @@ -31,7 +31,7 @@ jobs: - name: CMake configure-build-test uses: lukka/run-cmake@v10 with: - configurePreset: "cml-ci-msvc17-mt-s", + configurePreset: "cml-ci-msvc17-mt-s" configurePresetAdditionalArgs: "['-T version=14.40']" - buildPreset: "cml-ci-msvc17-mt-s-release", + buildPreset: "cml-ci-msvc17-mt-s-release" testPreset: "cml-ci-msvc17-mt-s-release-test" \ No newline at end of file From b053d8689292db37189465def90c67f9e72a2cda Mon Sep 17 00:00:00 2001 From: demianmnave Date: Tue, 19 Nov 2024 16:16:27 -0500 Subject: [PATCH 32/38] Build and test with the system MSVC --- .clang-format | 282 +++++++++++++++++------------------ .github/workflows/msvc17.yml | 58 ++++--- CMakePresets.json | 15 ++ 3 files changed, 194 insertions(+), 161 deletions(-) diff --git a/.clang-format b/.clang-format index 642eb4a..232dd1e 100644 --- a/.clang-format +++ b/.clang-format @@ -1,142 +1,142 @@ ---- -Language: Cpp -AccessModifierOffset: 0 -AlignAfterOpenBracket: DontAlign -AlignArrayOfStructures: None -AlignConsecutiveAssignments: None -AlignConsecutiveBitFields: AcrossEmptyLinesAndComments -AlignConsecutiveDeclarations: None -AlignConsecutiveMacros: None -AlignEscapedNewlines: Right -AlignOperands: DontAlign -AlignTrailingComments: true -AllowAllArgumentsOnNextLine: true -AllowAllParametersOfDeclarationOnNextLine: true -AllowShortBlocksOnASingleLine: Empty -AllowShortCaseLabelsOnASingleLine: true -AllowShortEnumsOnASingleLine: false -AllowShortFunctionsOnASingleLine: InlineOnly -AllowShortIfStatementsOnASingleLine: AllIfsAndElse -AllowShortLambdasOnASingleLine: All -AllowShortLoopsOnASingleLine: true -AlwaysBreakAfterReturnType: TopLevelDefinitions -AlwaysBreakBeforeMultilineStrings: true -AlwaysBreakTemplateDeclarations: MultiLine -BinPackArguments: true -BinPackParameters: true -BitFieldColonSpacing: Both -BraceWrapping: - AfterCaseLabel: false - AfterClass: true - AfterControlStatement: MultiLine - AfterEnum: true - AfterFunction: true - AfterNamespace: false - AfterStruct: true - AfterUnion: true - AfterExternBlock: false - BeforeCatch: false - BeforeElse: false - BeforeLambdaBody: false - BeforeWhile: false - IndentBraces: false - SplitEmptyFunction: false - SplitEmptyRecord: false - SplitEmptyNamespace: false -BreakAfterAttributes: Leave -BreakBeforeBinaryOperators: NonAssignment -BreakBeforeBraces: Custom -BreakBeforeConceptDeclarations: false -BreakBeforeTernaryOperators: true -BreakConstructorInitializers: BeforeComma -BreakInheritanceList: BeforeComma -BreakStringLiterals: false -ColumnLimit: 80 -CompactNamespaces: false -ConstructorInitializerIndentWidth: 0 -ContinuationIndentWidth: 2 -Cpp11BracedListStyle: true -DeriveLineEnding: false -DerivePointerAlignment: false -EmptyLineAfterAccessModifier: Never -EmptyLineBeforeAccessModifier: Always -ExperimentalAutoDetectBinPacking: false -FixNamespaceComments: true -ForEachMacros: ['foreach', 'Q_FOREACH', 'BOOST_FOREACH'] -IncludeBlocks: Preserve -IndentAccessModifiers: false -IndentCaseBlocks: false -IndentCaseLabels: true -IndentExternBlock: NoIndent -IndentGotoLabels: false -IndentPPDirectives: AfterHash -IndentRequires: true -IndentWidth: 2 -IndentWrappedFunctionNames: false -InsertBraces: false -InsertNewlineAtEOF: true -IntegerLiteralSeparator: - Binary: 4 - Decimal: 0 - Hex: 2 -KeepEmptyLinesAtTheStartOfBlocks: false -LambdaBodyIndentation: Signature -LineEnding: LF -MacroBlockBegin: '' -MacroBlockEnd: '' -MaxEmptyLinesToKeep: 2 -NamespaceIndentation: None -NamespaceMacros: [] -PPIndentWidth: -1 -PackConstructorInitializers: BinPack -PenaltyBreakAssignment: 2 -PenaltyBreakBeforeFirstCallParameter: 2 -PenaltyBreakComment: 2 -PenaltyBreakFirstLessLess: 10 -PenaltyBreakOpenParenthesis: 100 -PenaltyBreakString: 1000 -PenaltyBreakTemplateDeclaration: 2 -PenaltyExcessCharacter: 100000 -PenaltyIndentedWhitespace: 100 -PenaltyReturnTypeOnItsOwnLine: 1000 -PointerAlignment: Left -QualifierAlignment: Leave -ReferenceAlignment: Pointer -ReflowComments: false -RemoveBracesLLVM: false -SeparateDefinitionBlocks: Always -ShortNamespaceLines: 1 -SortIncludes: Never -SortUsingDeclarations: false -SpaceAfterCStyleCast: true -SpaceAfterLogicalNot: false -SpaceAfterTemplateKeyword: false -SpaceAroundPointerQualifiers: Default -SpaceBeforeAssignmentOperators: true -SpaceBeforeCaseColon: false -SpaceBeforeCpp11BracedList: false -SpaceBeforeCtorInitializerColon: true -SpaceBeforeInheritanceColon: true -SpaceBeforeParens: Never -SpaceBeforeRangeBasedForLoopColon: true -SpaceBeforeSquareBrackets: false -SpaceInEmptyBlock: false -SpaceInEmptyParentheses: false -SpacesBeforeTrailingComments: 2 -SpacesInAngles: Never -SpacesInCStyleCastParentheses: false -SpacesInConditionalStatement: false -SpacesInContainerLiterals: true -SpacesInLineCommentPrefix: - Minimum: 1 - Maximum: -1 -SpacesInParentheses: false -SpacesInSquareBrackets: false -Standard: Latest -StatementAttributeLikeMacros: [] -StatementMacros: [] -TypenameMacros: [] -TabWidth: 4 -UseCRLF: false -UseTab: Never +--- +Language: Cpp +AccessModifierOffset: 0 +AlignAfterOpenBracket: DontAlign +AlignArrayOfStructures: None +AlignConsecutiveAssignments: None +AlignConsecutiveBitFields: AcrossEmptyLinesAndComments +AlignConsecutiveDeclarations: None +AlignConsecutiveMacros: None +AlignEscapedNewlines: Right +AlignOperands: DontAlign +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortBlocksOnASingleLine: Empty +AllowShortCaseLabelsOnASingleLine: true +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: InlineOnly +AllowShortIfStatementsOnASingleLine: AllIfsAndElse +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterReturnType: TopLevelDefinitions +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: MultiLine +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: false + AfterClass: true + AfterControlStatement: MultiLine + AfterEnum: true + AfterFunction: true + AfterNamespace: false + AfterStruct: true + AfterUnion: true + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: false + SplitEmptyRecord: false + SplitEmptyNamespace: false +BreakAfterAttributes: Leave +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Custom +BreakBeforeConceptDeclarations: false +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeComma +BreakInheritanceList: BeforeComma +BreakStringLiterals: false +ColumnLimit: 80 +CompactNamespaces: false +ConstructorInitializerIndentWidth: 0 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: true +DeriveLineEnding: false +DerivePointerAlignment: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: Always +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: true +ForEachMacros: [] +IncludeBlocks: Preserve +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: true +IndentExternBlock: NoIndent +IndentGotoLabels: false +IndentPPDirectives: AfterHash +IndentRequires: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: true +IntegerLiteralSeparator: + Binary: 4 + Decimal: 0 + Hex: 2 +KeepEmptyLinesAtTheStartOfBlocks: false +LambdaBodyIndentation: Signature +LineEnding: LF +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 2 +NamespaceIndentation: None +NamespaceMacros: [] +PPIndentWidth: -1 +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 2 +PenaltyBreakComment: 2 +PenaltyBreakFirstLessLess: 10 +PenaltyBreakOpenParenthesis: 100 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 2 +PenaltyExcessCharacter: 100000 +PenaltyIndentedWhitespace: 100 +PenaltyReturnTypeOnItsOwnLine: 1000 +PointerAlignment: Left +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: false +RemoveBracesLLVM: false +SeparateDefinitionBlocks: Always +ShortNamespaceLines: 1 +SortIncludes: Never +SortUsingDeclarations: false +SpaceAfterCStyleCast: true +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: Never +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: Never +SpacesInCStyleCastParentheses: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Latest +StatementAttributeLikeMacros: [] +StatementMacros: [] +TypenameMacros: [] +TabWidth: 4 +UseCRLF: false +UseTab: Never WhitespaceSensitiveMacros: [] \ No newline at end of file diff --git a/.github/workflows/msvc17.yml b/.github/workflows/msvc17.yml index 78d4e0a..948e5fe 100644 --- a/.github/workflows/msvc17.yml +++ b/.github/workflows/msvc17.yml @@ -4,26 +4,13 @@ name: msvc17 on: push jobs: - job: - name: MSVC 17.10 + msvc-latest: + name: MSVC Latest runs-on: windows-2022 steps: - - name: Install MSVC 17.10 - shell: pwsh - run: | - $vspath = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise' - Test-Path -Path $vspath | Should -Be $true - - $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' - Test-Path -Path $vsinstaller | Should -Be $true - - Start-Process -NoNewWindow -Wait -FilePath $vsinstaller -ArgumentList ` - 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` - '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' - - uses: lukka/get-cmake@latest with: - cmakeVersion: "~3.27.0" + cmakeVersion: "~3.29.0" useCloudCache: true - uses: actions/checkout@v4 @@ -31,7 +18,38 @@ jobs: - name: CMake configure-build-test uses: lukka/run-cmake@v10 with: - configurePreset: "cml-ci-msvc17-mt-s" - configurePresetAdditionalArgs: "['-T version=14.40']" - buildPreset: "cml-ci-msvc17-mt-s-release" - testPreset: "cml-ci-msvc17-mt-s-release-test" \ No newline at end of file + configurePreset: "cml-ci-ninja-msvc-mt-s" + buildPreset: "cml-ci-ninja-msvc-mt-s-release" + testPreset: "cml-ci-ninja-msvc-mt-s-release-test" + +# msvc-17-10: +# name: MSVC 17.10 +# runs-on: windows-2022 +# steps: +# - name: Install MSVC 17.10 +# shell: pwsh +# run: | +# $vspath = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise' +# Test-Path -Path $vspath | Should -Be $true +# +# $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' +# Test-Path -Path $vsinstaller | Should -Be $true +# +# Start-Process -NoNewWindow -Wait -FilePath $vsinstaller -ArgumentList ` +# 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` +# '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' +# +# - uses: lukka/get-cmake@latest +# with: +# cmakeVersion: "~3.29.0" +# useCloudCache: true +# +# - uses: actions/checkout@v4 +# +# - name: CMake configure-build-test +# uses: lukka/run-cmake@v10 +# with: +# configurePreset: "cml-ci-msvc17-mt-s" +# configurePresetAdditionalArgs: "['-T version=14.40']" +# buildPreset: "cml-ci-msvc17-mt-s-release" +# testPreset: "cml-ci-msvc17-mt-s-release-test" \ No newline at end of file diff --git a/CMakePresets.json b/CMakePresets.json index 50f3bc1..d19afb9 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -187,6 +187,14 @@ } }, + { + // Static Ninja+MSVC release build: + "name": "cml-ci-ninja-msvc-mt-s-release", + "inherits": [ ".cml-windows-build-only" ], + "configurePreset": "cml-ci-ninja-msvc-mt-s", + "inheritConfigureEnvironment": true, + "configuration": "Release" + }, { // Static Ninja+ClangCl release build: "name": "cml-ci-ninja-msvc-clangcl-mt-s-release", @@ -222,6 +230,13 @@ } }, + { + "name": "cml-ci-ninja-msvc-mt-s-release-test", + "inherits": [ ".cml-windows-test-only" ], + "configurePreset": "cml-ci-ninja-msvc-mt-s", + "inheritConfigureEnvironment": true, + "configuration": "Release" + }, { "name": "cml-ci-ninja-msvc-clangcl-mt-s-release-test", "inherits": [ ".cml-windows-test-only" ], From 8c40f70ee3ff0e467502cdf22d85f8fcc94d03d6 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Tue, 19 Nov 2024 16:32:14 -0500 Subject: [PATCH 33/38] run-cmake needs vcpkg for MSVC env vars --- .github/workflows/msvc17.yml | 11 +++-------- vcpkg.json | 8 ++++++++ 2 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 vcpkg.json diff --git a/.github/workflows/msvc17.yml b/.github/workflows/msvc17.yml index 948e5fe..440a1a9 100644 --- a/.github/workflows/msvc17.yml +++ b/.github/workflows/msvc17.yml @@ -8,15 +8,10 @@ jobs: name: MSVC Latest runs-on: windows-2022 steps: - - uses: lukka/get-cmake@latest - with: - cmakeVersion: "~3.29.0" - useCloudCache: true - - uses: actions/checkout@v4 - - - name: CMake configure-build-test - uses: lukka/run-cmake@v10 + - uses: lukka/get-cmake@v3.29 + - uses: lukka/run-vcpkg@v11 + - uses: lukka/run-cmake@v10 with: configurePreset: "cml-ci-ninja-msvc-mt-s" buildPreset: "cml-ci-ninja-msvc-mt-s-release" diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..2d9e4f1 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,8 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "$1": "Baseline vcpkg-root commit hash (2024.11.16) for Catch2 v3.7.1", + "builtin-baseline": "b2cb0da531c2f1f740045bfe7c4dac59f0b2b69c", + "dependencies": [ + "catch2" + ] +} \ No newline at end of file From 29cf7f0db68f5952c9339e86a4c00d5cc7bfeeb7 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Tue, 19 Nov 2024 16:33:22 -0500 Subject: [PATCH 34/38] Fix get-cmake --- .github/workflows/msvc17.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/msvc17.yml b/.github/workflows/msvc17.yml index 440a1a9..eff6604 100644 --- a/.github/workflows/msvc17.yml +++ b/.github/workflows/msvc17.yml @@ -9,7 +9,9 @@ jobs: runs-on: windows-2022 steps: - uses: actions/checkout@v4 - - uses: lukka/get-cmake@v3.29 + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.29.0" - uses: lukka/run-vcpkg@v11 - uses: lukka/run-cmake@v10 with: From f21ea808d426f8d5db939d965a2cddf827f06d68 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Tue, 19 Nov 2024 18:54:44 -0500 Subject: [PATCH 35/38] Try MSVC 17.10 with CMake 3.29 --- .github/workflows/msvc17.yml | 71 +++++++++++++++++------------------- 1 file changed, 34 insertions(+), 37 deletions(-) diff --git a/.github/workflows/msvc17.yml b/.github/workflows/msvc17.yml index eff6604..d0bd2d5 100644 --- a/.github/workflows/msvc17.yml +++ b/.github/workflows/msvc17.yml @@ -4,10 +4,38 @@ name: msvc17 on: push jobs: - msvc-latest: - name: MSVC Latest + # msvc-latest: + # name: MSVC Latest + # runs-on: windows-2022 + # steps: + # - uses: actions/checkout@v4 + # - uses: lukka/get-cmake@latest + # with: + # cmakeVersion: "~3.29.0" + # - uses: lukka/run-vcpkg@v11 + # - uses: lukka/run-cmake@v10 + # with: + # configurePreset: "cml-ci-ninja-msvc-mt-s" + # buildPreset: "cml-ci-ninja-msvc-mt-s-release" + # testPreset: "cml-ci-ninja-msvc-mt-s-release-test" + + msvc-17-10: + name: MSVC 17.10 runs-on: windows-2022 steps: + - name: Install MSVC 17.10 + shell: pwsh + run: | + $vspath = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise' + Test-Path -Path $vspath | Should -Be $true + + $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' + Test-Path -Path $vsinstaller | Should -Be $true + + Start-Process -NoNewWindow -Wait -FilePath $vsinstaller -ArgumentList ` + 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` + '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' + - uses: actions/checkout@v4 - uses: lukka/get-cmake@latest with: @@ -15,38 +43,7 @@ jobs: - uses: lukka/run-vcpkg@v11 - uses: lukka/run-cmake@v10 with: - configurePreset: "cml-ci-ninja-msvc-mt-s" - buildPreset: "cml-ci-ninja-msvc-mt-s-release" - testPreset: "cml-ci-ninja-msvc-mt-s-release-test" - -# msvc-17-10: -# name: MSVC 17.10 -# runs-on: windows-2022 -# steps: -# - name: Install MSVC 17.10 -# shell: pwsh -# run: | -# $vspath = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise' -# Test-Path -Path $vspath | Should -Be $true -# -# $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' -# Test-Path -Path $vsinstaller | Should -Be $true -# -# Start-Process -NoNewWindow -Wait -FilePath $vsinstaller -ArgumentList ` -# 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` -# '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' -# -# - uses: lukka/get-cmake@latest -# with: -# cmakeVersion: "~3.29.0" -# useCloudCache: true -# -# - uses: actions/checkout@v4 -# -# - name: CMake configure-build-test -# uses: lukka/run-cmake@v10 -# with: -# configurePreset: "cml-ci-msvc17-mt-s" -# configurePresetAdditionalArgs: "['-T version=14.40']" -# buildPreset: "cml-ci-msvc17-mt-s-release" -# testPreset: "cml-ci-msvc17-mt-s-release-test" \ No newline at end of file + configurePreset: "cml-ci-msvc17-mt-s" + configurePresetAdditionalArgs: "['-T version=14.40']" + buildPreset: "cml-ci-msvc17-mt-s-release" + testPreset: "cml-ci-msvc17-mt-s-release-test" \ No newline at end of file From b2c6db05b47d31ddd0acd88c9a9d1559a4775cd3 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Tue, 19 Nov 2024 20:20:50 -0500 Subject: [PATCH 36/38] Add an MSVC ClangCL job --- .github/workflows/msvc17.yml | 66 ++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/.github/workflows/msvc17.yml b/.github/workflows/msvc17.yml index d0bd2d5..4b2dfb1 100644 --- a/.github/workflows/msvc17.yml +++ b/.github/workflows/msvc17.yml @@ -4,6 +4,22 @@ name: msvc17 on: push jobs: + + msvc-clangcl-latest: + name: MSVC ClangCL Latest + runs-on: windows-2022 + steps: + - uses: actions/checkout@v4 + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.29.0" + - uses: lukka/run-vcpkg@v11 + - uses: lukka/run-cmake@v10 + with: + configurePreset: "cml-ci-ninja-msvc-clangcl-mt-s" + buildPreset: "cml-ci-ninja-msvc-clangcl-mt-s-release" + testPreset: "cml-ci-ninja-msvc-clangcl-mt-s-release-test" + # msvc-latest: # name: MSVC Latest # runs-on: windows-2022 @@ -19,31 +35,31 @@ jobs: # buildPreset: "cml-ci-ninja-msvc-mt-s-release" # testPreset: "cml-ci-ninja-msvc-mt-s-release-test" - msvc-17-10: - name: MSVC 17.10 - runs-on: windows-2022 - steps: - - name: Install MSVC 17.10 - shell: pwsh - run: | - $vspath = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise' - Test-Path -Path $vspath | Should -Be $true + # msvc-17-10: + # name: MSVC 17.10 + # runs-on: windows-2022 + # steps: + # - name: Install MSVC 17.10 + # shell: pwsh + # run: | + # $vspath = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise' + # Test-Path -Path $vspath | Should -Be $true - $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' - Test-Path -Path $vsinstaller | Should -Be $true + # $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' + # Test-Path -Path $vsinstaller | Should -Be $true - Start-Process -NoNewWindow -Wait -FilePath $vsinstaller -ArgumentList ` - 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` - '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' + # Start-Process -NoNewWindow -Wait -FilePath $vsinstaller -ArgumentList ` + # 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` + # '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' - - uses: actions/checkout@v4 - - uses: lukka/get-cmake@latest - with: - cmakeVersion: "~3.29.0" - - uses: lukka/run-vcpkg@v11 - - uses: lukka/run-cmake@v10 - with: - configurePreset: "cml-ci-msvc17-mt-s" - configurePresetAdditionalArgs: "['-T version=14.40']" - buildPreset: "cml-ci-msvc17-mt-s-release" - testPreset: "cml-ci-msvc17-mt-s-release-test" \ No newline at end of file + # - uses: actions/checkout@v4 + # - uses: lukka/get-cmake@latest + # with: + # cmakeVersion: "~3.29.0" + # - uses: lukka/run-vcpkg@v11 + # - uses: lukka/run-cmake@v10 + # with: + # configurePreset: "cml-ci-msvc17-mt-s" + # configurePresetAdditionalArgs: "['-T version=14.40']" + # buildPreset: "cml-ci-msvc17-mt-s-release" + # testPreset: "cml-ci-msvc17-mt-s-release-test" \ No newline at end of file From 1683f1ce24e498a3f256b2ade027b624e6d72186 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Tue, 19 Nov 2024 20:39:26 -0500 Subject: [PATCH 37/38] Enable all MSVC jobs --- .github/workflows/msvc17.yml | 78 ++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 39 deletions(-) diff --git a/.github/workflows/msvc17.yml b/.github/workflows/msvc17.yml index 4b2dfb1..5073441 100644 --- a/.github/workflows/msvc17.yml +++ b/.github/workflows/msvc17.yml @@ -20,46 +20,46 @@ jobs: buildPreset: "cml-ci-ninja-msvc-clangcl-mt-s-release" testPreset: "cml-ci-ninja-msvc-clangcl-mt-s-release-test" - # msvc-latest: - # name: MSVC Latest - # runs-on: windows-2022 - # steps: - # - uses: actions/checkout@v4 - # - uses: lukka/get-cmake@latest - # with: - # cmakeVersion: "~3.29.0" - # - uses: lukka/run-vcpkg@v11 - # - uses: lukka/run-cmake@v10 - # with: - # configurePreset: "cml-ci-ninja-msvc-mt-s" - # buildPreset: "cml-ci-ninja-msvc-mt-s-release" - # testPreset: "cml-ci-ninja-msvc-mt-s-release-test" + msvc-latest: + name: MSVC Latest + runs-on: windows-2022 + steps: + - uses: actions/checkout@v4 + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.29.0" + - uses: lukka/run-vcpkg@v11 + - uses: lukka/run-cmake@v10 + with: + configurePreset: "cml-ci-ninja-msvc-mt-s" + buildPreset: "cml-ci-ninja-msvc-mt-s-release" + testPreset: "cml-ci-ninja-msvc-mt-s-release-test" - # msvc-17-10: - # name: MSVC 17.10 - # runs-on: windows-2022 - # steps: - # - name: Install MSVC 17.10 - # shell: pwsh - # run: | - # $vspath = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise' - # Test-Path -Path $vspath | Should -Be $true + msvc-17-10: + name: MSVC 17.10 + runs-on: windows-2022 + steps: + - name: Install MSVC 17.10 + shell: pwsh + run: | + $vspath = 'C:\Program Files\Microsoft Visual Studio\2022\Enterprise' + Test-Path -Path $vspath | Should -Be $true - # $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' - # Test-Path -Path $vsinstaller | Should -Be $true + $vsinstaller = 'C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe' + Test-Path -Path $vsinstaller | Should -Be $true - # Start-Process -NoNewWindow -Wait -FilePath $vsinstaller -ArgumentList ` - # 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` - # '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' + Start-Process -NoNewWindow -Wait -FilePath $vsinstaller -ArgumentList ` + 'modify', '--installPath', "`"$vspath`"", '--quiet', '--norestart', '--nocache', '--noUpdateInstaller', ` + '--add', 'Microsoft.VisualStudio.Component.VC.14.40.17.10.x86.x64' - # - uses: actions/checkout@v4 - # - uses: lukka/get-cmake@latest - # with: - # cmakeVersion: "~3.29.0" - # - uses: lukka/run-vcpkg@v11 - # - uses: lukka/run-cmake@v10 - # with: - # configurePreset: "cml-ci-msvc17-mt-s" - # configurePresetAdditionalArgs: "['-T version=14.40']" - # buildPreset: "cml-ci-msvc17-mt-s-release" - # testPreset: "cml-ci-msvc17-mt-s-release-test" \ No newline at end of file + - uses: actions/checkout@v4 + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.29.0" + - uses: lukka/run-vcpkg@v11 + - uses: lukka/run-cmake@v10 + with: + configurePreset: "cml-ci-msvc17-mt-s" + configurePresetAdditionalArgs: "['-T version=14.40']" + buildPreset: "cml-ci-msvc17-mt-s-release" + testPreset: "cml-ci-msvc17-mt-s-release-test" \ No newline at end of file From 060cfb225690a75e769cf18e275b7708d5668a48 Mon Sep 17 00:00:00 2001 From: demianmnave Date: Tue, 19 Nov 2024 21:03:46 -0500 Subject: [PATCH 38/38] Split the MSVC workflows and add a badge for each - Also, only run the workflows when sources change. --- .../workflows/{msvc17.yml => msvc-17-10.yml} | 45 +++++-------------- .github/workflows/msvc-clangcl-latest.yml | 30 +++++++++++++ .github/workflows/msvc-latest.yml | 30 +++++++++++++ README.md | 4 ++ 4 files changed, 76 insertions(+), 33 deletions(-) rename .github/workflows/{msvc17.yml => msvc-17-10.yml} (55%) create mode 100644 .github/workflows/msvc-clangcl-latest.yml create mode 100644 .github/workflows/msvc-latest.yml diff --git a/.github/workflows/msvc17.yml b/.github/workflows/msvc-17-10.yml similarity index 55% rename from .github/workflows/msvc17.yml rename to .github/workflows/msvc-17-10.yml index 5073441..a70cf64 100644 --- a/.github/workflows/msvc17.yml +++ b/.github/workflows/msvc-17-10.yml @@ -1,40 +1,19 @@ # SPDX short identifier: BSL-1.0 -name: msvc17 -on: push +name: msvc17-17-10 +on: + push: + paths: + - '.github/**' + - 'cmake/**' + - 'cml/**' + - 'tests/**' + - 'CMakeLists.txt' + - 'CMakePresets.json' + - 'CML.cmake' + - 'vcpkg.json' jobs: - - msvc-clangcl-latest: - name: MSVC ClangCL Latest - runs-on: windows-2022 - steps: - - uses: actions/checkout@v4 - - uses: lukka/get-cmake@latest - with: - cmakeVersion: "~3.29.0" - - uses: lukka/run-vcpkg@v11 - - uses: lukka/run-cmake@v10 - with: - configurePreset: "cml-ci-ninja-msvc-clangcl-mt-s" - buildPreset: "cml-ci-ninja-msvc-clangcl-mt-s-release" - testPreset: "cml-ci-ninja-msvc-clangcl-mt-s-release-test" - - msvc-latest: - name: MSVC Latest - runs-on: windows-2022 - steps: - - uses: actions/checkout@v4 - - uses: lukka/get-cmake@latest - with: - cmakeVersion: "~3.29.0" - - uses: lukka/run-vcpkg@v11 - - uses: lukka/run-cmake@v10 - with: - configurePreset: "cml-ci-ninja-msvc-mt-s" - buildPreset: "cml-ci-ninja-msvc-mt-s-release" - testPreset: "cml-ci-ninja-msvc-mt-s-release-test" - msvc-17-10: name: MSVC 17.10 runs-on: windows-2022 diff --git a/.github/workflows/msvc-clangcl-latest.yml b/.github/workflows/msvc-clangcl-latest.yml new file mode 100644 index 0000000..08cdd23 --- /dev/null +++ b/.github/workflows/msvc-clangcl-latest.yml @@ -0,0 +1,30 @@ +# SPDX short identifier: BSL-1.0 + +name: msvc-clangcl-latest +on: + push: + paths: + - '.github/**' + - 'cmake/**' + - 'cml/**' + - 'tests/**' + - 'CMakeLists.txt' + - 'CMakePresets.json' + - 'CML.cmake' + - 'vcpkg.json' + +jobs: + msvc-clangcl-latest: + name: MSVC ClangCL Latest + runs-on: windows-2022 + steps: + - uses: actions/checkout@v4 + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.29.0" + - uses: lukka/run-vcpkg@v11 + - uses: lukka/run-cmake@v10 + with: + configurePreset: "cml-ci-ninja-msvc-clangcl-mt-s" + buildPreset: "cml-ci-ninja-msvc-clangcl-mt-s-release" + testPreset: "cml-ci-ninja-msvc-clangcl-mt-s-release-test" \ No newline at end of file diff --git a/.github/workflows/msvc-latest.yml b/.github/workflows/msvc-latest.yml new file mode 100644 index 0000000..fefd691 --- /dev/null +++ b/.github/workflows/msvc-latest.yml @@ -0,0 +1,30 @@ +# SPDX short identifier: BSL-1.0 + +name: msvc-latest.yml +on: + push: + paths: + - '.github/**' + - 'cmake/**' + - 'cml/**' + - 'tests/**' + - 'CMakeLists.txt' + - 'CMakePresets.json' + - 'CML.cmake' + - 'vcpkg.json' + +jobs: + msvc-latest: + name: MSVC Latest + runs-on: windows-2022 + steps: + - uses: actions/checkout@v4 + - uses: lukka/get-cmake@latest + with: + cmakeVersion: "~3.29.0" + - uses: lukka/run-vcpkg@v11 + - uses: lukka/run-cmake@v10 + with: + configurePreset: "cml-ci-ninja-msvc-mt-s" + buildPreset: "cml-ci-ninja-msvc-mt-s-release" + testPreset: "cml-ci-ninja-msvc-mt-s-release-test" \ No newline at end of file diff --git a/README.md b/README.md index dee1218..f1f164b 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +[![msvc-latest](https://github.com/demianmnave/CML/actions/workflows/msvc-latest.yml/badge.svg)](https://github.com/demianmnave/CML/actions/workflows/msvc-latest.yml) +[![msvc-clangcl-latest](https://github.com/demianmnave/CML/actions/workflows/msvc-clangcl-latest.yml/badge.svg)](https://github.com/demianmnave/CML/actions/workflows/msvc-clangcl-latest.yml) +[![msvc-17-10](https://github.com/demianmnave/CML/actions/workflows/msvc-17-10.yml/badge.svg)](https://github.com/demianmnave/CML/actions/workflows/msvc-17-10.yml) + ## Configurable Math Library For CML version 1, please see https://github.com/demianmnave/CML1. ## License