   Template Conditionals [C++]
  I already know this is impossible at least as I'm writing it, but I need something that will work... without having to write a template conditional construct.template <typename return_type>return_type getFunction(const char *func_name, const char *args, ...){   ...   if <return_type != void>   { return *(return_type*)getReturnPointer();   }}Basically, the issue is that if my return type is void, in normal C++, it won't compile because you can't dereference a void*, nor can you have a return with a return value. A static conditional would solve this. Since C++ doesn't have static conditionals for templates, does anyone know if it's upcoming with C++0x?   
  boost::optional.It's something like this:template < class T > struct Placeholder {  T value;};struct Placeholder<void> {};template <typename return_type>Placeholder<return_type> getFunction(const char *func_name, const char *args, ...)Also, I cannot see any sane reason why one would ever need to write code like that.What problem are you trying to solve?   ;  It's an interface function for calling a function that lies in a scripting VM that may or may not have a return type, and can have multiple types -- it's a typed language.   ;  I get around this with my scripting stuff by returning a dummy value from things that "should" return void. Essentially; I use metaprogramming to conditionally return either return_type or size_t. The same technique is used to statically branch within the function, so it looks something like...typename if_< is_same<void, T>::value, size_t, T>::value doStuff( args ){    if ( is_same<void, T>::value )    {   stuffThatReturnsVoid();   return size_t();    } else{   return static_cast<T>(*stuffThatDoesNotReturnVoid());    }}EDIT: Oh; without template conditionals. Disregard that.   ;  That's probably what I'm going to end up having to do anyways. So ist es.   ;Quote:Original post by Ameisenor can you have a return with a return value.I do not understand this statement could you clarify please?I think you are saying you can not do the following, but you cantemplate<typename ReturnType>struct getResult {static ReturnType work(){return *(ReturnType*)getReturnPointer();}};template<>struct getResult <void>{static void work()//noop{}};template <typename return_type>return_type doFunction(const char *func_name, const char *args, ...){   ...   return getResult<return_type>::work();};  I'm at work so can't test it... but that doesn't look like it would work -- void is a type... so it would default to the first, I'd think?   ;Quote:Original post by AmeiseI'm at work so can't test it... but that doesn't look like it would work -- void is a type... so it would default to the first, I'd think?Sorry you think incorrectly :) void is a type yet the struct is specialised for it.;Quote:Original post by dmailQuote:Original post by AmeiseI'm at work so can't test it... but that doesn't look like it would work -- void is a type... so it would default to the first, I'd think?Sorry you think incorrectly :) void is a type yet the struct is specialised for it.Whoops, my mind skipped over a line. It's still what I wanted to avoid... but I don't have much of a choice. Other than using, say, D... but that's not going to happen.   ;Quote:Original post by Ameiseit's a typed language.Strong or weak typing? Static or dynamic typing? (And you are aware that these are different things, yes?)   