mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-01-23 20:46:37 +00:00
fix addressof implementation
This commit is contained in:
parent
586c9972dc
commit
5b190c8b6e
9 changed files with 34 additions and 28 deletions
|
@ -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();
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace sprout {
|
|||
sprout::detail::div_t_traits2<T>::offsetof_rem == 0,
|
||||
typename sprout::detail::div_t_traits2<T>::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<T>::type result = {numer % denom, numer / denom};
|
||||
return result;
|
||||
|
|
|
@ -67,7 +67,7 @@ namespace sprout {
|
|||
sprout::detail::div_t_traits<T>::offsetof_rem == 0,
|
||||
typename sprout::detail::div_t_traits<T>::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<T>::type result = {numer % denom, numer / denom};
|
||||
return result;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/limits.hpp>
|
||||
#include <sprout/memory/addressof.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/value_holder/value_holder.hpp>
|
||||
|
@ -128,7 +129,7 @@ namespace sprout {
|
|||
>::type
|
||||
operator==(sprout::detail::forward_item_iterator<List1> const& lhs, sprout::detail::forward_item_iterator<List2> const& rhs) {
|
||||
return !lhs.is_initialized() ? !rhs.is_initialized()
|
||||
: rhs.is_initialized() && &*lhs == &*rhs
|
||||
: rhs.is_initialized() && sprout::addressof(*lhs) == sprout::addressof(*rhs)
|
||||
;
|
||||
}
|
||||
template<typename List1, typename List2>
|
||||
|
@ -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<typename InputIterator>
|
||||
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;
|
||||
|
|
|
@ -143,7 +143,7 @@ namespace sprout {
|
|||
}
|
||||
template<typename T, std::size_t N>
|
||||
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<typename T>
|
||||
|
@ -151,7 +151,7 @@ namespace sprout {
|
|||
!std::is_arithmetic<T>::value && !std::is_enum<T>::value && !std::is_pointer<T>::value,
|
||||
std::size_t
|
||||
>::type
|
||||
hash_value_impl(T const &v) {
|
||||
hash_value_impl(T const& v) {
|
||||
return std::hash<typename std::decay<T>::type>()(v);
|
||||
}
|
||||
} // namespace hash_detail
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include <sprout/functional/base.hpp>
|
||||
#include <sprout/functional/type_traits/weak_result_type.hpp>
|
||||
#include <sprout/functional/type_traits/has_type.hpp>
|
||||
#include <sprout/memory/addressof.hpp>
|
||||
|
||||
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
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
namespace sprout {
|
||||
namespace detail {
|
||||
struct address_op_helper {};
|
||||
void operator&(sprout::detail::address_op_helper const&);
|
||||
|
||||
template<typename T>
|
||||
struct has_mem_address_op_test {
|
||||
public:
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <type_traits>
|
||||
#include <initializer_list>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/memory/addressof.hpp>
|
||||
#include <sprout/utility/swap.hpp>
|
||||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
|
@ -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<typename T>
|
||||
|
@ -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<typename T>
|
||||
|
@ -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;
|
||||
|
|
|
@ -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)),
|
||||
|
|
Loading…
Reference in a new issue