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 --- include/newtype/impl/type_traits_extensions.hpp | 43 +++++++++++++++++++++++-- include/newtype/new_type.hpp | 20 ++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) (limited to 'include') 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 -- cgit v1.2.3