xref: /aosp_15_r20/external/cronet/base/macros/if.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2023 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef BASE_MACROS_IF_H_
6 #define BASE_MACROS_IF_H_
7 
8 #include "base/macros/concat.h"
9 
10 // Given a `_Cond` that evaluates to exactly 0 or 1, this macro evaluates to
11 // either the `_Then` or `_Else` args. Unlike a real conditional expression,
12 // this does not support conditions other than `0` and `1`.
13 #define BASE_IF(_Cond, _Then, _Else) \
14   BASE_CONCAT(BASE_INTERNAL_IF_, _Cond)(_Then, _Else)
15 
16 // Implementation details: do not use directly.
17 #define BASE_INTERNAL_IF_1(_Then, _Else) _Then
18 #define BASE_INTERNAL_IF_0(_Then, _Else) _Else
19 
20 #endif  // BASE_MACROS_IF_H_
21