shared_ptr(std::auto_ptr<Y> & r)
От: Aera Беларусь  
Дата: 11.10.04 03:37
Оценка:

template<class Y> shared_ptr(std::auto_ptr<Y> & r);

[This constructor takes a the source auto_ptr by reference and not by value, and cannot accept auto_ptr temporaries. This is by design, as the constructor offers the strong guarantee; an rvalue reference would solve this problem, too.]


Я не совсем понимаю что за гарантия имеется здесь ввиду. Почему нельзя было использовать передачу по значению?
... << RSDN@Home 1.1.4 beta 3 rev. 185>>
--
RedApe
Re: shared_ptr(std::auto_ptr<Y> & r)
От: Sergey Shelomencev  
Дата: 11.10.04 04:38
Оценка: 2 (2)
Здравствуйте, Aera, Вы писали:

A>

A>template<class Y> shared_ptr(std::auto_ptr<Y> & r);

A>[This constructor takes a the source auto_ptr by reference and not by value, and cannot accept auto_ptr temporaries. This is by design, as the constructor offers the strong guarantee; an rvalue reference would solve this problem, too.]


A>Я не совсем понимаю что за гарантия имеется здесь ввиду. Почему нельзя было использовать передачу по значению?



Я так понимаю это относится к этому.
Exception safety: If an exception is thrown, the constructor has no effect.
Т.е. если будет сгенерировано исключение auto_ptr будет все еще владеть указателем.

Чот то вроде этого описывает эту ситуацию.
int _tmain(int argc, _TCHAR* argv[])
{
    std::auto_ptr< int > a_ptr( new int );
    try
    {
        // Если генерируется исключение здесь
        boost::shared_ptr< int >    s_ptr( ap );
    }
    catch( ... )
    {
    }
    // Место 1
    // Здесь у тебя auto_ptr все еще владеет указателем
}


Еслм бы у тебя была передача по значению, то в "месте 1" у тебя бы указатель был бы удален.
Re: shared_ptr(std::auto_ptr<Y> & r)
От: korzhik Россия  
Дата: 11.10.04 05:05
Оценка:
Здравствуйте, Aera, Вы писали:

A>

A>template<class Y> shared_ptr(std::auto_ptr<Y> & r);

A>[This constructor takes a the source auto_ptr by reference and not by value, and cannot accept auto_ptr temporaries. This is by design, as the constructor offers the strong guarantee; an rvalue reference would solve this problem, too.]


A>Я не совсем понимаю что за гарантия имеется здесь ввиду.

Гарантия безопасности.
Строгая гарантия: если операция прекращается из-за генерации исключения, состояние программы остаётся неизменным.
Подробнее можно почитать здесь
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.