Re: It would be better if unique_ptr were a type modifier?
* Better error messages
This is in my view the best and only argument for unique type modifier.
One more point:
Sometimes we use pointers only to hold polymorphic items.
For instance, at the beginning the code was like this:
DoSomething(const FilterBase& ) {...}
{
const SpecialFilter specialFilter;
DoSomething(specialFilter);
}
....and then it had to be changed to select the Filter in runtime:
{
std::auto_ptr<const FilterBase> pFilter =
SelectFilterClass(arguments);
DoSomething(*pFilter.get());
}
In this case the pointer is not what I want because I don?t need
the address concept or pFilter++ or iterator concept and it cannot be
null.
All I want is a polymorphic object in this scope.
The point is:
Is the unique modifier applicable for references as well?
What is the "smart reference class"?
If we had this, the code would be expressed as:
{
const unique FilterBase & filter = SelectFilterClass(arguments);
}
Different syntaxes could be:
auto FilterBase & filter = SelectFilterClass(arguments);
delete FilterBase & filter = SelectFilterClass(arguments);
and if could express the idea of
"list of polimorphic items non null"
vector<unique FilterBase& > v;
Everthing is about RAII and the language.
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]