Advertisement
Guest User

Untitled

a guest
Nov 16th, 2011
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. template <int n, int x, int... xs>
  4. struct is_unique {
  5.   static const bool value = x != n &&is_unique<n, xs...>::value;
  6. };
  7.  
  8. template <int n, int x>
  9. struct is_unique<n, x> {
  10.   static const bool value = x != n;
  11. };
  12.  
  13. template <int n>
  14. struct unique_acc {
  15.   static const int value = n;
  16. };
  17.  
  18. template <typename acc, int... xs>
  19. struct unique_n {
  20.   static const int value = is_unique<acc::value, xs...>::value ?
  21.    acc::value :
  22.    unique_n<unique_acc<acc::value + 1>, xs...>::value;
  23. };
  24.  
  25. template <int... xs>
  26. struct unique_n<unique_acc<sizeof...(xs)>, xs...> {
  27. static const int value = sizeof...(xs);
  28. };
  29.  
  30. template <int... xs>
  31. using unique = unique_n<unique_acc<0>, xs...>;
  32.  
  33. enum my_enum {
  34.   a = 5,
  35.   b = 2,
  36.   c = 0
  37. };
  38.  
  39. int main() {
  40.   std::cout << unique<a, b, c>::value;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement