Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- struct CoverageNode
- {
- CoverageNode(const int in_line)
- : line(in_line)
- {
- if (first)
- {
- next = first;
- }
- first = this;
- }
- int line;
- bool covered;
- CoverageNode *next;
- static CoverageNode *first;
- };
- CoverageNode *CoverageNode::first;
- template<class Function>
- void for_each_coverage(const Function &function)
- {
- for (const auto *node = CoverageNode::first; node; node = node->next)
- {
- function(*node);
- }
- }
- template<int line>
- struct LineCoverage
- {
- static CoverageNode node;
- };
- template<int line>
- CoverageNode LineCoverage<line>::node = CoverageNode(line);
- #define BRANCH() LineCoverage<__LINE__>::node.covered = true
- void foo(const bool b)
- {
- if (b)
- BRANCH();
- else
- BRANCH();
- }
- int main()
- {
- foo(false);
- for_each_coverage([] (const CoverageNode &node) {
- std::cout << node.line << " " << node.covered << std::endl;
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement