Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Community » U++ community news and announcements » MakeOne
MakeOne [message #47648] Tue, 21 February 2017 11:39 Go to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Little useful helper class...

void DumpFile(One<Stream>& s)
{
	LOG("=========");
	int ii = 0;
	while(!s->IsEof())
		LOG(++ii << ": " << s->GetLine());
}

CONSOLE_APP_MAIN
{
	String fn = GetDataFile("One.cpp");
	{
		One<Stream> s;
		s.Create<FileIn>(fn);
		DumpFile(s);
	}
	{
		MakeOne<FileIn> in(fn);
		One<Stream> s = pick(in);
		DumpFile(s);
	}
	{
		One<Stream> s = MakeOne<FileIn>(fn);
		DumpFile(s);
	}
}
Re: MakeOne [message #47649 is a reply to message #47648] Tue, 21 February 2017 12:14 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
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 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Klugier wrote on Tue, 21 February 2017 12:14
Hello,

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 #47661 is a reply to message #47650] Wed, 22 February 2017 19:24 Go to previous messageGo to next message
Didier is currently offline  Didier
Messages: 680
Registered: November 2008
Location: France
Contributor
It may be obvious, but I don't see the point to the 'MakeOne' helper ==> you only gain one line of writing.
I suppose there is more to it ??
Re: MakeOne [message #47662 is a reply to message #47661] Wed, 22 February 2017 20:43 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Didier wrote on Wed, 22 February 2017 19:24
It may be obvious, but I don't see the point to the 'MakeOne' helper ==> you only gain one line of writing.
I suppose there is more to it ??


Yes, you are right. Still, it was requested by users. And personally I longed for it in certain situations too (perhaps being lazy to write that one line... Smile

Mirek
Re: MakeOne [message #50054 is a reply to message #47662] Sat, 30 June 2018 14:45 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1075
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

Re: MakeOne [message #50057 is a reply to message #50054] Sat, 30 June 2018 20:30 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Hopefully fixed.
Re: MakeOne [message #50058 is a reply to message #50057] Sat, 30 June 2018 21:55 Go to previous message
Klugier is currently offline  Klugier
Messages: 1075
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello,

You are absolutely amazing - thanks for immediate fix Smile

Sincerely,
Klugier


U++ - one framework to rule them all.
Previous Topic: Pdf signing
Next Topic: New verion of msbt2017 openssl library for win32
Goto Forum:
  


Current Time: Thu Mar 28 16:01:46 CET 2024

Total time taken to generate the page: 0.01545 seconds