JoshDreamland icon

Full CLion test case

JoshDreamland | PRO | 07/26/15 03:45:35 PM UTC | 0 ⭐ | 472 👁️ | Never ⏰ | []
C++ |

1.98 KB

|

None

|

0 👍

/

0 👎

#include <iostream>
#include <functional>
 
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<SomeNamespace::CorrectReturnType(const MyData&)> 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);
  });
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎