Advertisement
JoshDreamland

Full CLion test case

Jul 26th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <functional>
  3.  
  4. using namespace std;
  5.  
  6. namespace SomeNamespace {
  7.   struct IncorrectReturnType {};
  8.   struct CorrectReturnType {
  9.     CorrectReturnType(int a, int b, int c, int d) {}
  10.   };
  11. }
  12.  
  13. struct OpaqueData {};
  14.  
  15. enum FooEnum {
  16.   A, B, C, NONE
  17. };
  18. enum BarEnum {
  19.   Q, U, X, NONE
  20. };
  21.  
  22. struct MyData {
  23.   bool hasTile;
  24.   FooEnum fooValue;
  25.   BarEnum barValue;
  26.   double someGrade;
  27. };
  28.  
  29. typedef std::function<SomeNamespace::CorrectReturnType(const MyData&)> Lambda;
  30.  
  31. SomeNamespace::IncorrectReturnType helperFunction(const OpaqueData&, Lambda) {
  32.   return SomeNamespace::IncorrectReturnType();
  33. }
  34.  
  35. SomeNamespace::IncorrectReturnType mainFunction(const OpaqueData &data) {
  36.   return helperFunction(data, [](const MyData & t) {
  37.     if (t.hasTile) {
  38.       const BarEnum barValue = t.barValue;
  39.       if (barValue != NONE) {
  40.         return barValue & (int) BarEnum::Q
  41.                ? SomeNamespace::CorrectReturnType(255, 0, 0, 255)
  42.                : barValue & (int) BarEnum::U
  43.                  ? SomeNamespace::CorrectReturnType(128, 0, 255, 255)
  44.                  : barValue & (int) BarEnum::X
  45.                    ? SomeNamespace::CorrectReturnType(64, 128, 255, 255)
  46.                    : SomeNamespace::CorrectReturnType(32, 200, 64, 255);
  47.       }
  48.     }
  49.  
  50.     // ===========================================================================
  51.     // I attempted to extract from here downward, originally: ====================
  52.     // ===========================================================================
  53.  
  54.     if (t.someGrade > 0 && t.fooValue != FooEnum::NONE) {
  55.       return t.fooValue == FooEnum::A
  56.              ? SomeNamespace::CorrectReturnType(0, 0, 255, t.someGrade * 255)
  57.              : t.fooValue == FooEnum::B
  58.                ? SomeNamespace::CorrectReturnType(255, 255, 0, t.someGrade * 255)
  59.                : SomeNamespace::CorrectReturnType(255, 0, 0, t.someGrade * 255);
  60.     }
  61.     return SomeNamespace::CorrectReturnType(255, 255, 255, 255);
  62.   });
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement