Home » Community » U++ community news and announcements » MakeOne
|
Re: MakeOne [message #47649 is a reply to message #47648] |
Tue, 21 February 2017 12:14 |
|
Klugier
Messages: 1082 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello,
I have got one question. Will it work with auto?
auto stream = MakeOne<FileIn>(fn); // Is auot MakeOne or One?
Why not make MakeOne function rather than class?
Sincerely,
Klugier
U++ - one framework to rule them all.
[Updated on: Tue, 21 February 2017 12:34] Report message to a moderator
|
|
|
Re: MakeOne [message #47650 is a reply to message #47649] |
Tue, 21 February 2017 16:05 |
|
mirek
Messages: 14038 Registered: November 2005
|
Ultimate Member |
|
|
Klugier wrote on Tue, 21 February 2017 12:14Hello,
I have got one question. Will it work with auto?
auto stream = MakeOne<FileIn>(fn); // Is auot MakeOne or One?
Sure. It will be MakeOne, but that hardly matters.
{
auto in = MakeOne<FileIn>(GetDataFile("Console.cpp"));
One<Stream> s = pick(in);
while(!s->IsEof())
DDUMP(s->GetLine());
}
Quote:
Why not make MakeOne function rather than class?
Class seems to be more versatile here - you can use it just like function, but you can declare the variable too.
E.g. you can do this:
One<Stream> OpenFile()
{
MakeOne<FileIn> in;
in->Open("asd");
return in;
}
With "function only" you would have to type a bit more...
Mirek
[Updated on: Tue, 21 February 2017 16:07] Report message to a moderator
|
|
|
|
|
Re: MakeOne [message #50054 is a reply to message #47662] |
Sat, 30 June 2018 14:45 |
|
Klugier
Messages: 1082 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello,
I have a problem with current MakeOne implementation. It doesn't work greate with auto:
One<Foo> CreateFoo() {
auto pFoo = MakeOne<Foo>();
int i = 0;
if (i == 0) {
return nullptr;
}
return pFoo; // Compilation error - /home/klugier/MyApps/MakeOneTest/MakeOneTest.cpp (19): error: use of deleted function 'Upp::One<T>::One(const Upp::One<T>&) [with T = Foo]'
}
The below example works as expected:
One<Foo> CreateFoo() {
One<Foo> pFoo = MakeOne<Foo>();
int i = 0;
if (i == 0) {
return nullptr;
}
return pFoo;
}
I am not sure it is the good design to limit it to only explicit types. std::make_shared and std::make_unique works in above case.
Sincerely,
Klugier
U++ - one framework to rule them all.
[Updated on: Sat, 30 June 2018 14:45] Report message to a moderator
|
|
|
|
|
Goto Forum:
Current Time: Fri Sep 20 07:26:08 CEST 2024
Total time taken to generate the page: 0.04870 seconds
|