Project

General

Profile

Actions

Task #2112

closed

Face: use lambda expression and smart pointers

Added by Junxiao Shi over 9 years ago. Updated almost 9 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Base
Target version:
Start date:
05/18/2015
Due date:
% Done:

100%

Estimated time:
3.00 h

Description

Enhance Face and Face::Impl with C++11 features:

  • use lambda expression instead of bind where applicable
  • use unique_ptr on member fields where they are currently regular pointers
  • use unique_ptr instead of shared_ptr where applicable
Actions #1

Updated by Alex Afanasyev almost 9 years ago

  • Assignee set to Joao Pereira
Actions #2

Updated by Joao Pereira almost 9 years ago

  • Status changed from New to In Progress
  • Start date set to 05/18/2015

Start changes

Actions #3

Updated by Joao Pereira almost 9 years ago

  • Status changed from In Progress to Code review
  • % Done changed from 0 to 100
Actions #4

Updated by Joao Pereira almost 9 years ago

Previously:


RegisteredPrefix::Unregistrator bindedUnregistrator =
bind(unregistrator, m_face.m_nfdController, unregisterParameters, _1, _2,
options);



New version:

RegisteredPrefix::Unregistrator bindedUnregistrator =
[this, &unregistrator, unregisterParameters, options] (const Controller::CommandSucceedCallback& successCallback,
const Controller::CommandFailCallback& failCallback)
{
((*this->m_face.m_nfdController).*unregistrator)(unregisterParameters, successCallback, failCallback, options);
};

I have been asked to revert this part and use again bind function instead of lambda.

========
My answer:

Before changing the Controller attribute we had a pointer and it made sense to allow it to be copied into the bind function. But now that we have a unique_ptr we cannot copy the pointer, nor can we copy the object inside the pointer because Controller is noncopyable.
If you think we should keep the shared I see 2 solutions:

  1. Keep the pointer instead of having a unique_ptr

  2. Change the unique_ptr to a shared_ptr so it can be copied around

With the lambda what we do is to copy the reference of the face_impl in order to use it. Can we do this with the bind?

Actions #5

Updated by Davide Pesavento almost 9 years ago

Use get() if you need a naked pointer, or operator* if you need a reference.

Actions #6

Updated by Junxiao Shi almost 9 years ago

  • Status changed from Code review to Closed
Actions

Also available in: Atom PDF