We can even have a native syntax:

template<typename T>
inline T operator | (T a, T b) { return static_cast<T>(a | b); }

Although, this may introduce subtle bugs.

On Tue, Oct 5, 2010 at 18:06, Vitaly Repeshko <[email protected]> wrote:
> On Tue, Oct 5, 2010 at 5:55 PM,  <[email protected]> wrote:
>> Should we fix those places as well? Otherwise it looks ugly when API client
>> need
>> to do an explicit cast to the enum type instead of just passing result of
>> or'ed
>> literals. The cast will break compiler type checks anyway so I think int
>> parameter with a commentary is more convenient in this case.
>
> I agree that it looks ugly, but still an explicit cast is better
> especially in cases where a method takes more than one bit field (e.g.
> SetAccessor): you are less likely to do a wrong cast than pass the
> arguments in the wrong order. What about adding a helper function to
> do flag combining?
>
> template <typename T>
> inline T Combine(T t1, T t2, T t3=T(0), T t4=T(0)) {
>  return static_cast<T>(t1 | t2 | t3 | t4);
> }
>
> v8::RegExp::New(v8_str("foobarbaz"),
> v8::Combine(v8::RegExp::kIgnoreCase, v8::RegExp::kMultiline));
>
>
> -- Vitaly
>
>> On 2010/10/05 13:48:11, Vitaly wrote:
>>>
>>> Drive-by comment. This is inconsistent with other similar places in the
>>> API
>>> where we still take an enum-typed argument even if the enum literals can
>>> be
>>> or'ed.
>>
>>
>>> -- Vitaly
>>
>>
>>
>> http://codereview.chromium.org/3611008/show
>>
>

-- 
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to