title: Comparison tricks in C++
body: <p>A class:</p>
  
  <pre><code>class foo{
  public:
      int data;
  };
  </code></pre>
  
  <p>Now I want to add a method to this class, to do some comparison, to see if its data is equal to one of given numbers.</p>
  
  <p>Of course, I can write <code>if(data==num1|| data == num2|| data ==num3.....)</code>, but honestly speaking, I feel sick when I write <code>data ==</code> every time I compare it to a number.</p>
  
  <p>So, I hope I would be able to write something like this:</p>
  
  <pre><code>if(data is equal to one of these(num1,num2,num3,num4,num5...))
      return true;
  else
      return false;
  </code></pre>
  
  <p>I want to implement this statement, <code>data is equal to one of these(num1, num2, num3, num4, num5...)</code></p>
  
  <p>Here is my approach:</p>
  
  <pre><code>#include &lt;stdarg.h&gt;
  bool is_equal_to_one_of_these(int count,...){
      int i;
      bool equal = false;
      va_list arg_ptr;
      va_start(arg_prt,count);
      for(int x=0;x&lt;count;x++){
          i = va_arg(arg_ptr,int);
          if( i == data ){
              equal = true;
              break;
          }
      }
      va_end(arg_ptr);
      return equal;
  }
  </code></pre>
  
  <p>This piece of code will do the job for me. But every time I use this method, I'll have to count the parameters and pass it in.</p>
  
  <p>Does anyone have a better idea?</p>