Created
March 30, 2021 12:59
-
-
Save sharkdp/76a219b864145bfce0e81f574afeb547 to your computer and use it in GitHub Desktop.
A todo() macro for C++, inspired by Rusts todo!()
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> | |
struct todo_statement { | |
public: | |
todo_statement(const char* file, const int line) | |
: m_file(file), m_line(line) {} | |
template <typename T> | |
operator T() { | |
std::cerr << "Error: Remove todo() statement in " << m_file << ":" << m_line | |
<< std::endl; | |
throw; | |
} | |
const char* m_file; | |
const int m_line; | |
}; | |
#define todo() (todo_statement{__FILE__, __LINE__}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The idea is that you can put
todo()
in places where you still need to write some code. Due to the genericoperator T()
implementation, the resulting expression can be cast into any type. At least during compile time.