This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[cxx] | |
gtest_dep = //googletest:gtest |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cxx_binary( | |
name = 'demo', | |
header_namespace = 'demo', | |
headers = subdir_glob([ | |
('demo/include', '**/*.hpp'), | |
]), | |
srcs = glob([ | |
'demo/src/**/*.cpp', | |
]), | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gtest/gtest.h> | |
#include <mathutils/add.hpp> | |
TEST(mathutils, add) { | |
ASSERT_EQ(3, add(1, 2)); | |
ASSERT_EQ(7, add(4, 3)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cxx_test( | |
name = 'add', | |
srcs = [ | |
'add.cpp', | |
], | |
deps = [ | |
'//mathutils:mathutils', | |
], | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
int divide(int x, int y) { | |
if (y == 0) { | |
throw std::string("Divide by zero"); | |
} | |
return x / y; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int compute(int x) noexcept { | |
return x; | |
} | |
int compute(int x) throw(std::exception) { | |
return x; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int foo() throw(int) { | |
throw "bar"; | |
return 1; | |
} | |
int bar() noexcept { | |
throw 42; | |
return 1; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int result = compute1(input); | |
int result2 = compute2(result); | |
if (has_errors()) { | |
std::cout << pop_error_message() << std::endl; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class Left, class Right> | |
struct Either { | |
union { | |
Left leftValue; | |
Right rightValue; | |
}; | |
bool isLeft; | |
}; |