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 » Newbie corner » Tricky template non-typeParameter
Tricky template non-typeParameter [message #51822] Sat, 08 June 2019 16:36 Go to next message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello,

Is it possible to do something like that :

using namespace Upp;

template<dword> struct Type_selector;
template<> struct Type_selector<1> { using Type = int;};
template<> struct Type_selector<3> { using Type = String;};
template<> struct Type_selector<4> { using Type = Date;};
template<> struct Type_selector<134217728> { using Type = long;};
template<> struct Type_selector<134217729> { using Type = float;};
template<> struct Type_selector<2> { using Type = double;};
template<> struct Type_selector<11> { using Type = bool;};

template<dword type> using Type = typename Type_selector<type>::Type;

CONSOLE_APP_MAIN
{
	Type_selector<1>::Type E =1; //work
	Type<1> T =2;//Work
	
	// Is it possible to actually doing something like that :
	Type<"int"> F = 3; //I want F to be Int  from giving Upp::String to 'Type'	
}



thanks in advance

best regard
Re: Tricky template non-typeParameter [message #51825 is a reply to message #51822] Sat, 08 June 2019 17:27 Go to previous message
Novo is currently offline  Novo
Messages: 1358
Registered: December 2006
Ultimate Contributor
According to this Non-type template parameter can be

    std::nullptr_t (since C++11);
    an integral type;
    a pointer type (to object or to function);
    a pointer to member type (to member object or to member function);
    an enumeration type. 

It cannot be string (const char*) or double/float.
Try to use enums instead ...


Regards,
Novo
Previous Topic: Value strange behaviour result in ValueTypeError
Next Topic: What is the difference between learning U++ and Learning C++ through Microsoft Visual Studio?
Goto Forum:
  


Current Time: Fri Mar 29 00:54:13 CET 2024

Total time taken to generate the page: 0.01221 seconds