c++ - calling different function depending on type -


I want to call different functions in templated functions based on type, such as:

 < Code> template & lt; Typename T & gt; T Funk () {static_assert (std :: is_same ; :: value} / * other permissions type * /, "type is not allowed"); T rate {}; // if T == int funkix (& amp; ret); // If T == / * Other Type * / / * Other Functions * /}   

Is such a thing possible?

I tried to do this:

  std :: function & lt; Integer (* T)> Query; If (std :: is_same  :: value) {query = funcInt; }   

but it gives me an error:

Error: 't' does not represent any value

is_same can be used in if statements:

  if (std :: is_same  :: value & gt;) {/ * stuff * /} if (std :: is_same & lt; t, float & Gt; :: value) {/ * Other stuff This investigation has been done in theory on runtime, the compiler knows all the values ​​in compile time and most likely that any dead Eliminate Eche. The negativity is that the whole code in  func  should be syntactically and semantically well, even if it is  T , it can not always be possible.  

The proper template-it would be like this:

  template & lt; Typename & gt; Guardian Assistant; The template's & lt; & Gt; Strip Helper & lt; Int & gt; {Static zero do_work () (/) stuff *}}; Template & lt; Typename T & gt; T Funk () {static_assert (std :: is_same ; :: value} / * other permissions type * /, "type is not allowed"); Assistant & LT; T & gt; :: do_work (); }   

This lets you write common stuff in func and puts the rest in the privileges.

OTOH, if the sign of the code> joke is really easy and will not be very code duplicate, you can also be an expert in func .

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -