From 5b190c8b6ecebaef990e41a7501ff4a25f070090 Mon Sep 17 00:00:00 2001 From: bolero-MURAKAMI Date: Wed, 4 Mar 2015 23:01:10 +0900 Subject: [PATCH] fix addressof implementation --- sprout/array/array.hpp | 16 ++++++++-------- sprout/cinttypes/div.hpp | 2 +- sprout/cstdlib/div.hpp | 2 +- sprout/forward_clist.hpp | 17 +++++++++-------- sprout/functional/hash/hash_value_traits.hpp | 4 ++-- sprout/functional/ref.hpp | 3 ++- sprout/memory/addressof.hpp | 3 +++ sprout/utility/value_holder/value_holder.hpp | 13 +++++++------ .../context/parse_context/terminal/string.hpp | 2 +- 9 files changed, 34 insertions(+), 28 deletions(-) diff --git a/sprout/array/array.hpp b/sprout/array/array.hpp index 7ccc8a88..2a8ecb6e 100644 --- a/sprout/array/array.hpp +++ b/sprout/array/array.hpp @@ -111,16 +111,16 @@ namespace sprout { } #else SPROUT_CXX14_CONSTEXPR iterator begin() SPROUT_NOEXCEPT { - return &elems[0]; + return iterator(elems); } SPROUT_CONSTEXPR const_iterator begin() const SPROUT_NOEXCEPT { - return &elems[0]; + return iterator(elems); } SPROUT_CXX14_CONSTEXPR iterator end() SPROUT_NOEXCEPT { - return &elems[0] + size(); + return iterator(elems) + size(); } SPROUT_CONSTEXPR const_iterator end() const SPROUT_NOEXCEPT { - return &elems[0] + size(); + return iterator(elems) + size(); } #endif SPROUT_CXX14_CONSTEXPR reverse_iterator rbegin() SPROUT_NOEXCEPT { @@ -144,10 +144,10 @@ namespace sprout { } #else SPROUT_CONSTEXPR const_iterator cbegin() const SPROUT_NOEXCEPT { - return &elems[0]; + return const_iterator(elems); } SPROUT_CONSTEXPR const_iterator cend() const SPROUT_NOEXCEPT { - return &elems[0] + size(); + return const_iterator(elems) + size(); } #endif SPROUT_CONSTEXPR const_reverse_iterator crbegin() const SPROUT_NOEXCEPT { @@ -199,10 +199,10 @@ namespace sprout { } SPROUT_CXX14_CONSTEXPR pointer data() SPROUT_NOEXCEPT { - return &elems[0]; + return pointer(elems); } SPROUT_CONSTEXPR const_pointer data() const SPROUT_NOEXCEPT { - return &elems[0]; + return const_pointer(elems); } SPROUT_CXX14_CONSTEXPR pointer c_array() SPROUT_NOEXCEPT { return data(); diff --git a/sprout/cinttypes/div.hpp b/sprout/cinttypes/div.hpp index 9d74c7fc..70279689 100644 --- a/sprout/cinttypes/div.hpp +++ b/sprout/cinttypes/div.hpp @@ -72,7 +72,7 @@ namespace sprout { sprout::detail::div_t_traits2::offsetof_rem == 0, typename sprout::detail::div_t_traits2::type >::type - div_impl2(T const &numer, T const& denom) { + div_impl2(T const& numer, T const& denom) { #if defined(_MSC_VER) typename sprout::detail::div_t_traits2::type result = {numer % denom, numer / denom}; return result; diff --git a/sprout/cstdlib/div.hpp b/sprout/cstdlib/div.hpp index 70bc8336..df3fdeaf 100644 --- a/sprout/cstdlib/div.hpp +++ b/sprout/cstdlib/div.hpp @@ -67,7 +67,7 @@ namespace sprout { sprout::detail::div_t_traits::offsetof_rem == 0, typename sprout::detail::div_t_traits::type >::type - div_impl(T const &numer, T const& denom) { + div_impl(T const& numer, T const& denom) { #if defined(_MSC_VER) typename sprout::detail::div_t_traits::type result = {numer % denom, numer / denom}; return result; diff --git a/sprout/forward_clist.hpp b/sprout/forward_clist.hpp index ed970229..bb993ebb 100644 --- a/sprout/forward_clist.hpp +++ b/sprout/forward_clist.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -128,7 +129,7 @@ namespace sprout { >::type operator==(sprout::detail::forward_item_iterator const& lhs, sprout::detail::forward_item_iterator const& rhs) { return !lhs.is_initialized() ? !rhs.is_initialized() - : rhs.is_initialized() && &*lhs == &*rhs + : rhs.is_initialized() && sprout::addressof(*lhs) == sprout::addressof(*rhs) ; } template @@ -324,10 +325,10 @@ namespace sprout { SPROUT_CXX14_CONSTEXPR forward_clist(InputIterator first, InputIterator last) : fst() { - item_holder_type* p = &fst.next; + item_holder_type* p = sprout::addressof(fst.next); for (; first != last; ++first) { *p = *first; - p = &(*p)->next; + p = sprout::addressof(*p)->next; } } SPROUT_CXX14_CONSTEXPR forward_clist(forward_clist&& x) @@ -394,10 +395,10 @@ namespace sprout { template SPROUT_CXX14_CONSTEXPR void push_front(InputIterator first, InputIterator last) { item_holder_type nxt(fst.next); - item_holder_type* p = &fst.next; + item_holder_type* p = sprout::addressof(fst.next); for (; first != last; ++first) { *p = *first; - p = &(*p)->next; + p = sprout::addressof(*p)->next; } *p = nxt; } @@ -417,10 +418,10 @@ namespace sprout { SPROUT_CXX14_CONSTEXPR iterator insert_after(const_iterator position, InputIterator first, InputIterator last) { item_holder_type nxt(position.item->next); item_holder_type pos(position.item); - item_holder_type* p = &pos; + item_holder_type* p = sprout::addressof(pos); for (; first != last; ++first) { (*p)->next = *first; - p = &(*p)->next; + p = sprout::addressof(*p)->next; } (*p)->next = nxt; return iterator(*p); @@ -453,7 +454,7 @@ namespace sprout { SPROUT_CXX14_CONSTEXPR void unlink(item& x) { for (iterator first = before_begin(), last = end(); first != last; ++first) { iterator nxt = first.next(); - if (nxt.item.get_pointer() == &x) { + if (nxt.item.get_pointer() == sprout::addressof(x)) { first.item->next = sprout::move(nxt.item->next); nxt.item->unlink(); break; diff --git a/sprout/functional/hash/hash_value_traits.hpp b/sprout/functional/hash/hash_value_traits.hpp index 5ad57f46..c2738c8b 100644 --- a/sprout/functional/hash/hash_value_traits.hpp +++ b/sprout/functional/hash/hash_value_traits.hpp @@ -143,7 +143,7 @@ namespace sprout { } template inline SPROUT_CONSTEXPR std::size_t - hash_value_impl(T const (&v)[N]) { + hash_value_impl(T const (& v)[N]) { return sprout::hash_range(v); } template @@ -151,7 +151,7 @@ namespace sprout { !std::is_arithmetic::value && !std::is_enum::value && !std::is_pointer::value, std::size_t >::type - hash_value_impl(T const &v) { + hash_value_impl(T const& v) { return std::hash::type>()(v); } } // namespace hash_detail diff --git a/sprout/functional/ref.hpp b/sprout/functional/ref.hpp index 6ecf9f8e..13802eba 100644 --- a/sprout/functional/ref.hpp +++ b/sprout/functional/ref.hpp @@ -19,6 +19,7 @@ #include #include #include +#include namespace sprout { // 20.8.3 reference_wrapper @@ -152,7 +153,7 @@ namespace sprout { public: // construct/copy/destroy SPROUT_CONSTEXPR reference_wrapper(T& t) SPROUT_NOEXCEPT - : t_(&t) + : t_(sprout::addressof(t)) {} reference_wrapper(reference_wrapper const&) = default; // assignment diff --git a/sprout/memory/addressof.hpp b/sprout/memory/addressof.hpp index a65a8ca7..6442fe64 100644 --- a/sprout/memory/addressof.hpp +++ b/sprout/memory/addressof.hpp @@ -18,6 +18,9 @@ namespace sprout { namespace detail { + struct address_op_helper {}; + void operator&(sprout::detail::address_op_helper const&); + template struct has_mem_address_op_test { public: diff --git a/sprout/utility/value_holder/value_holder.hpp b/sprout/utility/value_holder/value_holder.hpp index 9a6c9d11..995b0271 100644 --- a/sprout/utility/value_holder/value_holder.hpp +++ b/sprout/utility/value_holder/value_holder.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -50,10 +51,10 @@ namespace sprout { return r; } static SPROUT_CONSTEXPR pointer ptr(holder_type& r) SPROUT_NOEXCEPT { - return &r; + return sprout::addressof(r); } static SPROUT_CONSTEXPR const_pointer ptr(holder_type const& r) SPROUT_NOEXCEPT { - return &r; + return sprout::addressof(r); } }; template @@ -87,10 +88,10 @@ namespace sprout { return *r; } static SPROUT_CONSTEXPR pointer ptr(holder_type& r) SPROUT_NOEXCEPT { - return &r; + return sprout::addressof(r); } static SPROUT_CONSTEXPR const_pointer ptr(holder_type const& r) SPROUT_NOEXCEPT { - return &r; + return sprout::addressof(r); } }; template @@ -112,7 +113,7 @@ namespace sprout { typedef T* holder_type; public: static SPROUT_CONSTEXPR holder_type hold(param_type p) SPROUT_NOEXCEPT { - return &p; + return sprout::addressof(p); } static SPROUT_CONSTEXPR reference ref(holder_type r) { return *r; @@ -140,7 +141,7 @@ namespace sprout { typedef T const* holder_type; public: static SPROUT_CONSTEXPR holder_type hold(param_type p) SPROUT_NOEXCEPT { - return &p; + return sprout::addressof(p); } static SPROUT_CONSTEXPR reference ref(holder_type r) { return *r; diff --git a/sprout/weed/context/parse_context/terminal/string.hpp b/sprout/weed/context/parse_context/terminal/string.hpp index 568acf1b..e025a9bb 100644 --- a/sprout/weed/context/parse_context/terminal/string.hpp +++ b/sprout/weed/context/parse_context/terminal/string.hpp @@ -55,7 +55,7 @@ namespace sprout { ) const { return sprout::distance(ctx.begin(), ctx.end()) >= sprout::size(arg) - &&sprout::equal(sprout::begin(arg), sprout::end(arg), ctx.begin()) + && sprout::equal(sprout::begin(arg), sprout::end(arg), ctx.begin()) ? result_type( true, sprout::next(ctx.begin(), sprout::size(arg)),