Skip to content

Instantly share code, notes, and snippets.

@nathiss
Created January 7, 2018 19:19
Show Gist options
  • Save nathiss/075a17368715406d6b434edb85e4ec2e to your computer and use it in GitHub Desktop.
Save nathiss/075a17368715406d6b434edb85e4ec2e to your computer and use it in GitHub Desktop.
Template for checking if two types are the same (C++).
#ifndef _SAME_H
#define _SAME_H
template <bool C>
struct bool_type {
static constexpr bool value = C;
};
using true_type = bool_type<true>;
using false_type = bool_type<false>;
template <typename T, typename U>
struct is_same : false_type {};
template <typename T>
struct is_same<T, T> : true_type {};
#endif // _SAME_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment