mirror of
https://github.com/mfocko/blog.git
synced 2025-05-08 12:22:58 +02:00
deploy: c06941d75a
This commit is contained in:
parent
34fc48031b
commit
e7e47384d5
125 changed files with 414 additions and 198 deletions
files
algorithms
graphs
recursion
time-complexity
c/bonuses
03.tar.bz203.tar.gz04.tar.bz204.tar.gz05-06.tar.bz205-06.tar.gz08.tar.bz208.tar.gz10.tar.bz210.tar.gz
cpp/exceptions-and-raii/placeholders
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
77
files/cpp/exceptions-and-raii/placeholders/placeholders.hpp
Normal file
77
files/cpp/exceptions-and-raii/placeholders/placeholders.hpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
#include <exception>
|
||||
#include <format>
|
||||
#include <string>
|
||||
|
||||
class _todo : public std::exception {
|
||||
std::string cause;
|
||||
|
||||
public:
|
||||
_todo() : cause("not yet implemented") {}
|
||||
_todo(std::string&& excuse) : cause("not yet implemented: " + excuse) {}
|
||||
virtual const char* what() const throw() { return cause.c_str(); }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Indicates unfinished code.
|
||||
*/
|
||||
void todo() { throw _todo(); }
|
||||
|
||||
/**
|
||||
* @brief Indicates unfinished code.
|
||||
* @param fmt an object that represents the format string
|
||||
* @param args arguments to be formatted
|
||||
*/
|
||||
template <class... Args>
|
||||
void todo(std::format_string<Args...> fmt, Args&&... args) {
|
||||
throw _todo(std::format(fmt, args...));
|
||||
}
|
||||
|
||||
class _unimplemented : public std::exception {
|
||||
std::string cause;
|
||||
|
||||
public:
|
||||
_unimplemented() : cause("not implemented") {}
|
||||
_unimplemented(std::string&& excuse)
|
||||
: cause("not implemented: " + excuse) {}
|
||||
virtual const char* what() const throw() { return cause.c_str(); }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Indicates unimplemented code by throwing with a message of “not implemented”.
|
||||
*/
|
||||
void unimplemented() { throw _unimplemented(); }
|
||||
|
||||
/**
|
||||
* @brief Indicates unimplemented code by throwing with a message of “not implemented”.
|
||||
* @param fmt an object that represents the format string
|
||||
* @param args arguments to be formatted
|
||||
*/
|
||||
template <class... Args>
|
||||
void unimplemented(std::format_string<Args...> fmt, Args&&... args) {
|
||||
throw _unimplemented(std::format(fmt, args...));
|
||||
}
|
||||
|
||||
class _unreachable : public std::exception {
|
||||
std::string cause;
|
||||
|
||||
public:
|
||||
_unreachable() : cause("entered unreachable code") {}
|
||||
_unreachable(std::string&& excuse)
|
||||
: cause("entered unreachable code: " + excuse) {}
|
||||
virtual const char* what() const throw() { return cause.c_str(); }
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Indicates unreachable code.
|
||||
*/
|
||||
void unreachable() { throw _unreachable(); }
|
||||
|
||||
/**
|
||||
* @brief Indicates unreachable code.
|
||||
* @param fmt an object that represents the format string
|
||||
* @param args arguments to be formatted
|
||||
*/
|
||||
template <class... Args>
|
||||
void unreachable(std::format_string<Args...> fmt, Args&&... args) {
|
||||
throw _unreachable(std::format(fmt, args...));
|
||||
}
|
6
files/cpp/exceptions-and-raii/placeholders/test.cpp
Normal file
6
files/cpp/exceptions-and-raii/placeholders/test.cpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#include "placeholders.hpp"
|
||||
|
||||
int main() {
|
||||
todo("finish later ({})", "in 3 days");
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue