Example
void newapi();
void oldapi() = delete("This old API is outdated and already been removed. Please use newapi() instead.");
int main () {
oldapi();
}
Puzzle
- Can you implment simplified addressof with
delete("Cannot take address of rvalue.")
when used incorreclty?
// TODO addressof
int main() {
int i{};
addressof(i); // okay
addressof(int{}); // error: "Cannot take address of rvalue."
}
Solutions
template<class T> constexpr T* addressof(T& r) noexcept { return &r; }
template<class T> const T* addressof(const T&&) = delete("Cannot take address of rvalue.");
int main() {
int i{};
addressof(i); // okay
addressof(int{}); // error: "Cannot take address of rvalue."
}