From 300bf973264dd9ecd876582685bfa7471ba83554 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Feb 2020 14:31:25 +0100 Subject: build: set standard dependency on library --- CMakeLists.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba03c5f..c6a645c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,11 +6,6 @@ project("newtype" DESCRIPTION "A library of types and functions to create strong type aliases" ) -set(CMAKE_CXX_STANDARD "20") -set(CMAKE_CXX_STANDARD_REQUIRED YES) -set(CMAKE_CXX_EXTENSIONS OFF) -set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) - include("CTest") include("CMakePackageConfigHelpers") @@ -23,6 +18,10 @@ target_include_directories("${PROJECT_NAME}" INTERFACE $ ) +target_compile_features("${PROJECT_NAME}" INTERFACE + "cxx_std_20" +) + install(TARGETS "${PROJECT_NAME}" EXPORT "${PROJECT_NAME}Targets" PUBLIC_HEADER DESTINATION "include" -- cgit v1.2.3 From 714c18a369e8d974821de0c86598163672533c70 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Feb 2020 14:31:53 +0100 Subject: build: convert test execution to command --- CMakeLists.txt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6a645c..37a3460 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,10 @@ project("newtype" include("CTest") include("CMakePackageConfigHelpers") +# Project Options + +option(RUN_TESTS_AFTER_BUILD "Automatically run the unit tests after building" ON) + # 'newtype' library add_library("${PROJECT_NAME}" INTERFACE) @@ -78,12 +82,14 @@ if(BUILD_TESTING) discover_tests(TARGET "${PROJECT_NAME}_tests") - add_custom_target("run_all_tests" - COMMAND ${CMAKE_CTEST_COMMAND} "--output-on-failure" - WORKING_DIRECTORY ${PROJECT_BINARY_DIR} - DEPENDS "newtype_tests" - COMMENT "Running unit tests" + if(RUN_TESTS_AFTER_BUILD) + add_custom_command(TARGET "${PROJECT_NAME}_tests" + POST_BUILD + COMMAND "${CMAKE_CTEST_COMMAND}" "--output-on-failure" + WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" + COMMENT "Running unit tests" ) + endif() endif() # 'newtype' docs -- cgit v1.2.3 From 03280974d3cd82106ff988b4e6541644f4be6759 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Feb 2020 14:43:33 +0100 Subject: pkg: read package description from CMakeLists --- conanfile.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/conanfile.py b/conanfile.py index 8b3e147..1d14249 100644 --- a/conanfile.py +++ b/conanfile.py @@ -4,11 +4,11 @@ from conans import ConanFile, CMake from conans.tools import load -def get_version(): +def read_project_property(property): try: - content = load("CMakeLists.txt") - version = re.search("project\(\"newtype\"\s*VERSION \"(.*)\"", content).group(1) - return version.strip() + cmake_lists = load("CMakeLists.txt") + value = re.search(r"project\(.*{} \"(.*?)\"".format(property), cmake_lists, re.S).group(1) + return value.strip() except: return None @@ -21,10 +21,10 @@ class NewtypeConan(ConanFile): "revision": "auto", } settings = ("compiler",) - version = get_version() + version = read_project_property("VERSION") license = "BSD-3-Clause" url = "https://github.com/fmorgner/newtype" - description = "A library of types and functions to create strong type aliases" + description = read_project_property("DESCRIPTION") generators = "cmake" build_requires = ( "CUTE/2.2.6@fmorgner/stable", @@ -34,9 +34,13 @@ class NewtypeConan(ConanFile): def _configure_cmake(self): cmake = CMake(self) cmake.definitions["BUILD_TESTING"] = True + cmake.definitions["RUN_TESTS_AFTER_BUILD"] = True cmake.configure() return cmake + def configure(self): + del self.settings.compiler.libcxx + def build(self): cmake = self._configure_cmake() cmake.build() -- cgit v1.2.3 From c693d32a3647166b99565f011bbe7e754495ce64 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Feb 2020 15:08:20 +0100 Subject: pkg: mark package as header-only --- conanfile.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/conanfile.py b/conanfile.py index 1d14249..000831e 100644 --- a/conanfile.py +++ b/conanfile.py @@ -20,7 +20,7 @@ class NewtypeConan(ConanFile): "url": "https://github.com/fmorgner/newtype.git", "revision": "auto", } - settings = ("compiler",) + settings = None version = read_project_property("VERSION") license = "BSD-3-Clause" url = "https://github.com/fmorgner/newtype" @@ -38,18 +38,13 @@ class NewtypeConan(ConanFile): cmake.configure() return cmake - def configure(self): - del self.settings.compiler.libcxx - def build(self): cmake = self._configure_cmake() cmake.build() - cmake.test() def package(self): cmake = self._configure_cmake() cmake.install() - def package_info(self): - if self.settings.compiler in ["gcc"]: - self.cpp_info.cxxflags.append("-std=c++2a") \ No newline at end of file + def package_id(self): + self.info.header_only() \ No newline at end of file -- cgit v1.2.3 From 074be923a5e3509297db170c66af37de3082c991 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Feb 2020 15:26:54 +0100 Subject: pkg: add package test --- test_package/.gitignore | 1 + test_package/CMakeLists.txt | 10 ++++++++++ test_package/conanfile.py | 17 +++++++++++++++++ test_package/main.cpp | 11 +++++++++++ 4 files changed, 39 insertions(+) create mode 100644 test_package/.gitignore create mode 100644 test_package/CMakeLists.txt create mode 100644 test_package/conanfile.py create mode 100644 test_package/main.cpp diff --git a/test_package/.gitignore b/test_package/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/test_package/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 0000000..1aafacf --- /dev/null +++ b/test_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION "3.0") + +project("TestPackage" CXX) + +set(CMAKE_CXX_STANDARD "20") + +include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") +conan_basic_setup() + +add_executable("test_package" "main.cpp") \ No newline at end of file diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 0000000..0b12b5f --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,17 @@ +import os +from conans import ConanFile, CMake + + +class NewtypeTestConan(ConanFile): + settings = None + requires = "newtype/[~=1.0]@fmorgner/stable" + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + os.chdir("bin") + self.run(".%stest_package" % os.sep) \ No newline at end of file diff --git a/test_package/main.cpp b/test_package/main.cpp new file mode 100644 index 0000000..95fe763 --- /dev/null +++ b/test_package/main.cpp @@ -0,0 +1,11 @@ +#include "newtype/new_type.hpp" + +#include + +using Integer = nt::new_type; + +auto main() -> int +{ + auto n = Integer{42}; + std::cout << "n == " << n.decay() << '\n'; +} \ No newline at end of file -- cgit v1.2.3 From 52d5330cbb866f050a8f0736c139586c8a22c387 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Feb 2020 21:19:45 +0100 Subject: new_type: begin Iterable implementation --- CMakeLists.txt | 1 + doc/src/index.rst | 126 ++++++++++++++++++----- include/newtype/derivable.hpp | 7 ++ include/newtype/impl/new_type_iterator_types.hpp | 42 ++++++++ include/newtype/impl/type_traits_extensions.hpp | 72 +++++++++++++ include/newtype/new_type.hpp | 80 +++++++++++++- test/include/iterable_suite.hpp | 11 ++ test/src/driver.cpp | 2 + test/src/iterable_suite.cpp | 61 +++++++++++ 9 files changed, 377 insertions(+), 25 deletions(-) create mode 100644 include/newtype/impl/new_type_iterator_types.hpp create mode 100644 test/include/iterable_suite.hpp create mode 100644 test/src/iterable_suite.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 37a3460..fe85a55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,7 @@ if(BUILD_TESTING) "${PROJECT_SOURCE_DIR}/test/src/equality_comparison_suite.cpp" "${PROJECT_SOURCE_DIR}/test/src/hash_suite.cpp" "${PROJECT_SOURCE_DIR}/test/src/io_operators_suite.cpp" + "${PROJECT_SOURCE_DIR}/test/src/iterable_suite.cpp" "${PROJECT_SOURCE_DIR}/test/src/new_type_constructor_suite.cpp" "${PROJECT_SOURCE_DIR}/test/src/relational_operators_suite.cpp" ) diff --git a/doc/src/index.rst b/doc/src/index.rst index 49db3b6..e8d50d6 100644 --- a/doc/src/index.rst +++ b/doc/src/index.rst @@ -28,7 +28,7 @@ In it, :cpp:class:`new_type` is used to create thre new strong aliases :literal: .. literalinclude:: ../../examples/src/basic_usage.cpp :language: c++ :linenos: - :name: new-type-usage-basic + :name: new-type-usage-basic :caption: Basic usage of :cpp:class:`new_type` However, using :cpp:class:`new_type` in this fashion seem quite cumbersome. @@ -76,7 +76,7 @@ Class template :cpp:class:`new_type` :tparam BaseType: |BaseTypeDoc| :tparam TagType: |TagTypeDoc| :tparam DerivationClause: |DerivationClauseDoc| - + .. versionadded:: 1.0.0 **Member Type Aliases** @@ -87,6 +87,18 @@ Class template :cpp:class:`new_type` .. cpp:type:: derivation_clause_type = decltype(DerivationClause) + .. cpp:type:: iterator = typename BaseType::iterator + + :enablement: This type alias shall be defined iff. this :cpp:class:`new_type`'s :cpp:type:`base_type` has a member type :cpp:type:`iterator ` and the :cpp:var:`derivation clause ` contains :cpp:var:`Iterable`. + + .. versionadded:: 1.1.0 + + .. cpp:type:: const_iterator = typename BaseType::const_iterator + + :enablement: This type alias shall be defined iff. this :cpp:class:`new_type`'s :cpp:type:`base_type` has a member type :cpp:type:`const_iterator ` and the :cpp:var:`derivation clause ` contains :cpp:var:`Iterable`. + + .. versionadded:: 1.1.0 + **Static Data Members** .. cpp:var:: static derivation_clause_type constexpr derivation_clause = DerivationClause @@ -195,6 +207,30 @@ Class template :cpp:class:`new_type` :enablement: This operator shall be available iff. this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Indirection` + **Iterators** + + .. cpp:function:: constexpr iterator begin() + + Get an iterator to the beginning of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`begin() ` that returns an instance of type :cpp:type:`iterator` + + .. versionadded:: 1.1.0 + + .. cpp:function:: constexpr iterator begin() const + + Get a constant iterator to the beginning of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`begin() const ` that returns an instance of type :cpp:type:`const_iterator` + + .. versionadded:: 1.1.0 + :literal:`namespace`-level functions and function templates ----------------------------------------------------------- @@ -233,7 +269,7 @@ Equality Comparison Operators :returns: The value returned by the comparison of object contained by :literal:`lhs` with an object of the :cpp:type:`base type `. :throws: Any exception thrown by the comparison of object contained by :literal:`lhs` with an object of the :cpp:type:`base type `. This operator shall be noexcept iff. :cpp:type:`new_type::base_type` is *nothrow equals-comparable*. :enablement: This operator shall be available iff. - + a. :cpp:type:`new_type::base_type` supports comparison using :literal:`==` and b. the :cpp:var:`derivation clause ` contains :cpp:var:`EqBase` @@ -252,7 +288,7 @@ Equality Comparison Operators :returns: The value returned by the comparison of an object of :cpp:type:`base type ` with the object contained by :literal:`rhs`. :throws: Any exception thrown by the comparison of an object of :cpp:type:`base type ` with the object contained by :literal:`rhs`. This operator shall be noexcept iff. :cpp:type:`new_type::base_type` is *nothrow equals-comparable*. :enablement: This operator shall be available iff. - + a. :cpp:type:`new_type::base_type` supports comparison using :literal:`==` and b. the :cpp:var:`derivation clause ` contains :cpp:var:`EqBase` @@ -308,7 +344,7 @@ Equality Comparison Operators :returns: The value returned by the comparison of an object of :cpp:type:`base type ` with the object contained by :literal:`rhs`. :throws: Any exception thrown by the comparison of an object of :cpp:type:`base type ` with the object contained by :literal:`rhs`. This operator shall be noexcept iff. :cpp:type:`new_type::base_type` is *nothrow not-equals-comparable*. :enablement: This operator shall be available iff. - + a. :cpp:type:`new_type::base_type` supports comparison using :literal:`!=` and b. the :cpp:var:`derivation clause ` contains :cpp:var:`EqBase` @@ -464,7 +500,7 @@ Arithmetic Operators :returns: A new instance of :cpp:class:`new_type\` containing the result of applying :literal:`+` to the objects contained by :literal:`lhs` and :literal:`rhs`. :throws: Any exception thrown by the addition operator of the objects contained by :literal:`lhs` and :literal:`rhs`. This operator shall be noexcept iff. - + a. :cpp:type:`new_type::base_type` is *nothrow addable* and b. :cpp:type:`new_type::base_type` is *nothrow copy-constructible* @@ -488,7 +524,7 @@ Arithmetic Operators :returns: A reference to the first argument containing the value modified by applying :literal:`+=` to the objects contained by :literal:`lhs` and :literal:`rhs`. :throws: Any exception thrown by the addition-assignment operator of the objects contained by :literal:`lhs` and :literal:`rhs`. This operator shall be noexcept iff. - + a. :cpp:type:`new_type::base_type` is *nothrow add-assignable* and b. :cpp:type:`new_type::base_type` is *nothrow copy-constructible* @@ -512,7 +548,7 @@ Arithmetic Operators :returns: A new instance of :cpp:class:`new_type\` containing the result of applying :literal:`-` to the objects contained by :literal:`lhs` and :literal:`rhs`. :throws: Any exception thrown by the subtraction operator of the objects contained by :literal:`lhs` and :literal:`rhs`. This operator shall be noexcept iff. - + a. :cpp:type:`new_type::base_type` is *nothrow subtractable* and b. :cpp:type:`new_type::base_type` is *nothrow copy-constructible* @@ -536,7 +572,7 @@ Arithmetic Operators :returns: A reference to the first argument containing the value modified by applying :literal:`-=` to the objects contained by :literal:`lhs` and :literal:`rhs`. :throws: Any exception thrown by the subtraction-assignment operator of the objects contained by :literal:`lhs` and :literal:`rhs`. This operator shall be noexcept iff. - + a. :cpp:type:`new_type::base_type` is *nothrow subtract-assignable* and b. :cpp:type:`new_type::base_type` is *nothrow copy-constructible* @@ -560,7 +596,7 @@ Arithmetic Operators :returns: A new instance of :cpp:class:`new_type\` containing the result of applying :literal:`*` to the objects contained by :literal:`lhs` and :literal:`rhs`. :throws: Any exception thrown by the multiplication operator of the objects contained by :literal:`lhs` and :literal:`rhs`. This operator shall be noexcept iff. - + a. :cpp:type:`new_type::base_type` is *nothrow multipliable* and b. :cpp:type:`new_type::base_type` is *nothrow copy-constructible* @@ -584,7 +620,7 @@ Arithmetic Operators :returns: A reference to the first argument containing the value modified by applying :literal:`*=` to the objects contained by :literal:`lhs` and :literal:`rhs`. :throws: Any exception thrown by the multiplication-assignment operator of the objects contained by :literal:`lhs` and :literal:`rhs`. This operator shall be noexcept iff. - + a. :cpp:type:`new_type::base_type` is *nothrow multiply-assignable* and b. :cpp:type:`new_type::base_type` is *nothrow copy-constructible* @@ -608,7 +644,7 @@ Arithmetic Operators :returns: A new instance of :cpp:class:`new_type\` containing the result of applying :literal:`/` to the objects contained by :literal:`lhs` and :literal:`rhs`. :throws: Any exception thrown by the division operator of the objects contained by :literal:`lhs` and :literal:`rhs`. This operator shall be noexcept iff. - + a. :cpp:type:`new_type::base_type` is *nothrow dividable* and b. :cpp:type:`new_type::base_type` is *nothrow copy-constructible* @@ -631,7 +667,7 @@ Arithmetic Operators :returns: A reference to the first argument containing the value modified by applying :literal:`/=` to the objects contained by :literal:`lhs` and :literal:`rhs`. :throws: Any exception thrown by the division-assignment operator of the objects contained by :literal:`lhs` and :literal:`rhs`. This operator shall be noexcept iff. - + a. :cpp:type:`new_type::base_type` is *nothrow divide-assignable* and b. :cpp:type:`new_type::base_type` is *nothrow copy-constructible* @@ -642,6 +678,45 @@ Arithmetic Operators .. versionadded:: 1.0.0 +Iterators +~~~~~~~~~ + +.. cpp:function:: template \ + constexpr new_type::iterator begin(new_type & obj) + + Get an iterator to the beginning of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator to the begining of the object of contained by :literal:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`begin(BaseType &)` that returns an instance of type :cpp:type:`new_type::iterator` + + .. versionadded:: 1.1.0 + +.. cpp:function:: template \ + constexpr new_type::const_iterator begin(new_type const & obj) + + Get a constant iterator to the beginning of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator to the begining of the object of contained by :cpp:var:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`begin(BaseType const &)` that returns an instance of type :cpp:type:`new_type::const_iterator` + + .. versionadded:: 1.1.0 + :cpp:class:`std::hash` Support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -660,7 +735,7 @@ Arithmetic Operators :returns: The result of applying :cpp:class:`std::hash` to the object contained by :literal:`value` :throws: Any exception thrown by the call operator of the specialization of :cpp:class`std::hash` for the type of the object contained by :literal:`value`. :enablement: This operator shall be available iff. - + a. :cpp:type:`nt::new_type::base_type` is hashable and b. the :cpp:var:`derivation clause ` contains :cpp:var:`Hash `. @@ -731,15 +806,18 @@ Standard derivation tags .. cpp:var:: auto constexpr Indirection = derivable{} - .. .. cpp:function:: constexpr BaseType operator->() noexcept + This tag enables the derivation of the "member access through pointer" operator :cpp:func:`operator->() ()()>` (both in :literal:`const` and non-:literal:`const` variants). + + .. versionadded:: 1.0.0 - .. **enablement:** This operator shall be available iff. this :cpp:class:`new_type`'s :cpp:var:`derivation_clause` contains :cpp:var:`Indirection` +.. cpp:var:: auto constexpr Iterable = derivable{} - .. .. cpp:function:: constexpr BaseType const * operator->() const noexcept + This tag enables the derivation of the following "standard iterator functions": - This tag enables the derivation of the "member access through pointer" operator :cpp:func:`operator->() ()()>` (both in :literal:`const` and non-:literal:`const` variants). + * :cpp:func:`begin() ` + * :cpp:func:`begin() const ` - .. versionadded:: 1.0.0 + .. versionadded:: 1.1.0 .. cpp:var:: auto constexpr Read = derivable{} @@ -750,7 +828,7 @@ Standard derivation tags .. cpp:var:: auto constexpr Relational = derivable{} This tag enables the derivation of the following relational operators: - + * :cpp:func:`operator\<(new_type const &, new_type const &) constexpr bool operator<(new_type const &, new_type const &)>` * :cpp:func:`operator>(new_type const &, new_type const &) constexpr bool operator>(new_type const &, new_type const &)>` * :cpp:func:`operator\<=(new_type const &, new_type const &) constexpr bool operator<=(new_type const &, new_type const &)>` @@ -774,7 +852,7 @@ Function template :cpp:func:`deriving` .. cpp:function:: template \ constexpr derivation_clause deriving(derivable... features) noexcept - + This function can be used to create a new :cpp:class:`derivation_clause` for use in the definitions of instances of :cpp:class:`new_type`. .. versionadded:: 1.0.0 @@ -811,8 +889,8 @@ Class template :cpp:class:`derivation_clause` Check if this :cpp:class:`derivation clause ` contains the given derivation - :tparam DerivableTag: A tag uniquely identifying a derivation - + :tparam DerivableTag: A tag uniquely identifying a derivation + .. cpp:function:: template \ constexpr bool operator()(derivable, derivable...) const noexcept @@ -845,7 +923,7 @@ Class template :cpp:class:`derivation_clause` .. cpp:function:: template \ constexpr bool operator<(derivation_clause other) const noexcept - + Check if this :cpp:class:`derivation clause ` is a subset of the one represented by :cpp:any:`other`. One :cpp:class:`derivation clause ` is considered to be a subset of another iff. the list of derivations of this instance forms a proper subset of the list of derivations of the other. diff --git a/include/newtype/derivable.hpp b/include/newtype/derivable.hpp index 19c79d9..faa844d 100644 --- a/include/newtype/derivable.hpp +++ b/include/newtype/derivable.hpp @@ -60,6 +60,13 @@ namespace nt */ auto constexpr Indirection = derivable{}; + /** + * @brief A tag to enable derivation of the iterator accessors + * + * @since 1.0.0 + */ + auto constexpr Iterable = derivable{}; + /** * @brief A tag to enable derivation of the stream input operator * diff --git a/include/newtype/impl/new_type_iterator_types.hpp b/include/newtype/impl/new_type_iterator_types.hpp new file mode 100644 index 0000000..037f08d --- /dev/null +++ b/include/newtype/impl/new_type_iterator_types.hpp @@ -0,0 +1,42 @@ +#ifndef NEWTYPE_IMPL_NEW_TYPE_ITERATOR_TYPES_HPP +#define NEWTYPE_IMPL_NEW_TYPE_ITERATOR_TYPES_HPP + +#include "newtype/version.hpp" + +#include + +namespace nt::impl +{ + + template> + struct new_type_iterator + { + }; + + template + struct new_type_iterator> + { + using iterator = typename T::iterator; + }; + + template> + struct new_type_const_iterator + { + }; + + template + struct new_type_const_iterator> + { + using const_iterator = typename T::const_iterator; + }; + + template + struct new_type_iterator_types + : new_type_iterator + , new_type_const_iterator + { + }; + +} // namespace nt::impl + +#endif \ No newline at end of file diff --git a/include/newtype/impl/type_traits_extensions.hpp b/include/newtype/impl/type_traits_extensions.hpp index 1f46fb4..7096578 100644 --- a/include/newtype/impl/type_traits_extensions.hpp +++ b/include/newtype/impl/type_traits_extensions.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include namespace nt::impl @@ -1051,6 +1052,77 @@ namespace nt::impl } // namespace std_support + inline namespace iterable + { + template + struct has_std_begin : std::false_type + { + }; + + template + struct has_std_begin()))>> + : std::is_same()))>> + { + }; + + template + struct has_std_begin()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_std_begin_v = has_std_begin::value; + + template + struct has_free_begin : std::false_type + { + }; + + template + struct has_free_begin()))>> + : std::is_same()))>> + { + }; + + template + struct has_free_begin()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_begin_v = has_free_begin::value; + + template + struct has_member_begin : std::false_type + { + }; + + template + struct has_member_begin().begin())>> + : std::is_same().begin())>> + { + }; + + template + struct has_member_begin().begin())>> + : std::is_same().begin())>> + { + }; + + template + auto constexpr has_member_begin_v = has_member_begin::value; + + template + struct has_begin : std::disjunction, has_free_begin, has_member_begin> + { + }; + + template + auto constexpr has_begin_v = has_begin::value; + } // namespace iterable + } // namespace nt::impl #endif \ No newline at end of file diff --git a/include/newtype/new_type.hpp b/include/newtype/new_type.hpp index ed1de44..0aa1a2e 100644 --- a/include/newtype/new_type.hpp +++ b/include/newtype/new_type.hpp @@ -3,12 +3,14 @@ #include "newtype/derivable.hpp" #include "newtype/deriving.hpp" +#include "newtype/impl/new_type_iterator_types.hpp" #include "newtype/impl/new_type_storage.hpp" #include "newtype/impl/type_traits_extensions.hpp" #include "newtype/version.hpp" #include #include +#include #include #include @@ -26,7 +28,9 @@ namespace nt * @tparam DervivationClause An nt::derivation_clause describing which features shall be automatically derived for the new type alias */ template - class new_type : impl::new_type_move_assignment + class new_type + : impl::new_type_move_assignment + , public impl::new_type_iterator_types { static_assert(!std::is_reference_v, "The base type must not be a reference type"); static_assert(!std::is_void_v>, "The base type must not be possibly cv-qualified void"); @@ -209,6 +213,51 @@ namespace nt { return std::addressof(this->m_value); } + + /// @section Iterators + + /** + * @brief Get the begin iterator of the base type + * + * @return An iterator to the beginning of the base type sequence + * @throw Any exception thrown by the overload of 'begin' selected + */ + template * = nullptr> + auto constexpr begin() + -> std::enable_if_t, typename NewType::iterator> + { + if constexpr (impl::has_member_begin_v) + { + return this->m_value.begin(); + } + else + { + using std::begin; + return begin(this->m_value); + } + } + + /** + * @brief Get the begin iterator of the base type + * + * @note Overload for constant instances + * @return An iterator to the beginning of the base type sequence + * @throw Any exception thrown by the overload of 'begin' selected + */ + template + auto constexpr begin() const + -> std::enable_if_t, typename NewType::const_iterator> + { + if constexpr (impl::has_member_begin_v) + { + return this->m_value.begin(); + } + else + { + using std::begin; + return begin(this->m_value); + } + } }; /// @section Equality comparison operators @@ -569,6 +618,35 @@ namespace nt return lhs; } + /// @section Free Iterator Accessors + + /** + * @brief Get the begin iterator of the base type + * + * @return An iterator to the beginning of the base type sequence + * @throw Any exception thrown by the overload of 'begin' selected + */ + template> + auto constexpr begin(new_type & obj) + -> std::enable_if_t, typename NewType::iterator> + { + return begin(obj); + } + + /** + * @brief Get the begin iterator of the base type + * + * @note Overload for constant instances + * @return An iterator to the beginning of the base type sequence + * @throw Any exception thrown by the overload of 'begin' selected + */ + template> + auto constexpr begin(new_type const & obj) + -> std::enable_if_t, typename NewType::const_iterator> + { + return begin(obj); + } + } // namespace nt namespace std diff --git a/test/include/iterable_suite.hpp b/test/include/iterable_suite.hpp new file mode 100644 index 0000000..c2bbc6e --- /dev/null +++ b/test/include/iterable_suite.hpp @@ -0,0 +1,11 @@ +#ifndef NEWTYPE_TEST_ITERABLE_SUITE_HPP +#define NEWTYPE_TEST_ITERABLE_SUITE_HPP + +#include + +#include +#include + +auto iterable_suite() -> std::pair; + +#endif \ No newline at end of file diff --git a/test/src/driver.cpp b/test/src/driver.cpp index cfd6b90..a0e8904 100644 --- a/test/src/driver.cpp +++ b/test/src/driver.cpp @@ -4,6 +4,7 @@ #include "equality_comparison_suite.hpp" #include "hash_suite.hpp" #include "io_operators_suite.hpp" +#include "iterable_suite.hpp" #include "new_type_constructor_suite.hpp" #include "relational_operators_suite.hpp" @@ -61,6 +62,7 @@ int main(int argc, char ** argv) io_operators_suite(), arithmetic_suite(), hash_suite(), + iterable_suite(), }; auto selectors = get_test_selectors(suites); diff --git a/test/src/iterable_suite.cpp b/test/src/iterable_suite.cpp new file mode 100644 index 0000000..2470571 --- /dev/null +++ b/test/src/iterable_suite.cpp @@ -0,0 +1,61 @@ +#include "iterable_suite.hpp" + +#include "kawaii.hpp" +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" +#include "newtype/impl/type_traits_extensions.hpp" +#include "newtype/new_type.hpp" + +#include + +#include +#include + +namespace +{ + +} + +inline namespace begin_tests +{ + + auto a_new__type_not_deriving_iterable_has_no_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_begin_v)); + } + + auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_begin() -> void + { + static_assert(!nt::impl::has_begin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_begin_v)); + } + + auto a_new__type_based_on_an_iterable_type_with_member_begin_deriving_iterable_has_member_begin() -> void + { + static_assert(nt::impl::has_member_begin_v>); + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + ASSERT(nt::impl::has_member_begin_v); + } + + auto a_new__type_based_on_an_iterable_type_with_constant_member_begin_deriving_iterable_has_constant_member_begin() -> void + { + static_assert(nt::impl::has_member_begin_v>); + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + ASSERT(nt::impl::has_member_begin_v); + } + +} // namespace begin_tests + +auto iterable_suite() -> std::pair +{ + return {{ + /// 'begin' Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_begin), + KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_begin), + KAWAII(a_new__type_based_on_an_iterable_type_with_member_begin_deriving_iterable_has_member_begin), + KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_begin_deriving_iterable_has_constant_member_begin), + }, + "Iterable Tests"}; +} \ No newline at end of file -- cgit v1.2.3 From aff9ce77fa93c0ecd530e0c39c89ebd0b3fb1ae5 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Feb 2020 21:26:15 +0100 Subject: doc: update python dependencies --- doc/Pipfile.lock | 74 +++++++++++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 35 deletions(-) diff --git a/doc/Pipfile.lock b/doc/Pipfile.lock index f23f13b..5cf9831 100644 --- a/doc/Pipfile.lock +++ b/doc/Pipfile.lock @@ -25,10 +25,10 @@ }, "babel": { "hashes": [ - "sha256:af92e6106cb7c55286b25b38ad7695f8b4efb36a90ba483d7f7a6628c46158ab", - "sha256:e86135ae101e31e2c8ec20a4e0c5220f4eed12487d5cf3f78be7e98d3a57fc28" + "sha256:1aac2ae2d0d8ea368fa90906567f5c08463d98ade155c0c4bfedd6a0f7160e38", + "sha256:d670ea0b10f8b723672d3a6abeb87b565b244da220d76b4dba1b66269ec152d4" ], - "version": "==2.7.0" + "version": "==2.8.0" }, "certifi": { "hashes": [ @@ -46,32 +46,31 @@ }, "docutils": { "hashes": [ - "sha256:6c4f696463b79f1fb8ba0c594b63840ebd41f059e92b31957c46b74a4599b6d0", - "sha256:9e4d7ecfc600058e07ba661411a2b7de2fd0fafa17d1a7f7361cd47b1175c827", - "sha256:a2aeea129088da402665e92e0b25b04b073c04b2dce4ab65caaa38b7ce2e1a99" + "sha256:0c5b78adfbf7762415433f5515cd5c9e762339e23369dbe8000d84a4bf4ab3af", + "sha256:c2de3a60e9e7d07be26b7f2b00ca0309c207e06c100f9cc2a94931fc75a478fc" ], - "version": "==0.15.2" + "version": "==0.16" }, "idna": { "hashes": [ - "sha256:c357b3f628cf53ae2c4c05627ecc484553142ca23264e593d327bcde5e9c3407", - "sha256:ea8b7f6188e6fa117537c3df7da9fc686d485087abf6ac197f9c46432f7e4a3c" + "sha256:7588d1c14ae4c77d74036e8c22ff447b26d0fde8f007354fd48a7814db15b7cb", + "sha256:a068a21ceac8a4d63dbfd964670474107f541babbd2250d61922f029858365fa" ], - "version": "==2.8" + "version": "==2.9" }, "imagesize": { "hashes": [ - "sha256:3f349de3eb99145973fefb7dbe38554414e5c30abd0c8e4b970a7c9d09f3a1d8", - "sha256:f3832918bc3c66617f92e35f5d70729187676313caa60c187eb0f28b8fe5e3b5" + "sha256:6965f19a6a2039c7d48bca7dba2473069ff854c36ae6f19d2cde309d998228a1", + "sha256:b1f6b5a4eab1f73479a50fb79fcf729514a900c341d8503d62a62dbc4127a2b1" ], - "version": "==1.1.0" + "version": "==1.2.0" }, "jinja2": { "hashes": [ - "sha256:74320bb91f31270f9551d46522e33af46a80c3d619f4a4bf42b3164d30b5911f", - "sha256:9fe95f19286cfefaa917656583d020be14e7859c6b0252588391e47db34527de" + "sha256:93187ffbc7808079673ef52771baa950426fd664d3aad1d0fa3e95644360e250", + "sha256:b0eaf100007721b5c16c1fc1eecb87409464edc10469ddc9a22a27a99123be49" ], - "version": "==2.10.3" + "version": "==2.11.1" }, "markupsafe": { "hashes": [ @@ -79,13 +78,16 @@ "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161", "sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235", "sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5", + "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42", "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff", "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b", "sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1", "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e", "sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183", "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66", + "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b", "sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1", + "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15", "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1", "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e", "sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b", @@ -102,16 +104,18 @@ "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6", "sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f", "sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f", - "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7" + "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2", + "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7", + "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be" ], "version": "==1.1.1" }, "packaging": { "hashes": [ - "sha256:28b924174df7a2fa32c1953825ff29c61e2f5e082343165438812f00d3a7fc47", - "sha256:d9551545c6d761f3def1677baf08ab2a3ca17c56879e70fecba2fc4dde4ed108" + "sha256:170748228214b70b672c581a3dd610ee51f733018650740e98c7df862a583f73", + "sha256:e665345f9eef0c621aa0bf2f8d78cf6d21904eef16a93f020240b704a57f1334" ], - "version": "==19.2" + "version": "==20.1" }, "pygments": { "hashes": [ @@ -136,17 +140,17 @@ }, "requests": { "hashes": [ - "sha256:11e007a8a2aa0323f5a921e9e6a2d7e4e67d9877e85773fba9ba6419025cbeb4", - "sha256:9cf5292fcd0f598c671cfc1e0d7d1a7f13bb8085e9a590f48c010551dc6c4b31" + "sha256:43999036bfa82904b6af1d99e4882b560e5e2c68e5c4b0aa03b655f3d7d73fee", + "sha256:b3f43d496c6daba4493e7c431722aeb7dbc6288f52a6e04e7b6023b0247817e6" ], - "version": "==2.22.0" + "version": "==2.23.0" }, "six": { "hashes": [ - "sha256:1f1b7d42e254082a9db6279deae68afb421ceba6158efa6131de7b3003ee93fd", - "sha256:30f610279e8b2578cab6db20741130331735c781b56053c59c4076da27f06b66" + "sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a", + "sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c" ], - "version": "==1.13.0" + "version": "==1.14.0" }, "snowballstemmer": { "hashes": [ @@ -157,11 +161,11 @@ }, "sphinx": { "hashes": [ - "sha256:298537cb3234578b2d954ff18c5608468229e116a9757af3b831c2b2b4819159", - "sha256:e6e766b74f85f37a5f3e0773a1e1be8db3fcb799deb58ca6d18b70b0b44542a5" + "sha256:525527074f2e0c2585f68f73c99b4dc257c34bbe308b27f5f8c7a6e20642742f", + "sha256:543d39db5f82d83a5c1aa0c10c88f2b6cff2da3e711aa849b2c627b4b403bbd9" ], "index": "pypi", - "version": "==2.3.1" + "version": "==2.4.2" }, "sphinxcontrib-applehelp": { "hashes": [ @@ -179,10 +183,10 @@ }, "sphinxcontrib-htmlhelp": { "hashes": [ - "sha256:4670f99f8951bd78cd4ad2ab962f798f5618b17675c35c5ac3b2132a14ea8422", - "sha256:d4fd39a65a625c9df86d7fa8a2d9f3cd8299a3a4b15db63b50aac9e161d8eff7" + "sha256:3c0bc24a2c41e340ac37c85ced6dafc879ab485c095b1d65d2461ac2f7cca86f", + "sha256:e8f5bb7e31b2dbb25b9cc435c8ab7a79787ebf7f906155729338f3156d93659b" ], - "version": "==1.0.2" + "version": "==1.0.3" }, "sphinxcontrib-jsmath": { "hashes": [ @@ -207,10 +211,10 @@ }, "urllib3": { "hashes": [ - "sha256:a8a318824cc77d1fd4b2bec2ded92646630d7fe8619497b142c84a9e6f5a7293", - "sha256:f3c5fd51747d450d4dcf6f923c81f78f811aab8205fda64b0aba34a4e48b0745" + "sha256:2f3db8b19923a873b3e5256dc9c2dedfa883e33d87c690d9c7913e1f40673cdc", + "sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc" ], - "version": "==1.25.7" + "version": "==1.25.8" } }, "develop": {} -- cgit v1.2.3 From e86b0f201c48fc36b1f635a892d3d0ee3d1e3dfe Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Feb 2020 21:40:17 +0100 Subject: doc: try to install deps from Pipfile --- .readthedocs.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 6514c09..041d294 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -8,7 +8,9 @@ formats: python: version: 3.7 + install: + - pipfile: doc sphinx: builder: singlehtml - configuration: doc/src/conf.py \ No newline at end of file + configuration: doc/src/conf.py -- cgit v1.2.3 From 4ae07755ec05877a4ad88e82429b2ea9685b5587 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Feb 2020 21:42:09 +0100 Subject: doc: try to fix rtd configuration --- .readthedocs.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 041d294..fcbb0ed 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -9,7 +9,8 @@ formats: python: version: 3.7 install: - - pipfile: doc + - method: pipfile + path: doc sphinx: builder: singlehtml -- cgit v1.2.3 From 8f94dedb7bf0eb02af42199ef5ebb26de498b176 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Feb 2020 21:51:50 +0100 Subject: doc: replace Pipfile with requirements.txt --- .readthedocs.yml | 3 +- CMakeLists.txt | 2 +- doc/.gitignore | 2 + doc/Pipfile | 12 --- doc/Pipfile.lock | 221 --------------------------------------------------- doc/requirements.txt | 1 + 6 files changed, 5 insertions(+), 236 deletions(-) create mode 100644 doc/.gitignore delete mode 100644 doc/Pipfile delete mode 100644 doc/Pipfile.lock create mode 100644 doc/requirements.txt diff --git a/.readthedocs.yml b/.readthedocs.yml index fcbb0ed..9f785e6 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -9,8 +9,7 @@ formats: python: version: 3.7 install: - - method: pipfile - path: doc + - requirements: docs/requirements.txt sphinx: builder: singlehtml diff --git a/CMakeLists.txt b/CMakeLists.txt index fe85a55..398b0c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -103,7 +103,7 @@ if(BUILD_DOCS) message(FATAL_ERROR "Could not find pipenv") endif() - execute_process(COMMAND "${PIPENV_EXE}" "install" + execute_process(COMMAND "${PIPENV_EXE}" "install" "-r" "requirements.txt" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/doc" OUTPUT_QUIET ) diff --git a/doc/.gitignore b/doc/.gitignore new file mode 100644 index 0000000..ee826c1 --- /dev/null +++ b/doc/.gitignore @@ -0,0 +1,2 @@ +Pipfile +Pipfile.lock diff --git a/doc/Pipfile b/doc/Pipfile deleted file mode 100644 index 83bd30b..0000000 --- a/doc/Pipfile +++ /dev/null @@ -1,12 +0,0 @@ -[[source]] -name = "pypi" -url = "https://pypi.org/simple" -verify_ssl = true - -[dev-packages] - -[packages] -sphinx = "*" - -[requires] -python_version = "3" diff --git a/doc/Pipfile.lock b/doc/Pipfile.lock deleted file mode 100644 index 5cf9831..0000000 --- a/doc/Pipfile.lock +++ /dev/null @@ -1,221 +0,0 @@ -{ - "_meta": { - "hash": { - "sha256": "776b8d64e53c6045ac2d3198bb1516e980e399d054e903e0769d4e6c13350e50" - }, - "pipfile-spec": 6, - "requires": { - "python_version": "3" - }, - "sources": [ - { - "name": "pypi", - "url": "https://pypi.org/simple", - "verify_ssl": true - } - ] - }, - "default": { - "alabaster": { - "hashes": [ - "sha256:446438bdcca0e05bd45ea2de1668c1d9b032e1a9154c2c259092d77031ddd359", - "sha256:a661d72d58e6ea8a57f7a86e37d86716863ee5e92788398526d58b26a4e4dc02" - ], - "version": "==0.7.12" - }, - "babel": { - "hashes": [ - "sha256:1aac2ae2d0d8ea368fa90906567f5c08463d98ade155c0c4bfedd6a0f7160e38", - "sha256:d670ea0b10f8b723672d3a6abeb87b565b244da220d76b4dba1b66269ec152d4" - ], - "version": "==2.8.0" - }, - "certifi": { - "hashes": [ - "sha256:017c25db2a153ce562900032d5bc68e9f191e44e9a0f762f373977de9df1fbb3", - "sha256:25b64c7da4cd7479594d035c08c2d809eb4aab3a26e5a990ea98cc450c320f1f" - ], - "version": "==2019.11.28" - }, - "chardet": { - "hashes": [ - "sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae", - "sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691" - ], - "version": "==3.0.4" - }, - "docutils": { - "hashes": [ - "sha256:0c5b78adfbf7762415433f5515cd5c9e762339e23369dbe8000d84a4bf4ab3af", - "sha256:c2de3a60e9e7d07be26b7f2b00ca0309c207e06c100f9cc2a94931fc75a478fc" - ], - "version": "==0.16" - }, - "idna": { - "hashes": [ - "sha256:7588d1c14ae4c77d74036e8c22ff447b26d0fde8f007354fd48a7814db15b7cb", - "sha256:a068a21ceac8a4d63dbfd964670474107f541babbd2250d61922f029858365fa" - ], - "version": "==2.9" - }, - "imagesize": { - "hashes": [ - "sha256:6965f19a6a2039c7d48bca7dba2473069ff854c36ae6f19d2cde309d998228a1", - "sha256:b1f6b5a4eab1f73479a50fb79fcf729514a900c341d8503d62a62dbc4127a2b1" - ], - "version": "==1.2.0" - }, - "jinja2": { - "hashes": [ - "sha256:93187ffbc7808079673ef52771baa950426fd664d3aad1d0fa3e95644360e250", - "sha256:b0eaf100007721b5c16c1fc1eecb87409464edc10469ddc9a22a27a99123be49" - ], - "version": "==2.11.1" - }, - "markupsafe": { - "hashes": [ - "sha256:00bc623926325b26bb9605ae9eae8a215691f33cae5df11ca5424f06f2d1f473", - "sha256:09027a7803a62ca78792ad89403b1b7a73a01c8cb65909cd876f7fcebd79b161", - "sha256:09c4b7f37d6c648cb13f9230d847adf22f8171b1ccc4d5682398e77f40309235", - "sha256:1027c282dad077d0bae18be6794e6b6b8c91d58ed8a8d89a89d59693b9131db5", - "sha256:13d3144e1e340870b25e7b10b98d779608c02016d5184cfb9927a9f10c689f42", - "sha256:24982cc2533820871eba85ba648cd53d8623687ff11cbb805be4ff7b4c971aff", - "sha256:29872e92839765e546828bb7754a68c418d927cd064fd4708fab9fe9c8bb116b", - "sha256:43a55c2930bbc139570ac2452adf3d70cdbb3cfe5912c71cdce1c2c6bbd9c5d1", - "sha256:46c99d2de99945ec5cb54f23c8cd5689f6d7177305ebff350a58ce5f8de1669e", - "sha256:500d4957e52ddc3351cabf489e79c91c17f6e0899158447047588650b5e69183", - "sha256:535f6fc4d397c1563d08b88e485c3496cf5784e927af890fb3c3aac7f933ec66", - "sha256:596510de112c685489095da617b5bcbbac7dd6384aeebeda4df6025d0256a81b", - "sha256:62fe6c95e3ec8a7fad637b7f3d372c15ec1caa01ab47926cfdf7a75b40e0eac1", - "sha256:6788b695d50a51edb699cb55e35487e430fa21f1ed838122d722e0ff0ac5ba15", - "sha256:6dd73240d2af64df90aa7c4e7481e23825ea70af4b4922f8ede5b9e35f78a3b1", - "sha256:717ba8fe3ae9cc0006d7c451f0bb265ee07739daf76355d06366154ee68d221e", - "sha256:79855e1c5b8da654cf486b830bd42c06e8780cea587384cf6545b7d9ac013a0b", - "sha256:7c1699dfe0cf8ff607dbdcc1e9b9af1755371f92a68f706051cc8c37d447c905", - "sha256:88e5fcfb52ee7b911e8bb6d6aa2fd21fbecc674eadd44118a9cc3863f938e735", - "sha256:8defac2f2ccd6805ebf65f5eeb132adcf2ab57aa11fdf4c0dd5169a004710e7d", - "sha256:98c7086708b163d425c67c7a91bad6e466bb99d797aa64f965e9d25c12111a5e", - "sha256:9add70b36c5666a2ed02b43b335fe19002ee5235efd4b8a89bfcf9005bebac0d", - "sha256:9bf40443012702a1d2070043cb6291650a0841ece432556f784f004937f0f32c", - "sha256:ade5e387d2ad0d7ebf59146cc00c8044acbd863725f887353a10df825fc8ae21", - "sha256:b00c1de48212e4cc9603895652c5c410df699856a2853135b3967591e4beebc2", - "sha256:b1282f8c00509d99fef04d8ba936b156d419be841854fe901d8ae224c59f0be5", - "sha256:b2051432115498d3562c084a49bba65d97cf251f5a331c64a12ee7e04dacc51b", - "sha256:ba59edeaa2fc6114428f1637ffff42da1e311e29382d81b339c1817d37ec93c6", - "sha256:c8716a48d94b06bb3b2524c2b77e055fb313aeb4ea620c8dd03a105574ba704f", - "sha256:cd5df75523866410809ca100dc9681e301e3c27567cf498077e8551b6d20e42f", - "sha256:cdb132fc825c38e1aeec2c8aa9338310d29d337bebbd7baa06889d09a60a1fa2", - "sha256:e249096428b3ae81b08327a63a485ad0878de3fb939049038579ac0ef61e17e7", - "sha256:e8313f01ba26fbbe36c7be1966a7b7424942f670f38e666995b88d012765b9be" - ], - "version": "==1.1.1" - }, - "packaging": { - "hashes": [ - "sha256:170748228214b70b672c581a3dd610ee51f733018650740e98c7df862a583f73", - "sha256:e665345f9eef0c621aa0bf2f8d78cf6d21904eef16a93f020240b704a57f1334" - ], - "version": "==20.1" - }, - "pygments": { - "hashes": [ - "sha256:2a3fe295e54a20164a9df49c75fa58526d3be48e14aceba6d6b1e8ac0bfd6f1b", - "sha256:98c8aa5a9f778fcd1026a17361ddaf7330d1b7c62ae97c3bb0ae73e0b9b6b0fe" - ], - "version": "==2.5.2" - }, - "pyparsing": { - "hashes": [ - "sha256:4c830582a84fb022400b85429791bc551f1f4871c33f23e44f353119e92f969f", - "sha256:c342dccb5250c08d45fd6f8b4a559613ca603b57498511740e65cd11a2e7dcec" - ], - "version": "==2.4.6" - }, - "pytz": { - "hashes": [ - "sha256:1c557d7d0e871de1f5ccd5833f60fb2550652da6be2693c1e02300743d21500d", - "sha256:b02c06db6cf09c12dd25137e563b31700d3b80fcc4ad23abb7a315f2789819be" - ], - "version": "==2019.3" - }, - "requests": { - "hashes": [ - "sha256:43999036bfa82904b6af1d99e4882b560e5e2c68e5c4b0aa03b655f3d7d73fee", - "sha256:b3f43d496c6daba4493e7c431722aeb7dbc6288f52a6e04e7b6023b0247817e6" - ], - "version": "==2.23.0" - }, - "six": { - "hashes": [ - "sha256:236bdbdce46e6e6a3d61a337c0f8b763ca1e8717c03b369e87a7ec7ce1319c0a", - "sha256:8f3cd2e254d8f793e7f3d6d9df77b92252b52637291d0f0da013c76ea2724b6c" - ], - "version": "==1.14.0" - }, - "snowballstemmer": { - "hashes": [ - "sha256:209f257d7533fdb3cb73bdbd24f436239ca3b2fa67d56f6ff88e86be08cc5ef0", - "sha256:df3bac3df4c2c01363f3dd2cfa78cce2840a79b9f1c2d2de9ce8d31683992f52" - ], - "version": "==2.0.0" - }, - "sphinx": { - "hashes": [ - "sha256:525527074f2e0c2585f68f73c99b4dc257c34bbe308b27f5f8c7a6e20642742f", - "sha256:543d39db5f82d83a5c1aa0c10c88f2b6cff2da3e711aa849b2c627b4b403bbd9" - ], - "index": "pypi", - "version": "==2.4.2" - }, - "sphinxcontrib-applehelp": { - "hashes": [ - "sha256:edaa0ab2b2bc74403149cb0209d6775c96de797dfd5b5e2a71981309efab3897", - "sha256:fb8dee85af95e5c30c91f10e7eb3c8967308518e0f7488a2828ef7bc191d0d5d" - ], - "version": "==1.0.1" - }, - "sphinxcontrib-devhelp": { - "hashes": [ - "sha256:6c64b077937330a9128a4da74586e8c2130262f014689b4b89e2d08ee7294a34", - "sha256:9512ecb00a2b0821a146736b39f7aeb90759834b07e81e8cc23a9c70bacb9981" - ], - "version": "==1.0.1" - }, - "sphinxcontrib-htmlhelp": { - "hashes": [ - "sha256:3c0bc24a2c41e340ac37c85ced6dafc879ab485c095b1d65d2461ac2f7cca86f", - "sha256:e8f5bb7e31b2dbb25b9cc435c8ab7a79787ebf7f906155729338f3156d93659b" - ], - "version": "==1.0.3" - }, - "sphinxcontrib-jsmath": { - "hashes": [ - "sha256:2ec2eaebfb78f3f2078e73666b1415417a116cc848b72e5172e596c871103178", - "sha256:a9925e4a4587247ed2191a22df5f6970656cb8ca2bd6284309578f2153e0c4b8" - ], - "version": "==1.0.1" - }, - "sphinxcontrib-qthelp": { - "hashes": [ - "sha256:513049b93031beb1f57d4daea74068a4feb77aa5630f856fcff2e50de14e9a20", - "sha256:79465ce11ae5694ff165becda529a600c754f4bc459778778c7017374d4d406f" - ], - "version": "==1.0.2" - }, - "sphinxcontrib-serializinghtml": { - "hashes": [ - "sha256:c0efb33f8052c04fd7a26c0a07f1678e8512e0faec19f4aa8f2473a8b81d5227", - "sha256:db6615af393650bf1151a6cd39120c29abaf93cc60db8c48eb2dddbfdc3a9768" - ], - "version": "==1.1.3" - }, - "urllib3": { - "hashes": [ - "sha256:2f3db8b19923a873b3e5256dc9c2dedfa883e33d87c690d9c7913e1f40673cdc", - "sha256:87716c2d2a7121198ebcb7ce7cccf6ce5e9ba539041cfbaeecfb641dc0bf6acc" - ], - "version": "==1.25.8" - } - }, - "develop": {} -} diff --git a/doc/requirements.txt b/doc/requirements.txt new file mode 100644 index 0000000..b80a564 --- /dev/null +++ b/doc/requirements.txt @@ -0,0 +1 @@ +sphinx==2.4.2 -- cgit v1.2.3 From da08fcb57fd7276649af800a61ee9c008026b6c2 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 21 Feb 2020 21:53:05 +0100 Subject: doc: fix requirements path in rtd config --- .readthedocs.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 9f785e6..6dd17ed 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -9,7 +9,7 @@ formats: python: version: 3.7 install: - - requirements: docs/requirements.txt + - requirements: doc/requirements.txt sphinx: builder: singlehtml -- cgit v1.2.3 From c4e3450fb1de240ec10eea27e8b9079cab5f8a55 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 22 Feb 2020 17:16:23 +0100 Subject: new_type: adjust enablement of begin --- include/newtype/new_type.hpp | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/include/newtype/new_type.hpp b/include/newtype/new_type.hpp index 0aa1a2e..ef36a75 100644 --- a/include/newtype/new_type.hpp +++ b/include/newtype/new_type.hpp @@ -224,17 +224,9 @@ namespace nt */ template * = nullptr> auto constexpr begin() - -> std::enable_if_t, typename NewType::iterator> + -> std::enable_if_t, typename NewType::iterator> { - if constexpr (impl::has_member_begin_v) - { - return this->m_value.begin(); - } - else - { - using std::begin; - return begin(this->m_value); - } + return this->m_value.begin(); } /** @@ -245,18 +237,10 @@ namespace nt * @throw Any exception thrown by the overload of 'begin' selected */ template - auto constexpr begin() const - -> std::enable_if_t, typename NewType::const_iterator> + auto constexpr begin() const -> std::enable_if_t, + typename NewType::const_iterator> { - if constexpr (impl::has_member_begin_v) - { - return this->m_value.begin(); - } - else - { - using std::begin; - return begin(this->m_value); - } + return this->m_value.begin(); } }; -- cgit v1.2.3 From 85f86c2045135748146606866fc257a2f0e571a0 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 22 Feb 2020 17:19:45 +0100 Subject: doc: add rst linter configuration --- doc8.ini | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 doc8.ini diff --git a/doc8.ini b/doc8.ini new file mode 100644 index 0000000..882336a --- /dev/null +++ b/doc8.ini @@ -0,0 +1,2 @@ +[doc8] +ignore=D001 \ No newline at end of file -- cgit v1.2.3 From dc3d24f193743541cc7e7b623a240fecc2d095f4 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 22 Feb 2020 17:24:31 +0100 Subject: ide: clean up configuration --- .vscode/settings.json | 72 +++++---------------------------------------------- 1 file changed, 6 insertions(+), 66 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 8caed1c..d237db4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,75 +1,15 @@ { - "files.associations": { - ".clang-format": "yaml", - "array": "cpp", - "chrono": "cpp", - "functional": "cpp", - "istream": "cpp", - "ostream": "cpp", - "ratio": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "variant": "cpp", - "atomic": "cpp", - "hash_map": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "condition_variable": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "cstring": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "list": "cpp", - "map": "cpp", - "set": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "string": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iomanip": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "limits": "cpp", - "mutex": "cpp", - "new": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "cfenv": "cpp", - "cinttypes": "cpp", - "typeinfo": "cpp", - "valarray": "cpp", - "*.ipp": "cpp", - "bitset": "cpp", - "netfwd": "cpp" - }, + // CMake Configuration "cmake.configureArguments": "-DCMAKE_EXPORT_COMPILE_COMMANDS=YES", "cmake.cpptools.intelliSenseMode": "gcc-x64", "cmake.cpptools.guessSourceFileConfigurations": true, + + // C++ Configuration "[cpp]": { "editor.formatOnSave": true }, + "C_Cpp.autoAddFileAssociations": false, + + // RST Configuration "restructuredtext.confPath": "${workspaceFolder}/doc/src" } \ No newline at end of file -- cgit v1.2.3 From db75b825ab983ac731516622898a706035473d15 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 22 Feb 2020 17:50:10 +0100 Subject: doc: reduce header inline documentation --- doc/src/index.rst | 10 +- include/newtype/new_type.hpp | 271 +++++++++---------------------------------- 2 files changed, 62 insertions(+), 219 deletions(-) diff --git a/doc/src/index.rst b/doc/src/index.rst index e8d50d6..17101c9 100644 --- a/doc/src/index.rst +++ b/doc/src/index.rst @@ -180,14 +180,14 @@ Class template :cpp:class:`new_type` .. cpp:function:: constexpr BaseType decay() const - Retrieve the object contained by this :cpp:class:`new_type` object + Retrieve a copy of the object contained by this :cpp:class:`new_type` object :throws: Any exception thrown by the copy-constructor of this :cpp:class:`new_type`'s :cpp:type:`base_type`. This operator shall be noexcept iff. this :cpp:class:`new_type`'s :cpp:type:`base_type` is *nothrow copy-constructible*. .. cpp:function:: constexpr operator BaseType() const - Retrieve the object contained by this :cpp:class:`new_type` object + Retrieve a copy of the object contained by this :cpp:class:`new_type` object :throws: Any exception thrown by the copy-constructor of this :cpp:class:`new_type`'s :cpp:type:`base_type`. This operator shall be noexcept iff. this :cpp:class:`new_type`'s :cpp:type:`base_type` is *nothrow copy-constructible*. @@ -443,6 +443,8 @@ Stream I/O Operators typename StreamTraits> \ std::basic_ostream & operator<<(std::basic_ostream & out, new_type const & value) + Write an instance of :cpp:class:`new_type\` to a standard :cpp:type:`ostream `. + :tparam BaseType: |BaseTypeDoc| :tparam TagType: |TagTypeDoc| :tparam DerivationClause: |DerivationClauseDoc| @@ -467,6 +469,8 @@ Stream I/O Operators typename StreamTraits> \ std::basic_istream & operator>>(std::basic_istream & in, new_type & value) + Read an instance of :cpp:class:`new_type\` from a standard :cpp:type:`istream `. + :tparam BaseType: |BaseTypeDoc| :tparam TagType: |TagTypeDoc| :tparam DerivationClause: |DerivationClauseDoc| @@ -729,6 +733,8 @@ Iterators :tparam TagType: |TagTypeDoc| :tparam DerivationClause: |DerivationClauseDoc| + Hash an instance of :cpp:class:`new_type` using the hash implementation of the :cpp:type:`base type `. + .. cpp:function:: constexpr std::size operator()(nt::new_type const & value) const :param value: A :cpp:class:`nt::new_type` value to be hashed diff --git a/include/newtype/new_type.hpp b/include/newtype/new_type.hpp index ef36a75..0cf6ec3 100644 --- a/include/newtype/new_type.hpp +++ b/include/newtype/new_type.hpp @@ -18,14 +18,7 @@ namespace nt { /** - * @brief Create a new type based on an existing one - * - * The class template nt::new_type is designed to allow the creation of new types based on existing types. Similarly to the Haskell newtype, - * this class template creates a new type that is layout equivalent to the underlying type. - * - * @tparam BaseType An existing type that shall aliased - * @tparam TagType A unique type to identify this nt::new_type - * @tparam DervivationClause An nt::derivation_clause describing which features shall be automatically derived for the new type alias + * Create a new type based on an existing one */ template class new_type @@ -72,96 +65,65 @@ namespace nt using super = impl::new_type_move_assignment; public: - /// @section Type aliases + /// Member Type Aliases /** - * @brief The base type of this nt::new_type - * - * This type alias provides convenient access to the contained objects type + * The base type of this nt::new_type */ using base_type = BaseType; /** - * @brief The tag type of this nt::new_type - * - * This type alias provides convenient access to the tag type of this nt::new_type instance + * The tag type of this nt::new_type */ using tag_type = TagType; /** - * @brief The type of the derivation clause of this nt::newtype - * - * This type alias provides convenient access to the type of the derivation clause of this nt::new_type instance + * The type of the derivation clause of this nt::newtype */ using derivation_clause_type = decltype(DerivationClause); - /// @section Derivation clause access + /// Static Data Members /** - * @brief The derivation clause fo this nt::new_type - * - * This static data-member provides conevient access to the derivation clause of this nt::new_type instance + * The derivation clause fo this nt::new_type */ auto constexpr static derivation_clause = DerivationClause; - /// @section Constructors + /// Constructors using super::super; /** - * @brief Construct an instance of this nt::new_type by default initializing the contained object - * - * @note This constructor is available iff. the base type is default-constructible. Otherwise is is defined as deleted. - * @throw This constructor throws any exception thrown the base type constructor. It is noexcept iff. the base type constructor is noexcept + * Construct an instance of this nt::new_type by default initializing the contained object */ constexpr new_type() noexcept(std::is_nothrow_default_constructible_v) = default; /** - * @brief Copy-construct an instance of this nt::new_type from an existing one - * - * @note This constructor is available iff. the base type is copy-constructible. Otherwise is is defined as deleted. - * @throw This constructor throws any exception thrown the base type copy-constructor. It is noexcept iff. the base type copy-constructor - * is noexcept + * Copy-construct an instance of this nt::new_type from an existing one */ constexpr new_type(new_type const &) noexcept(std::is_nothrow_copy_constructible_v) = default; /** - * @brief Move-construct an instance of this nt::new_type from an existing one - * - * @note This constructor is available iff. the base type is move-constructible. Otherwise is is defined as deleted. - * @throw This constructor throws any exception thrown the base type move-constructor. It is noexcept iff. the base types move-constructor - * is noexcept + * Move-construct an instance of this nt::new_type from an existing one */ constexpr new_type(new_type &&) noexcept(std::is_nothrow_move_constructible_v) = default; - /// @section Assignment operators + /// Assignment Operators /** - * @brief Copy-assign the value of an existing instance of this nt::new_type to this instance - * - * @note This assignment operator is available iff. the base type is copy-assignable. Otherwise it is defined as deleted. - * @throw This assignment operator throws any exception thrown by the base type copy-assignment operator. It is noexcept iff. the base type - * copy-assignment operator is noexcept. - * @return A reference to this instance + * Copy-assign the value of an existing instance of this nt::new_type to this instance */ auto constexpr operator=(new_type const &) noexcept(std::is_nothrow_copy_assignable_v) -> new_type & = default; /** - * @brief Move-assign the value of an existing instance of this nt::new_type to this instance - * - * @note This assignment operator is available iff. the base type is move-assignable. Otherwise it is defined as deleted. - * @throw This assignment operator throws any exception thrown by the base type move-assignment operator. It is noexcept iff. the base type - * move-assignment operator is noexcept. - * @return A reference to this instance + * Move-assign the value of an existing instance of this nt::new_type to this instance */ auto constexpr operator=(new_type &&) noexcept(std::is_nothrow_move_assignable_v) -> new_type & = default; - /// @section Accessors + /// Accessors /** - * @brief Obtain a copy of the contained base type object - * - * @return BaseType + * Retrieve a copy of the object contained by this new_type object */ auto constexpr decay() const noexcept(std::is_nothrow_copy_constructible_v) -> BaseType { @@ -169,9 +131,7 @@ namespace nt } /** - * @brief Convert this instance into the equivalent base type value - * - * @note This is only available if the derivation clause of this nt::new_type contains nt::ImplicitConversion + * Retrieve a copy of the object contained by this new_type object */ template * = nullptr> constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) @@ -180,9 +140,7 @@ namespace nt } /** - * @brief Convert this instance into the equivalent base type value - * - * @note This overload is only avalaible if the derivation clause of this nt::new_type does not contain nt::ImplicitConversion + * Convert this instance into the equivalent base type value */ template * = nullptr> explicit constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) @@ -190,12 +148,10 @@ namespace nt return decay(); } - /// @section Indirection operators + /// Member Access Through Pointer /** - * @brief Perform an access to a member of the base type - * - * @return A pointer to the contained base type object + * Perform "member access through pointer" via a pointer to object contained by this new_type */ template auto constexpr operator-> () noexcept -> std::enable_if_t @@ -204,9 +160,7 @@ namespace nt } /** - * @brief Perform an access to a member of the base type - * - * @return A pointer to the contained base type object + * Perform "member access through pointer" via a pointer to object contained by this new_type */ template auto constexpr operator-> () const noexcept -> std::enable_if_t @@ -214,13 +168,10 @@ namespace nt return std::addressof(this->m_value); } - /// @section Iterators + /// Iterators /** - * @brief Get the begin iterator of the base type - * - * @return An iterator to the beginning of the base type sequence - * @throw Any exception thrown by the overload of 'begin' selected + * Get an iterator to the beginning of the object contained by this new_type */ template * = nullptr> auto constexpr begin() @@ -230,11 +181,7 @@ namespace nt } /** - * @brief Get the begin iterator of the base type - * - * @note Overload for constant instances - * @return An iterator to the beginning of the base type sequence - * @throw Any exception thrown by the overload of 'begin' selected + * Get an iterator to the beginning of the object contained by this new_type */ template auto constexpr begin() const -> std::enable_if_t, @@ -244,14 +191,10 @@ namespace nt } }; - /// @section Equality comparison operators + /// Equality Comparison Operators /** - * @brief Compare two objects for equality - * - * @throw This comparison operator throws any exception thrown by the base type comparison operator. It it noexcept iff. the base type - * comparison operator is noexcept. - * @return true iff. the base type comparison operator returns true, false otherwise. + * Check two instances of new_type for equality */ template auto constexpr @@ -263,11 +206,7 @@ namespace nt } /** - * @brief Compare an instance of a given nt::new_type with an object of its base type - * - * @throw This comparison operator throws any exception thrown by the base type comparison operator. It it noexcept iff. the base type - * comparison operator is noexcept. - * @return true iff. the base type comparison operator returns true, false otherwise. + * Check an instance of new_type for equality with an instance of BaseType */ template auto constexpr operator==(new_type const & lhs, @@ -278,11 +217,7 @@ namespace nt } /** - * @brief Compare an instance of the base type with an instance of a given nt::new_type - * - * @throw This comparison operator throws any exception thrown by the base type comparison operator. It it noexcept iff. the base type - * comparison operator is noexcept. - * @return true iff. the base type comparison operator returns true, false otherwise. + * Check an instance of BaseType for equality with an instance of new_type */ template auto constexpr @@ -294,11 +229,7 @@ namespace nt } /** - * @brief Compare two objects for non-equality - * - * @throw This comparison operator throws any exception thrown by the base type comparison operator. It it noexcept iff. the base type - * comparison operator is noexcept. - * @return true iff. the base type comparison operator returns true, false otherwise. + * Check two instances of new_type for in-equality */ template auto constexpr @@ -310,11 +241,7 @@ namespace nt } /** - * @brief Compare an instance of a given nt::new_type with an object of its base type - * - * @throw This comparison operator throws any exception thrown by the base type comparison operator. It it noexcept iff. the base type - * comparison operator is noexcept. - * @return true iff. the base type comparison operator returns true, false otherwise. + * Check an instance of new_type for in-equality with an instance of BaseType */ template auto constexpr operator!=(new_type const & lhs, @@ -325,11 +252,7 @@ namespace nt } /** - * @brief Compare an instance of the base type with an instance of a given nt::new_type - * - * @throw This comparison operator throws any exception thrown by the base type comparison operator. It it noexcept iff. the base type - * comparison operator is noexcept. - * @return true iff. the base type comparison operator returns true, false otherwise. + * Check an instance of BaseType for in-equality with an instance of new_type */ template auto constexpr @@ -340,16 +263,10 @@ namespace nt return lhs != rhs.decay(); } - /// @section Relational operators + /// Relational Comparison Operators /** - * @brief Check if one nt::new_type object is less-than an other - * - * @note This operator is only available if the the derivation clause of this nt::new_type does contains nt::Relational and the base type is - * less-than comparable. - * @throw This comparison operator throws any exception thrown by the base type comparison operator. It it noexcept iff. the base type - * comparison operator is noexcept. - * @return true iff. the base type comparison operator returns true, false otherwise. + * Compare two instances of the same new_type using '<' (less-than) */ template auto constexpr @@ -361,13 +278,7 @@ namespace nt } /** - * Check if one nt::new_type object is greater-than an other - * - * @note This operator is only available if the the derivation clause of this nt::new_type does contains nt::Relational and the base type is - * greater-than comparable. - * @throw This comparison operator throws any exception thrown by the base type comparison operator. It it noexcept iff. the base type - * comparison operator is noexcept. - * @return true iff. the base type comparison operator returns true, false otherwise. + * Compare two instances of the same new_type using '>' (greater-than) */ template auto constexpr @@ -379,13 +290,7 @@ namespace nt } /** - * Check if one nt::new_type object is less-than or equal-to an other - * - * @note This operator is only available if the the derivation clause of this nt::new_type does contains nt::Relational and the base type is - * less-than-or-equal-to comparable. - * @throw This comparison operator throws any exception thrown by the base type comparison operator. It it noexcept iff. the base type - * comparison operator is noexcept. - * @return true iff. the base type comparison operator returns true, false otherwise. + * Compare two instances of the same new_type using '<=' (less-than-equal) */ template auto constexpr @@ -397,13 +302,7 @@ namespace nt } /** - * Check if one nt::new_type object is greater-than or equal-to an other - * - * @note This operator is only available if the the derivation clause of this nt::new_type does contains nt::Relational and the base type is - * greater-than-or-equal comparable - * @throw This comparison operator throws any exception thrown by the base type comparison operator. It it noexcept iff. the base type - * comparison operator is noexcept. - * @return true iff. the base type comparison operator returns true, false otherwise. + * Compare two instances of the same new_type using '>=' (greater-than-equal) */ template auto constexpr @@ -414,15 +313,10 @@ namespace nt return lhs.decay() >= rhs.decay(); } - /// @section Stream input/output operators + /// Stream I/O Operators /** - * @brief Write the contained base type object to a standard output stream - * - * @note This operator is only available if the derivation clause of the passed in nt::new_type object contains nt::Show. - * @param output The output stream to write to - * @param source An instance of an nt::new_type that shall be written to the stream - * @return The a reference to the output stream + * Write an instance of new_type to a standard ostream */ template auto operator<<(std::basic_ostream & output, new_type const & source) noexcept( @@ -434,12 +328,7 @@ namespace nt } /** - * @brief Read an object of the base type from a standard input stream - * - * @note This operator is only available if the derivation clause of the passed in nt::new_type object contains nt::Read. - * @param output The input stream to read from - * @param source An instance of an nt::new_type that shall be read from the stream - * @return The a reference to the input stream + * Read an instance of new_type from the a standard istream */ template auto operator>>(std::basic_istream & input, new_type & target) noexcept( @@ -450,16 +339,10 @@ namespace nt return input >> target.m_value; } - /// @section Arithmetic operators + /// Arithmetic Operators /** - * @brief Add two instances of the same nt::new_type - * - * @note This operator is only available if the derivation clause of the passed in nt::new_type objects contains nt::Arithmetic and the base - * type is addable. - * @param lhs The left-hand side of the addition - * @param rhs The right-hand side of the addition - * @return a new instance of the same nt::new_type + * Add two instances of the same new_type */ template auto constexpr @@ -471,13 +354,7 @@ namespace nt } /** - * @brief Add two instances of the same nt::new_type, modifying the left-hand side - * - * @note This operator is only available if the derivation clause of the passed in nt::new_type objects contains nt::Arithmetic and the base - * type is addable. - * @param lhs The left-hand side of the addition - * @param rhs The right-hand side of the addition - * @return a reference to the the modified value + * Add two instances of the same new_type by overwriting the first one */ template auto constexpr operator+=(new_type & lhs, @@ -490,13 +367,7 @@ namespace nt } /** - * @brief Subtract two instances of the same nt::new_type - * - * @note This operator is only available if the derivation clause of the passed in nt::new_type objects contains nt::Arithmetic and the base - * type is subtractable. - * @param lhs The left-hand side of the subtraction - * @param rhs The right-hand side of the subtraction - * @return a new instance of the same nt::new_type + * Subtract two instances of the same new_type */ template auto constexpr @@ -508,13 +379,7 @@ namespace nt } /** - * @brief Subtract two instances of the same nt::new_type, modifying the left-hand side - * - * @note This operator is only available if the derivation clause of the passed in nt::new_type objects contains nt::Arithmetic and the base - * type is subtractable. - * @param lhs The left-hand side of the subtractition - * @param rhs The right-hand side of the subtractition - * @return a reference to the the modified value + * Subtract two instances of the same new_type by overwriting the first one */ template auto constexpr @@ -528,13 +393,7 @@ namespace nt } /** - * @brief Multiply two instances of the same nt::new_type - * - * @note This operator is only available if the derivation clause of the passed in nt::new_type objects contains nt::Arithmetic and the base - * type is multipliable. - * @param lhs The left-hand side of the multiplication - * @param rhs The right-hand side of the multiplication - * @return a new instance of the same nt::new_type + * Multiply two instances of the same new_type */ template auto constexpr @@ -546,13 +405,7 @@ namespace nt } /** - * @brief Multiply two instances of the same nt::new_type, modifying the left-hand side - * - * @note This operator is only available if the derivation clause of the passed in nt::new_type objects contains nt::Arithmetic and the base - * type is multiplyable. - * @param lhs The left-hand side of the multiplication - * @param rhs The right-hand side of the multiplication - * @return a reference to the the modified value + * Multiply two instances of the same new_type by overwriting the first one */ template auto constexpr @@ -566,13 +419,7 @@ namespace nt } /** - * @brief Divide two instances of the same nt::new_type - * - * @note This operator is only available if the derivation clause of the passed in nt::new_type objects contains nt::Arithmetic and the base - * type is dividable. - * @param lhs The left-hand side of the division - * @param rhs The right-hand side of the division - * @return a new instance of the same nt::new_type + * Divide two instances of the same nt::new_type */ template auto constexpr @@ -584,13 +431,7 @@ namespace nt } /** - * @brief Divide two instances of the same nt::new_type, modifying the left-hand side - * - * @note This operator is only available if the derivation clause of the passed in nt::new_type objects contains nt::Arithmetic and the base - * type is dividable. - * @param lhs The left-hand side of the division - * @param rhs The right-hand side of the division - * @return a reference to the the modified value + * Divide two instances of the same new_type by overwriting the first one */ template auto constexpr operator/=(new_type & lhs, @@ -602,13 +443,10 @@ namespace nt return lhs; } - /// @section Free Iterator Accessors + /// Iterators /** - * @brief Get the begin iterator of the base type - * - * @return An iterator to the beginning of the base type sequence - * @throw Any exception thrown by the overload of 'begin' selected + * Get an iterator to the beginning of the object contained by an instance of new_type */ template> auto constexpr begin(new_type & obj) @@ -618,11 +456,7 @@ namespace nt } /** - * @brief Get the begin iterator of the base type - * - * @note Overload for constant instances - * @return An iterator to the beginning of the base type sequence - * @throw Any exception thrown by the overload of 'begin' selected + * Get a constant iterator to the beginning of the object contained by an instance of new_type */ template> auto constexpr begin(new_type const & obj) @@ -635,6 +469,9 @@ namespace nt namespace std { + /** + * Hash an instance of new_type using the hash implementation of the base type + */ template struct hash> { -- cgit v1.2.3 From 89a9db0dfee60421a5d1a6093af0e554c6cf6be6 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 22 Feb 2020 17:51:33 +0100 Subject: doc: clean up trailing whitespace --- doc/src/index.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/index.rst b/doc/src/index.rst index 17101c9..8ef515f 100644 --- a/doc/src/index.rst +++ b/doc/src/index.rst @@ -772,7 +772,7 @@ Standard derivation tags .. cpp:var:: auto constexpr Arithmetic = derivable{} This tag enables the derivation of the following arithmetic operators: - + * :cpp:func:`operator+(new_type const &, new_type const &) constexpr new_type operator+(new_type const & lhs, new_type const & rhs)>` * :cpp:func:`operator-(new_type const &, new_type const &) constexpr new_type operator-(new_type const & lhs, new_type const & rhs)>` * :cpp:func:`operator*(new_type const &, new_type const &) constexpr new_type operator*(new_type const & lhs, new_type const & rhs)>` -- cgit v1.2.3 From 943033bc921bb328bbc354f15627dbf4bd6ab1e4 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 22 Feb 2020 18:29:07 +0100 Subject: new_type: fix enablement of begin --- include/newtype/impl/type_traits_extensions.hpp | 23 +--------------- include/newtype/new_type.hpp | 25 +++++++++++++----- test/src/iterable_suite.cpp | 35 +++++++++++++++++++++---- 3 files changed, 49 insertions(+), 34 deletions(-) diff --git a/include/newtype/impl/type_traits_extensions.hpp b/include/newtype/impl/type_traits_extensions.hpp index 7096578..80ba5b0 100644 --- a/include/newtype/impl/type_traits_extensions.hpp +++ b/include/newtype/impl/type_traits_extensions.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include namespace nt::impl @@ -1054,26 +1053,6 @@ namespace nt::impl inline namespace iterable { - template - struct has_std_begin : std::false_type - { - }; - - template - struct has_std_begin()))>> - : std::is_same()))>> - { - }; - - template - struct has_std_begin()))>> - : std::is_same()))>> - { - }; - - template - auto constexpr has_std_begin_v = has_std_begin::value; - template struct has_free_begin : std::false_type { @@ -1115,7 +1094,7 @@ namespace nt::impl auto constexpr has_member_begin_v = has_member_begin::value; template - struct has_begin : std::disjunction, has_free_begin, has_member_begin> + struct has_begin : std::disjunction, has_member_begin> { }; diff --git a/include/newtype/new_type.hpp b/include/newtype/new_type.hpp index 0cf6ec3..0db01b2 100644 --- a/include/newtype/new_type.hpp +++ b/include/newtype/new_type.hpp @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -62,6 +61,16 @@ namespace nt -> std::enable_if_t, new_type &>; + template + auto constexpr friend begin(new_type & obj) + -> std::enable_if_t, + typename new_type::iterator>; + + template + auto constexpr friend begin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + using super = impl::new_type_move_assignment; public: @@ -448,21 +457,23 @@ namespace nt /** * Get an iterator to the beginning of the object contained by an instance of new_type */ - template> + template auto constexpr begin(new_type & obj) - -> std::enable_if_t, typename NewType::iterator> + -> std::enable_if_t, + typename new_type::iterator> { - return begin(obj); + return begin(obj.m_value); } /** * Get a constant iterator to the beginning of the object contained by an instance of new_type */ - template> + template auto constexpr begin(new_type const & obj) - -> std::enable_if_t, typename NewType::const_iterator> + -> std::enable_if_t, + typename new_type::const_iterator> { - return begin(obj); + return begin(obj.m_value); } } // namespace nt diff --git a/test/src/iterable_suite.cpp b/test/src/iterable_suite.cpp index 2470571..bf478e1 100644 --- a/test/src/iterable_suite.cpp +++ b/test/src/iterable_suite.cpp @@ -14,7 +14,16 @@ namespace { -} + struct with_member + { + using iterator = void *; + using const_iterator = void const *; + + auto begin() -> iterator; + auto begin() const -> const_iterator; + }; + +} // namespace inline namespace begin_tests { @@ -34,18 +43,32 @@ inline namespace begin_tests auto a_new__type_based_on_an_iterable_type_with_member_begin_deriving_iterable_has_member_begin() -> void { - static_assert(nt::impl::has_member_begin_v>); - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + static_assert(nt::impl::has_member_begin_v); + using type_alias = nt::new_type; ASSERT(nt::impl::has_member_begin_v); } auto a_new__type_based_on_an_iterable_type_with_constant_member_begin_deriving_iterable_has_constant_member_begin() -> void { - static_assert(nt::impl::has_member_begin_v>); - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + static_assert(nt::impl::has_member_begin_v); + using type_alias = nt::new_type; ASSERT(nt::impl::has_member_begin_v); } + auto a_new__type_based_on_an_iterable_type_without_free_begin_deriving_iterable_has_no_free_begin() -> void + { + static_assert(!nt::impl::has_free_begin_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_begin_v); + } + + auto a_new__type_based_on_an_iterable_type_without_constant_free_begin_deriving_iterable_has_no_constant_free_begin() -> void + { + static_assert(!nt::impl::has_free_begin_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_begin_v); + } + } // namespace begin_tests auto iterable_suite() -> std::pair @@ -56,6 +79,8 @@ auto iterable_suite() -> std::pair KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_begin), KAWAII(a_new__type_based_on_an_iterable_type_with_member_begin_deriving_iterable_has_member_begin), KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_begin_deriving_iterable_has_constant_member_begin), + KAWAII(a_new__type_based_on_an_iterable_type_without_free_begin_deriving_iterable_has_no_free_begin), + KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_begin_deriving_iterable_has_no_constant_free_begin), }, "Iterable Tests"}; } \ No newline at end of file -- cgit v1.2.3 From 62ca586910736b5aba6d622ec27a7b00e3c37359 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 22 Feb 2020 19:32:12 +0100 Subject: new_type: add additional iterable tests --- test/src/iterable_suite.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/src/iterable_suite.cpp b/test/src/iterable_suite.cpp index bf478e1..8c08a66 100644 --- a/test/src/iterable_suite.cpp +++ b/test/src/iterable_suite.cpp @@ -69,6 +69,21 @@ inline namespace begin_tests ASSERT(!nt::impl::has_free_begin_v); } + auto accessing_the_first_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto weak = std::array{42, 21, 10}; + auto strong = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(*weak.begin(), *strong.begin()); + } + + auto an_iterator_obtained_via_member_begin_compares_equal_to_an_iterator_obtained_via_free_begin() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto instance = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(begin(instance), instance.begin()); + } + } // namespace begin_tests auto iterable_suite() -> std::pair @@ -81,6 +96,8 @@ auto iterable_suite() -> std::pair KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_begin_deriving_iterable_has_constant_member_begin), KAWAII(a_new__type_based_on_an_iterable_type_without_free_begin_deriving_iterable_has_no_free_begin), KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_begin_deriving_iterable_has_no_constant_free_begin), + KAWAII(accessing_the_first_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), + KAWAII(an_iterator_obtained_via_member_begin_compares_equal_to_an_iterator_obtained_via_free_begin), }, "Iterable Tests"}; } \ No newline at end of file -- cgit v1.2.3 From bb58e65e6596a2ffac2e85e9fda1e8568aa9b4b1 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 25 Feb 2020 20:57:06 +0100 Subject: new_type: implement cbegin --- doc/src/index.rst | 29 +++++++++ include/newtype/impl/type_traits_extensions.hpp | 43 ++++++++++++- include/newtype/new_type.hpp | 20 ++++++ test/src/iterable_suite.cpp | 84 +++++++++++++++++++++---- 4 files changed, 162 insertions(+), 14 deletions(-) diff --git a/doc/src/index.rst b/doc/src/index.rst index 8ef515f..cd016b9 100644 --- a/doc/src/index.rst +++ b/doc/src/index.rst @@ -231,6 +231,17 @@ Class template :cpp:class:`new_type` .. versionadded:: 1.1.0 + .. cpp:function:: constexpr iterator cbegin() const + + Get a constant iterator to the beginning of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`cbegin() const ` that returns an instance of type :cpp:type:`const_iterator` + + .. versionadded:: 1.1.0 + :literal:`namespace`-level functions and function templates ----------------------------------------------------------- @@ -721,6 +732,24 @@ Iterators .. versionadded:: 1.1.0 +.. cpp:function:: template \ + constexpr new_type::const_iterator cbegin(new_type const & obj) + + Get a constant iterator to the beginning of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator to the begining of the object of contained by :cpp:var:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`cbegin(BaseType const &)` that returns an instance of type :cpp:type:`new_type::const_iterator` + + .. versionadded:: 1.1.0 + :cpp:class:`std::hash` Support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/newtype/impl/type_traits_extensions.hpp b/include/newtype/impl/type_traits_extensions.hpp index 80ba5b0..ee33730 100644 --- a/include/newtype/impl/type_traits_extensions.hpp +++ b/include/newtype/impl/type_traits_extensions.hpp @@ -1051,7 +1051,7 @@ namespace nt::impl } // namespace std_support - inline namespace iterable + inline namespace iterable_begin { template struct has_free_begin : std::false_type @@ -1100,7 +1100,46 @@ namespace nt::impl template auto constexpr has_begin_v = has_begin::value; - } // namespace iterable + } // namespace iterable_begin + + inline namespace iterable_cbegin + { + template + struct has_free_cbegin : std::false_type + { + }; + + template + struct has_free_cbegin()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_cbegin_v = has_free_cbegin::value; + + template + struct has_member_cbegin : std::false_type + { + }; + + template + struct has_member_cbegin().cbegin())>> + : std::is_same().cbegin())> + { + }; + + template + auto constexpr has_member_cbegin_v = has_member_cbegin::value; + + template + struct has_cbegin : std::disjunction, has_member_cbegin> + { + }; + + template + auto constexpr has_cbegin_v = has_cbegin::value; + } // namespace iterable_cbegin } // namespace nt::impl diff --git a/include/newtype/new_type.hpp b/include/newtype/new_type.hpp index 0db01b2..474ac88 100644 --- a/include/newtype/new_type.hpp +++ b/include/newtype/new_type.hpp @@ -71,6 +71,11 @@ namespace nt -> std::enable_if_t, typename new_type::const_iterator>; + template + auto constexpr friend cbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + using super = impl::new_type_move_assignment; public: @@ -198,6 +203,13 @@ namespace nt { return this->m_value.begin(); } + + template + auto constexpr cbegin() const -> std::enable_if_t, + typename NewType::const_iterator> + { + return this->m_value.cbegin(); + } }; /// Equality Comparison Operators @@ -476,6 +488,14 @@ namespace nt return begin(obj.m_value); } + template + auto constexpr cbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator> + { + return cbegin(obj.m_value); + } + } // namespace nt namespace std diff --git a/test/src/iterable_suite.cpp b/test/src/iterable_suite.cpp index 8c08a66..3bdb16b 100644 --- a/test/src/iterable_suite.cpp +++ b/test/src/iterable_suite.cpp @@ -21,6 +21,7 @@ namespace auto begin() -> iterator; auto begin() const -> const_iterator; + auto cbegin() const -> const_iterator; }; } // namespace @@ -86,18 +87,77 @@ inline namespace begin_tests } // namespace begin_tests +inline namespace cbegin_tests +{ + + auto a_new__type_not_deriving_iterable_has_no_cbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cbegin_v)); + } + + auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_cbegin() -> void + { + static_assert(!nt::impl::has_cbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cbegin_v)); + } + + auto a_new__type_based_on_an_iterable_type_with_member_cbegin_deriving_iterable_has_member_cbegin() -> void + { + static_assert(nt::impl::has_member_cbegin_v); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_cbegin_v); + } + + auto a_new__type_based_on_an_iterable_type_without_free_cbegin_deriving_iterable_has_no_free_cbegin() -> void + { + static_assert(!nt::impl::has_free_cbegin_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_cbegin_v); + } + + auto accessing_the_first_element_of_a_constant_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() + -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto weak = std::array{42, 21, 10}; + auto strong = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(*weak.cbegin(), *strong.cbegin()); + } + + auto an_iterator_obtained_via_member_cbegin_compares_equal_to_an_iterator_obtained_via_free_cbegin() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto instance = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(cbegin(instance), instance.cbegin()); + } + +} // namespace cbegin_tests + auto iterable_suite() -> std::pair { - return {{ - /// 'begin' Tests - KAWAII(a_new__type_not_deriving_iterable_has_no_begin), - KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_begin), - KAWAII(a_new__type_based_on_an_iterable_type_with_member_begin_deriving_iterable_has_member_begin), - KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_begin_deriving_iterable_has_constant_member_begin), - KAWAII(a_new__type_based_on_an_iterable_type_without_free_begin_deriving_iterable_has_no_free_begin), - KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_begin_deriving_iterable_has_no_constant_free_begin), - KAWAII(accessing_the_first_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), - KAWAII(an_iterator_obtained_via_member_begin_compares_equal_to_an_iterator_obtained_via_free_begin), - }, - "Iterable Tests"}; + return { + { + // clang-format off + /// 'begin' Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_begin), + KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_begin), + KAWAII(a_new__type_based_on_an_iterable_type_with_member_begin_deriving_iterable_has_member_begin), + KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_begin_deriving_iterable_has_constant_member_begin), + KAWAII(a_new__type_based_on_an_iterable_type_without_free_begin_deriving_iterable_has_no_free_begin), + KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_begin_deriving_iterable_has_no_constant_free_begin), + KAWAII(accessing_the_first_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), + KAWAII(an_iterator_obtained_via_member_begin_compares_equal_to_an_iterator_obtained_via_free_begin), + + /// 'begin' Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_cbegin), + KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_cbegin), + KAWAII(a_new__type_based_on_an_iterable_type_with_member_cbegin_deriving_iterable_has_member_cbegin), + KAWAII(a_new__type_based_on_an_iterable_type_without_free_cbegin_deriving_iterable_has_no_free_cbegin), + KAWAII(accessing_the_first_element_of_a_constant_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), + KAWAII(an_iterator_obtained_via_member_cbegin_compares_equal_to_an_iterator_obtained_via_free_cbegin), + // clang-format on + }, + "Iterable Tests"}; } \ No newline at end of file -- cgit v1.2.3 From dc369b4c559b33868ffdb99eb4a2feadd90a84f2 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Thu, 27 Feb 2020 09:32:48 +0100 Subject: new_type: remove doc comments --- include/newtype/derivable.hpp | 63 --- include/newtype/derivation_clause.hpp | 45 -- include/newtype/deriving.hpp | 3 - include/newtype/impl/type_traits_extensions.hpp | 563 ------------------------ include/newtype/new_type.hpp | 149 ------- 5 files changed, 823 deletions(-) diff --git a/include/newtype/derivable.hpp b/include/newtype/derivable.hpp index faa844d..c798c59 100644 --- a/include/newtype/derivable.hpp +++ b/include/newtype/derivable.hpp @@ -12,80 +12,17 @@ namespace nt using tag_type = DerivableTag; }; - /** - * @brief A set of standard derivation tags - * - * This convenience namespace contains all standard derivation tags. - * - * @since 1.0.0 - */ inline namespace derivables { - /** - * @brief A tag to enable derivation of arithmetic operators - * - * @since 1.0.0 - */ auto constexpr Arithmetic = derivable{}; - - /** - * @brief A tag to enable derivation of "equality comparison with base type" operators - * - * @note Deriving this feature seriously weakens the using nt::new_type instance - * @since 1.0.0 - */ auto constexpr EqBase = derivable{}; - - /** - * @brief A tag to enable derivation of a specialization of std::hash - * - * @since 1.0.0 - */ auto constexpr Hash = derivable{}; - - /** - * @brief A tag to enable derivation of the implicit "conversion to base type" operator - * - * @note If this tag is not present in the derivation clause of any given nt::new_type, the type instance only supports explicit - * "conversion to base type" - * @since 1.0.0 - */ auto constexpr ImplicitConversion = derivable{}; - - /** - * @brief A tag to enable access to the members of the base type object through a pointer - * - * @since 1.0.0 - */ auto constexpr Indirection = derivable{}; - - /** - * @brief A tag to enable derivation of the iterator accessors - * - * @since 1.0.0 - */ auto constexpr Iterable = derivable{}; - - /** - * @brief A tag to enable derivation of the stream input operator - * - * @since 1.0.0 - */ auto constexpr Read = derivable{}; - - /** - * @brief A tag to enable derivation of the relational operators - * - * @since 1.0.0 - */ auto constexpr Relational = derivable{}; - - /** - * @brief A tag to enable derivation of the stream output operator - * - * @since 1.0.0 - */ auto constexpr Show = derivable{}; } // namespace derivables diff --git a/include/newtype/derivation_clause.hpp b/include/newtype/derivation_clause.hpp index edb2f85..6de70e1 100644 --- a/include/newtype/derivation_clause.hpp +++ b/include/newtype/derivation_clause.hpp @@ -9,11 +9,6 @@ namespace nt { - /** - * A @p deriving clause type - * - * @tparam DerivableTags A list of tag types defining a set of derivable features - */ template struct derivation_clause { @@ -21,88 +16,48 @@ namespace nt { } - /** - * Check whether the derivation clause contains a given derivable - */ template auto constexpr operator()(derivable) const noexcept -> bool { return (std::is_same_v || ...); } - /** - * Check whether the derivation clause contains all derivables in a given lists - */ template auto constexpr operator()(derivable, derivable...) const noexcept -> bool { return (*this)(derivable{}) && (*this)(derivable{}...); } - /** - * Check whether this derivation clause is less than an other derivation clause - * - * A derivation clause is considered less than an other derivation clause iff. its set of derivables is a strict subset of - * the set derivables of the other. - */ template auto constexpr operator<(derivation_clause other) const noexcept -> bool { return (sizeof...(DerivableTags) < sizeof...(OtherDerivableTags)) && other(derivable{}...); } - /** - * Check whether this derivation clause is greater than an other derivation clause - * - * A derivation clause is considered greater than an other derivation clause iff. its set of derivables is a strict superset - * of the set derivables of the other. - */ template auto constexpr operator>(derivation_clause other) const noexcept -> bool { return other < *this; } - /** - * Check whether this derivation clause is equal to an other derivation clause - * - * Two derivation clauses are considered equal if both have the same set of derivables - */ template auto constexpr operator==(derivation_clause other) const noexcept -> bool { return sizeof...(DerivableTags) == sizeof...(OtherDerivableTags) && other(derivable{}...); } - /** - * Check whether this derivation clause is not equal to an other derivation clause - * - * Two derivation clauses are considered not equal if neither has the same set of derivables as the other - */ template auto constexpr operator!=(derivation_clause other) const noexcept -> bool { return !(*this == other); } - /** - * Check whether this derivation clause is less-than or equal to an other derivation clause - * - * @see nt::distinct::operator== - * @see nt::distinct::operator< - */ template auto constexpr operator<=(derivation_clause other) const noexcept -> bool { return *this < other || *this == other; } - /** - * Check whether this derivation clause is greater-than or equal to an other derivation clause - * - * @see nt::distinct::operator== - * @see nt::distinct::operator< - */ template auto constexpr operator>=(derivation_clause other) const noexcept -> bool { diff --git a/include/newtype/deriving.hpp b/include/newtype/deriving.hpp index e762c9b..ae10bab 100644 --- a/include/newtype/deriving.hpp +++ b/include/newtype/deriving.hpp @@ -10,9 +10,6 @@ namespace nt { - /** - * Create a new derivation clause with the given derivables - */ template auto constexpr deriving(derivable... features) noexcept -> derivation_clause { diff --git a/include/newtype/impl/type_traits_extensions.hpp b/include/newtype/impl/type_traits_extensions.hpp index ee33730..a9bd6af 100644 --- a/include/newtype/impl/type_traits_extensions.hpp +++ b/include/newtype/impl/type_traits_extensions.hpp @@ -14,125 +14,57 @@ namespace nt::impl inline namespace equality_comparable { - /** - * @brief A trait to test if a given type is comparable using operator== - * - * @tparam T The type to test - * @note This specialization forms the base case for non-equals-comparable T - */ template struct is_equality_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is comparable using operator== - * - * @tparam T The type to test - * @note This specialization forms the case for equals-comparable T - */ template struct is_equality_comparable() == std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is comparable using operator== - * - * @tparam T The type to test - */ template auto constexpr is_equality_comparable_v = is_equality_comparable::value; - /** - * @brief A trait to test if a given type is noexcept comparable using operator== - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept equals-comparable or non-equals-comparable T - */ template struct is_nothrow_equality_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept comparable using operator== - * - * @tparam T The type to test - * @note This specialization forms the case for equals-comparable T detemining if T is noexcept comparable using operator== - */ template struct is_nothrow_equality_comparable() == std::declval())>> : std::bool_constant() == std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept comparable using operator== - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_equality_comparable_v = is_nothrow_equality_comparable::value; - /** - * @brief A trait to test if a given type is comparable using operator!= - * - * @tparam T The type to test - * @note This specialization forms the base case for non-not-equals-comparable T - */ template struct is_inequality_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is comparable using operator!= - * - * @tparam T The type to test - * @note This specialization forms the case for not-equals-comparable T - */ template struct is_inequality_comparable() != std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is comparable using operator!= - * - * @tparam T The type to test - */ template auto constexpr is_inequality_comparable_v = is_inequality_comparable::value; - /** - * @brief A trait to test if a given type is noexcept comparable using operator!= - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept not-equals-comparable or non-not-equals-comparable T - */ template struct is_nothrow_inequality_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept comparable using operator== - * - * @tparam T The type to test - * @note This specialization forms the case for equals-comparable T detemining if T is noexcept comparable using operator!= - */ template struct is_nothrow_inequality_comparable() != std::declval())>> : std::bool_constant() != std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept comparable using operator!= - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_inequality_comparable_v = is_nothrow_inequality_comparable::value; @@ -141,250 +73,112 @@ namespace nt::impl inline namespace relationally_comparable { - /** - * @brief A trait to test if a given type is comparable using operator< - * - * @tparam T The type to test - * @note This specialization forms the base case for non-less-than-comparable T - */ template struct is_less_than_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is comparable using operator< - * - * @tparam T The type to test - * @note This specialization forms the case for less-than-comparable T - */ template struct is_less_than_comparable() < std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is comparable using operator< - * - * @tparam T The type to test - */ template auto constexpr is_less_than_comparable_v = is_less_than_comparable::value; - /** - * @brief A trait to test if a given type is noexcept comparable using operator< - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept less-than-comparable or non-less-than-comparable T - */ template struct is_nothrow_less_than_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept comparable using operator< - * - * @tparam T The type to test - * @note This specialization forms the case for less-than-comparable T detemining if T is noexcept comparable using operator< - */ template struct is_nothrow_less_than_comparable() < std::declval())>> : std::bool_constant() < std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept comparable using operator< - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_less_than_comparable_v = is_nothrow_less_than_comparable::value; - /** - * @brief A trait to test if a given type is comparable using operator> - * - * @tparam T The type to test - * @note This specialization forms the base case for non-greater-than-comparable T - */ template struct is_greater_than_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is comparable using operator> - * - * @tparam T The type to test - * @note This specialization forms the case for greater-than-comparable T - */ template struct is_greater_than_comparable() > std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is comparable using operator> - * - * @tparam T The type to test - */ template auto constexpr is_greater_than_comparable_v = is_greater_than_comparable::value; - /** - * @brief A trait to test if a given type is noexcept comparable using operator> - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept greater-than-comparable or non-greater-than-comparable T - */ template struct is_nothrow_greater_than_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept comparable using operator> - * - * @tparam T The type to test - * @note This specialization forms the case for greater-than-comparable T detemining if T is noexcept comparable using operator> - */ template struct is_nothrow_greater_than_comparable() > std::declval())>> : std::bool_constant() > std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept comparable using operator> - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_greater_than_comparable_v = is_nothrow_greater_than_comparable::value; - /** - * @brief A trait to test if a given type is comparable using operator<= - * - * @tparam T The type to test - * @note This specialization forms the base case for non-less-than-or-equal-to-comparable T - */ template struct is_less_than_equal_to_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is comparable using operator<= - * - * @tparam T The type to test - * @note This specialization forms the case for less-than-or-equal-to-comparable T - */ template struct is_less_than_equal_to_comparable() <= std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is comparable using operator<= - * - * @tparam T The type to test - */ template auto constexpr is_less_than_equal_to_comparable_v = is_less_than_equal_to_comparable::value; - /** - * @brief A trait to test if a given type is noexcept comparable using operator<= - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept less-than-or-equal-to-comparable or non-less-than-or-equal-to-comparable T - */ template struct is_nothrow_less_than_equal_to_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept comparable using operator<= - * - * @tparam T The type to test - * @note This specialization forms the case for less-than-or-equal-to-comparable T detemining if T is noexcept comparable using operator<= - */ template struct is_nothrow_less_than_equal_to_comparable() <= std::declval())>> : std::bool_constant() <= std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept comparable using operator<= - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_less_than_equal_to_comparable_v = is_nothrow_less_than_equal_to_comparable::value; - /** - * @brief A trait to test if a given type is comparable using operator>= - * - * @tparam T The type to test - * @note This specialization forms the base case for non-greater-than-or-equal-to-comparable T - */ template struct is_greater_than_equal_to_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is comparable using operator>= - * - * @tparam T The type to test - * @note This specialization forms the case for greater-than-or-equal-to-comparable T - */ template struct is_greater_than_equal_to_comparable() >= std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is comparable using operator>= - * - * @tparam T The type to test - */ template auto constexpr is_greater_than_equal_to_comparable_v = is_greater_than_equal_to_comparable::value; - /** - * @brief A trait to test if a given type is noexcept comparable using operator>= - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept greater-than-or-equal-to-comparable or - * non-greater-than-or-equal-to-comparable T - */ template struct is_nothrow_greater_than_equal_to_comparable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept comparable using operator>= - * - * @tparam T The type to test - * @note This specialization forms the case for greater-than-or-equal-to-comparable T detemining if T is noexcept comparable using - * operator>= - */ template struct is_nothrow_greater_than_equal_to_comparable() >= std::declval())>> : std::bool_constant() >= std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept comparable using operator>= - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_greater_than_equal_to_comparable_v = is_nothrow_greater_than_equal_to_comparable::value; } // namespace relationally_comparable @@ -392,126 +186,58 @@ namespace nt::impl inline namespace iostreamable { - /** - * @brief A trait to test if a given type is output streamable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-output-streamable T - */ template struct is_output_streamable : std::false_type { }; - /** - * @brief A trait to test if a given type is output streamable - * - * @tparam T The type to test - * @note This specialization forms the case for output-streamable T - */ template struct is_output_streamable() << std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is output streamable - * - * @tparam T The type to test - */ template auto constexpr is_output_streamable_v = is_output_streamable::value; - /** - * @brief A trait to test if a given type is noexcept output streamable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept output-streamable or non-output-streamable T - */ template struct is_nothrow_output_streamable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept output streamable - * - * @tparam T The type to test - * @note This specialization forms the case for output-streamable T detemining if T is noexcept output-streamable - */ template struct is_nothrow_output_streamable() << std::declval())>> : std::bool_constant() << std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept output streamable - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_output_streamable_v = is_nothrow_output_streamable::value; - /** - * @brief A trait to test if a given type is input streamable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-input-streamable T - */ template struct is_input_streamable : std::false_type { }; - /** - * @brief A trait to test if a given type is input streamable - * - * @tparam T The type to test - * @note This specialization forms the case for input-streamable T - */ template struct is_input_streamable() >> std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is input streamable - * - * @tparam T The type to test - */ template auto constexpr is_input_streamable_v = is_input_streamable::value; - /** - * @brief A trait to test if a given type is noexcept input streamable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept input-streamable or non-input-streamable T - */ template struct is_nothrow_input_streamable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept input streamable - * - * @tparam T The type to test - * @note This specialization forms the case for input-streamable T detemining if T is noexcept input-streamable - */ template struct is_nothrow_input_streamable() >> std::declval())>> : std::bool_constant() >> std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept input streamable - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_input_streamable_v = is_nothrow_input_streamable::value; @@ -520,247 +246,111 @@ namespace nt::impl inline namespace arithmetic { - /** - * @brief A trait to test if a given type is addable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-addable T - */ template struct is_addable : std::false_type { }; - /** - * @brief A trait to test if a given type is addable - * - * @tparam T The type to test - * @note This specialization forms the case for addable T - */ template struct is_addable() + std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is addable - * - * @tparam T The type to test - */ template auto constexpr is_addable_v = is_addable::value; - /** - * @brief A trait to test if a given type is noexcept addable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept addable or non-addable T - */ template struct is_nothrow_addable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept addable - * - * @tparam T The type to test - * @note This specialization forms the case for addable T detemining if T is noexcept addable - */ template struct is_nothrow_addable() + std::declval())>> : std::bool_constant() + std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept addable - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_addable_v = is_nothrow_addable::value; - /** - * @brief A trait to test if a given type is subtractable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-subtractable T - */ template struct is_subtractable : std::false_type { }; - /** - * @brief A trait to test if a given type is subtractable - * - * @tparam T The type to test - * @note This specialization forms the case for subtractable T - */ template struct is_subtractable() - std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is subtractable - * - * @tparam T The type to test - */ template auto constexpr is_subtractable_v = is_subtractable::value; - /** - * @brief A trait to test if a given type is noexcept subtractable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept subtractable or non-subtractable T - */ template struct is_nothrow_subtractable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept subtractable - * - * @tparam T The type to test - * @note This specialization forms the case for subtractable T detemining if T is noexcept subtractable - */ template struct is_nothrow_subtractable() - std::declval())>> : std::bool_constant() - std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept subtractable - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_subtractable_v = is_nothrow_subtractable::value; - /** - * @brief A trait to test if a given type is multipliable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-multipliable T - */ template struct is_multipliable : std::false_type { }; - /** - * @brief A trait to test if a given type is multipliable - * - * @tparam T The type to test - * @note This specialization forms the case for multipliable T - */ template struct is_multipliable() * std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is multipliable - * - * @tparam T The type to test - */ template auto constexpr is_multipliable_v = is_multipliable::value; - /** - * @brief A trait to test if a given type is noexcept multipliable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept multipliable or non-multipliable T - */ template struct is_nothrow_multipliable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept multipliable - * - * @tparam T The type to test - * @note This specialization forms the case for multipliable T detemining if T is noexcept multipliable - */ template struct is_nothrow_multipliable() * std::declval())>> : std::bool_constant() * std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept multipliable - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_multipliable_v = is_nothrow_multipliable::value; - /** - * @brief A trait to test if a given type is dividable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-dividable T - */ template struct is_dividable : std::false_type { }; - /** - * @brief A trait to test if a given type is dividable - * - * @tparam T The type to test - * @note This specialization forms the case for dividable T - */ template struct is_dividable() / std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is dividable - * - * @tparam T The type to test - */ template auto constexpr is_dividable_v = is_dividable::value; - /** - * @brief A trait to test if a given type is noexcept dividable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept dividable or non-dividable T - */ template struct is_nothrow_dividable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept dividable - * - * @tparam T The type to test - * @note This specialization forms the case for dividable T detemining if T is noexcept dividable - */ template struct is_nothrow_dividable() / std::declval())>> : std::bool_constant() / std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept dividable - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_dividable_v = is_nothrow_dividable::value; @@ -769,247 +359,111 @@ namespace nt::impl inline namespace compound_arithmetic { - /** - * @brief A trait to test if a given type is add-assignable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-add-assignable T - */ template struct is_add_assignable : std::false_type { }; - /** - * @brief A trait to test if a given type is add-assignable - * - * @tparam T The type to test - * @note This specialization forms the case for add-assignable T - */ template struct is_add_assignable() += std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is add-assignable - * - * @tparam T The type to test - */ template auto constexpr is_add_assignable_v = is_add_assignable::value; - /** - * @brief A trait to test if a given type is noexcept add-assignable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept add-assignable or non-add-assignable T - */ template struct is_nothrow_add_assignable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept add-assignable - * - * @tparam T The type to test - * @note This specialization forms the case for add-assignable T detemining if T is noexcept add-assignable - */ template struct is_nothrow_add_assignable() += std::declval())>> : std::bool_constant() += std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept add-assignable - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_add_assignable_v = is_nothrow_add_assignable::value; - /** - * @brief A trait to test if a given type is subtract-assignable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-subtract-assignable T - */ template struct is_subtract_assignable : std::false_type { }; - /** - * @brief A trait to test if a given type is subtract-assignable - * - * @tparam T The type to test - * @note This specialization forms the case for subtract-assignable T - */ template struct is_subtract_assignable() -= std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is subtract-assignable - * - * @tparam T The type to test - */ template auto constexpr is_subtract_assignable_v = is_subtract_assignable::value; - /** - * @brief A trait to test if a given type is noexcept subtract-assignable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept subtract-assignable or non-subtract-assignable T - */ template struct is_nothrow_subtract_assignable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept subtract-assignable - * - * @tparam T The type to test - * @note This specialization forms the case for subtract-assignable T detemining if T is noexcept subtract-assignable - */ template struct is_nothrow_subtract_assignable() -= std::declval())>> : std::bool_constant() -= std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept subtract-assignable - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_subtract_assignable_v = is_nothrow_subtract_assignable::value; - /** - * @brief A trait to test if a given type is multiply-assignable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-multiply-assignable T - */ template struct is_multiply_assignable : std::false_type { }; - /** - * @brief A trait to test if a given type is multiply-assignable - * - * @tparam T The type to test - * @note This specialization forms the case for multiply-assignable T - */ template struct is_multiply_assignable() *= std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is multiply-assignable - * - * @tparam T The type to test - */ template auto constexpr is_multiply_assignable_v = is_multiply_assignable::value; - /** - * @brief A trait to test if a given type is noexcept multiply-assignable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept multiply-assignable or non-multiply-assignable T - */ template struct is_nothrow_multiply_assignable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept multiply-assignable - * - * @tparam T The type to test - * @note This specialization forms the case for multiply-assignable T detemining if T is noexcept multiply-assignable - */ template struct is_nothrow_multiply_assignable() *= std::declval())>> : std::bool_constant() *= std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept multiply-assignable - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_multiply_assignable_v = is_nothrow_multiply_assignable::value; - /** - * @brief A trait to test if a given type is divide-assignable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-divide-assignable T - */ template struct is_divide_assignable : std::false_type { }; - /** - * @brief A trait to test if a given type is divide-assignable - * - * @tparam T The type to test - * @note This specialization forms the case for divide-assignable T - */ template struct is_divide_assignable() /= std::declval())>> : std::true_type { }; - /** - * @brief A variable template to test if a given type is divide-assignable - * - * @tparam T The type to test - */ template auto constexpr is_divide_assignable_v = is_divide_assignable::value; - /** - * @brief A trait to test if a given type is noexcept divide-assignable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-noexcept divide-assignable or non-divide-assignable T - */ template struct is_nothrow_divide_assignable : std::false_type { }; - /** - * @brief A trait to test if a given type is noexcept divide-assignable - * - * @tparam T The type to test - * @note This specialization forms the case for divide-assignable T detemining if T is noexcept divide-assignable - */ template struct is_nothrow_divide_assignable() /= std::declval())>> : std::bool_constant() /= std::declval())> { }; - /** - * @brief A variable template to test if a given type is noexcept divide-assignable - * - * @tparam T The type to test - */ template auto constexpr is_nothrow_divide_assignable_v = is_nothrow_divide_assignable::value; @@ -1018,34 +472,17 @@ namespace nt::impl inline namespace std_support { - /** - * @brief A trait to test if a given type is hashable - * - * @tparam T The type to test - * @note This specialization forms the base case for non-hashable T - */ template struct is_hashable : std::false_type { }; - /** - * @brief A trait to test if a given type is hashable - * - * @tparam T The type to test - * @note This specialization forms the case for hashable T - */ template struct is_hashable const &>()(std::declval()))>> : std::is_same const &>()(std::declval()))> { }; - /** - * @brief A variable template to test if a given type is hashable - * - * @tparam T The type to test - */ template auto constexpr is_hashable_v = is_hashable::value; diff --git a/include/newtype/new_type.hpp b/include/newtype/new_type.hpp index 474ac88..24ac71a 100644 --- a/include/newtype/new_type.hpp +++ b/include/newtype/new_type.hpp @@ -16,9 +16,6 @@ namespace nt { - /** - * Create a new type based on an existing one - */ template class new_type : impl::new_type_move_assignment @@ -79,114 +76,50 @@ namespace nt using super = impl::new_type_move_assignment; public: - /// Member Type Aliases - - /** - * The base type of this nt::new_type - */ using base_type = BaseType; - - /** - * The tag type of this nt::new_type - */ using tag_type = TagType; - - /** - * The type of the derivation clause of this nt::newtype - */ using derivation_clause_type = decltype(DerivationClause); - /// Static Data Members - - /** - * The derivation clause fo this nt::new_type - */ auto constexpr static derivation_clause = DerivationClause; - /// Constructors - using super::super; - /** - * Construct an instance of this nt::new_type by default initializing the contained object - */ constexpr new_type() noexcept(std::is_nothrow_default_constructible_v) = default; - - /** - * Copy-construct an instance of this nt::new_type from an existing one - */ constexpr new_type(new_type const &) noexcept(std::is_nothrow_copy_constructible_v) = default; - - /** - * Move-construct an instance of this nt::new_type from an existing one - */ constexpr new_type(new_type &&) noexcept(std::is_nothrow_move_constructible_v) = default; - /// Assignment Operators - - /** - * Copy-assign the value of an existing instance of this nt::new_type to this instance - */ auto constexpr operator=(new_type const &) noexcept(std::is_nothrow_copy_assignable_v) -> new_type & = default; - - /** - * Move-assign the value of an existing instance of this nt::new_type to this instance - */ auto constexpr operator=(new_type &&) noexcept(std::is_nothrow_move_assignable_v) -> new_type & = default; - /// Accessors - - /** - * Retrieve a copy of the object contained by this new_type object - */ auto constexpr decay() const noexcept(std::is_nothrow_copy_constructible_v) -> BaseType { return this->m_value; } - /** - * Retrieve a copy of the object contained by this new_type object - */ template * = nullptr> constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) { return decay(); } - /** - * Convert this instance into the equivalent base type value - */ template * = nullptr> explicit constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) { return decay(); } - /// Member Access Through Pointer - - /** - * Perform "member access through pointer" via a pointer to object contained by this new_type - */ template auto constexpr operator-> () noexcept -> std::enable_if_t { return std::addressof(this->m_value); } - /** - * Perform "member access through pointer" via a pointer to object contained by this new_type - */ template auto constexpr operator-> () const noexcept -> std::enable_if_t { return std::addressof(this->m_value); } - /// Iterators - - /** - * Get an iterator to the beginning of the object contained by this new_type - */ template * = nullptr> auto constexpr begin() -> std::enable_if_t, typename NewType::iterator> @@ -194,9 +127,6 @@ namespace nt return this->m_value.begin(); } - /** - * Get an iterator to the beginning of the object contained by this new_type - */ template auto constexpr begin() const -> std::enable_if_t, typename NewType::const_iterator> @@ -212,11 +142,6 @@ namespace nt } }; - /// Equality Comparison Operators - - /** - * Check two instances of new_type for equality - */ template auto constexpr operator==(new_type const & lhs, @@ -226,9 +151,6 @@ namespace nt return lhs.decay() == rhs.decay(); } - /** - * Check an instance of new_type for equality with an instance of BaseType - */ template auto constexpr operator==(new_type const & lhs, BaseType const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) @@ -237,9 +159,6 @@ namespace nt return lhs.decay() == rhs; } - /** - * Check an instance of BaseType for equality with an instance of new_type - */ template auto constexpr operator==(BaseType const & lhs, @@ -249,9 +168,6 @@ namespace nt return lhs == rhs.decay(); } - /** - * Check two instances of new_type for in-equality - */ template auto constexpr operator!=(new_type const & lhs, @@ -261,9 +177,6 @@ namespace nt return lhs.decay() != rhs.decay(); } - /** - * Check an instance of new_type for in-equality with an instance of BaseType - */ template auto constexpr operator!=(new_type const & lhs, BaseType const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) @@ -272,9 +185,6 @@ namespace nt return lhs.decay() != rhs; } - /** - * Check an instance of BaseType for in-equality with an instance of new_type - */ template auto constexpr operator!=(BaseType const & lhs, @@ -284,11 +194,6 @@ namespace nt return lhs != rhs.decay(); } - /// Relational Comparison Operators - - /** - * Compare two instances of the same new_type using '<' (less-than) - */ template auto constexpr operator<(new_type const & lhs, @@ -298,9 +203,6 @@ namespace nt return lhs.decay() < rhs.decay(); } - /** - * Compare two instances of the same new_type using '>' (greater-than) - */ template auto constexpr operator>(new_type const & lhs, @@ -310,9 +212,6 @@ namespace nt return lhs.decay() > rhs.decay(); } - /** - * Compare two instances of the same new_type using '<=' (less-than-equal) - */ template auto constexpr operator<=(new_type const & lhs, @@ -322,9 +221,6 @@ namespace nt return lhs.decay() <= rhs.decay(); } - /** - * Compare two instances of the same new_type using '>=' (greater-than-equal) - */ template auto constexpr operator>=(new_type const & lhs, @@ -334,11 +230,6 @@ namespace nt return lhs.decay() >= rhs.decay(); } - /// Stream I/O Operators - - /** - * Write an instance of new_type to a standard ostream - */ template auto operator<<(std::basic_ostream & output, new_type const & source) noexcept( impl::is_nothrow_output_streamable_v, BaseType>) @@ -348,9 +239,6 @@ namespace nt return output << source.decay(); } - /** - * Read an instance of new_type from the a standard istream - */ template auto operator>>(std::basic_istream & input, new_type & target) noexcept( impl::is_nothrow_input_streamable_v, BaseType>) @@ -360,11 +248,6 @@ namespace nt return input >> target.m_value; } - /// Arithmetic Operators - - /** - * Add two instances of the same new_type - */ template auto constexpr operator+(new_type const & lhs, new_type const & rhs) noexcept( @@ -374,9 +257,6 @@ namespace nt return {lhs.decay() + rhs.decay()}; } - /** - * Add two instances of the same new_type by overwriting the first one - */ template auto constexpr operator+=(new_type & lhs, new_type const & rhs) noexcept(impl::is_nothrow_add_assignable_v) @@ -387,9 +267,6 @@ namespace nt return lhs; } - /** - * Subtract two instances of the same new_type - */ template auto constexpr operator-(new_type const & lhs, new_type const & rhs) noexcept( @@ -399,9 +276,6 @@ namespace nt return {lhs.decay() - rhs.decay()}; } - /** - * Subtract two instances of the same new_type by overwriting the first one - */ template auto constexpr operator-=(new_type & lhs, @@ -413,9 +287,6 @@ namespace nt return lhs; } - /** - * Multiply two instances of the same new_type - */ template auto constexpr operator*(new_type const & lhs, new_type const & rhs) noexcept( @@ -425,9 +296,6 @@ namespace nt return {lhs.decay() * rhs.decay()}; } - /** - * Multiply two instances of the same new_type by overwriting the first one - */ template auto constexpr operator*=(new_type & lhs, @@ -439,9 +307,6 @@ namespace nt return lhs; } - /** - * Divide two instances of the same nt::new_type - */ template auto constexpr operator/(new_type const & lhs, new_type const & rhs) noexcept( @@ -451,9 +316,6 @@ namespace nt return {lhs.decay() / rhs.decay()}; } - /** - * Divide two instances of the same new_type by overwriting the first one - */ template auto constexpr operator/=(new_type & lhs, new_type const & rhs) noexcept(impl::is_nothrow_divide_assignable_v) @@ -464,11 +326,6 @@ namespace nt return lhs; } - /// Iterators - - /** - * Get an iterator to the beginning of the object contained by an instance of new_type - */ template auto constexpr begin(new_type & obj) -> std::enable_if_t, @@ -477,9 +334,6 @@ namespace nt return begin(obj.m_value); } - /** - * Get a constant iterator to the beginning of the object contained by an instance of new_type - */ template auto constexpr begin(new_type const & obj) -> std::enable_if_t, @@ -500,9 +354,6 @@ namespace nt namespace std { - /** - * Hash an instance of new_type using the hash implementation of the base type - */ template struct hash> { -- cgit v1.2.3 From b01d495beb586d8d18ef592d80f593ea1bbe10e2 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 28 Feb 2020 06:46:26 +0100 Subject: new_type: implement rbegin and crbegin --- doc/src/index.rst | 99 +++++++++++++++++ include/newtype/impl/new_type_iterator_types.hpp | 24 ++++ include/newtype/impl/type_traits_extensions.hpp | 90 +++++++++++++++ include/newtype/new_type.hpp | 62 ++++++++++- test/src/iterable_suite.cpp | 136 ++++++++++++++++++++++- 5 files changed, 409 insertions(+), 2 deletions(-) diff --git a/doc/src/index.rst b/doc/src/index.rst index cd016b9..a54d54c 100644 --- a/doc/src/index.rst +++ b/doc/src/index.rst @@ -99,6 +99,18 @@ Class template :cpp:class:`new_type` .. versionadded:: 1.1.0 + .. cpp:type:: reverse_iterator = typename BaseType::reverse_iterator + + :enablement: This type alias shall be defined iff. this :cpp:class:`new_type`'s :cpp:type:`base_type` has a member type :cpp:type:`reverse_iterator ` and the :cpp:var:`derivation clause ` contains :cpp:var:`Iterable`. + + .. versionadded:: 1.1.0 + + .. cpp:type:: const_reverse_iterator = typename BaseType::const_reverse_iterator + + :enablement: This type alias shall be defined iff. this :cpp:class:`new_type`'s :cpp:type:`base_type` has a member type :cpp:type:`const_reverse_iterator ` and the :cpp:var:`derivation clause ` contains :cpp:var:`Iterable`. + + .. versionadded:: 1.1.0 + **Static Data Members** .. cpp:var:: static derivation_clause_type constexpr derivation_clause = DerivationClause @@ -242,6 +254,39 @@ Class template :cpp:class:`new_type` .. versionadded:: 1.1.0 + .. cpp:function:: constexpr iterator rbegin() + + Get a reverse iterator to the beginning of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`rbegin() ` that returns an instance of type :cpp:type:`reverse_iterator` + + .. versionadded:: 1.1.0 + + .. cpp:function:: constexpr iterator rbegin() const + + Get a constant reverse iterator to the beginning of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`rbegin() const ` that returns an instance of type :cpp:type:`const_reverse_iterator` + + .. versionadded:: 1.1.0 + + .. cpp:function:: constexpr iterator crbegin() const + + Get a constant reverse iterator to the beginning of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`crbegin() const ` that returns an instance of type :cpp:type:`const_reverse_iterator` + + .. versionadded:: 1.1.0 + :literal:`namespace`-level functions and function templates ----------------------------------------------------------- @@ -750,6 +795,60 @@ Iterators .. versionadded:: 1.1.0 +.. cpp:function:: template \ + constexpr new_type::reverse_iterator rbegin(new_type & obj) + + Get a reverse iterator to the beginning of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator to the begining of the object of contained by :literal:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`rbegin(BaseType &)` that returns an instance of type :cpp:type:`new_type::reverse_iterator` + + .. versionadded:: 1.1.0 + +.. cpp:function:: template \ + constexpr new_type::const_reverse_iterator rbegin(new_type const & obj) + + Get a constant reverse iterator to the beginning of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator to the begining of the object of contained by :cpp:var:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`rbegin(BaseType const &)` that returns an instance of type :cpp:type:`new_type::const_reverse_iterator` + + .. versionadded:: 1.1.0 + +.. cpp:function:: template \ + constexpr new_type::const_reverse_iterator crbegin(new_type const & obj) + + Get a constant reverse iterator to the beginning of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator to the begining of the object of contained by :cpp:var:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`crbegin(BaseType const &)` that returns an instance of type :cpp:type:`new_type::const_reverse_iterator` + + .. versionadded:: 1.1.0 + :cpp:class:`std::hash` Support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/newtype/impl/new_type_iterator_types.hpp b/include/newtype/impl/new_type_iterator_types.hpp index 037f08d..2ea8274 100644 --- a/include/newtype/impl/new_type_iterator_types.hpp +++ b/include/newtype/impl/new_type_iterator_types.hpp @@ -30,10 +30,34 @@ namespace nt::impl using const_iterator = typename T::const_iterator; }; + template> + struct new_type_reverse_iterator + { + }; + + template + struct new_type_reverse_iterator> + { + using reverse_iterator = typename T::reverse_iterator; + }; + + template> + struct new_type_const_reverse_iterator + { + }; + + template + struct new_type_const_reverse_iterator> + { + using const_reverse_iterator = typename T::const_reverse_iterator; + }; + template struct new_type_iterator_types : new_type_iterator , new_type_const_iterator + , new_type_reverse_iterator + , new_type_const_reverse_iterator { }; diff --git a/include/newtype/impl/type_traits_extensions.hpp b/include/newtype/impl/type_traits_extensions.hpp index a9bd6af..f7dafef 100644 --- a/include/newtype/impl/type_traits_extensions.hpp +++ b/include/newtype/impl/type_traits_extensions.hpp @@ -578,6 +578,96 @@ namespace nt::impl auto constexpr has_cbegin_v = has_cbegin::value; } // namespace iterable_cbegin + inline namespace iterable_rbegin + { + template + struct has_free_rbegin : std::false_type + { + }; + + template + struct has_free_rbegin()))>> + : std::is_same()))>> + { + }; + + template + struct has_free_rbegin()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_rbegin_v = has_free_rbegin::value; + + template + struct has_member_rbegin : std::false_type + { + }; + + template + struct has_member_rbegin().rbegin())>> + : std::is_same().rbegin())>> + { + }; + + template + struct has_member_rbegin().rbegin())>> + : std::is_same().rbegin())>> + { + }; + + template + auto constexpr has_member_rbegin_v = has_member_rbegin::value; + + template + struct has_rbegin : std::disjunction, has_member_rbegin> + { + }; + + template + auto constexpr has_rbegin_v = has_rbegin::value; + } // namespace iterable_rbegin + + inline namespace iterable_rbegin + { + template + struct has_free_crbegin : std::false_type + { + }; + + template + struct has_free_crbegin()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_crbegin_v = has_free_crbegin::value; + + template + struct has_member_crbegin : std::false_type + { + }; + + template + struct has_member_crbegin().crbegin())>> + : std::is_same().crbegin())>> + { + }; + + template + auto constexpr has_member_crbegin_v = has_member_crbegin::value; + + template + struct has_crbegin : std::disjunction, has_member_crbegin> + { + }; + + template + auto constexpr has_crbegin_v = has_crbegin::value; + } // namespace iterable_rbegin + } // namespace nt::impl #endif \ No newline at end of file diff --git a/include/newtype/new_type.hpp b/include/newtype/new_type.hpp index 24ac71a..36a3927 100644 --- a/include/newtype/new_type.hpp +++ b/include/newtype/new_type.hpp @@ -65,7 +65,7 @@ namespace nt template auto constexpr friend begin(new_type const & obj) - -> std::enable_if_t, + -> std::enable_if_t, typename new_type::const_iterator>; template @@ -73,6 +73,21 @@ namespace nt -> std::enable_if_t, typename new_type::const_iterator>; + template + auto constexpr friend rbegin(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator>; + + template + auto constexpr friend rbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + + template + auto constexpr friend crbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + using super = impl::new_type_move_assignment; public: @@ -140,6 +155,27 @@ namespace nt { return this->m_value.cbegin(); } + + template * = nullptr> + auto constexpr rbegin() + -> std::enable_if_t, typename NewType::reverse_iterator> + { + return this->m_value.rbegin(); + } + + template + auto constexpr rbegin() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.rbegin(); + } + + template + auto constexpr crbegin() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.crbegin(); + } }; template @@ -350,6 +386,30 @@ namespace nt return cbegin(obj.m_value); } + template + auto constexpr rbegin(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator> + { + return rbegin(obj.m_value); + } + + template + auto constexpr rbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return rbegin(obj.m_value); + } + + template + auto constexpr crbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return crbegin(obj.m_value); + } + } // namespace nt namespace std diff --git a/test/src/iterable_suite.cpp b/test/src/iterable_suite.cpp index 3bdb16b..778dc35 100644 --- a/test/src/iterable_suite.cpp +++ b/test/src/iterable_suite.cpp @@ -18,10 +18,15 @@ namespace { using iterator = void *; using const_iterator = void const *; + using reverse_iterator = void *; + using const_reverse_iterator = void const *; auto begin() -> iterator; auto begin() const -> const_iterator; auto cbegin() const -> const_iterator; + auto rbegin() -> reverse_iterator; + auto rbegin() const -> const_reverse_iterator; + auto crbegin() const -> const_reverse_iterator; }; } // namespace @@ -135,6 +140,117 @@ inline namespace cbegin_tests } // namespace cbegin_tests +inline namespace rbegin_tests +{ + + auto a_new__type_not_deriving_iterable_has_no_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rbegin_v)); + } + + auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_rbegin() -> void + { + static_assert(!nt::impl::has_rbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rbegin_v)); + } + + auto a_new__type_based_on_an_iterable_type_with_member_rbegin_deriving_iterable_has_member_rbegin() -> void + { + static_assert(nt::impl::has_member_rbegin_v); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_rbegin_v); + } + + auto a_new__type_based_on_an_iterable_type_with_constant_member_rbegin_deriving_iterable_has_constant_member_rbegin() -> void + { + static_assert(nt::impl::has_member_rbegin_v); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_rbegin_v); + } + + auto a_new__type_based_on_an_iterable_type_without_free_rbegin_deriving_iterable_has_no_free_rbegin() -> void + { + static_assert(!nt::impl::has_free_rbegin_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_rbegin_v); + } + + auto a_new__type_based_on_an_iterable_type_without_constant_free_rbegin_deriving_iterable_has_no_constant_free_rbegin() -> void + { + static_assert(!nt::impl::has_free_rbegin_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_rbegin_v); + } + + auto accessing_the_first_element_of_a_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() + -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto weak = std::array{42, 21, 10}; + auto strong = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(*weak.rbegin(), *strong.rbegin()); + } + + auto an_iterator_obtained_via_member_rbegin_compares_equal_to_an_iterator_obtained_via_free_rbegin() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto instance = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(rbegin(instance), instance.rbegin()); + } + +} // namespace rbegin_tests + +inline namespace crbegin_tests +{ + + auto a_new__type_not_deriving_iterable_has_no_crbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crbegin_v)); + } + + auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_crbegin() -> void + { + static_assert(!nt::impl::has_crbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crbegin_v)); + } + + auto a_new__type_based_on_an_iterable_type_with_member_crbegin_deriving_iterable_has_member_crbegin() -> void + { + static_assert(nt::impl::has_member_crbegin_v); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_crbegin_v); + } + + auto a_new__type_based_on_an_iterable_type_without_free_crbegin_deriving_iterable_has_no_free_crbegin() -> void + { + static_assert(!nt::impl::has_free_crbegin_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_crbegin_v); + } + + auto + accessing_the_first_element_of_a_constant_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() + -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto weak = std::array{42, 21, 10}; + auto strong = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(*weak.crbegin(), *strong.crbegin()); + } + + auto an_iterator_obtained_via_member_crbegin_compares_equal_to_an_iterator_obtained_via_free_crbegin() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto instance = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(crbegin(instance), instance.crbegin()); + } + +} // namespace crbegin_tests + auto iterable_suite() -> std::pair { return { @@ -150,13 +266,31 @@ auto iterable_suite() -> std::pair KAWAII(accessing_the_first_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), KAWAII(an_iterator_obtained_via_member_begin_compares_equal_to_an_iterator_obtained_via_free_begin), - /// 'begin' Tests + /// 'cbegin' Tests KAWAII(a_new__type_not_deriving_iterable_has_no_cbegin), KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_cbegin), KAWAII(a_new__type_based_on_an_iterable_type_with_member_cbegin_deriving_iterable_has_member_cbegin), KAWAII(a_new__type_based_on_an_iterable_type_without_free_cbegin_deriving_iterable_has_no_free_cbegin), KAWAII(accessing_the_first_element_of_a_constant_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), KAWAII(an_iterator_obtained_via_member_cbegin_compares_equal_to_an_iterator_obtained_via_free_cbegin), + + /// 'rbegin' Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_rbegin), + KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_rbegin), + KAWAII(a_new__type_based_on_an_iterable_type_with_member_rbegin_deriving_iterable_has_member_rbegin), + KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_rbegin_deriving_iterable_has_constant_member_rbegin), + KAWAII(a_new__type_based_on_an_iterable_type_without_free_rbegin_deriving_iterable_has_no_free_rbegin), + KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_rbegin_deriving_iterable_has_no_constant_free_rbegin), + KAWAII(accessing_the_first_element_of_a_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), + KAWAII(an_iterator_obtained_via_member_rbegin_compares_equal_to_an_iterator_obtained_via_free_rbegin), + + /// 'cbegin' Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_crbegin), + KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_crbegin), + KAWAII(a_new__type_based_on_an_iterable_type_with_member_crbegin_deriving_iterable_has_member_crbegin), + KAWAII(a_new__type_based_on_an_iterable_type_without_free_crbegin_deriving_iterable_has_no_free_crbegin), + KAWAII(accessing_the_first_element_of_a_constant_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), + KAWAII(an_iterator_obtained_via_member_crbegin_compares_equal_to_an_iterator_obtained_via_free_crbegin), // clang-format on }, "Iterable Tests"}; -- cgit v1.2.3 From 9e79f0cbfa074f7766f6fea04d41f7803c6cee58 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Fri, 28 Feb 2020 07:13:29 +0100 Subject: newtype: implement end iterators --- doc/src/index.rst | 174 ++++++++++++++++ include/newtype/impl/type_traits_extensions.hpp | 184 ++++++++++++++++- include/newtype/new_type.hpp | 120 +++++++++++ test/src/iterable_suite.cpp | 264 +++++++++++++++++++++++- 4 files changed, 739 insertions(+), 3 deletions(-) diff --git a/doc/src/index.rst b/doc/src/index.rst index a54d54c..290f17e 100644 --- a/doc/src/index.rst +++ b/doc/src/index.rst @@ -287,6 +287,72 @@ Class template :cpp:class:`new_type` .. versionadded:: 1.1.0 + .. cpp:function:: constexpr iterator end() + + Get an iterator beyond the end of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`end() ` that returns an instance of type :cpp:type:`iterator` + + .. versionadded:: 1.1.0 + + .. cpp:function:: constexpr iterator end() const + + Get a constant iterator beyond the end of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`end() const ` that returns an instance of type :cpp:type:`const_iterator` + + .. versionadded:: 1.1.0 + + .. cpp:function:: constexpr iterator cend() const + + Get a constant iterator beyond the end of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`cend() const ` that returns an instance of type :cpp:type:`const_iterator` + + .. versionadded:: 1.1.0 + + .. cpp:function:: constexpr iterator rend() + + Get a reverse iterator beyond the end of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`rend() ` that returns an instance of type :cpp:type:`reverse_iterator` + + .. versionadded:: 1.1.0 + + .. cpp:function:: constexpr iterator rend() const + + Get a constant reverse iterator beyond the end of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`rend() const ` that returns an instance of type :cpp:type:`const_reverse_iterator` + + .. versionadded:: 1.1.0 + + .. cpp:function:: constexpr iterator crend() const + + Get a constant reverse iterator beyond the end of the object contained by this :cpp:class:`new_type` + + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) this :cpp:class:`new_type`'s :cpp:type:`base type ` has a non-static member function :cpp:func:`crend() const ` that returns an instance of type :cpp:type:`const_reverse_iterator` + + .. versionadded:: 1.1.0 + :literal:`namespace`-level functions and function templates ----------------------------------------------------------- @@ -849,6 +915,114 @@ Iterators .. versionadded:: 1.1.0 +.. cpp:function:: template \ + constexpr new_type::iterator end(new_type & obj) + + Get an iterator beyond the end of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator beyond the end of the object of contained by :literal:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`end(BaseType &)` that returns an instance of type :cpp:type:`new_type::iterator` + + .. versionadded:: 1.1.0 + +.. cpp:function:: template \ + constexpr new_type::const_iterator end(new_type const & obj) + + Get a constant iterator beyond the end of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator beyond the end of the object of contained by :cpp:var:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`end(BaseType const &)` that returns an instance of type :cpp:type:`new_type::const_iterator` + + .. versionadded:: 1.1.0 + +.. cpp:function:: template \ + constexpr new_type::const_iterator cend(new_type const & obj) + + Get a constant iterator beyond the end of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator beyond the end of the object of contained by :cpp:var:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`cend(BaseType const &)` that returns an instance of type :cpp:type:`new_type::const_iterator` + + .. versionadded:: 1.1.0 + +.. cpp:function:: template \ + constexpr new_type::reverse_iterator rend(new_type & obj) + + Get a reverse iterator beyond the end of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator beyond the end of the object of contained by :literal:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`rend(BaseType &)` that returns an instance of type :cpp:type:`new_type::reverse_iterator` + + .. versionadded:: 1.1.0 + +.. cpp:function:: template \ + constexpr new_type::const_reverse_iterator rend(new_type const & obj) + + Get a constant reverse iterator beyond the end of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator beyond the end of the object of contained by :cpp:var:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`rend(BaseType const &)` that returns an instance of type :cpp:type:`new_type::const_reverse_iterator` + + .. versionadded:: 1.1.0 + +.. cpp:function:: template \ + constexpr new_type::const_reverse_iterator crend(new_type const & obj) + + Get a constant reverse iterator beyond the end of the object contained by an instance of :cpp:class:`new_type` + + :tparam BaseType: |BaseTypeDoc| + :tparam TagType: |TagTypeDoc| + :tparam DerivationClause: |DerivationClauseDoc| + :param obj: The object to retrieve the iterator from + :returns: An iterator beyond the end of the object of contained by :cpp:var:`obj`. + :throws: Any exception + :enablement: This function shall be available iff. + + a) this :cpp:class:`new_type`'s :cpp:var:`derivation clause ` contains :cpp:var:`Iterable` and + b) for the :cpp:class:`new_type`'s :cpp:type:`base type ` exists a namespace-level function :literal:`crend(BaseType const &)` that returns an instance of type :cpp:type:`new_type::const_reverse_iterator` + + .. versionadded:: 1.1.0 + :cpp:class:`std::hash` Support ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/include/newtype/impl/type_traits_extensions.hpp b/include/newtype/impl/type_traits_extensions.hpp index f7dafef..121e2c0 100644 --- a/include/newtype/impl/type_traits_extensions.hpp +++ b/include/newtype/impl/type_traits_extensions.hpp @@ -629,7 +629,7 @@ namespace nt::impl auto constexpr has_rbegin_v = has_rbegin::value; } // namespace iterable_rbegin - inline namespace iterable_rbegin + inline namespace iterable_crbegin { template struct has_free_crbegin : std::false_type @@ -666,7 +666,187 @@ namespace nt::impl template auto constexpr has_crbegin_v = has_crbegin::value; - } // namespace iterable_rbegin + } // namespace iterable_crbegin + + inline namespace iterable_end + { + template + struct has_free_end : std::false_type + { + }; + + template + struct has_free_end()))>> + : std::is_same()))>> + { + }; + + template + struct has_free_end()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_end_v = has_free_end::value; + + template + struct has_member_end : std::false_type + { + }; + + template + struct has_member_end().end())>> + : std::is_same().end())>> + { + }; + + template + struct has_member_end().end())>> + : std::is_same().end())>> + { + }; + + template + auto constexpr has_member_end_v = has_member_end::value; + + template + struct has_end : std::disjunction, has_member_end> + { + }; + + template + auto constexpr has_end_v = has_end::value; + } // namespace iterable_end + + inline namespace iterable_cend + { + template + struct has_free_cend : std::false_type + { + }; + + template + struct has_free_cend()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_cend_v = has_free_cend::value; + + template + struct has_member_cend : std::false_type + { + }; + + template + struct has_member_cend().cend())>> + : std::is_same().cend())> + { + }; + + template + auto constexpr has_member_cend_v = has_member_cend::value; + + template + struct has_cend : std::disjunction, has_member_cend> + { + }; + + template + auto constexpr has_cend_v = has_cend::value; + } // namespace iterable_cend + + inline namespace iterable_rend + { + template + struct has_free_rend : std::false_type + { + }; + + template + struct has_free_rend()))>> + : std::is_same()))>> + { + }; + + template + struct has_free_rend()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_rend_v = has_free_rend::value; + + template + struct has_member_rend : std::false_type + { + }; + + template + struct has_member_rend().rend())>> + : std::is_same().rend())>> + { + }; + + template + struct has_member_rend().rend())>> + : std::is_same().rend())>> + { + }; + + template + auto constexpr has_member_rend_v = has_member_rend::value; + + template + struct has_rend : std::disjunction, has_member_rend> + { + }; + + template + auto constexpr has_rend_v = has_rend::value; + } // namespace iterable_rend + + inline namespace iterable_crend + { + template + struct has_free_crend : std::false_type + { + }; + + template + struct has_free_crend()))>> + : std::is_same()))>> + { + }; + + template + auto constexpr has_free_crend_v = has_free_crend::value; + + template + struct has_member_crend : std::false_type + { + }; + + template + struct has_member_crend().crend())>> + : std::is_same().crend())>> + { + }; + + template + auto constexpr has_member_crend_v = has_member_crend::value; + + template + struct has_crend : std::disjunction, has_member_crend> + { + }; + + template + auto constexpr has_crend_v = has_crend::value; + } // namespace iterable_crend } // namespace nt::impl diff --git a/include/newtype/new_type.hpp b/include/newtype/new_type.hpp index 36a3927..66ff332 100644 --- a/include/newtype/new_type.hpp +++ b/include/newtype/new_type.hpp @@ -88,6 +88,36 @@ namespace nt -> std::enable_if_t, typename new_type::const_reverse_iterator>; + template + auto constexpr friend end(new_type & obj) + -> std::enable_if_t, + typename new_type::iterator>; + + template + auto constexpr friend end(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + + template + auto constexpr friend cend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + + template + auto constexpr friend rend(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator>; + + template + auto constexpr friend rend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + + template + auto constexpr friend crend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + using super = impl::new_type_move_assignment; public: @@ -176,6 +206,48 @@ namespace nt { return this->m_value.crbegin(); } + + template * = nullptr> + auto constexpr end() + -> std::enable_if_t, typename NewType::iterator> + { + return this->m_value.end(); + } + + template + auto constexpr end() const -> std::enable_if_t, + typename NewType::const_iterator> + { + return this->m_value.end(); + } + + template + auto constexpr cend() const -> std::enable_if_t, + typename NewType::const_iterator> + { + return this->m_value.cend(); + } + + template * = nullptr> + auto constexpr rend() + -> std::enable_if_t, typename NewType::reverse_iterator> + { + return this->m_value.rend(); + } + + template + auto constexpr rend() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.rend(); + } + + template + auto constexpr crend() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.crend(); + } }; template @@ -410,6 +482,54 @@ namespace nt return crbegin(obj.m_value); } + template + auto constexpr end(new_type & obj) + -> std::enable_if_t, + typename new_type::iterator> + { + return end(obj.m_value); + } + + template + auto constexpr end(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator> + { + return end(obj.m_value); + } + + template + auto constexpr cend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator> + { + return cend(obj.m_value); + } + + template + auto constexpr rend(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator> + { + return rend(obj.m_value); + } + + template + auto constexpr rend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return rend(obj.m_value); + } + + template + auto constexpr crend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return crend(obj.m_value); + } + } // namespace nt namespace std diff --git a/test/src/iterable_suite.cpp b/test/src/iterable_suite.cpp index 778dc35..a75ab19 100644 --- a/test/src/iterable_suite.cpp +++ b/test/src/iterable_suite.cpp @@ -27,6 +27,13 @@ namespace auto rbegin() -> reverse_iterator; auto rbegin() const -> const_reverse_iterator; auto crbegin() const -> const_reverse_iterator; + + auto end() -> iterator; + auto end() const -> const_iterator; + auto cend() const -> const_iterator; + auto rend() -> reverse_iterator; + auto rend() const -> const_reverse_iterator; + auto crend() const -> const_reverse_iterator; }; } // namespace @@ -251,6 +258,225 @@ inline namespace crbegin_tests } // namespace crbegin_tests +inline namespace end_tests +{ + + auto a_new__type_not_deriving_iterable_has_no_end() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_end_v)); + } + + auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_end() -> void + { + static_assert(!nt::impl::has_end_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_end_v)); + } + + auto a_new__type_based_on_an_iterable_type_with_member_end_deriving_iterable_has_member_end() -> void + { + static_assert(nt::impl::has_member_end_v); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_end_v); + } + + auto a_new__type_based_on_an_iterable_type_with_constant_member_end_deriving_iterable_has_constant_member_end() -> void + { + static_assert(nt::impl::has_member_end_v); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_end_v); + } + + auto a_new__type_based_on_an_iterable_type_without_free_end_deriving_iterable_has_no_free_end() -> void + { + static_assert(!nt::impl::has_free_end_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_end_v); + } + + auto a_new__type_based_on_an_iterable_type_without_constant_free_end_deriving_iterable_has_no_constant_free_end() -> void + { + static_assert(!nt::impl::has_free_end_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_end_v); + } + + auto accessing_the_last_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto weak = std::array{42, 21, 10}; + auto strong = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(*(weak.end() - 1), *(strong.end() - 1)); + } + + auto an_iterator_obtained_via_member_end_compares_equal_to_an_iterator_obtained_via_free_end() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto instance = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(end(instance), instance.end()); + } + +} // namespace end_tests + +inline namespace cend_tests +{ + + auto a_new__type_not_deriving_iterable_has_no_cend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cend_v)); + } + + auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_cend() -> void + { + static_assert(!nt::impl::has_cend_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cend_v)); + } + + auto a_new__type_based_on_an_iterable_type_with_member_cend_deriving_iterable_has_member_cend() -> void + { + static_assert(nt::impl::has_member_cend_v); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_cend_v); + } + + auto a_new__type_based_on_an_iterable_type_without_free_cend_deriving_iterable_has_no_free_cend() -> void + { + static_assert(!nt::impl::has_free_cend_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_cend_v); + } + + auto accessing_the_last_element_of_a_constant_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() + -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto weak = std::array{42, 21, 10}; + auto strong = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(*(weak.cend() - 1), *(strong.cend() - 1)); + } + + auto an_iterator_obtained_via_member_cend_compares_equal_to_an_iterator_obtained_via_free_cend() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto instance = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(cend(instance), instance.cend()); + } + +} // namespace cend_tests + +inline namespace rend_tests +{ + + auto a_new__type_not_deriving_iterable_has_no_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rend_v)); + } + + auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_rend() -> void + { + static_assert(!nt::impl::has_rend_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rend_v)); + } + + auto a_new__type_based_on_an_iterable_type_with_member_rend_deriving_iterable_has_member_rend() -> void + { + static_assert(nt::impl::has_member_rend_v); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_rend_v); + } + + auto a_new__type_based_on_an_iterable_type_with_constant_member_rend_deriving_iterable_has_constant_member_rend() -> void + { + static_assert(nt::impl::has_member_rend_v); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_rend_v); + } + + auto a_new__type_based_on_an_iterable_type_without_free_rend_deriving_iterable_has_no_free_rend() -> void + { + static_assert(!nt::impl::has_free_rend_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_rend_v); + } + + auto a_new__type_based_on_an_iterable_type_without_constant_free_rend_deriving_iterable_has_no_constant_free_rend() -> void + { + static_assert(!nt::impl::has_free_rend_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_rend_v); + } + + auto accessing_the_last_element_of_a_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto weak = std::array{42, 21, 10}; + auto strong = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(*(weak.rend() - 1), *(strong.rend() - 1)); + } + + auto an_iterator_obtained_via_member_rend_compares_equal_to_an_iterator_obtained_via_free_rend() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto instance = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(rend(instance), instance.rend()); + } + +} // namespace rend_tests + +inline namespace crend_tests +{ + + auto a_new__type_not_deriving_iterable_has_no_crend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crend_v)); + } + + auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_crend() -> void + { + static_assert(!nt::impl::has_crend_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crend_v)); + } + + auto a_new__type_based_on_an_iterable_type_with_member_crend_deriving_iterable_has_member_crend() -> void + { + static_assert(nt::impl::has_member_crend_v); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_crend_v); + } + + auto a_new__type_based_on_an_iterable_type_without_free_crend_deriving_iterable_has_no_free_crend() -> void + { + static_assert(!nt::impl::has_free_crend_v); + using type_alias = nt::new_type; + ASSERT(!nt::impl::has_free_crend_v); + } + + auto + accessing_the_last_element_of_a_constant_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() + -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto weak = std::array{42, 21, 10}; + auto strong = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(*(weak.crend() - 1), *(strong.crend() - 1)); + } + + auto an_iterator_obtained_via_member_crend_compares_equal_to_an_iterator_obtained_via_free_crend() -> void + { + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto instance = type_alias{{42, 21, 10}}; + ASSERT_EQUAL(crend(instance), instance.crend()); + } + +} // namespace crend_tests + auto iterable_suite() -> std::pair { return { @@ -284,13 +510,49 @@ auto iterable_suite() -> std::pair KAWAII(accessing_the_first_element_of_a_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), KAWAII(an_iterator_obtained_via_member_rbegin_compares_equal_to_an_iterator_obtained_via_free_rbegin), - /// 'cbegin' Tests + /// 'crbegin' Tests KAWAII(a_new__type_not_deriving_iterable_has_no_crbegin), KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_crbegin), KAWAII(a_new__type_based_on_an_iterable_type_with_member_crbegin_deriving_iterable_has_member_crbegin), KAWAII(a_new__type_based_on_an_iterable_type_without_free_crbegin_deriving_iterable_has_no_free_crbegin), KAWAII(accessing_the_first_element_of_a_constant_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), KAWAII(an_iterator_obtained_via_member_crbegin_compares_equal_to_an_iterator_obtained_via_free_crbegin), + + /// 'end' Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_end), + KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_end), + KAWAII(a_new__type_based_on_an_iterable_type_with_member_end_deriving_iterable_has_member_end), + KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_end_deriving_iterable_has_constant_member_end), + KAWAII(a_new__type_based_on_an_iterable_type_without_free_end_deriving_iterable_has_no_free_end), + KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_end_deriving_iterable_has_no_constant_free_end), + KAWAII(accessing_the_last_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), + KAWAII(an_iterator_obtained_via_member_end_compares_equal_to_an_iterator_obtained_via_free_end), + + /// 'cend' Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_cend), + KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_cend), + KAWAII(a_new__type_based_on_an_iterable_type_with_member_cend_deriving_iterable_has_member_cend), + KAWAII(a_new__type_based_on_an_iterable_type_without_free_cend_deriving_iterable_has_no_free_cend), + KAWAII(accessing_the_last_element_of_a_constant_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), + KAWAII(an_iterator_obtained_via_member_cend_compares_equal_to_an_iterator_obtained_via_free_cend), + + /// 'rend' Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_rend), + KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_rend), + KAWAII(a_new__type_based_on_an_iterable_type_with_member_rend_deriving_iterable_has_member_rend), + KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_rend_deriving_iterable_has_constant_member_rend), + KAWAII(a_new__type_based_on_an_iterable_type_without_free_rend_deriving_iterable_has_no_free_rend), + KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_rend_deriving_iterable_has_no_constant_free_rend), + KAWAII(accessing_the_last_element_of_a_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), + KAWAII(an_iterator_obtained_via_member_rend_compares_equal_to_an_iterator_obtained_via_free_rend), + + /// 'crend' Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_crend), + KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_crend), + KAWAII(a_new__type_based_on_an_iterable_type_with_member_crend_deriving_iterable_has_member_crend), + KAWAII(a_new__type_based_on_an_iterable_type_without_free_crend_deriving_iterable_has_no_free_crend), + KAWAII(accessing_the_last_element_of_a_constant_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), + KAWAII(an_iterator_obtained_via_member_crend_compares_equal_to_an_iterator_obtained_via_free_crend), // clang-format on }, "Iterable Tests"}; -- cgit v1.2.3 From 1e99bd1e7da5b4e337d5067255d24926267dcf6d Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 29 Feb 2020 12:32:36 +0100 Subject: build: enable code coverage support --- .travis.yml | 3 ++- CMakeLists.txt | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5091396..c5e6a8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,7 @@ addons: sources: - sourceline: "ppa:ubuntu-toolchain-r/test" packages: ['g++-9'] + packages: lcov compiler: - gcc @@ -26,6 +27,6 @@ install: script: - mkdir -p build - cd build - - cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON .. + - cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=YES -DRUN_TESTS_AFTER_BUILD=YES -DENABLE_CODE_COVERAGE=YES -DPRINT_COVERAGE_REPORT=YES .. - cmake --build . --target all - ctest diff --git a/CMakeLists.txt b/CMakeLists.txt index 398b0c2..571d320 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,12 +6,15 @@ project("newtype" DESCRIPTION "A library of types and functions to create strong type aliases" ) -include("CTest") include("CMakePackageConfigHelpers") # Project Options option(RUN_TESTS_AFTER_BUILD "Automatically run the unit tests after building" ON) +option(BUILD_TESTING "Build the unit tests" ON) +option(ENABLE_CODE_COVERAGE "Enable building support for code coverage report generation" ON) +option(PRINT_COVERAGE_REPORT "Print a coverage report after running the unit tests" ON) +option(GENERATE_COVERAGE_REPORT "Generate an HTML coverage report after running the unit tests" OFF) # 'newtype' library @@ -38,6 +41,24 @@ install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/" # 'newtype' tests if(BUILD_TESTING) + enable_testing() + + if(PRINT_COVERAGE_REPORT) + find_program(LCOV_EXE NAMES "lcov") + mark_as_advanced(LCOV_EXE) + if(NOT LCOV_EXE) + message(FATAL_ERROR "lcov is required to generate code coverage reports") + endif() + endif() + + if(GENERATE_COVERAGE_REPORT) + find_program(GENHTML_EXE NAMES "genhtml") + mark_as_advanced(GENHTML_EXE) + if(NOT GENHTML_EXE) + message(FATAL_ERROR "genhtml is required to generate code coverage reports") + endif() + endif() + include("${PROJECT_SOURCE_DIR}/cmake/Modules/DiscoverTests.cmake") include("${PROJECT_SOURCE_DIR}/cmake/Modules/Conan.cmake") @@ -79,6 +100,15 @@ if(BUILD_TESTING) "-Wextra" "-Werror" "-pedantic-errors" + $<$:--coverage> + ) + + target_link_options("${PROJECT_NAME}_tests" PRIVATE + $<$:--coverage> + ) + + set_target_properties("${PROJECT_NAME}_tests" PROPERTIES + CXX_EXTENSIONS OFF ) discover_tests(TARGET "${PROJECT_NAME}_tests") @@ -86,11 +116,56 @@ if(BUILD_TESTING) if(RUN_TESTS_AFTER_BUILD) add_custom_command(TARGET "${PROJECT_NAME}_tests" POST_BUILD - COMMAND "${CMAKE_CTEST_COMMAND}" "--output-on-failure" + DEPENDS "${PROJECT_NAME}_tests" + COMMAND "${CMAKE_CTEST_COMMAND}" + ARGS + "--output-on-failure" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" COMMENT "Running unit tests" - ) + ) endif() + + if(GENERATE_COVERAGE_REPORT AND RUN_TESTS_AFTER_BUILD) + add_custom_command(TARGET "${PROJECT_NAME}_tests" + POST_BUILD + BYPRODUCTS "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.coverage.info" + COMMAND "${LCOV_EXE}" + ARGS + "--capture" + "--base-directory" "${PROJECT_SOURCE_DIR}" + "--directory" "${PROJECT_BINARY_DIR}" + "--output-file" "${PROJECT_NAME}.coverage.info" + "--no-external" + "--exclude" "${PROJECT_SOURCE_DIR}/test/\\*" + WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" + COMMENT "Capturing code coverage data" + ) + add_custom_command(TARGET "${PROJECT_NAME}_tests" + POST_BUILD + COMMAND "${LCOV_EXE}" + ARGS + "--list" + "${PROJECT_NAME}.coverage.info" + WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" + COMMENT "Printing code coverage report" + ) + if(PRINT_COVERAGE_REPORT) + add_custom_command(TARGET "${PROJECT_NAME}_tests" + POST_BUILD + BYPRODUCTS "${PROJECT_BINARY_DIR}/coverage-report/index.html" + COMMAND "${GENHTML_EXE}" + ARGS + "--demangle-cpp" + "--highlight" + "--missed" + "--show-details" + "--output" "coverage-report" + "${PROJECT_NAME}.coverage.info" + WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" + COMMENT "Generating code coverage report" + ) + endif() + endif() endif() # 'newtype' docs @@ -99,6 +174,7 @@ option(BUILD_DOCS "Build the library documentation" OFF) if(BUILD_DOCS) find_program(PIPENV_EXE NAMES "pipenv3" "pipenv") + mark_as_advanced(PIPENV_EXE) if(NOT PIPENV_EXE) message(FATAL_ERROR "Could not find pipenv") endif() -- cgit v1.2.3 From e24b0c0affba86ce6953fc33e43e8382b92f4daf Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 29 Feb 2020 12:36:24 +0100 Subject: ci: fix CI package configuration --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c5e6a8e..8ff810d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,9 @@ addons: apt: sources: - sourceline: "ppa:ubuntu-toolchain-r/test" - packages: ['g++-9'] - packages: lcov + packages: + - g++-9 + - lcov compiler: - gcc -- cgit v1.2.3 From 4ccf8aabdef2be5d52a91b24dd2e026dce85cdeb Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 29 Feb 2020 12:41:19 +0100 Subject: ci: upgrade cmake --- .travis.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8ff810d..eba74f0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,10 +24,11 @@ cache: install: - pip install conan - conan user + - wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add - + - sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' + - sudo apt-get update + - sudo apt-get install cmake script: - - mkdir -p build - - cd build - - cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=YES -DRUN_TESTS_AFTER_BUILD=YES -DENABLE_CODE_COVERAGE=YES -DPRINT_COVERAGE_REPORT=YES .. - - cmake --build . --target all - - ctest + - /usr/bin/cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=YES -DRUN_TESTS_AFTER_BUILD=YES -DENABLE_CODE_COVERAGE=YES -DPRINT_COVERAGE_REPORT=YES .. + - /usr/bin/cmake --build build --target all --parallel $(nproc) -- cgit v1.2.3 From eee66b517673da38e51b61dc7ed6a4dfdd2a83c9 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 29 Feb 2020 13:00:39 +0100 Subject: build: fix coverage conditions --- .travis.yml | 2 +- CMakeLists.txt | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index eba74f0..a348464 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,5 +30,5 @@ install: - sudo apt-get install cmake script: - - /usr/bin/cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=YES -DRUN_TESTS_AFTER_BUILD=YES -DENABLE_CODE_COVERAGE=YES -DPRINT_COVERAGE_REPORT=YES .. + - /usr/bin/cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=YES -DRUN_TESTS_AFTER_BUILD=YES -DENABLE_CODE_COVERAGE=YES -DPRINT_COVERAGE_REPORT=YES - /usr/bin/cmake --build build --target all --parallel $(nproc) diff --git a/CMakeLists.txt b/CMakeLists.txt index 571d320..fdd2fa3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -125,7 +125,7 @@ if(BUILD_TESTING) ) endif() - if(GENERATE_COVERAGE_REPORT AND RUN_TESTS_AFTER_BUILD) + if(ENABLE_CODE_COVERAGE AND RUN_TESTS_AFTER_BUILD) add_custom_command(TARGET "${PROJECT_NAME}_tests" POST_BUILD BYPRODUCTS "${PROJECT_BINARY_DIR}/${PROJECT_NAME}.coverage.info" @@ -140,16 +140,20 @@ if(BUILD_TESTING) WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" COMMENT "Capturing code coverage data" ) - add_custom_command(TARGET "${PROJECT_NAME}_tests" - POST_BUILD - COMMAND "${LCOV_EXE}" - ARGS - "--list" - "${PROJECT_NAME}.coverage.info" - WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" - COMMENT "Printing code coverage report" - ) + if(PRINT_COVERAGE_REPORT) + add_custom_command(TARGET "${PROJECT_NAME}_tests" + POST_BUILD + COMMAND "${LCOV_EXE}" + ARGS + "--list" + "${PROJECT_NAME}.coverage.info" + WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" + COMMENT "Printing code coverage report" + ) + endif() + + if(GENERATE_COVERAGE_REPORT) add_custom_command(TARGET "${PROJECT_NAME}_tests" POST_BUILD BYPRODUCTS "${PROJECT_BINARY_DIR}/coverage-report/index.html" -- cgit v1.2.3 From 22f3ea999fbe89fd199fad8227dd96f6b2982844 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 29 Feb 2020 13:17:40 +0100 Subject: ci: install lcov from git --- .travis.yml | 24 +++++++++++++++--------- CMakeLists.txt | 1 + 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index a348464..d148321 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,28 +6,34 @@ dist: bionic addons: apt: sources: - - sourceline: "ppa:ubuntu-toolchain-r/test" + - sourceline: 'ppa:ubuntu-toolchain-r/test' + - sourceline: 'deb https://apt.kitware.com/ubuntu/ bionic main' + key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc' packages: - g++-9 - - lcov + - cmake compiler: - gcc -env: - - CXX=g++-9 - cache: directories: - $HOME/.conan/data +before_install: + - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 20 + - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-9 20 + - sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-9 20 + - sudo update-alternatives --config gcc + - sudo update-alternatives --config g++ + - sudo update-alternatives --config gcov + install: - pip install conan - conan user - - wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | sudo apt-key add - - - sudo apt-add-repository 'deb https://apt.kitware.com/ubuntu/ bionic main' - - sudo apt-get update - - sudo apt-get install cmake + - git clone git://github.com/linux-test-project/lcov.git + - cd lcov && sudo make install + - cd .. script: - /usr/bin/cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=YES -DRUN_TESTS_AFTER_BUILD=YES -DENABLE_CODE_COVERAGE=YES -DPRINT_COVERAGE_REPORT=YES diff --git a/CMakeLists.txt b/CMakeLists.txt index fdd2fa3..951ad62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ if(BUILD_TESTING) conan_check(REQUIRED) conan_add_remote(NAME "fmorgner-public" URL "https://api.bintray.com/conan/fmorgner/conan-public") conan_cmake_run(CONANFILE "conanfile.py" + OUTPUT_QUIET BASIC_SETUP CMAKE_TARGETS BUILD "missing" -- cgit v1.2.3 From cb4a299b43616dc94a0e6d09116a703a69755ce0 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 29 Feb 2020 13:23:39 +0100 Subject: ci: add missing lcov dependencies --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index d148321..f523e70 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,8 @@ addons: packages: - g++-9 - cmake + - libperlio-gzip-perl + - libjson-perl compiler: - gcc -- cgit v1.2.3 From 943b85617691a9a14472ceac29dc81e38134ef9a Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sat, 29 Feb 2020 13:29:18 +0100 Subject: build: quiet down cmake output --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 951ad62..0a81d64 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,6 +138,7 @@ if(BUILD_TESTING) "--output-file" "${PROJECT_NAME}.coverage.info" "--no-external" "--exclude" "${PROJECT_SOURCE_DIR}/test/\\*" + ">/dev/null" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" COMMENT "Capturing code coverage data" ) @@ -166,6 +167,7 @@ if(BUILD_TESTING) "--show-details" "--output" "coverage-report" "${PROJECT_NAME}.coverage.info" + ">/dev/null" WORKING_DIRECTORY "${PROJECT_BINARY_DIR}" COMMENT "Generating code coverage report" ) @@ -184,9 +186,11 @@ if(BUILD_DOCS) message(FATAL_ERROR "Could not find pipenv") endif() + message(STATUS "Installing documentation dependencies via pipenv") execute_process(COMMAND "${PIPENV_EXE}" "install" "-r" "requirements.txt" WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}/doc" OUTPUT_QUIET + ERROR_QUIET ) set(DOC_SOURCES -- cgit v1.2.3 From 081688443d12de12d7b66b44630e4c7e0681fabe Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 1 Mar 2020 12:06:23 +0100 Subject: new_type: restructure iterable tests --- include/newtype/impl/type_traits_extensions.hpp | 4 +- test/src/iterable_suite.cpp | 790 ++++++++++++++---------- 2 files changed, 477 insertions(+), 317 deletions(-) diff --git a/include/newtype/impl/type_traits_extensions.hpp b/include/newtype/impl/type_traits_extensions.hpp index 121e2c0..dc41649 100644 --- a/include/newtype/impl/type_traits_extensions.hpp +++ b/include/newtype/impl/type_traits_extensions.hpp @@ -587,7 +587,7 @@ namespace nt::impl template struct has_free_rbegin()))>> - : std::is_same()))>> + : std::is_same()))>> { }; @@ -767,7 +767,7 @@ namespace nt::impl template struct has_free_rend()))>> - : std::is_same()))>> + : std::is_same()))>> { }; diff --git a/test/src/iterable_suite.cpp b/test/src/iterable_suite.cpp index a75ab19..3b46024 100644 --- a/test/src/iterable_suite.cpp +++ b/test/src/iterable_suite.cpp @@ -8,18 +8,20 @@ #include +#include #include #include +#include namespace { struct with_member { - using iterator = void *; - using const_iterator = void const *; - using reverse_iterator = void *; - using const_reverse_iterator = void const *; + using iterator = char *; + using const_iterator = char const *; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; auto begin() -> iterator; auto begin() const -> const_iterator; @@ -36,9 +38,77 @@ namespace auto crend() const -> const_reverse_iterator; }; + struct with_free + { + using iterator = char *; + using const_iterator = char const *; + using reverse_iterator = std::reverse_iterator; + using const_reverse_iterator = std::reverse_iterator; + }; + + auto begin(with_free &) -> with_free::iterator + { + return {}; + } + + auto begin(with_free const &) -> with_free::const_iterator + { + return {}; + } + + auto cbegin(with_free const &) -> with_free::const_iterator + { + return {}; + } + + auto rbegin(with_free &) -> with_free::reverse_iterator + { + return {}; + } + + auto rbegin(with_free const &) -> with_free::const_reverse_iterator + { + return {}; + } + + auto crbegin(with_free const &) -> with_free::const_reverse_iterator + { + return {}; + } + + auto end(with_free &) -> with_free::iterator + { + return {}; + } + + auto end(with_free const &) -> with_free::const_iterator + { + return {}; + } + + auto cend(with_free const &) -> with_free::const_iterator + { + return {}; + } + + auto rend(with_free &) -> with_free::reverse_iterator + { + return {}; + } + + auto rend(with_free const &) -> with_free::const_reverse_iterator + { + return {}; + } + + auto crend(with_free const &) -> with_free::const_reverse_iterator + { + return {}; + } + } // namespace -inline namespace begin_tests +inline namespace combined_enablement_tests { auto a_new__type_not_deriving_iterable_has_no_begin() -> void @@ -47,513 +117,603 @@ inline namespace begin_tests ASSERT(!(nt::impl::has_begin_v)); } - auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_begin() -> void + auto a_new__type_not_deriving_iterable_has_no_constant_begin() -> void { - static_assert(!nt::impl::has_begin_v); - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_begin_v)); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_begin_v)); } - auto a_new__type_based_on_an_iterable_type_with_member_begin_deriving_iterable_has_member_begin() -> void + auto a_new__type_not_deriving_iterable_has_no_cbegin() -> void { - static_assert(nt::impl::has_member_begin_v); - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_begin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cbegin_v)); } - auto a_new__type_based_on_an_iterable_type_with_constant_member_begin_deriving_iterable_has_constant_member_begin() -> void + auto a_new__type_not_deriving_iterable_has_no_rbegin() -> void { - static_assert(nt::impl::has_member_begin_v); - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_begin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rbegin_v)); } - auto a_new__type_based_on_an_iterable_type_without_free_begin_deriving_iterable_has_no_free_begin() -> void + auto a_new__type_not_deriving_iterable_has_no_constant_rbegin() -> void { - static_assert(!nt::impl::has_free_begin_v); - using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_begin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rbegin_v)); } - auto a_new__type_based_on_an_iterable_type_without_constant_free_begin_deriving_iterable_has_no_constant_free_begin() -> void + auto a_new__type_not_deriving_iterable_has_no_crbegin() -> void { - static_assert(!nt::impl::has_free_begin_v); - using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_begin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crbegin_v)); } - auto accessing_the_first_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() -> void + auto a_new__type_not_deriving_iterable_has_no_end() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto weak = std::array{42, 21, 10}; - auto strong = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(*weak.begin(), *strong.begin()); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_end_v)); } - auto an_iterator_obtained_via_member_begin_compares_equal_to_an_iterator_obtained_via_free_begin() -> void + auto a_new__type_not_deriving_iterable_has_no_constant_end() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto instance = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(begin(instance), instance.begin()); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_end_v)); } -} // namespace begin_tests + auto a_new__type_not_deriving_iterable_has_no_cend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cend_v)); + } -inline namespace cbegin_tests -{ + auto a_new__type_not_deriving_iterable_has_no_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rend_v)); + } - auto a_new__type_not_deriving_iterable_has_no_cbegin() -> void + auto a_new__type_not_deriving_iterable_has_no_constant_rend() -> void { using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_cbegin_v)); + ASSERT(!(nt::impl::has_rend_v)); + } + + auto a_new__type_not_deriving_iterable_has_no_crend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crend_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_begin_v)); + } + + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_begin_v)); } - auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_cbegin() -> void + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cbegin() -> void { - static_assert(!nt::impl::has_cbegin_v); using type_alias = nt::new_type; ASSERT(!(nt::impl::has_cbegin_v)); } - auto a_new__type_based_on_an_iterable_type_with_member_cbegin_deriving_iterable_has_member_cbegin() -> void + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rbegin() -> void { - static_assert(nt::impl::has_member_cbegin_v); - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_cbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rbegin_v)); } - auto a_new__type_based_on_an_iterable_type_without_free_cbegin_deriving_iterable_has_no_free_cbegin() -> void + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rbegin() -> void { - static_assert(!nt::impl::has_free_cbegin_v); - using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_cbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rbegin_v)); } - auto accessing_the_first_element_of_a_constant_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() - -> void + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crbegin() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto weak = std::array{42, 21, 10}; - auto strong = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(*weak.cbegin(), *strong.cbegin()); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crbegin_v)); } - auto an_iterator_obtained_via_member_cbegin_compares_equal_to_an_iterator_obtained_via_free_cbegin() -> void + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_end() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto instance = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(cbegin(instance), instance.cbegin()); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_end_v)); } -} // namespace cbegin_tests + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_end() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_end_v)); + } -inline namespace rbegin_tests -{ + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cend() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_cend_v)); + } - auto a_new__type_not_deriving_iterable_has_no_rbegin() -> void + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rend() -> void { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rbegin_v)); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_rend_v)); } - auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_rbegin() -> void + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rend() -> void { - static_assert(!nt::impl::has_rbegin_v); using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rbegin_v)); + ASSERT(!(nt::impl::has_rend_v)); } - auto a_new__type_based_on_an_iterable_type_with_member_rbegin_deriving_iterable_has_member_rbegin() -> void + auto a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crend() -> void { - static_assert(nt::impl::has_member_rbegin_v); - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_rbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_crend_v)); } - auto a_new__type_based_on_an_iterable_type_with_constant_member_rbegin_deriving_iterable_has_constant_member_rbegin() -> void +} // namespace combined_enablement_tests + +inline namespace member_enablement_tests +{ + + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_begin() -> void { - static_assert(nt::impl::has_member_rbegin_v); - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_rbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_begin_v)); } - auto a_new__type_based_on_an_iterable_type_without_free_rbegin_deriving_iterable_has_no_free_rbegin() -> void + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_begin() -> void { - static_assert(!nt::impl::has_free_rbegin_v); - using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_rbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_begin_v)); } - auto a_new__type_based_on_an_iterable_type_without_constant_free_rbegin_deriving_iterable_has_no_constant_free_rbegin() -> void + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cbegin() -> void { - static_assert(!nt::impl::has_free_rbegin_v); - using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_rbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_cbegin_v)); } - auto accessing_the_first_element_of_a_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() - -> void + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rbegin() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto weak = std::array{42, 21, 10}; - auto strong = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(*weak.rbegin(), *strong.rbegin()); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_rbegin_v)); } - auto an_iterator_obtained_via_member_rbegin_compares_equal_to_an_iterator_obtained_via_free_rbegin() -> void + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rbegin() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto instance = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(rbegin(instance), instance.rbegin()); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_rbegin_v)); } -} // namespace rbegin_tests + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_crbegin_v)); + } -inline namespace crbegin_tests -{ + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_end() -> void + { + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_end_v)); + } - auto a_new__type_not_deriving_iterable_has_no_crbegin() -> void + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_end() -> void { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_crbegin_v)); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_end_v)); } - auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_crbegin() -> void + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cend() -> void { - static_assert(!nt::impl::has_crbegin_v); - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_crbegin_v)); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_cend_v)); } - auto a_new__type_based_on_an_iterable_type_with_member_crbegin_deriving_iterable_has_member_crbegin() -> void + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rend() -> void { - static_assert(nt::impl::has_member_crbegin_v); - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_crbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_rend_v)); } - auto a_new__type_based_on_an_iterable_type_without_free_crbegin_deriving_iterable_has_no_free_crbegin() -> void + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rend() -> void { - static_assert(!nt::impl::has_free_crbegin_v); - using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_crbegin_v); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_rend_v)); } - auto - accessing_the_first_element_of_a_constant_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() - -> void + auto a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crend() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto weak = std::array{42, 21, 10}; - auto strong = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(*weak.crbegin(), *strong.crbegin()); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_member_crend_v)); } - auto an_iterator_obtained_via_member_crbegin_compares_equal_to_an_iterator_obtained_via_free_crbegin() -> void + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_begin() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto instance = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(crbegin(instance), instance.crbegin()); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_begin_v); } -} // namespace crbegin_tests + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_begin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_begin_v); + } -inline namespace end_tests -{ + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_cbegin_v); + } - auto a_new__type_not_deriving_iterable_has_no_end() -> void + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rbegin() -> void { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_end_v)); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_rbegin_v); } - auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_end() -> void + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rbegin() -> void { - static_assert(!nt::impl::has_end_v); - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_end_v)); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_rbegin_v); } - auto a_new__type_based_on_an_iterable_type_with_member_end_deriving_iterable_has_member_end() -> void + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_crbegin_v); + } + + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_end() -> void { - static_assert(nt::impl::has_member_end_v); using type_alias = nt::new_type; ASSERT(nt::impl::has_member_end_v); } - auto a_new__type_based_on_an_iterable_type_with_constant_member_end_deriving_iterable_has_constant_member_end() -> void + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_end() -> void { - static_assert(nt::impl::has_member_end_v); using type_alias = nt::new_type; ASSERT(nt::impl::has_member_end_v); } - auto a_new__type_based_on_an_iterable_type_without_free_end_deriving_iterable_has_no_free_end() -> void + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cend() -> void { - static_assert(!nt::impl::has_free_end_v); using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_end_v); + ASSERT(nt::impl::has_member_cend_v); } - auto a_new__type_based_on_an_iterable_type_without_constant_free_end_deriving_iterable_has_no_constant_free_end() -> void + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rend() -> void { - static_assert(!nt::impl::has_free_end_v); using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_end_v); + ASSERT(nt::impl::has_member_rend_v); } - auto accessing_the_last_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() -> void + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rend() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto weak = std::array{42, 21, 10}; - auto strong = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(*(weak.end() - 1), *(strong.end() - 1)); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_rend_v); } - auto an_iterator_obtained_via_member_end_compares_equal_to_an_iterator_obtained_via_free_end() -> void + auto a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crend() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto instance = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(end(instance), instance.end()); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_member_crend_v); } -} // namespace end_tests +} // namespace member_enablement_tests -inline namespace cend_tests +inline namespace free_enablement_tests { - - auto a_new__type_not_deriving_iterable_has_no_cend() -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_begin() -> void { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_cend_v)); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_begin_v)); } - auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_cend() -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_begin() -> void { - static_assert(!nt::impl::has_cend_v); - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_cend_v)); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_begin_v)); } - auto a_new__type_based_on_an_iterable_type_with_member_cend_deriving_iterable_has_member_cend() -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cbegin() -> void { - static_assert(nt::impl::has_member_cend_v); using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_cend_v); + ASSERT(!(nt::impl::has_free_cbegin_v)); } - auto a_new__type_based_on_an_iterable_type_without_free_cend_deriving_iterable_has_no_free_cend() -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rbegin() -> void { - static_assert(!nt::impl::has_free_cend_v); using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_cend_v); + ASSERT(!(nt::impl::has_free_rbegin_v)); } - auto accessing_the_last_element_of_a_constant_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() - -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rbegin() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto weak = std::array{42, 21, 10}; - auto strong = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(*(weak.cend() - 1), *(strong.cend() - 1)); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_rbegin_v)); } - auto an_iterator_obtained_via_member_cend_compares_equal_to_an_iterator_obtained_via_free_cend() -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crbegin() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto instance = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(cend(instance), instance.cend()); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_crbegin_v)); } -} // namespace cend_tests - -inline namespace rend_tests -{ - - auto a_new__type_not_deriving_iterable_has_no_rend() -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_end() -> void { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rend_v)); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_end_v)); } - auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_rend() -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_end() -> void { - static_assert(!nt::impl::has_rend_v); - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_rend_v)); + using type_alias = nt::new_type; + ASSERT(!(nt::impl::has_free_end_v)); } - auto a_new__type_based_on_an_iterable_type_with_member_rend_deriving_iterable_has_member_rend() -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cend() -> void { - static_assert(nt::impl::has_member_rend_v); using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_rend_v); + ASSERT(!(nt::impl::has_free_cend_v)); } - auto a_new__type_based_on_an_iterable_type_with_constant_member_rend_deriving_iterable_has_constant_member_rend() -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rend() -> void { - static_assert(nt::impl::has_member_rend_v); using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_rend_v); + ASSERT(!(nt::impl::has_free_rend_v)); } - auto a_new__type_based_on_an_iterable_type_without_free_rend_deriving_iterable_has_no_free_rend() -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rend() -> void { - static_assert(!nt::impl::has_free_rend_v); using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_rend_v); + ASSERT(!(nt::impl::has_free_rend_v)); } - auto a_new__type_based_on_an_iterable_type_without_constant_free_rend_deriving_iterable_has_no_constant_free_rend() -> void + auto a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crend() -> void { - static_assert(!nt::impl::has_free_rend_v); using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_rend_v); + ASSERT(!(nt::impl::has_free_crend_v)); } - auto accessing_the_last_element_of_a_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() -> void + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_begin() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto weak = std::array{42, 21, 10}; - auto strong = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(*(weak.rend() - 1), *(strong.rend() - 1)); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_begin_v); } - auto an_iterator_obtained_via_member_rend_compares_equal_to_an_iterator_obtained_via_free_rend() -> void + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_begin() -> void { - using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto instance = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(rend(instance), instance.rend()); + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_begin_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_cbegin_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_rbegin_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_rbegin_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crbegin() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_crbegin_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_end() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_end_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_end() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_end_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_cend_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_rend_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_rend_v); + } + + auto a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crend() -> void + { + using type_alias = nt::new_type; + ASSERT(nt::impl::has_free_crend_v); } -} // namespace rend_tests +} // namespace free_enablement_tests -inline namespace crend_tests +inline namespace semantic_tests { - auto a_new__type_not_deriving_iterable_has_no_crend() -> void + auto a_non_const_object_of_iterable_new__type_can_be_used_in_value_range_for() -> void { - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_crend_v)); + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto object = type_alias{{1, 2, 3}}; + for (auto e : object) + { + (void)e; + } + ASSERT(true); } - auto a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_crend() -> void + auto a_const_object_of_iterable_new__type_can_be_used_in_value_range_for() -> void { - static_assert(!nt::impl::has_crend_v); - using type_alias = nt::new_type; - ASSERT(!(nt::impl::has_crend_v)); + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto const object = type_alias{{1, 2, 3}}; + for (auto e : object) + { + (void)e; + } + ASSERT(true); } - auto a_new__type_based_on_an_iterable_type_with_member_crend_deriving_iterable_has_member_crend() -> void + auto a_non_const_object_of_iterable_new__type_can_be_used_in_reference_range_for() -> void { - static_assert(nt::impl::has_member_crend_v); - using type_alias = nt::new_type; - ASSERT(nt::impl::has_member_crend_v); + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto object = type_alias{{1, 2, 3}}; + for (auto & e : object) + { + (void)e; + } + ASSERT(true); } - auto a_new__type_based_on_an_iterable_type_without_free_crend_deriving_iterable_has_no_free_crend() -> void + auto a_const_object_of_iterable_new__type_can_be_used_in_const_reference_range_for() -> void { - static_assert(!nt::impl::has_free_crend_v); - using type_alias = nt::new_type; - ASSERT(!nt::impl::has_free_crend_v); + using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; + auto const object = type_alias{{1, 2, 3}}; + for (auto const & e : object) + { + (void)e; + } + ASSERT(true); } - auto - accessing_the_last_element_of_a_constant_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type() - -> void + auto applying_accumulate_to_an_interable_new__type_yields_the_same_result_as_when_applied_to_the_base_type() -> void { using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto weak = std::array{42, 21, 10}; - auto strong = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(*(weak.crend() - 1), *(strong.crend() - 1)); + auto const nt_object = type_alias{{1, 2, 3}}; + auto const bt_object = type_alias::base_type{1, 2, 3}; + + auto nt_result = std::accumulate(std::cbegin(nt_object), std::cend(nt_object), 0); + auto bt_result = std::accumulate(std::cbegin(bt_object), std::cend(bt_object), 0); + + ASSERT_EQUAL(bt_result, nt_result); } - auto an_iterator_obtained_via_member_crend_compares_equal_to_an_iterator_obtained_via_free_crend() -> void + auto iterating_over_an_iterable_new__type_yields_the_elements_in_the_same_order_as_when_iterating_the_base_type() -> void { + using std::cbegin, std::cend, std::equal; using type_alias = nt::new_type, struct tag, deriving(nt::Iterable)>; - auto instance = type_alias{{42, 21, 10}}; - ASSERT_EQUAL(crend(instance), instance.crend()); + auto const nt_object = type_alias{{1, 2, 3}}; + auto const bt_object = type_alias::base_type{1, 2, 3}; + + ASSERT(equal(cbegin(nt_object), cend(nt_object), cbegin(bt_object), cend(bt_object))); } -} // namespace crend_tests +} // namespace semantic_tests auto iterable_suite() -> std::pair { - return { - { - // clang-format off - /// 'begin' Tests - KAWAII(a_new__type_not_deriving_iterable_has_no_begin), - KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_begin), - KAWAII(a_new__type_based_on_an_iterable_type_with_member_begin_deriving_iterable_has_member_begin), - KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_begin_deriving_iterable_has_constant_member_begin), - KAWAII(a_new__type_based_on_an_iterable_type_without_free_begin_deriving_iterable_has_no_free_begin), - KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_begin_deriving_iterable_has_no_constant_free_begin), - KAWAII(accessing_the_first_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), - KAWAII(an_iterator_obtained_via_member_begin_compares_equal_to_an_iterator_obtained_via_free_begin), - - /// 'cbegin' Tests - KAWAII(a_new__type_not_deriving_iterable_has_no_cbegin), - KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_cbegin), - KAWAII(a_new__type_based_on_an_iterable_type_with_member_cbegin_deriving_iterable_has_member_cbegin), - KAWAII(a_new__type_based_on_an_iterable_type_without_free_cbegin_deriving_iterable_has_no_free_cbegin), - KAWAII(accessing_the_first_element_of_a_constant_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), - KAWAII(an_iterator_obtained_via_member_cbegin_compares_equal_to_an_iterator_obtained_via_free_cbegin), - - /// 'rbegin' Tests - KAWAII(a_new__type_not_deriving_iterable_has_no_rbegin), - KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_rbegin), - KAWAII(a_new__type_based_on_an_iterable_type_with_member_rbegin_deriving_iterable_has_member_rbegin), - KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_rbegin_deriving_iterable_has_constant_member_rbegin), - KAWAII(a_new__type_based_on_an_iterable_type_without_free_rbegin_deriving_iterable_has_no_free_rbegin), - KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_rbegin_deriving_iterable_has_no_constant_free_rbegin), - KAWAII(accessing_the_first_element_of_a_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), - KAWAII(an_iterator_obtained_via_member_rbegin_compares_equal_to_an_iterator_obtained_via_free_rbegin), - - /// 'crbegin' Tests - KAWAII(a_new__type_not_deriving_iterable_has_no_crbegin), - KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_crbegin), - KAWAII(a_new__type_based_on_an_iterable_type_with_member_crbegin_deriving_iterable_has_member_crbegin), - KAWAII(a_new__type_based_on_an_iterable_type_without_free_crbegin_deriving_iterable_has_no_free_crbegin), - KAWAII(accessing_the_first_element_of_a_constant_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), - KAWAII(an_iterator_obtained_via_member_crbegin_compares_equal_to_an_iterator_obtained_via_free_crbegin), - - /// 'end' Tests - KAWAII(a_new__type_not_deriving_iterable_has_no_end), - KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_end), - KAWAII(a_new__type_based_on_an_iterable_type_with_member_end_deriving_iterable_has_member_end), - KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_end_deriving_iterable_has_constant_member_end), - KAWAII(a_new__type_based_on_an_iterable_type_without_free_end_deriving_iterable_has_no_free_end), - KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_end_deriving_iterable_has_no_constant_free_end), - KAWAII(accessing_the_last_element_of_an_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), - KAWAII(an_iterator_obtained_via_member_end_compares_equal_to_an_iterator_obtained_via_free_end), - - /// 'cend' Tests - KAWAII(a_new__type_not_deriving_iterable_has_no_cend), - KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_cend), - KAWAII(a_new__type_based_on_an_iterable_type_with_member_cend_deriving_iterable_has_member_cend), - KAWAII(a_new__type_based_on_an_iterable_type_without_free_cend_deriving_iterable_has_no_free_cend), - KAWAII(accessing_the_last_element_of_a_constant_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), - KAWAII(an_iterator_obtained_via_member_cend_compares_equal_to_an_iterator_obtained_via_free_cend), - - /// 'rend' Tests - KAWAII(a_new__type_not_deriving_iterable_has_no_rend), - KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_rend), - KAWAII(a_new__type_based_on_an_iterable_type_with_member_rend_deriving_iterable_has_member_rend), - KAWAII(a_new__type_based_on_an_iterable_type_with_constant_member_rend_deriving_iterable_has_constant_member_rend), - KAWAII(a_new__type_based_on_an_iterable_type_without_free_rend_deriving_iterable_has_no_free_rend), - KAWAII(a_new__type_based_on_an_iterable_type_without_constant_free_rend_deriving_iterable_has_no_constant_free_rend), - KAWAII(accessing_the_last_element_of_a_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), - KAWAII(an_iterator_obtained_via_member_rend_compares_equal_to_an_iterator_obtained_via_free_rend), - - /// 'crend' Tests - KAWAII(a_new__type_not_deriving_iterable_has_no_crend), - KAWAII(a_new__type_based_on_a_non_iterable_type_deriving_iterable_has_no_crend), - KAWAII(a_new__type_based_on_an_iterable_type_with_member_crend_deriving_iterable_has_member_crend), - KAWAII(a_new__type_based_on_an_iterable_type_without_free_crend_deriving_iterable_has_no_free_crend), - KAWAII(accessing_the_last_element_of_a_constant_reverse_iterator_on_a_new__type_yields_the_same_value_as_accessing_it_through_an_unwrapped_type), - KAWAII(an_iterator_obtained_via_member_crend_compares_equal_to_an_iterator_obtained_via_free_crend), - // clang-format on - }, - "Iterable Tests"}; + return {{ + /// Combined Enablement Tests + KAWAII(a_new__type_not_deriving_iterable_has_no_begin), + KAWAII(a_new__type_not_deriving_iterable_has_no_constant_begin), + KAWAII(a_new__type_not_deriving_iterable_has_no_cbegin), + KAWAII(a_new__type_not_deriving_iterable_has_no_rbegin), + KAWAII(a_new__type_not_deriving_iterable_has_no_constant_rbegin), + KAWAII(a_new__type_not_deriving_iterable_has_no_crbegin), + KAWAII(a_new__type_not_deriving_iterable_has_no_end), + KAWAII(a_new__type_not_deriving_iterable_has_no_constant_end), + KAWAII(a_new__type_not_deriving_iterable_has_no_cend), + KAWAII(a_new__type_not_deriving_iterable_has_no_rend), + KAWAII(a_new__type_not_deriving_iterable_has_no_constant_rend), + KAWAII(a_new__type_not_deriving_iterable_has_no_crend), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_begin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_begin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cbegin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rbegin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rbegin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crbegin), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_end), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_end), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_cend), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_rend), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_constant_rend), + KAWAII(a_new__type_on_a_non_iterable_type_deriving_iterable_has_no_crend), + + /// Member Enablement Tests + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_begin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_begin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cbegin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rbegin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rbegin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crbegin), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_end), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_end), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_cend), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_rend), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_constant_rend), + KAWAII(a_new__type_on_a_non_member_iterable_type_deriving_iterable_has_no_member_crend), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_begin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_begin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cbegin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rbegin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rbegin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crbegin), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_end), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_end), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_cend), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_rend), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_constant_rend), + KAWAII(a_new__type_on_a_member_iterable_type_deriving_iterable_has_member_crend), + + /// Free Enablement Tests + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_begin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_begin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cbegin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rbegin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rbegin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crbegin), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_end), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_end), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_cend), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_rend), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_constant_rend), + KAWAII(a_new__type_on_a_non_free_iterable_type_deriving_iterable_has_no_free_crend), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_begin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_begin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cbegin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rbegin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rbegin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crbegin), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_end), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_end), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_cend), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_rend), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_constant_rend), + KAWAII(a_new__type_on_a_free_iterable_type_deriving_iterable_has_free_crend), + + /// Semantic Tests + KAWAII(a_non_const_object_of_iterable_new__type_can_be_used_in_value_range_for), + KAWAII(a_const_object_of_iterable_new__type_can_be_used_in_value_range_for), + KAWAII(a_non_const_object_of_iterable_new__type_can_be_used_in_reference_range_for), + KAWAII(a_const_object_of_iterable_new__type_can_be_used_in_const_reference_range_for), + KAWAII(applying_accumulate_to_an_interable_new__type_yields_the_same_result_as_when_applied_to_the_base_type), + KAWAII(iterating_over_an_iterable_new__type_yields_the_elements_in_the_same_order_as_when_iterating_the_base_type), + }, + + "Iterable Tests"}; } \ No newline at end of file -- cgit v1.2.3 From b0cef60cdfd21bb05a74d29eb4ecb63f143b04a3 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 1 Mar 2020 12:12:50 +0100 Subject: releng: bump version number --- doc/src/conf.py | 2 +- include/newtype/version.hpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/src/conf.py b/doc/src/conf.py index 437d275..b4c1de7 100644 --- a/doc/src/conf.py +++ b/doc/src/conf.py @@ -9,7 +9,7 @@ project = 'newtype' copyright = '2019, Felix Morgner' author = 'Felix Morgner' version = '1.0' -release = '1.0.0' +release = '1.1.0' # -- General configuration --------------------------------------------------- diff --git a/include/newtype/version.hpp b/include/newtype/version.hpp index b2dd19b..519ed50 100644 --- a/include/newtype/version.hpp +++ b/include/newtype/version.hpp @@ -13,8 +13,8 @@ namespace nt char const * const name; } version{ .major = 1, - .minor = 0, - .patch = 2, + .minor = 1, + .patch = 0, .name = "Francesca", }; -- cgit v1.2.3 From 5e6fe1d012468dbc66c992a062e50bc9ae5bc33f Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 1 Mar 2020 12:13:27 +0100 Subject: releng: bump license year --- LICENSE | 2 +- doc/src/conf.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 3959b78..18858da 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2019, Felix Morgner , all rights reserved +Copyright (c) 2020, Felix Morgner , all rights reserved Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/doc/src/conf.py b/doc/src/conf.py index b4c1de7..2727f58 100644 --- a/doc/src/conf.py +++ b/doc/src/conf.py @@ -6,7 +6,7 @@ import os # -- Project information ----------------------------------------------------- project = 'newtype' -copyright = '2019, Felix Morgner' +copyright = '2020, Felix Morgner' author = 'Felix Morgner' version = '1.0' release = '1.1.0' -- cgit v1.2.3 From db435b92b06836fca28994972438c84a374733f0 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 1 Mar 2020 12:14:28 +0100 Subject: releng: bump version number in build configuration --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a81d64..3c29a76 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION "3.9.0") project("newtype" - VERSION "1.0.2" + VERSION "1.1.0" LANGUAGES CXX DESCRIPTION "A library of types and functions to create strong type aliases" ) -- cgit v1.2.3 From 2634acf29bdb25661446cafdd848def9bda84adb Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 1 Mar 2020 12:16:55 +0100 Subject: releng: bump version number in doc configuration --- doc/src/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/src/conf.py b/doc/src/conf.py index 2727f58..1337ce3 100644 --- a/doc/src/conf.py +++ b/doc/src/conf.py @@ -8,7 +8,7 @@ import os project = 'newtype' copyright = '2020, Felix Morgner' author = 'Felix Morgner' -version = '1.0' +version = '1.1' release = '1.1.0' -- cgit v1.2.3 From 8c5f53f0c3052cc30c2fe78feb1432b2a5c4e847 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Sun, 1 Mar 2020 12:18:55 +0100 Subject: releng: update codename --- include/newtype/version.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/newtype/version.hpp b/include/newtype/version.hpp index 519ed50..8678514 100644 --- a/include/newtype/version.hpp +++ b/include/newtype/version.hpp @@ -15,7 +15,7 @@ namespace nt .major = 1, .minor = 1, .patch = 0, - .name = "Francesca", + .name = "Anastasia", }; } // namespace nt -- cgit v1.2.3