Task #2234
closedBlock abstraction: move constructor
100%
Description
Implement move constructors for Block
and Buffer
types.
Static assertions should be declared (in implementation .cpp, on supported platforms) to guarantee those types are move constructible.
Updated by Junxiao Shi about 10 years ago
- Subject changed from Implement move constructor for Block abstraction to Block abstraction: move constructor
- Description updated (diff)
- Status changed from New to In Progress
- Assignee set to Junxiao Shi
- Estimated time set to 1.00 h
I'll code this as a learning experience, so time estimation might be higher than it's supposed to be.
Updated by Davide Pesavento about 10 years ago
You should also implement a move assignment operator then...
Updated by Junxiao Shi about 10 years ago
- % Done changed from 0 to 40
Buffer
http://gerrit.named-data.net/1478
Buffer
is already move constructible. A static_assert
is added.
I'll add move constructor to Block
in the next commit.
Updated by Junxiao Shi about 10 years ago
You should also implement a move assignment operator then...
I agree.
Is there a type property from <type_traits>
that I can use to guarantee a type has move assignment operator?
From MoveAssignable reference:
The type does not have to implement move assignment operator in order to satisfy this type requirement: a copy assignment operator that takes its parameter by value or as a const Type&, will bind to rvalue argument.
Updated by Davide Pesavento about 10 years ago
Junxiao Shi wrote:
Is there a type property from
<type_traits>
that I can use to guarantee a type has move assignment operator?
Use std::is_move_assignable
. Of course that doesn't guarantee that your type implements move semantics, that's a different thing and it only depends on how you implement the body of the move constructor and the move assignment operator.
From MoveAssignable reference:
The type does not have to implement move assignment operator in order to satisfy this type requirement: a copy assignment operator that takes its parameter by value or as a const Type&, will bind to rvalue argument.
Obviously... the same is true for MoveConstructible and a copy constructor (which takes a const reference).
Updated by Junxiao Shi about 10 years ago
From http://en.cppreference.com/w/cpp/language/move_constructor:
For non-union class types (class and struct), the move constructor performs full member-wise move of the object's bases and non-static members, in their initialization order, using direct initialization with an xvalue argument.
Therefore, Block
type already has a move constructor and a move assignment operator that can satisfy the needs.
I'll just add static assertions.
Updated by Junxiao Shi about 10 years ago
- Status changed from In Progress to Code review
- % Done changed from 40 to 100
http://gerrit.named-data.net/1489
It seems that implicitly-defined move constructor is generated, as seen in the symbol table:
shijunxiao@vm104:~/ndn-cxx$ nm --demangle=auto build/libndn-cxx.a | grep Block::Block | sort -u
0000000000000000 n ndn::Block::Block(ndn::Block&&)
0000000000000000 n ndn::Block::Block(ndn::Block const&)
0000000000000000 W ndn::Block::Block(ndn::Block&&)
0000000000000000 W ndn::Block::Block(ndn::Block const&)
0000000000000198 T ndn::Block::Block()
00000000000001e8 T ndn::Block::Block(std::shared_ptr<ndn::Buffer const> const&, unsigned int, __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > > const&, __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > > const&, __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > > const&, __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > > const&)
0000000000000258 T ndn::Block::Block(unsigned int)
00000000000002a4 T ndn::Block::Block(unsigned int, std::shared_ptr<ndn::Buffer const> const&)
00000000000022da T ndn::Block::Block(ndn::EncodingImpl<true> const&)
00000000000028a6 T ndn::Block::Block(std::shared_ptr<ndn::Buffer const> const&)
0000000000002e74 T ndn::Block::Block(std::shared_ptr<ndn::Buffer const> const&, __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > > const&, __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > > const&, bool)
000000000000344a T ndn::Block::Block(unsigned int, ndn::Block const&)
00000000000047ba T ndn::Block::Block(unsigned char const*, unsigned long)
0000000000004f16 T ndn::Block::Block(void const*, unsigned long)
U ndn::Block::Block()
U ndn::Block::Block(std::shared_ptr<ndn::Buffer const> const&)
U ndn::Block::Block(std::shared_ptr<ndn::Buffer const> const&, __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > > const&, __gnu_cxx::__normal_iterator<unsigned char const*, std::vector<unsigned char, std::allocator<unsigned char> > > const&, bool)
U ndn::Block::Block(unsigned char const*, unsigned long)
U ndn::Block::Block(unsigned int)
U ndn::Block::Block(unsigned int, ndn::Block const&)
U ndn::Block::Block(unsigned int, std::shared_ptr<ndn::Buffer const> const&)
Updated by Junxiao Shi about 10 years ago
- Blocked by Task #2263: code-style: Doxygen syntax added
Updated by Junxiao Shi about 10 years ago
- Status changed from Code review to Resolved
This Task is blocked by #2263 because reviewer suggests in commit e71d53f7153caab9815c15ec203257353dd84a64
to follow a certain Doxygen code style which is not yet documented.
I'll wait for a guideline for Doxygen code style and then rework this Change.
Updated by Junxiao Shi almost 10 years ago
- Blocked by deleted (Task #2263: code-style: Doxygen syntax)
Updated by Junxiao Shi almost 10 years ago
- Status changed from Resolved to Closed