Question: I have functions of this type:

```
type uniRndtype()
{
    return typeValue;
}

```

and now I'm trying to wrap them inside another template function like this:

```
template<typename T>
T(* uniRndType(void))()
{
    if (is_same<T, bool>::value)
    {
        return uniRndBool;
    } else if (is_same<T, char>::value)
    {
        return uniRndChar;
    } else
    ...
}

```

and calling it like this:

```
uniRndType<int>();

```

But I'm getting an error: **"error: return value type does not match the function type"** 
because each return has a different type.. 

I there a way to make it work? Because from a runtime point of view I see no errors, only the compiler have problems.

Answer: 
```
template <typename T> T (*uniRndType())()
{
    //else
    ...
}

template <> bool (*uniRndType())()
{
    return uniRndBool;
}

template <> char (*uniRndType())()
{
    return uniRndChar;
}

```

That's all.

edit: In principle, we must do like @Angew. but it's little troublesome
This won't work because when the compiler expands the template method for a given type the method has to be valid. Your type, T, needs to be compatible with all the return types listed, eg `bool`, `char`, etc. As I mentioned in the comments, if you passed in a `std::string` you wouldn't expect the method to work, would you?

One way around this is to use [template specialization](http://www.cprogramming.com/tutorial/template_specialization.html) to indicate what you want for each type.