Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- template <int n, int x, int... xs>
- struct is_unique {
- static const bool value = x != n &&is_unique<n, xs...>::value;
- };
- template <int n, int x>
- struct is_unique<n, x> {
- static const bool value = x != n;
- };
- template <int n>
- struct unique_acc {
- static const int value = n;
- };
- template <typename acc, int... xs>
- struct unique_n {
- static const int value = is_unique<acc::value, xs...>::value ?
- acc::value :
- unique_n<unique_acc<acc::value + 1>, xs...>::value;
- };
- template <int... xs>
- struct unique_n<unique_acc<sizeof...(xs)>, xs...> {
- static const int value = sizeof...(xs);
- };
- template <int... xs>
- using unique = unique_n<unique_acc<0>, xs...>;
- enum my_enum {
- a = 5,
- b = 2,
- c = 0
- };
- int main() {
- std::cout << unique<a, b, c>::value;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement