Add deterministic C++ reference adapter
This commit is contained in:
parent
f00aa65a73
commit
7bee0220c2
7 changed files with 1915 additions and 0 deletions
19
tests/fixtures/reference-cpp/compile_commands.json
vendored
Normal file
19
tests/fixtures/reference-cpp/compile_commands.json
vendored
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
[
|
||||
{
|
||||
"arguments": [
|
||||
"c++",
|
||||
"-std=c++20",
|
||||
"-Iinclude",
|
||||
"-c",
|
||||
"src/main.cpp"
|
||||
],
|
||||
"directory": ".",
|
||||
"file": "src/main.cpp"
|
||||
},
|
||||
{
|
||||
"command": "c++ -std=c++20 -Iinclude -c src/worker.cpp",
|
||||
"directory": ".",
|
||||
"file": "src/worker.cpp",
|
||||
"output": "worker.o"
|
||||
}
|
||||
]
|
||||
15
tests/fixtures/reference-cpp/include/config.hpp
vendored
Normal file
15
tests/fixtures/reference-cpp/include/config.hpp
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include "detail.hpp"
|
||||
|
||||
namespace demo {
|
||||
|
||||
struct Config {
|
||||
int limit;
|
||||
};
|
||||
|
||||
inline int effective_limit(const Config& config) {
|
||||
return normalize(config.limit);
|
||||
}
|
||||
|
||||
} // namespace demo
|
||||
12
tests/fixtures/reference-cpp/include/detail.hpp
vendored
Normal file
12
tests/fixtures/reference-cpp/include/detail.hpp
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
namespace demo {
|
||||
|
||||
inline int normalize(int value) {
|
||||
if (value < 0) {
|
||||
return 0;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
} // namespace demo
|
||||
17
tests/fixtures/reference-cpp/src/main.cpp
vendored
Normal file
17
tests/fixtures/reference-cpp/src/main.cpp
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include "../include/config.hpp"
|
||||
|
||||
namespace demo {
|
||||
|
||||
int execute(int value) {
|
||||
Config config{value};
|
||||
if (value == 0) {
|
||||
return effective_limit(config);
|
||||
}
|
||||
return normalize(value);
|
||||
}
|
||||
|
||||
} // namespace demo
|
||||
|
||||
int main() {
|
||||
return demo::execute(3);
|
||||
}
|
||||
17
tests/fixtures/reference-cpp/src/worker.cpp
vendored
Normal file
17
tests/fixtures/reference-cpp/src/worker.cpp
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#include "../include/config.hpp"
|
||||
|
||||
namespace demo {
|
||||
|
||||
class Worker {
|
||||
public:
|
||||
int run(int value) {
|
||||
for (int attempt = 0; attempt < 2; ++attempt) {
|
||||
if (value > attempt) {
|
||||
return effective_limit(Config{value});
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace demo
|
||||
Loading…
Add table
Add a link
Reference in a new issue