diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2023-06-09 13:59:51 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2023-06-09 13:59:51 +0200 |
| commit | bb9a394db891b9b1105be9fe5738489e356cdb77 (patch) | |
| tree | 96ce7840901f63da7a6667bbd3a479ebbe3e0f2e | |
| parent | ea48c9f6545e2c12b64a03212130af9bf4c41e86 (diff) | |
| download | newtype-bb9a394db891b9b1105be9fe5738489e356cdb77.tar.xz newtype-bb9a394db891b9b1105be9fe5738489e356cdb77.zip | |
newtype: merge impl headers to main header
| -rw-r--r-- | source/lib/include/newtype/impl/new_type_iterator_types.hpp | 64 | ||||
| -rw-r--r-- | source/lib/include/newtype/impl/new_type_storage.hpp | 137 | ||||
| -rw-r--r-- | source/lib/include/newtype/newtype.hpp | 197 |
3 files changed, 194 insertions, 204 deletions
diff --git a/source/lib/include/newtype/impl/new_type_iterator_types.hpp b/source/lib/include/newtype/impl/new_type_iterator_types.hpp deleted file mode 100644 index cda0221..0000000 --- a/source/lib/include/newtype/impl/new_type_iterator_types.hpp +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef NEWTYPE_IMPL_NEW_TYPE_ITERATOR_TYPES_HPP -#define NEWTYPE_IMPL_NEW_TYPE_ITERATOR_TYPES_HPP - -#include <type_traits> - -namespace nt::impl -{ - - template<typename T, bool = false, typename = std::void_t<>> - struct new_type_iterator - { - }; - - template<typename T> - struct new_type_iterator<T, true, std::void_t<typename T::iterator>> - { - using iterator = typename T::iterator; - }; - - template<typename T, bool = false, typename = std::void_t<>> - struct new_type_const_iterator - { - }; - - template<typename T> - struct new_type_const_iterator<T, true, std::void_t<typename T::const_iterator>> - { - using const_iterator = typename T::const_iterator; - }; - - template<typename T, bool = false, typename = std::void_t<>> - struct new_type_reverse_iterator - { - }; - - template<typename T> - struct new_type_reverse_iterator<T, true, std::void_t<typename T::reverse_iterator>> - { - using reverse_iterator = typename T::reverse_iterator; - }; - - template<typename T, bool = false, typename = std::void_t<>> - struct new_type_const_reverse_iterator - { - }; - - template<typename T> - struct new_type_const_reverse_iterator<T, true, std::void_t<typename T::const_reverse_iterator>> - { - using const_reverse_iterator = typename T::const_reverse_iterator; - }; - - template<typename T, bool Enabled> - struct new_type_iterator_types - : new_type_iterator<T, Enabled> - , new_type_const_iterator<T, Enabled> - , new_type_reverse_iterator<T, Enabled> - , new_type_const_reverse_iterator<T, Enabled> - { - }; - -} // namespace nt::impl - -#endif
\ No newline at end of file diff --git a/source/lib/include/newtype/impl/new_type_storage.hpp b/source/lib/include/newtype/impl/new_type_storage.hpp deleted file mode 100644 index 5cec601..0000000 --- a/source/lib/include/newtype/impl/new_type_storage.hpp +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef NEWTYPE_IMPL_NEW_TYPE_STORAGE_HPP -#define NEWTYPE_IMPL_NEW_TYPE_STORAGE_HPP - -#include <type_traits> -#include <utility> - -namespace nt::impl -{ - - template<typename BaseType, typename TagType> - struct new_type_storage - { - constexpr new_type_storage() noexcept(std::is_nothrow_default_constructible_v<BaseType>) - : m_value{} - { - } - - constexpr new_type_storage(BaseType const & value) - : m_value{value} - { - } - - constexpr new_type_storage(BaseType && value) - : m_value{std::move(value)} - { - } - - BaseType m_value; - }; - - template<typename BaseType, typename TagType, bool = std::is_default_constructible_v<BaseType>> - struct new_type_constructor : new_type_storage<BaseType, TagType> - { - using new_type_storage<BaseType, TagType>::new_type_storage; - }; - - template<typename BaseType, typename TagType> - struct new_type_constructor<BaseType, TagType, false> : new_type_storage<BaseType, TagType> - { - using new_type_storage<BaseType, TagType>::new_type_storage; - - constexpr new_type_constructor() = delete; - }; - - template<typename BaseType, typename TagType, bool = std::is_copy_constructible_v<BaseType>> - struct new_type_copy_constructor : new_type_constructor<BaseType, TagType> - { - using new_type_constructor<BaseType, TagType>::new_type_constructor; - - constexpr new_type_copy_constructor(new_type_copy_constructor const &) = default; - constexpr new_type_copy_constructor(new_type_copy_constructor &&) = default; - auto constexpr operator=(new_type_copy_constructor &) -> new_type_copy_constructor & = default; - auto constexpr operator=(new_type_copy_constructor &&) -> new_type_copy_constructor & = default; - }; - - template<typename BaseType, typename TagType> - struct new_type_copy_constructor<BaseType, TagType, false> : new_type_constructor<BaseType, TagType> - { - using new_type_constructor<BaseType, TagType>::new_type_constructor; - - constexpr new_type_copy_constructor(new_type_copy_constructor const &) = delete; - constexpr new_type_copy_constructor(new_type_copy_constructor &&) = default; - constexpr new_type_copy_constructor(BaseType const &) = delete; - auto constexpr operator=(new_type_copy_constructor &) -> new_type_copy_constructor & = default; - auto constexpr operator=(new_type_copy_constructor &&) -> new_type_copy_constructor & = default; - }; - - template<typename BaseType, typename TagType, bool = std::is_move_constructible_v<BaseType>> - struct new_type_move_constructor : new_type_copy_constructor<BaseType, TagType> - { - using new_type_copy_constructor<BaseType, TagType>::new_type_copy_constructor; - - constexpr new_type_move_constructor(new_type_move_constructor const &) = default; - constexpr new_type_move_constructor(new_type_move_constructor &&) = default; - auto constexpr operator=(new_type_move_constructor &) -> new_type_move_constructor & = default; - auto constexpr operator=(new_type_move_constructor &&) -> new_type_move_constructor & = default; - }; - - template<typename BaseType, typename TagType> - struct new_type_move_constructor<BaseType, TagType, false> : new_type_copy_constructor<BaseType, TagType> - { - using new_type_copy_constructor<BaseType, TagType>::new_type_copy_constructor; - - constexpr new_type_move_constructor(new_type_move_constructor const &) = default; - constexpr new_type_move_constructor(new_type_move_constructor &&) = delete; - constexpr new_type_move_constructor(BaseType &&) = delete; - auto constexpr operator=(new_type_move_constructor &) -> new_type_move_constructor & = default; - auto constexpr operator=(new_type_move_constructor &&) -> new_type_move_constructor & = default; - }; - - template<typename BaseType, typename TagType, bool = std::is_copy_assignable_v<BaseType>> - struct new_type_copy_assignment : new_type_move_constructor<BaseType, TagType> - { - using new_type_move_constructor<BaseType, TagType>::new_type_move_constructor; - - constexpr new_type_copy_assignment(new_type_copy_assignment const &) = default; - constexpr new_type_copy_assignment(new_type_copy_assignment &&) = default; - auto constexpr operator=(new_type_copy_assignment &) -> new_type_copy_assignment & = default; - auto constexpr operator=(new_type_copy_assignment &&) -> new_type_copy_assignment & = default; - }; - - template<typename BaseType, typename TagType> - struct new_type_copy_assignment<BaseType, TagType, false> : new_type_move_constructor<BaseType, TagType> - { - using new_type_move_constructor<BaseType, TagType>::new_type_move_constructor; - - constexpr new_type_copy_assignment(new_type_copy_assignment const &) = default; - constexpr new_type_copy_assignment(new_type_copy_assignment &&) = default; - auto constexpr operator=(new_type_copy_assignment &) -> new_type_copy_assignment & = default; - auto constexpr operator=(new_type_copy_assignment &&) -> new_type_copy_assignment & = delete; - }; - - template<typename BaseType, typename TagType, bool = std::is_move_assignable_v<BaseType>> - struct new_type_move_assignment : new_type_copy_assignment<BaseType, TagType> - { - using new_type_copy_assignment<BaseType, TagType>::new_type_copy_assignment; - - constexpr new_type_move_assignment(new_type_move_assignment const &) = default; - constexpr new_type_move_assignment(new_type_move_assignment &&) = default; - auto constexpr operator=(new_type_move_assignment &) -> new_type_move_assignment & = default; - auto constexpr operator=(new_type_move_assignment &&) -> new_type_move_assignment & = default; - }; - - template<typename BaseType, typename TagType> - struct new_type_move_assignment<BaseType, TagType, false> : new_type_copy_assignment<BaseType, TagType> - { - using new_type_copy_assignment<BaseType, TagType>::new_type_copy_assignment; - - constexpr new_type_move_assignment(new_type_move_assignment const &) = default; - constexpr new_type_move_assignment(new_type_move_assignment &&) = default; - auto constexpr operator=(new_type_move_assignment &) -> new_type_move_assignment & = default; - auto constexpr operator=(new_type_move_assignment &&) -> new_type_move_assignment & = delete; - }; - -} // namespace nt::impl - -#endif diff --git a/source/lib/include/newtype/newtype.hpp b/source/lib/include/newtype/newtype.hpp index 55ca19c..aee68da 100644 --- a/source/lib/include/newtype/newtype.hpp +++ b/source/lib/include/newtype/newtype.hpp @@ -1,17 +1,208 @@ #ifndef NEWTYPE_NEWTYPE_HPP #define NEWTYPE_NEWTYPE_HPP -#include "newtype/impl/new_type_iterator_types.hpp" -#include "newtype/impl/new_type_storage.hpp" - #include <functional> #include <istream> #include <ostream> #include <type_traits> +#include <utility> namespace nt { + namespace impl + { + + inline namespace storage + { + + template<typename BaseType, typename TagType> + struct new_type_storage + { + constexpr new_type_storage() noexcept(std::is_nothrow_default_constructible_v<BaseType>) + : m_value{} + { + } + + constexpr new_type_storage(BaseType const & value) + : m_value{value} + { + } + + constexpr new_type_storage(BaseType && value) + : m_value{std::move(value)} + { + } + + BaseType m_value; + }; + + template<typename BaseType, typename TagType, bool = std::is_default_constructible_v<BaseType>> + struct new_type_constructor : new_type_storage<BaseType, TagType> + { + using new_type_storage<BaseType, TagType>::new_type_storage; + }; + + template<typename BaseType, typename TagType> + struct new_type_constructor<BaseType, TagType, false> : new_type_storage<BaseType, TagType> + { + using new_type_storage<BaseType, TagType>::new_type_storage; + + constexpr new_type_constructor() = delete; + }; + + template<typename BaseType, typename TagType, bool = std::is_copy_constructible_v<BaseType>> + struct new_type_copy_constructor : new_type_constructor<BaseType, TagType> + { + using new_type_constructor<BaseType, TagType>::new_type_constructor; + + constexpr new_type_copy_constructor(new_type_copy_constructor const &) = default; + constexpr new_type_copy_constructor(new_type_copy_constructor &&) = default; + auto constexpr operator=(new_type_copy_constructor &) -> new_type_copy_constructor & = default; + auto constexpr operator=(new_type_copy_constructor &&) -> new_type_copy_constructor & = default; + }; + + template<typename BaseType, typename TagType> + struct new_type_copy_constructor<BaseType, TagType, false> : new_type_constructor<BaseType, TagType> + { + using new_type_constructor<BaseType, TagType>::new_type_constructor; + + constexpr new_type_copy_constructor(new_type_copy_constructor const &) = delete; + constexpr new_type_copy_constructor(new_type_copy_constructor &&) = default; + constexpr new_type_copy_constructor(BaseType const &) = delete; + auto constexpr operator=(new_type_copy_constructor &) -> new_type_copy_constructor & = default; + auto constexpr operator=(new_type_copy_constructor &&) -> new_type_copy_constructor & = default; + }; + + template<typename BaseType, typename TagType, bool = std::is_move_constructible_v<BaseType>> + struct new_type_move_constructor : new_type_copy_constructor<BaseType, TagType> + { + using new_type_copy_constructor<BaseType, TagType>::new_type_copy_constructor; + + constexpr new_type_move_constructor(new_type_move_constructor const &) = default; + constexpr new_type_move_constructor(new_type_move_constructor &&) = default; + auto constexpr operator=(new_type_move_constructor &) -> new_type_move_constructor & = default; + auto constexpr operator=(new_type_move_constructor &&) -> new_type_move_constructor & = default; + }; + + template<typename BaseType, typename TagType> + struct new_type_move_constructor<BaseType, TagType, false> : new_type_copy_constructor<BaseType, TagType> + { + using new_type_copy_constructor<BaseType, TagType>::new_type_copy_constructor; + + constexpr new_type_move_constructor(new_type_move_constructor const &) = default; + constexpr new_type_move_constructor(new_type_move_constructor &&) = delete; + constexpr new_type_move_constructor(BaseType &&) = delete; + auto constexpr operator=(new_type_move_constructor &) -> new_type_move_constructor & = default; + auto constexpr operator=(new_type_move_constructor &&) -> new_type_move_constructor & = default; + }; + + template<typename BaseType, typename TagType, bool = std::is_copy_assignable_v<BaseType>> + struct new_type_copy_assignment : new_type_move_constructor<BaseType, TagType> + { + using new_type_move_constructor<BaseType, TagType>::new_type_move_constructor; + + constexpr new_type_copy_assignment(new_type_copy_assignment const &) = default; + constexpr new_type_copy_assignment(new_type_copy_assignment &&) = default; + auto constexpr operator=(new_type_copy_assignment &) -> new_type_copy_assignment & = default; + auto constexpr operator=(new_type_copy_assignment &&) -> new_type_copy_assignment & = default; + }; + + template<typename BaseType, typename TagType> + struct new_type_copy_assignment<BaseType, TagType, false> : new_type_move_constructor<BaseType, TagType> + { + using new_type_move_constructor<BaseType, TagType>::new_type_move_constructor; + + constexpr new_type_copy_assignment(new_type_copy_assignment const &) = default; + constexpr new_type_copy_assignment(new_type_copy_assignment &&) = default; + auto constexpr operator=(new_type_copy_assignment &) -> new_type_copy_assignment & = default; + auto constexpr operator=(new_type_copy_assignment &&) -> new_type_copy_assignment & = delete; + }; + + template<typename BaseType, typename TagType, bool = std::is_move_assignable_v<BaseType>> + struct new_type_move_assignment : new_type_copy_assignment<BaseType, TagType> + { + using new_type_copy_assignment<BaseType, TagType>::new_type_copy_assignment; + + constexpr new_type_move_assignment(new_type_move_assignment const &) = default; + constexpr new_type_move_assignment(new_type_move_assignment &&) = default; + auto constexpr operator=(new_type_move_assignment &) -> new_type_move_assignment & = default; + auto constexpr operator=(new_type_move_assignment &&) -> new_type_move_assignment & = default; + }; + + template<typename BaseType, typename TagType> + struct new_type_move_assignment<BaseType, TagType, false> : new_type_copy_assignment<BaseType, TagType> + { + using new_type_copy_assignment<BaseType, TagType>::new_type_copy_assignment; + + constexpr new_type_move_assignment(new_type_move_assignment const &) = default; + constexpr new_type_move_assignment(new_type_move_assignment &&) = default; + auto constexpr operator=(new_type_move_assignment &) -> new_type_move_assignment & = default; + auto constexpr operator=(new_type_move_assignment &&) -> new_type_move_assignment & = delete; + }; + + } // namespace storage + + inline namespace member_types + { + + template<typename T, bool = false, typename = std::void_t<>> + struct new_type_iterator + { + }; + + template<typename T> + struct new_type_iterator<T, true, std::void_t<typename T::iterator>> + { + using iterator = typename T::iterator; + }; + + template<typename T, bool = false, typename = std::void_t<>> + struct new_type_const_iterator + { + }; + + template<typename T> + struct new_type_const_iterator<T, true, std::void_t<typename T::const_iterator>> + { + using const_iterator = typename T::const_iterator; + }; + + template<typename T, bool = false, typename = std::void_t<>> + struct new_type_reverse_iterator + { + }; + + template<typename T> + struct new_type_reverse_iterator<T, true, std::void_t<typename T::reverse_iterator>> + { + using reverse_iterator = typename T::reverse_iterator; + }; + + template<typename T, bool = false, typename = std::void_t<>> + struct new_type_const_reverse_iterator + { + }; + + template<typename T> + struct new_type_const_reverse_iterator<T, true, std::void_t<typename T::const_reverse_iterator>> + { + using const_reverse_iterator = typename T::const_reverse_iterator; + }; + + template<typename T, bool Enabled> + struct new_type_iterator_types + : new_type_iterator<T, Enabled> + , new_type_const_iterator<T, Enabled> + , new_type_reverse_iterator<T, Enabled> + , new_type_const_reverse_iterator<T, Enabled> + { + }; + + } // namespace member_types + + } // namespace impl + inline namespace lib { constexpr struct |
