From 80802e1ed843c061fe06e1474e192851c215d786 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Tue, 15 Dec 2020 10:36:04 +0100 Subject: newtype: rename new_type.hpp to newtype.hpp --- examples/src/basic_usage.cpp | 2 +- examples/src/basic_usage_with_read.cpp | 2 +- examples/src/basic_usage_with_show.cpp | 2 +- include/newtype/new_type.hpp | 550 -------------------------------- include/newtype/newtype.hpp | 550 ++++++++++++++++++++++++++++++++ test/src/arithmetic_suite.cpp | 2 +- test/src/conversion_suite.cpp | 2 +- test/src/equality_comparison_suite.cpp | 2 +- test/src/hash_suite.cpp | 2 +- test/src/io_operators_suite.cpp | 2 +- test/src/iterable_suite.cpp | 2 +- test/src/new_type_constructor_suite.cpp | 2 +- test/src/relational_operators_suite.cpp | 2 +- 13 files changed, 561 insertions(+), 561 deletions(-) delete mode 100644 include/newtype/new_type.hpp create mode 100644 include/newtype/newtype.hpp diff --git a/examples/src/basic_usage.cpp b/examples/src/basic_usage.cpp index a2a50cd..35d1d2c 100644 --- a/examples/src/basic_usage.cpp +++ b/examples/src/basic_usage.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/examples/src/basic_usage_with_read.cpp b/examples/src/basic_usage_with_read.cpp index 87fcc1a..2dabe2e 100644 --- a/examples/src/basic_usage_with_read.cpp +++ b/examples/src/basic_usage_with_read.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include diff --git a/examples/src/basic_usage_with_show.cpp b/examples/src/basic_usage_with_show.cpp index 1a83968..4bb68f6 100644 --- a/examples/src/basic_usage_with_show.cpp +++ b/examples/src/basic_usage_with_show.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include diff --git a/include/newtype/new_type.hpp b/include/newtype/new_type.hpp deleted file mode 100644 index 66ff332..0000000 --- a/include/newtype/new_type.hpp +++ /dev/null @@ -1,550 +0,0 @@ -#ifndef NEWTYPE_NEW_TYPE_HPP -#define NEWTYPE_NEW_TYPE_HPP - -#include "newtype/derivable.hpp" -#include "newtype/deriving.hpp" -#include "newtype/impl/new_type_iterator_types.hpp" -#include "newtype/impl/new_type_storage.hpp" -#include "newtype/impl/type_traits_extensions.hpp" -#include "newtype/version.hpp" - -#include -#include -#include -#include - -namespace nt -{ - - template - class new_type - : impl::new_type_move_assignment - , public impl::new_type_iterator_types - { - static_assert(!std::is_reference_v, "The base type must not be a reference type"); - static_assert(!std::is_void_v>, "The base type must not be possibly cv-qualified void"); - - template - auto friend operator>>(std::basic_istream &, new_type &) noexcept( - impl::is_nothrow_input_streamable_v, BaseTypeT>) - -> std::enable_if_t, BaseTypeT>, - std::basic_istream> &; - - template - auto constexpr friend - operator+=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_add_assignable_v) - -> std::enable_if_t, - new_type &>; - - template - auto constexpr friend - operator-=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_subtract_assignable_v) - -> std::enable_if_t, - new_type &>; - - template - auto constexpr friend - operator*=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_multiply_assignable_v) - -> std::enable_if_t, - new_type &>; - - template - auto constexpr friend - operator/=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_divide_assignable_v) - -> std::enable_if_t, - new_type &>; - - template - auto constexpr friend begin(new_type & obj) - -> std::enable_if_t, - typename new_type::iterator>; - - template - auto constexpr friend begin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator>; - - template - auto constexpr friend cbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator>; - - template - auto constexpr friend rbegin(new_type & obj) - -> std::enable_if_t, - typename new_type::reverse_iterator>; - - template - auto constexpr friend rbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator>; - - template - auto constexpr friend crbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator>; - - template - auto constexpr friend end(new_type & obj) - -> std::enable_if_t, - typename new_type::iterator>; - - template - auto constexpr friend end(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator>; - - template - auto constexpr friend cend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator>; - - template - auto constexpr friend rend(new_type & obj) - -> std::enable_if_t, - typename new_type::reverse_iterator>; - - template - auto constexpr friend rend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator>; - - template - auto constexpr friend crend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator>; - - using super = impl::new_type_move_assignment; - - public: - using base_type = BaseType; - using tag_type = TagType; - using derivation_clause_type = decltype(DerivationClause); - - auto constexpr static derivation_clause = DerivationClause; - - using super::super; - - constexpr new_type() noexcept(std::is_nothrow_default_constructible_v) = default; - constexpr new_type(new_type const &) noexcept(std::is_nothrow_copy_constructible_v) = default; - constexpr new_type(new_type &&) noexcept(std::is_nothrow_move_constructible_v) = default; - - auto constexpr operator=(new_type const &) noexcept(std::is_nothrow_copy_assignable_v) -> new_type & = default; - auto constexpr operator=(new_type &&) noexcept(std::is_nothrow_move_assignable_v) -> new_type & = default; - - auto constexpr decay() const noexcept(std::is_nothrow_copy_constructible_v) -> BaseType - { - return this->m_value; - } - - template * = nullptr> - constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) - { - return decay(); - } - - template * = nullptr> - explicit constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) - { - return decay(); - } - - template - auto constexpr operator-> () noexcept -> std::enable_if_t - { - return std::addressof(this->m_value); - } - - template - auto constexpr operator-> () const noexcept -> std::enable_if_t - { - return std::addressof(this->m_value); - } - - template * = nullptr> - auto constexpr begin() - -> std::enable_if_t, typename NewType::iterator> - { - return this->m_value.begin(); - } - - template - auto constexpr begin() const -> std::enable_if_t, - typename NewType::const_iterator> - { - return this->m_value.begin(); - } - - template - auto constexpr cbegin() const -> std::enable_if_t, - typename NewType::const_iterator> - { - return this->m_value.cbegin(); - } - - template * = nullptr> - auto constexpr rbegin() - -> std::enable_if_t, typename NewType::reverse_iterator> - { - return this->m_value.rbegin(); - } - - template - auto constexpr rbegin() const -> std::enable_if_t, - typename NewType::const_reverse_iterator> - { - return this->m_value.rbegin(); - } - - template - auto constexpr crbegin() const -> std::enable_if_t, - typename NewType::const_reverse_iterator> - { - return this->m_value.crbegin(); - } - - template * = nullptr> - auto constexpr end() - -> std::enable_if_t, typename NewType::iterator> - { - return this->m_value.end(); - } - - template - auto constexpr end() const -> std::enable_if_t, - typename NewType::const_iterator> - { - return this->m_value.end(); - } - - template - auto constexpr cend() const -> std::enable_if_t, - typename NewType::const_iterator> - { - return this->m_value.cend(); - } - - template * = nullptr> - auto constexpr rend() - -> std::enable_if_t, typename NewType::reverse_iterator> - { - return this->m_value.rend(); - } - - template - auto constexpr rend() const -> std::enable_if_t, - typename NewType::const_reverse_iterator> - { - return this->m_value.rend(); - } - - template - auto constexpr crend() const -> std::enable_if_t, - typename NewType::const_reverse_iterator> - { - return this->m_value.crend(); - } - }; - - template - auto constexpr - operator==(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() == rhs.decay(); - } - - template - auto constexpr operator==(new_type const & lhs, - BaseType const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() == rhs; - } - - template - auto constexpr - operator==(BaseType const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs == rhs.decay(); - } - - template - auto constexpr - operator!=(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() != rhs.decay(); - } - - template - auto constexpr operator!=(new_type const & lhs, - BaseType const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() != rhs; - } - - template - auto constexpr - operator!=(BaseType const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) - -> std::enable_if_t, bool> - { - return lhs != rhs.decay(); - } - - template - auto constexpr - operator<(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_less_than_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() < rhs.decay(); - } - - template - auto constexpr - operator>(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_greater_than_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() > rhs.decay(); - } - - template - auto constexpr - operator<=(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_less_than_equal_to_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() <= rhs.decay(); - } - - template - auto constexpr - operator>=(new_type const & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_greater_than_equal_to_comparable_v) - -> std::enable_if_t, bool> - { - return lhs.decay() >= rhs.decay(); - } - - template - auto operator<<(std::basic_ostream & output, new_type const & source) noexcept( - impl::is_nothrow_output_streamable_v, BaseType>) - -> std::enable_if_t, BaseType>, - std::basic_ostream> & - { - return output << source.decay(); - } - - template - auto operator>>(std::basic_istream & input, new_type & target) noexcept( - impl::is_nothrow_input_streamable_v, BaseType>) - -> std::enable_if_t, BaseType>, - std::basic_istream> & - { - return input >> target.m_value; - } - - template - auto constexpr - operator+(new_type const & lhs, new_type const & rhs) noexcept( - impl::is_nothrow_addable_v && std::is_nothrow_copy_constructible_v) - -> std::enable_if_t, new_type> - { - return {lhs.decay() + rhs.decay()}; - } - - template - auto constexpr operator+=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_add_assignable_v) - -> std::enable_if_t, - new_type &> - { - lhs.m_value += rhs.m_value; - return lhs; - } - - template - auto constexpr - operator-(new_type const & lhs, new_type const & rhs) noexcept( - impl::is_nothrow_subtractable_v && std::is_nothrow_copy_constructible_v) - -> std::enable_if_t, new_type> - { - return {lhs.decay() - rhs.decay()}; - } - - template - auto constexpr - operator-=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_subtract_assignable_v) - -> std::enable_if_t, - new_type &> - { - lhs.m_value -= rhs.m_value; - return lhs; - } - - template - auto constexpr - operator*(new_type const & lhs, new_type const & rhs) noexcept( - impl::is_nothrow_multipliable_v && std::is_nothrow_copy_constructible_v) - -> std::enable_if_t, new_type> - { - return {lhs.decay() * rhs.decay()}; - } - - template - auto constexpr - operator*=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_multiply_assignable_v) - -> std::enable_if_t, - new_type &> - { - lhs.m_value *= rhs.m_value; - return lhs; - } - - template - auto constexpr - operator/(new_type const & lhs, new_type const & rhs) noexcept( - impl::is_nothrow_dividable_v && std::is_nothrow_copy_constructible_v) - -> std::enable_if_t, new_type> - { - return {lhs.decay() / rhs.decay()}; - } - - template - auto constexpr operator/=(new_type & lhs, - new_type const & rhs) noexcept(impl::is_nothrow_divide_assignable_v) - -> std::enable_if_t, - new_type &> - { - lhs.m_value /= rhs.m_value; - return lhs; - } - - template - auto constexpr begin(new_type & obj) - -> std::enable_if_t, - typename new_type::iterator> - { - return begin(obj.m_value); - } - - template - auto constexpr begin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator> - { - return begin(obj.m_value); - } - - template - auto constexpr cbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator> - { - return cbegin(obj.m_value); - } - - template - auto constexpr rbegin(new_type & obj) - -> std::enable_if_t, - typename new_type::reverse_iterator> - { - return rbegin(obj.m_value); - } - - template - auto constexpr rbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator> - { - return rbegin(obj.m_value); - } - - template - auto constexpr crbegin(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator> - { - return crbegin(obj.m_value); - } - - template - auto constexpr end(new_type & obj) - -> std::enable_if_t, - typename new_type::iterator> - { - return end(obj.m_value); - } - - template - auto constexpr end(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator> - { - return end(obj.m_value); - } - - template - auto constexpr cend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_iterator> - { - return cend(obj.m_value); - } - - template - auto constexpr rend(new_type & obj) - -> std::enable_if_t, - typename new_type::reverse_iterator> - { - return rend(obj.m_value); - } - - template - auto constexpr rend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator> - { - return rend(obj.m_value); - } - - template - auto constexpr crend(new_type const & obj) - -> std::enable_if_t, - typename new_type::const_reverse_iterator> - { - return crend(obj.m_value); - } - -} // namespace nt - -namespace std -{ - template - struct hash> - { - template - auto constexpr operator()(nt::new_type const & object, - std::enable_if_t> * = nullptr) const - -> std::size_t - { - return std::hash{}(object.decay()); - } - }; -} // namespace std - -#endif diff --git a/include/newtype/newtype.hpp b/include/newtype/newtype.hpp new file mode 100644 index 0000000..e2704f3 --- /dev/null +++ b/include/newtype/newtype.hpp @@ -0,0 +1,550 @@ +#ifndef NEWTYPE_NEWTYPE_HPP +#define NEWTYPE_NEWTYPE_HPP + +#include "newtype/derivable.hpp" +#include "newtype/deriving.hpp" +#include "newtype/impl/new_type_iterator_types.hpp" +#include "newtype/impl/new_type_storage.hpp" +#include "newtype/impl/type_traits_extensions.hpp" +#include "newtype/version.hpp" + +#include +#include +#include +#include + +namespace nt +{ + + template + class new_type + : impl::new_type_move_assignment + , public impl::new_type_iterator_types + { + static_assert(!std::is_reference_v, "The base type must not be a reference type"); + static_assert(!std::is_void_v>, "The base type must not be possibly cv-qualified void"); + + template + auto friend operator>>(std::basic_istream &, new_type &) noexcept( + impl::is_nothrow_input_streamable_v, BaseTypeT>) + -> std::enable_if_t, BaseTypeT>, + std::basic_istream> &; + + template + auto constexpr friend + operator+=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_add_assignable_v) + -> std::enable_if_t, + new_type &>; + + template + auto constexpr friend + operator-=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_subtract_assignable_v) + -> std::enable_if_t, + new_type &>; + + template + auto constexpr friend + operator*=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_multiply_assignable_v) + -> std::enable_if_t, + new_type &>; + + template + auto constexpr friend + operator/=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_divide_assignable_v) + -> std::enable_if_t, + new_type &>; + + template + auto constexpr friend begin(new_type & obj) + -> std::enable_if_t, + typename new_type::iterator>; + + template + auto constexpr friend begin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + + template + auto constexpr friend cbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + + template + auto constexpr friend rbegin(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator>; + + template + auto constexpr friend rbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + + template + auto constexpr friend crbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + + template + auto constexpr friend end(new_type & obj) + -> std::enable_if_t, + typename new_type::iterator>; + + template + auto constexpr friend end(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + + template + auto constexpr friend cend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator>; + + template + auto constexpr friend rend(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator>; + + template + auto constexpr friend rend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + + template + auto constexpr friend crend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator>; + + using super = impl::new_type_move_assignment; + + public: + using base_type = BaseType; + using tag_type = TagType; + using derivation_clause_type = decltype(DerivationClause); + + auto constexpr static derivation_clause = DerivationClause; + + using super::super; + + constexpr new_type() noexcept(std::is_nothrow_default_constructible_v) = default; + constexpr new_type(new_type const &) noexcept(std::is_nothrow_copy_constructible_v) = default; + constexpr new_type(new_type &&) noexcept(std::is_nothrow_move_constructible_v) = default; + + auto constexpr operator=(new_type const &) noexcept(std::is_nothrow_copy_assignable_v) -> new_type & = default; + auto constexpr operator=(new_type &&) noexcept(std::is_nothrow_move_assignable_v) -> new_type & = default; + + auto constexpr decay() const noexcept(std::is_nothrow_copy_constructible_v) -> BaseType + { + return this->m_value; + } + + template * = nullptr> + constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) + { + return decay(); + } + + template * = nullptr> + explicit constexpr operator base_type() const noexcept(std::is_nothrow_copy_constructible_v) + { + return decay(); + } + + template + auto constexpr operator->() noexcept -> std::enable_if_t + { + return std::addressof(this->m_value); + } + + template + auto constexpr operator->() const noexcept -> std::enable_if_t + { + return std::addressof(this->m_value); + } + + template * = nullptr> + auto constexpr begin() + -> std::enable_if_t, typename NewType::iterator> + { + return this->m_value.begin(); + } + + template + auto constexpr begin() const -> std::enable_if_t, + typename NewType::const_iterator> + { + return this->m_value.begin(); + } + + template + auto constexpr cbegin() const -> std::enable_if_t, + typename NewType::const_iterator> + { + return this->m_value.cbegin(); + } + + template * = nullptr> + auto constexpr rbegin() + -> std::enable_if_t, typename NewType::reverse_iterator> + { + return this->m_value.rbegin(); + } + + template + auto constexpr rbegin() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.rbegin(); + } + + template + auto constexpr crbegin() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.crbegin(); + } + + template * = nullptr> + auto constexpr end() + -> std::enable_if_t, typename NewType::iterator> + { + return this->m_value.end(); + } + + template + auto constexpr end() const -> std::enable_if_t, + typename NewType::const_iterator> + { + return this->m_value.end(); + } + + template + auto constexpr cend() const -> std::enable_if_t, + typename NewType::const_iterator> + { + return this->m_value.cend(); + } + + template * = nullptr> + auto constexpr rend() + -> std::enable_if_t, typename NewType::reverse_iterator> + { + return this->m_value.rend(); + } + + template + auto constexpr rend() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.rend(); + } + + template + auto constexpr crend() const -> std::enable_if_t, + typename NewType::const_reverse_iterator> + { + return this->m_value.crend(); + } + }; + + template + auto constexpr + operator==(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() == rhs.decay(); + } + + template + auto constexpr operator==(new_type const & lhs, + BaseType const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() == rhs; + } + + template + auto constexpr + operator==(BaseType const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_equality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs == rhs.decay(); + } + + template + auto constexpr + operator!=(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() != rhs.decay(); + } + + template + auto constexpr operator!=(new_type const & lhs, + BaseType const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() != rhs; + } + + template + auto constexpr + operator!=(BaseType const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_inequality_comparable_v) + -> std::enable_if_t, bool> + { + return lhs != rhs.decay(); + } + + template + auto constexpr + operator<(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_less_than_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() < rhs.decay(); + } + + template + auto constexpr + operator>(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_greater_than_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() > rhs.decay(); + } + + template + auto constexpr + operator<=(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_less_than_equal_to_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() <= rhs.decay(); + } + + template + auto constexpr + operator>=(new_type const & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_greater_than_equal_to_comparable_v) + -> std::enable_if_t, bool> + { + return lhs.decay() >= rhs.decay(); + } + + template + auto operator<<(std::basic_ostream & output, new_type const & source) noexcept( + impl::is_nothrow_output_streamable_v, BaseType>) + -> std::enable_if_t, BaseType>, + std::basic_ostream> & + { + return output << source.decay(); + } + + template + auto operator>>(std::basic_istream & input, new_type & target) noexcept( + impl::is_nothrow_input_streamable_v, BaseType>) + -> std::enable_if_t, BaseType>, + std::basic_istream> & + { + return input >> target.m_value; + } + + template + auto constexpr + operator+(new_type const & lhs, new_type const & rhs) noexcept( + impl::is_nothrow_addable_v && std::is_nothrow_copy_constructible_v) + -> std::enable_if_t, new_type> + { + return {lhs.decay() + rhs.decay()}; + } + + template + auto constexpr operator+=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_add_assignable_v) + -> std::enable_if_t, + new_type &> + { + lhs.m_value += rhs.m_value; + return lhs; + } + + template + auto constexpr + operator-(new_type const & lhs, new_type const & rhs) noexcept( + impl::is_nothrow_subtractable_v && std::is_nothrow_copy_constructible_v) + -> std::enable_if_t, new_type> + { + return {lhs.decay() - rhs.decay()}; + } + + template + auto constexpr + operator-=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_subtract_assignable_v) + -> std::enable_if_t, + new_type &> + { + lhs.m_value -= rhs.m_value; + return lhs; + } + + template + auto constexpr + operator*(new_type const & lhs, new_type const & rhs) noexcept( + impl::is_nothrow_multipliable_v && std::is_nothrow_copy_constructible_v) + -> std::enable_if_t, new_type> + { + return {lhs.decay() * rhs.decay()}; + } + + template + auto constexpr + operator*=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_multiply_assignable_v) + -> std::enable_if_t, + new_type &> + { + lhs.m_value *= rhs.m_value; + return lhs; + } + + template + auto constexpr + operator/(new_type const & lhs, new_type const & rhs) noexcept( + impl::is_nothrow_dividable_v && std::is_nothrow_copy_constructible_v) + -> std::enable_if_t, new_type> + { + return {lhs.decay() / rhs.decay()}; + } + + template + auto constexpr operator/=(new_type & lhs, + new_type const & rhs) noexcept(impl::is_nothrow_divide_assignable_v) + -> std::enable_if_t, + new_type &> + { + lhs.m_value /= rhs.m_value; + return lhs; + } + + template + auto constexpr begin(new_type & obj) + -> std::enable_if_t, + typename new_type::iterator> + { + return begin(obj.m_value); + } + + template + auto constexpr begin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator> + { + return begin(obj.m_value); + } + + template + auto constexpr cbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator> + { + return cbegin(obj.m_value); + } + + template + auto constexpr rbegin(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator> + { + return rbegin(obj.m_value); + } + + template + auto constexpr rbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return rbegin(obj.m_value); + } + + template + auto constexpr crbegin(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return crbegin(obj.m_value); + } + + template + auto constexpr end(new_type & obj) + -> std::enable_if_t, + typename new_type::iterator> + { + return end(obj.m_value); + } + + template + auto constexpr end(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator> + { + return end(obj.m_value); + } + + template + auto constexpr cend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_iterator> + { + return cend(obj.m_value); + } + + template + auto constexpr rend(new_type & obj) + -> std::enable_if_t, + typename new_type::reverse_iterator> + { + return rend(obj.m_value); + } + + template + auto constexpr rend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return rend(obj.m_value); + } + + template + auto constexpr crend(new_type const & obj) + -> std::enable_if_t, + typename new_type::const_reverse_iterator> + { + return crend(obj.m_value); + } + +} // namespace nt + +namespace std +{ + template + struct hash> + { + template + auto constexpr operator()(nt::new_type const & object, + std::enable_if_t> * = nullptr) const + -> std::size_t + { + return std::hash{}(object.decay()); + } + }; +} // namespace std + +#endif diff --git a/test/src/arithmetic_suite.cpp b/test/src/arithmetic_suite.cpp index 2e7f1fd..0d8cfa8 100644 --- a/test/src/arithmetic_suite.cpp +++ b/test/src/arithmetic_suite.cpp @@ -4,7 +4,7 @@ #include "newtype/derivable.hpp" #include "newtype/deriving.hpp" #include "newtype/impl/type_traits_extensions.hpp" -#include "newtype/new_type.hpp" +#include "newtype/newtype.hpp" #include diff --git a/test/src/conversion_suite.cpp b/test/src/conversion_suite.cpp index b60a611..cbe2463 100644 --- a/test/src/conversion_suite.cpp +++ b/test/src/conversion_suite.cpp @@ -3,7 +3,7 @@ #include "kawaii.hpp" #include "newtype/derivable.hpp" #include "newtype/deriving.hpp" -#include "newtype/new_type.hpp" +#include "newtype/newtype.hpp" #include diff --git a/test/src/equality_comparison_suite.cpp b/test/src/equality_comparison_suite.cpp index 0789ae8..4e484f4 100644 --- a/test/src/equality_comparison_suite.cpp +++ b/test/src/equality_comparison_suite.cpp @@ -3,7 +3,7 @@ #include "kawaii.hpp" #include "newtype/derivable.hpp" #include "newtype/deriving.hpp" -#include "newtype/new_type.hpp" +#include "newtype/newtype.hpp" #include diff --git a/test/src/hash_suite.cpp b/test/src/hash_suite.cpp index 9ca362c..b482414 100644 --- a/test/src/hash_suite.cpp +++ b/test/src/hash_suite.cpp @@ -4,7 +4,7 @@ #include "newtype/derivable.hpp" #include "newtype/deriving.hpp" #include "newtype/impl/type_traits_extensions.hpp" -#include "newtype/new_type.hpp" +#include "newtype/newtype.hpp" #include diff --git a/test/src/io_operators_suite.cpp b/test/src/io_operators_suite.cpp index 7f19963..4e146a7 100644 --- a/test/src/io_operators_suite.cpp +++ b/test/src/io_operators_suite.cpp @@ -3,7 +3,7 @@ #include "kawaii.hpp" #include "newtype/derivable.hpp" #include "newtype/deriving.hpp" -#include "newtype/new_type.hpp" +#include "newtype/newtype.hpp" #include diff --git a/test/src/iterable_suite.cpp b/test/src/iterable_suite.cpp index 3b46024..add4696 100644 --- a/test/src/iterable_suite.cpp +++ b/test/src/iterable_suite.cpp @@ -4,7 +4,7 @@ #include "newtype/derivable.hpp" #include "newtype/deriving.hpp" #include "newtype/impl/type_traits_extensions.hpp" -#include "newtype/new_type.hpp" +#include "newtype/newtype.hpp" #include diff --git a/test/src/new_type_constructor_suite.cpp b/test/src/new_type_constructor_suite.cpp index 27b7452..fc3e9f6 100644 --- a/test/src/new_type_constructor_suite.cpp +++ b/test/src/new_type_constructor_suite.cpp @@ -2,7 +2,7 @@ #include "kawaii.hpp" #include "newtype/derivable.hpp" -#include "newtype/new_type.hpp" +#include "newtype/newtype.hpp" #include diff --git a/test/src/relational_operators_suite.cpp b/test/src/relational_operators_suite.cpp index 31955dd..64fcba0 100644 --- a/test/src/relational_operators_suite.cpp +++ b/test/src/relational_operators_suite.cpp @@ -3,7 +3,7 @@ #include "kawaii.hpp" #include "newtype/derivable.hpp" #include "newtype/deriving.hpp" -#include "newtype/new_type.hpp" +#include "newtype/newtype.hpp" #include -- cgit v1.2.3