#include #include using namespace std; namespace SomeNamespace { struct IncorrectReturnType {}; struct CorrectReturnType { CorrectReturnType(int a, int b, int c, int d) {} }; } struct OpaqueData {}; enum FooEnum { A, B, C, NONE }; enum BarEnum { Q, U, X, NONE }; struct MyData { bool hasTile; FooEnum fooValue; BarEnum barValue; double someGrade; }; typedef std::function Lambda; SomeNamespace::IncorrectReturnType helperFunction(const OpaqueData&, Lambda) { return SomeNamespace::IncorrectReturnType(); } SomeNamespace::IncorrectReturnType mainFunction(const OpaqueData &data) { return helperFunction(data, [](const MyData & t) { if (t.hasTile) { const BarEnum barValue = t.barValue; if (barValue != NONE) { return barValue & (int) BarEnum::Q ? SomeNamespace::CorrectReturnType(255, 0, 0, 255) : barValue & (int) BarEnum::U ? SomeNamespace::CorrectReturnType(128, 0, 255, 255) : barValue & (int) BarEnum::X ? SomeNamespace::CorrectReturnType(64, 128, 255, 255) : SomeNamespace::CorrectReturnType(32, 200, 64, 255); } } // =========================================================================== // I attempted to extract from here downward, originally: ==================== // =========================================================================== if (t.someGrade > 0 && t.fooValue != FooEnum::NONE) { return t.fooValue == FooEnum::A ? SomeNamespace::CorrectReturnType(0, 0, 255, t.someGrade * 255) : t.fooValue == FooEnum::B ? SomeNamespace::CorrectReturnType(255, 255, 0, t.someGrade * 255) : SomeNamespace::CorrectReturnType(255, 0, 0, t.someGrade * 255); } return SomeNamespace::CorrectReturnType(255, 255, 255, 255); }); }