Skip to content

Commit 4332933

Browse files
committed
Document Choice::Tag and remove unintended macros from being public
1 parent a1f3fe5 commit 4332933

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

sus/choice/choice.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,16 @@ struct CanConvertToStorage<I, ::sus::tuple_type::Tuple<Ts...>, U> {
174174
/// }
175175
/// }
176176
/// ```
177+
/// `Choice` will re-export the tag value type as a nested `Tag` subtype. This
178+
/// allows access to the Choice's values though `MyChoiceType::Tag::Name`.
179+
/// ```
180+
/// enum class Order { First, Second };
181+
/// using EitherOr = Choice<sus_choice_types(
182+
/// (Order::First, u64),
183+
/// (Order::Second, u32)
184+
/// )>;
185+
/// auto x = EitherOr::with<EitherOr::Tag::First>(987u);
186+
/// ```
177187
template <class... Ts, auto... Tags>
178188
class Choice<__private::TypeList<Ts...>, Tags...> final {
179189
static_assert(sizeof...(Ts) > 0,

sus/choice/choice_types.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@
2222
#include "sus/macros/remove_parens.h"
2323
#include "sus/tuple/tuple.h"
2424

25-
/// Construct a set of associated value and types pairings. The type of the
25+
/// A macro used to declare the value-type pairings in a [`Choice`](
26+
/// $sus::choice_type::Choice). See the [`Choice`](
27+
/// $sus::choice_type::Choice) type for examples of its use.
28+
///
29+
/// Constructs a set of associated value and types pairings. The type of the
2630
/// values need have no relationship to the specified types.
2731
///
32+
/// # Details
2833
/// The input takes the format: `(Value1, Type1A, Type1B), (Value2, Type2), ...`
2934
/// The output is the sequence `TypeList<Tuple<Type1A, Type1B>, Tuple<Type2>,
3035
/// ...>, Value1, Value2, ...`.
@@ -60,11 +65,11 @@
6065
// clang-format on
6166

6267
#define _sus__make_union_storage_type(types) \
63-
::sus::choice_type::__private::MakeStorageType<sus_remove_parens(types)>::type
68+
::sus::choice_type::__private::MakeStorageType<_sus_remove_parens(types)>::type
6469

6570
#define _sus__first(a, ...) a
6671
#define _sus__second_plus(a, ...) __VA_ARGS__
6772

6873
#define _sus__value_types_types(x) \
69-
(sus_remove_parens_and_eval(_sus__second_plus, x))
70-
#define _sus__value_types_value(x) sus_remove_parens_and_eval(_sus__first, x)
74+
(_sus_remove_parens_and_eval(_sus__second_plus, x))
75+
#define _sus__value_types_value(x) _sus_remove_parens_and_eval(_sus__first, x)

sus/choice/choice_unittest.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,6 +1026,12 @@ TEST(Choice, Example_Construct) {
10261026
}
10271027
}
10281028
}
1029+
{
1030+
enum class Order { First, Second };
1031+
using EitherOr =
1032+
Choice<sus_choice_types((Order::First, u64), (Order::Second, u32))>;
1033+
auto x = EitherOr::with<EitherOr::Tag::First>(987u);
1034+
}
10291035
}
10301036

10311037
} // namespace

sus/macros/eval_macro.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/// # Example
2323
/// ```
2424
/// #define f(s) hello(s)
25-
/// sus_eval_macro(f, "world")
25+
/// _sus_eval_macro(f, "world")
2626
/// // Evaluates to: `hello("world")`
2727
/// ```
28-
#define sus_eval_macro(x, ...) x(__VA_ARGS__)
28+
#define _sus_eval_macro(x, ...) x(__VA_ARGS__)

sus/macros/remove_parens.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
/// * `(x, y)` => `x, y`
2626
///
2727
/// Based on: https://stackoverflow.com/a/62984543
28-
#define sus_remove_parens(x) _sus__remove_inner_rename(_sus__remove_inner x)
28+
#define _sus_remove_parens(x) _sus__remove_inner_rename(_sus__remove_inner x)
2929

30-
#define sus_remove_parens_and_eval(e, x) \
31-
sus_eval_macro(e, sus_remove_parens(x))
30+
#define _sus_remove_parens_and_eval(e, x) \
31+
_sus_eval_macro(e, _sus_remove_parens(x))
3232

33-
// Implementation of sus_remove_parens(x).
33+
// Implementation of _sus_remove_parens(x).
3434

3535
// Step 1: If the input had brackets, now it no longer does. The result will
3636
// always be `_sus__remove_inner x` at the end.

0 commit comments

Comments
 (0)