Commit 267c043e authored by neverlord's avatar neverlord

fixed cow_tuple copying issue

parent 951b12cf
...@@ -57,24 +57,25 @@ namespace cppa { ...@@ -57,24 +57,25 @@ namespace cppa {
class any_tuple; class any_tuple;
class local_actor; class local_actor;
template<typename... ElementTypes>
class cow_tuple;
/** /**
* @ingroup CopyOnWrite * @ingroup CopyOnWrite
* @brief A fixed-length copy-on-write cow_tuple. * @brief A fixed-length copy-on-write cow_tuple.
*/ */
template<typename... ElementTypes> template<typename Head, typename... Tail>
class cow_tuple { class cow_tuple<Head, Tail...> {
static_assert(sizeof...(ElementTypes) > 0, "tuple is empty"); static_assert(util::tl_forall<util::type_list<Head, Tail...>,
static_assert(util::tl_forall<util::type_list<ElementTypes...>,
util::is_legal_tuple_type>::value, util::is_legal_tuple_type>::value,
"illegal types in cow_tuple definition: " "illegal types in cow_tuple definition: "
"pointers and references are prohibited"); "pointers and references are prohibited");
friend class any_tuple; friend class any_tuple;
typedef detail::tuple_vals<ElementTypes...> data_type; typedef detail::tuple_vals<Head, Tail...> data_type;
typedef detail::decorated_tuple<ElementTypes...> decorated_type; typedef detail::decorated_tuple<Head, Tail...> decorated_type;
cow_ptr<detail::abstract_tuple> m_vals; cow_ptr<detail::abstract_tuple> m_vals;
...@@ -84,17 +85,26 @@ class cow_tuple { ...@@ -84,17 +85,26 @@ class cow_tuple {
public: public:
typedef util::type_list<ElementTypes...> types; typedef util::type_list<Head, Tail...> types;
typedef cow_ptr<detail::abstract_tuple> cow_ptr_type; typedef cow_ptr<detail::abstract_tuple> cow_ptr_type;
static constexpr size_t num_elements = sizeof...(ElementTypes); static constexpr size_t num_elements = sizeof...(Tail) + 1;
/**
* @brief Initializes the cow_tuple with @p args.
* @param args Initialization values.
*/
template<typename... Args>
cow_tuple(const Head& arg0, Args&&... args)
: m_vals(new data_type(arg0, std::forward<Args>(args)...)) { }
/** /**
* @brief Initializes the cow_tuple with @p args. * @brief Initializes the cow_tuple with @p args.
* @param args Initialization values. * @param args Initialization values.
*/ */
template<typename... Args> template<typename... Args>
cow_tuple(Args&&... args) : m_vals(new data_type(std::forward<Args>(args)...)) { } cow_tuple(Head&& arg0, Args&&... args)
: m_vals(new data_type(std::move(arg0), std::forward<Args>(args)...)) { }
cow_tuple(cow_tuple&&) = default; cow_tuple(cow_tuple&&) = default;
cow_tuple(const cow_tuple&) = default; cow_tuple(const cow_tuple&) = default;
...@@ -119,7 +129,7 @@ class cow_tuple { ...@@ -119,7 +129,7 @@ class cow_tuple {
* @brief Gets the size of this cow_tuple. * @brief Gets the size of this cow_tuple.
*/ */
inline size_t size() const { inline size_t size() const {
return sizeof...(ElementTypes); return sizeof...(Tail) + 1;
} }
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment