Skip to content

Instantly share code, notes, and snippets.

View dbecker59's full-sized avatar

Daniel Becker dbecker59

View GitHub Profile
@bad-ed
bad-ed / template_traits.hpp
Created November 30, 2018 10:47
C++ traits for templates with type arguments (is_template, is_instance_of_template, is_derived_of_template)
#include <type_traits>
// Determine if `Instance` is instantiation of template
// e.g. static_assert(is_template<std::vector<int>>::value);
template<class Instance> struct is_template : std::false_type {};
template<class ...TemplateArgs, template<class...> class Template>
struct is_template<Template<TemplateArgs...>> : std::true_type {};
// Determine if `Instance` is instance of `Template`
// e.g. static_assert(is_instance_of_template<std::vector, std::vector<int>>::value);