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 » get_i
Re: get_i [message #54350 is a reply to message #54247] Thu, 02 July 2020 22:08 Go to previous messageGo to previous message
Novo is currently offline  Novo
Messages: 1430
Registered: December 2006
Ultimate Contributor
Sorry for the late response.
My code is correct. Temporary String lives only during function call. This is how C++ works.
Return type is a value, not a reference. So, no temporaries ...

"The type of the ternary ?: expression is the common type of its second and third argument. If both types are the same, you get a reference back. If they are convertable to each other, one gets chosen and the other gets converted (promoted in this case). Since you can't return an lvalue reference to a temporary (the converted / promoted variable), its type is a value type."

Basically, the ternary ?: is needed to convert "const char[N]" and "const char[M]" to "const char*".

On the other side, templates is a complicated thing.
If you have a non-template version of "decode" declared before template instantiation point, compiler will choose it ...
Also MSVC is very well known for broken "two-phase name lookup". Even till these days, I believe ...
IMHO, a safer version would look like this:
namespace details {
	template <class T, class V>
	constexpr auto decode(const T& sel, const V& def)
	{
		return def;
	}
	
	template <class T, class K, class V, typename... L>
	constexpr auto decode(const T& sel, const K& k, const V& v, const L& ...args)
	{
		return sel == k ? v : details::decode(sel, args...);
	}
}
	
template <class T, class K, class V, typename... L>
constexpr auto decode(const T& sel, const K& k, const V& v, const L& ...args)
{
	return details::decode(sel, k, v, args...);
}


Regards,
Novo
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: ide: Assist parsing now parallel and some of it background
Next Topic: 2020.1 officially released
Goto Forum:
  


Current Time: Wed Apr 30 03:46:31 CEST 2025

Total time taken to generate the page: 0.05803 seconds