title: How do I avoid compiler warnings when converting enum values to integer ones?
body: <p>I created a class <code>CMyClass</code> whose CTor takes a <code>UCHAR</code> as argument. That argument can have the values of various enums (all guaranteed to fit into a <code>UCHAR</code>). I need to convert these values to <code>UCHAR</code> because of a library function demanding its parameter as that type.</p>
  
  <p>I have to create a lot of those message objects and to save typing effort I use <code>boost::assign</code>:</p>
  
  <pre><code>std::vector&lt;CMyClass&gt; myObjects;
          boost::assign::push_back(myObjects)
              (MemberOfSomeEnum)
              (MemberOfSomeEnum);
  
  std::vector&lt;CMyClass&gt; myOtherObjects;
          boost::assign::push_back(myObjects)
              (MemberOfAnotherEnum)
              (MemberOfAnotherEnum);
  </code></pre>
  
  <p>The above code calls the <code>CMessage</code> CTor with each of the two enum members and then puts them in a list.
  My problem is, that this code throws the warning C4244 (possible loss of data during conversion from enum to UCHAR) on VC++9.</p>
  
  <p>My current solution is to create a conversion function for each enum type:</p>
  
  <pre><code>static UCHAR ToUchar(const SomeEnum eType)
  {
      return static_cast&lt;UCHAR&gt;(eType);
  }
  
  static UCHAR ToUchar(const AnotherEnum eType)
  {
      return static_cast&lt;UCHAR&gt;(eType);
  }
  </code></pre>
  
  <p>And then the above code looks like this:</p>
  
  <pre><code>std::vector&lt;CMyClass&gt; myObjects;
          boost::assign::push_back(myObjects)
              (ToUchar(MemberOfSomeEnum))
              (ToUchar(MemberOfSomeEnum));
  
  std::vector&lt;CMyClass&gt; myOtherObjects;
          boost::assign::push_back(myObjects)
              (ToUchar(MemberOfAnotherEnum))
              (ToUchar(MemberOfAnotherEnum));
  </code></pre>
  
  <p>This is the cleanest approach I could think of so far.</p>
  
  <p>Are there any better ways?<br>
  Maybe boost has something nice to offer?</p>
  
  <p>I don't want to disable warnings with pragma statements and I cannot modify the enums.</p>