Quantcast
Channel: Overloading a function using templates - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by ixjxk for Overloading a function using templates

$
0
0

What about this solution? A code with the function will be compiled if the type T is satisfied your requrements. Otherwise, the static assertion failed.

#include <type_traits>enum anEnum {    //};template <typename T, bool defined = std::is_same<T, int>::value ||                                     std::is_same<T, anEnum>::value>bool isFunction(const T& aVariable){    static_assert(defined, "Invalid specialization");    bool result = false;    // Put your code here    return result;}

Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>