From 95cc08a19ef0524456ce8cf9c25bcdc03392f7eb Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 20 Nov 2012 18:55:17 +0100 Subject: [PATCH] More type safety on SelectFlags --- src/main.cc | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main.cc b/src/main.cc index cbff8402..fe697e1b 100644 --- a/src/main.cc +++ b/src/main.cc @@ -335,18 +335,23 @@ private: template Repeated repeated(T func) { return Repeated(func); } -namespace SelectFlags +enum class SelectFlags { - enum Type - { - None = 0, - Reverse = 1, - Inclusive = 2, - Extend = 4 - }; + None = 0, + Reverse = 1, + Inclusive = 2, + Extend = 4 +}; +constexpr SelectFlags operator|(SelectFlags lhs, SelectFlags rhs) +{ + return (SelectFlags)((int) lhs | (int) rhs); +} +constexpr bool operator&(SelectFlags lhs, SelectFlags rhs) +{ + return ((int) lhs & (int) rhs) != 0; } -template +template void select_to_next_char(Context& context) { int param = context.numeric_param();