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 » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » Nested template question
Re: Nested template question [message #51871 is a reply to message #51869] Mon, 10 June 2019 23:48 Go to previous messageGo to previous message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
I don't really get what you need to do.
If it is just setting any class to zero, as in your example, then you do not need method GetAZero(). Class AZero will work out of the box.
If you are trying to specialize your template method for all possible variants of std::complex<T>, then this is called partial template specialization, and it works only for classes. You need to create a dummy class and partially specialize it.
template <typename T>
struct dummy {
	T DoIt() const { return T(); }
};

template <typename T>
struct dummy<std::complex<T>> {
	using PT = std::complex<T>;
	PT DoIt() const { return PT(0, 0); }
};

struct Boo {
	Boo() {
		double val    = GetAZero<double>();
		std::complex<float>  valc1 = GetAZero<std::complex<float>>();
		std::complex<double>  valc2 = GetAZero<std::complex<double>>();
	}
	
	template <class T>
	T GetAZero() { return dummy<T>().DoIt(); }
};


Regards,
Novo
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: prototype not found
Next Topic: Dumb bug. Improper use of Null
Goto Forum:
  


Current Time: Mon Apr 29 06:55:34 CEST 2024

Total time taken to generate the page: 0.04030 seconds