User avatar
Gazoo
Topic Author
Posts: 36
Joined: 14 Sep 2022, 10:00
Contact:

[Solved] Passing a member function to Noesis::SetLogHandler()

16 Oct 2022, 02:00

Hey y'all,

I prefer to avoid lambda functions unless necessary, given their increased power/complexity compared to 'standard' functions. I've unsuccessfully attempted to pass a member function to the Noesis::SetLogHandler() function. Attempted approaches:

std::bind()
Noesis::SetLogHandler( std::bind( &ApplicationNoesisGui::NoesisLogging, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 ) );
No bueno, as std::bind() returns an unspecified type https://stackoverflow.com/questions/631 ... d-function

std::function
	std::function<void( const char*, uint32_t, uint32_t, const char*, const char* )> f = std::bind( &ApplicationNoesisGui::NoesisLogging, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5 );
	Noesis::SetLogHandler( f );
Setting aside my concern for how long 'f' exists beyond the scope it's declared in, and if that'd cause issues, I still receive this error with this approach:

E0413 no suitable conversion function from "std::function<void (const char *, uint32_t, uint32_t, const char *, const char *)>" to "Noesis::LogHandler" exists

Which... Well... Alright, they're supposedly the same type, but I guess a typedef != std::function?

Anonymous namespace function

My current best solution is to simply implement a function in an anonymous namespace and use it:
namespace {
	void MyLogger( const char*, uint32_t, uint32_t level, const char*, const char* msg )
	{
	}
}
This avoids the lambda function, but doesn't allow me to use a member function.

I'm open to any ideas/suggestions!

Thanks in advance,
Gazoo
Last edited by Gazoo on 18 Oct 2022, 11:51, edited 1 time in total.
 
User avatar
jsantos
Site Admin
Posts: 3918
Joined: 20 Jan 2012, 17:18
Contact:

Re: Passing a member function to Noesis::SetLogHandler()

17 Oct 2022, 12:33

Unfortunately this is not possible with the current API. Please report if this is a blocking feature for your development.
 
User avatar
Gazoo
Topic Author
Posts: 36
Joined: 14 Sep 2022, 10:00
Contact:

Re: Passing a member function to Noesis::SetLogHandler()

18 Oct 2022, 11:51

Not a blocker as such. More of a minor annoyance. Really appreciate confirming that it isn't currently possible. The anonymous namespace function is preferable to me, compared to the lambda function.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 15 guests