Exemplo n.º 1
0
void		Logger::log( std::string  const & dest, std::string const & message) {
	int		i;

	i = -1;
	while (++i < this->nbr)
		if (dest == this->tab[i].name)
			(this->*tab[i].f)(makeLogEntry(message));
}
  makeInvestment(Ts&&... args);   // from the given args

int main ()
{
  // ...

  auto pInvestment =                    // pInvestment is of type
    makeInvestment( /* arguments */ );  // std::unique_ptr<Investment>

  // ...

}                                       // destroy *pInvestment

auto delInvmt = [](Investment* pInvestment)   // custom 
                {                             // deleter
                  makeLogEntry(pInvestment);  // (a lambda
                  delete pInvestment;         // expression)
                };

template<typename... Ts>                         // revised
std::unique_ptr<Investment, decltype(delInvmt)>  // return type
makeInvestment(Ts&&... args)
{
  std::unique_ptr<Investment, decltype(delInvmt)>  // ptr to be
    pInv(nullptr, delInvmt);                       // returned

  if ( /* a Stock object should be created */ )
  {
    pInv.reset(new Stock(std::forward<Ts>(args)...));
  }
  else if ( /* a Bond object shold be created */ )