Unordered: emplace cleanup.

- Always construct iterator in detail for consistency.
- Move 0-argument emplace to start of overloads.

[SVN r75744]
This commit is contained in:
Daniel James
2011-11-30 08:21:58 +00:00
parent 684e40464f
commit a61e876300
3 changed files with 198 additions and 182 deletions

View File

@ -453,22 +453,22 @@ namespace boost { namespace unordered { namespace detail {
}
#if defined(BOOST_NO_RVALUE_REFERENCES)
node_pointer emplace(boost::unordered::detail::emplace_args1<
iterator emplace(boost::unordered::detail::emplace_args1<
boost::unordered::detail::please_ignore_this_overload> const&)
{
BOOST_ASSERT(false);
return this->begin();
return iterator();
}
#endif
template <BOOST_UNORDERED_EMPLACE_TEMPLATE>
node_pointer emplace(BOOST_UNORDERED_EMPLACE_ARGS)
iterator emplace(BOOST_UNORDERED_EMPLACE_ARGS)
{
node_constructor a(this->node_alloc());
a.construct_node();
a.construct_value(BOOST_UNORDERED_EMPLACE_FORWARD);
return emplace_impl(a);
return iterator(emplace_impl(a));
}
////////////////////////////////////////////////////////////////////////

View File

@ -218,10 +218,35 @@ namespace unordered
template <class... Args>
iterator emplace_hint(const_iterator, Args&&... args)
{
return iterator(table_.emplace(std::forward<Args>(args)...).first);
return table_.emplace(std::forward<Args>(args)...).first;
}
#else
#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
// 0 argument emplace requires special treatment in case
// the container is instantiated with a value type that
// doesn't have a default constructor.
std::pair<iterator, bool> emplace(
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type())
{
return this->emplace(boost::move(v));
}
iterator emplace_hint(const_iterator hint,
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type()
)
{
return this->emplace_hint(hint, boost::move(v));
}
#endif
template <typename A0>
std::pair<iterator, bool> emplace(BOOST_FWD_REF(A0) a0)
{
@ -315,27 +340,6 @@ namespace unordered
#undef BOOST_UNORDERED_EMPLACE
#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
std::pair<iterator, bool> emplace(
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type())
{
return this->emplace(boost::move(v));
}
iterator emplace_hint(const_iterator hint,
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type()
)
{
return this->emplace_hint(hint, boost::move(v));
}
#endif
#endif
std::pair<iterator, bool> insert(value_type const& x)
@ -657,30 +661,55 @@ namespace unordered
template <class... Args>
iterator emplace(Args&&... args)
{
return iterator(table_.emplace(std::forward<Args>(args)...));
return table_.emplace(std::forward<Args>(args)...);
}
template <class... Args>
iterator emplace_hint(const_iterator, Args&&... args)
{
return iterator(table_.emplace(std::forward<Args>(args)...));
return table_.emplace(std::forward<Args>(args)...);
}
#else
#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
// 0 argument emplace requires special treatment in case
// the container is instantiated with a value type that
// doesn't have a default constructor.
iterator emplace(
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type())
{
return this->emplace(boost::move(v));
}
iterator emplace_hint(const_iterator hint,
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type()
)
{
return this->emplace_hint(hint, boost::move(v));
}
#endif
template <typename A0>
iterator emplace(BOOST_FWD_REF(A0) a0)
{
return iterator(table_.emplace(
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0)
));
);
}
template <typename A0>
iterator emplace_hint(const_iterator, BOOST_FWD_REF(A0) a0)
{
return iterator(table_.emplace(
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0)
));
);
}
template <typename A0, typename A1>
@ -688,9 +717,9 @@ namespace unordered
BOOST_FWD_REF(A0) a0,
BOOST_FWD_REF(A1) a1)
{
return iterator(table_.emplace(
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1)
));
);
}
template <typename A0, typename A1>
@ -698,9 +727,9 @@ namespace unordered
BOOST_FWD_REF(A0) a0,
BOOST_FWD_REF(A1) a1)
{
return iterator(table_.emplace(
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1)
));
);
}
template <typename A0, typename A1, typename A2>
@ -709,9 +738,9 @@ namespace unordered
BOOST_FWD_REF(A1) a1,
BOOST_FWD_REF(A2) a2)
{
return iterator(table_.emplace(
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1, a2)
));
);
}
template <typename A0, typename A1, typename A2>
@ -720,9 +749,9 @@ namespace unordered
BOOST_FWD_REF(A1) a1,
BOOST_FWD_REF(A2) a2)
{
return iterator(table_.emplace(
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1, a2)
));
);
}
#define BOOST_UNORDERED_EMPLACE(z, n, _) \
@ -733,11 +762,11 @@ namespace unordered
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \
) \
{ \
return iterator(table_.emplace( \
return table_.emplace( \
boost::unordered::detail::create_emplace_args( \
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \
a) \
))); \
)); \
} \
\
template < \
@ -748,11 +777,11 @@ namespace unordered
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \
) \
{ \
return iterator(table_.emplace( \
return table_.emplace( \
boost::unordered::detail::create_emplace_args( \
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \
a) \
))); \
)); \
}
BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT,
@ -760,27 +789,6 @@ namespace unordered
#undef BOOST_UNORDERED_EMPLACE
#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
iterator emplace(
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type())
{
return iterator(this->emplace(boost::move(v)));
}
iterator emplace_hint(const_iterator hint,
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type()
)
{
return iterator(this->emplace_hint(hint, boost::move(v)));
}
#endif
#endif
iterator insert(value_type const& x)

View File

@ -216,10 +216,35 @@ namespace unordered
template <class... Args>
iterator emplace_hint(const_iterator, Args&&... args)
{
return iterator(table_.emplace(std::forward<Args>(args)...).first);
return table_.emplace(std::forward<Args>(args)...).first;
}
#else
#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
// 0 argument emplace requires special treatment in case
// the container is instantiated with a value type that
// doesn't have a default constructor.
std::pair<iterator, bool> emplace(
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type())
{
return this->emplace(boost::move(v));
}
iterator emplace_hint(const_iterator hint,
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type()
)
{
return this->emplace_hint(hint, boost::move(v));
}
#endif
template <typename A0>
std::pair<iterator, bool> emplace(BOOST_FWD_REF(A0) a0)
{
@ -313,27 +338,6 @@ namespace unordered
#undef BOOST_UNORDERED_EMPLACE
#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
std::pair<iterator, bool> emplace(
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type())
{
return this->emplace(boost::move(v));
}
iterator emplace_hint(const_iterator hint,
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
value_type v = value_type()
)
{
return iterator(this->emplace_hint(hint, boost::move(v)));
}
#endif
#endif
std::pair<iterator, bool> insert(value_type const& x)
@ -640,111 +644,22 @@ namespace unordered
template <class... Args>
iterator emplace(Args&&... args)
{
return iterator(table_.emplace(std::forward<Args>(args)...));
return table_.emplace(std::forward<Args>(args)...);
}
template <class... Args>
iterator emplace_hint(const_iterator, Args&&... args)
{
return iterator(table_.emplace(std::forward<Args>(args)...));
return table_.emplace(std::forward<Args>(args)...);
}
#else
template <typename A0>
iterator emplace(BOOST_FWD_REF(A0) a0)
{
return iterator(table_.emplace(
boost::unordered::detail::create_emplace_args(a0)
));
}
template <typename A0>
iterator emplace_hint(const_iterator, BOOST_FWD_REF(A0) a0)
{
return iterator(table_.emplace(
boost::unordered::detail::create_emplace_args(a0)
));
}
template <typename A0, typename A1>
iterator emplace(
BOOST_FWD_REF(A0) a0,
BOOST_FWD_REF(A1) a1)
{
return iterator(table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1)
));
}
template <typename A0, typename A1>
iterator emplace_hint(const_iterator,
BOOST_FWD_REF(A0) a0,
BOOST_FWD_REF(A1) a1)
{
return iterator(table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1)
));
}
template <typename A0, typename A1, typename A2>
iterator emplace(
BOOST_FWD_REF(A0) a0,
BOOST_FWD_REF(A1) a1,
BOOST_FWD_REF(A2) a2)
{
return iterator(table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1, a2)
));
}
template <typename A0, typename A1, typename A2>
iterator emplace_hint(const_iterator,
BOOST_FWD_REF(A0) a0,
BOOST_FWD_REF(A1) a1,
BOOST_FWD_REF(A2) a2)
{
return iterator(table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1, a2)
));
}
#define BOOST_UNORDERED_EMPLACE(z, n, _) \
template < \
BOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \
> \
iterator emplace( \
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \
) \
{ \
return iterator(table_.emplace( \
boost::unordered::detail::create_emplace_args( \
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \
a) \
))); \
} \
\
template < \
BOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \
> \
iterator emplace_hint( \
const_iterator, \
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \
) \
{ \
return iterator(table_.emplace( \
boost::unordered::detail::create_emplace_args( \
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \
a) \
))); \
}
BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT,
BOOST_UNORDERED_EMPLACE, _)
#undef BOOST_UNORDERED_EMPLACE
#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x5100))
// 0 argument emplace requires special treatment in case
// the container is instantiated with a value type that
// doesn't have a default constructor.
iterator emplace(
boost::unordered::detail::empty_emplace
= boost::unordered::detail::empty_emplace(),
@ -764,6 +679,99 @@ namespace unordered
#endif
template <typename A0>
iterator emplace(BOOST_FWD_REF(A0) a0)
{
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0)
);
}
template <typename A0>
iterator emplace_hint(const_iterator, BOOST_FWD_REF(A0) a0)
{
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0)
);
}
template <typename A0, typename A1>
iterator emplace(
BOOST_FWD_REF(A0) a0,
BOOST_FWD_REF(A1) a1)
{
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1)
);
}
template <typename A0, typename A1>
iterator emplace_hint(const_iterator,
BOOST_FWD_REF(A0) a0,
BOOST_FWD_REF(A1) a1)
{
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1)
);
}
template <typename A0, typename A1, typename A2>
iterator emplace(
BOOST_FWD_REF(A0) a0,
BOOST_FWD_REF(A1) a1,
BOOST_FWD_REF(A2) a2)
{
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1, a2)
);
}
template <typename A0, typename A1, typename A2>
iterator emplace_hint(const_iterator,
BOOST_FWD_REF(A0) a0,
BOOST_FWD_REF(A1) a1,
BOOST_FWD_REF(A2) a2)
{
return table_.emplace(
boost::unordered::detail::create_emplace_args(a0, a1, a2)
);
}
#define BOOST_UNORDERED_EMPLACE(z, n, _) \
template < \
BOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \
> \
iterator emplace( \
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \
) \
{ \
return table_.emplace( \
boost::unordered::detail::create_emplace_args( \
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \
a) \
)); \
} \
\
template < \
BOOST_PP_ENUM_PARAMS_Z(z, n, typename A) \
> \
iterator emplace_hint( \
const_iterator, \
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_FWD_PARAM, a) \
) \
{ \
return table_.emplace( \
boost::unordered::detail::create_emplace_args( \
BOOST_PP_ENUM_##z(n, BOOST_UNORDERED_CALL_FORWARD, \
a) \
)); \
}
BOOST_PP_REPEAT_FROM_TO(4, BOOST_UNORDERED_EMPLACE_LIMIT,
BOOST_UNORDERED_EMPLACE, _)
#undef BOOST_UNORDERED_EMPLACE
#endif
iterator insert(value_type const& x)