From cc7e6f78067c68c3f04d893cd4f5ad570db8b7e1 Mon Sep 17 00:00:00 2001 From: ado Date: Sun, 3 Jan 2021 03:18:33 +0100 Subject: [PATCH] add sqare shape to example --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0f6a56c..edf0438 100644 --- a/README.md +++ b/README.md @@ -250,12 +250,13 @@ Custom types can be used when converting values. An override of the **ss::extrac function needs to be made and you are good to go. Custom conversion for an enum would look like this: ```cpp -enum class shape { circle, rectangle, triangle }; +enum class shape { circle, square, rectangle, triangle }; template <> inline bool ss::extract(const char* begin, const char* end, shape& dst) { const static std::unordered_map shapes{{"circle", shape::circle}, + {"square", shape::square}, {"rectangle", shape::rectangle}, {"triangle", shape::triangle}}; @@ -298,15 +299,16 @@ std::vector> shapes; while (!p.eof()) { using ss::nx; - auto [circle, rectangle, triangle] = - p.try_next, double>() + auto [circle_or_square, rectangle, triangle] = + p.try_next, double>() .or_else, double, double>() .or_else, double, double, double>() .values(); - if (circle) { - auto& [s, r] = circle.value(); - shapes.emplace_back(s, r * r * M_PI); + if (circle_or_square) { + auto& [s, x] = circle_or_square.value(); + double area = (s == shape::circle) ? x * x * M_PI : x * x; + shapes.emplace_back(s, area); } if (rectangle) {