mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-04-27 10:26:01 +02:00
Fixed #422.
Replaced the inheriting constructor with a forwarding constructor. Removed the template constructors that are covered by the forwarding constructor. Added std::forward() to make_tuple. Added conversion constructor. Moved msgpack::type::tuple to include/msgpack/v1/adaptor/detail/cpp11_msgpack_tuple_decl.hpp from include/msgpack/v1/adaptor/detail/cpp11_msgpack_tuple.hpp. msgpack::type::tuple_cat requires the class template tuple definition.
This commit is contained in:
parent
0e7345c282
commit
664ab708e4
@ -21,60 +21,10 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
|||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
namespace type {
|
namespace type {
|
||||||
// tuple
|
|
||||||
using std::get;
|
|
||||||
using std::tuple_size;
|
|
||||||
using std::tuple_element;
|
|
||||||
using std::uses_allocator;
|
|
||||||
using std::ignore;
|
|
||||||
using std::swap;
|
|
||||||
|
|
||||||
template< class... Types >
|
|
||||||
class tuple : public std::tuple<Types...> {
|
|
||||||
public:
|
|
||||||
using base = std::tuple<Types...>;
|
|
||||||
|
|
||||||
using base::base;
|
|
||||||
|
|
||||||
tuple() = default;
|
|
||||||
tuple(tuple const&) = default;
|
|
||||||
tuple(tuple&&) = default;
|
|
||||||
|
|
||||||
template<typename... OtherTypes>
|
|
||||||
tuple(tuple<OtherTypes...> const& other):base(static_cast<std::tuple<OtherTypes...> const&>(other)) {}
|
|
||||||
template<typename... OtherTypes>
|
|
||||||
tuple(tuple<OtherTypes...> && other):base(static_cast<std::tuple<OtherTypes...> &&>(other)) {}
|
|
||||||
|
|
||||||
tuple& operator=(tuple const&) = default;
|
|
||||||
tuple& operator=(tuple&&) = default;
|
|
||||||
|
|
||||||
template<typename... OtherTypes>
|
|
||||||
tuple& operator=(tuple<OtherTypes...> const& other) {
|
|
||||||
*static_cast<base*>(this) = static_cast<std::tuple<OtherTypes...> const&>(other);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
template<typename... OtherTypes>
|
|
||||||
tuple& operator=(tuple<OtherTypes...> && other) {
|
|
||||||
*static_cast<base*>(this) = static_cast<std::tuple<OtherTypes...> &&>(other);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
template< std::size_t I>
|
|
||||||
typename tuple_element<I, base >::type&
|
|
||||||
get() & { return std::get<I>(*this); }
|
|
||||||
|
|
||||||
template< std::size_t I>
|
|
||||||
typename tuple_element<I, base >::type const&
|
|
||||||
get() const& { return std::get<I>(*this); }
|
|
||||||
|
|
||||||
template< std::size_t I>
|
|
||||||
typename tuple_element<I, base >::type&&
|
|
||||||
get() && { return std::get<I>(*this); }
|
|
||||||
};
|
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
inline tuple<Args...> make_tuple(Args&&... args) {
|
inline tuple<Args...> make_tuple(Args&&... args) {
|
||||||
return tuple<Args...>(args...);
|
return tuple<Args...>(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class... Args>
|
template<class... Args>
|
||||||
@ -89,6 +39,7 @@ namespace type {
|
|||||||
) {
|
) {
|
||||||
return std::tuple_cat(std::forward<typename std::remove_reference<Tuples>::type::base>(args)...);
|
return std::tuple_cat(std::forward<typename std::remove_reference<Tuples>::type::base>(args)...);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
inline tuple<Args&...> tie(Args&... args) {
|
inline tuple<Args&...> tie(Args&... args) {
|
||||||
return tuple<Args&...>(args...);
|
return tuple<Args&...>(args...);
|
||||||
|
@ -32,7 +32,45 @@ namespace type {
|
|||||||
using std::swap;
|
using std::swap;
|
||||||
|
|
||||||
template< class... Types >
|
template< class... Types >
|
||||||
class tuple;
|
class tuple : public std::tuple<Types...> {
|
||||||
|
public:
|
||||||
|
using base = std::tuple<Types...>;
|
||||||
|
|
||||||
|
tuple(tuple const&) = default;
|
||||||
|
tuple(tuple&&) = default;
|
||||||
|
|
||||||
|
template<typename... OtherTypes>
|
||||||
|
tuple(OtherTypes&&... other):base(std::forward<OtherTypes>(other)...) {}
|
||||||
|
|
||||||
|
template<typename... OtherTypes>
|
||||||
|
tuple(tuple<OtherTypes...> && other):base(static_cast<std::tuple<OtherTypes...>>(other)) {}
|
||||||
|
|
||||||
|
tuple& operator=(tuple const&) = default;
|
||||||
|
tuple& operator=(tuple&&) = default;
|
||||||
|
|
||||||
|
template<typename... OtherTypes>
|
||||||
|
tuple& operator=(tuple<OtherTypes...> const& other) {
|
||||||
|
*static_cast<base*>(this) = static_cast<std::tuple<OtherTypes...> const&>(other);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
template<typename... OtherTypes>
|
||||||
|
tuple& operator=(tuple<OtherTypes...> && other) {
|
||||||
|
*static_cast<base*>(this) = static_cast<std::tuple<OtherTypes...> &&>(other);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template< std::size_t I>
|
||||||
|
typename tuple_element<I, base >::type&
|
||||||
|
get() & { return std::get<I>(*this); }
|
||||||
|
|
||||||
|
template< std::size_t I>
|
||||||
|
typename tuple_element<I, base >::type const&
|
||||||
|
get() const& { return std::get<I>(*this); }
|
||||||
|
|
||||||
|
template< std::size_t I>
|
||||||
|
typename tuple_element<I, base >::type&&
|
||||||
|
get() && { return std::get<I>(*this); }
|
||||||
|
};
|
||||||
|
|
||||||
template <class... Args>
|
template <class... Args>
|
||||||
tuple<Args...> make_tuple(Args&&... args);
|
tuple<Args...> make_tuple(Args&&... args);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user