Skip to content

Instantly share code, notes, and snippets.

View njlr's full-sized avatar
🌏
F# ing

njlr njlr

🌏
F# ing
View GitHub Profile
[cxx]
gtest_dep = //googletest:gtest
cxx_binary(
name = 'demo',
header_namespace = 'demo',
headers = subdir_glob([
('demo/include', '**/*.hpp'),
]),
srcs = glob([
'demo/src/**/*.cpp',
]),
)
#include <gtest/gtest.h>
#include <mathutils/add.hpp>
TEST(mathutils, add) {
ASSERT_EQ(3, add(1, 2));
ASSERT_EQ(7, add(4, 3));
}
cxx_test(
name = 'add',
srcs = [
'add.cpp',
],
deps = [
'//mathutils:mathutils',
],
)
#include <iostream>
#include <string>
int divide(int x, int y) {
if (y == 0) {
throw std::string("Divide by zero");
}
return x / y;
}
int compute(int x) noexcept {
return x;
}
int compute(int x) throw(std::exception) {
return x;
}
int foo() throw(int) {
throw "bar";
return 1;
}
int bar() noexcept {
throw 42;
return 1;
}
const int ERROR = 1;
const int SUCCESS = 0;
int compute(int input, int* output) {
if (cond(input)) {
return ERROR;
} else {
*output = computeOutput(input);
return SUCCESS;
}
int result = compute1(input);
int result2 = compute2(result);
if (has_errors()) {
std::cout << pop_error_message() << std::endl;
}
template<class Left, class Right>
struct Either {
union {
Left leftValue;
Right rightValue;
};
bool isLeft;
};