Skip to content

Instantly share code, notes, and snippets.

@Jules-Baratoux
Created October 28, 2014 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jules-Baratoux/6a7b5e992fcbf5ff6c8c to your computer and use it in GitHub Desktop.
Save Jules-Baratoux/6a7b5e992fcbf5ff6c8c to your computer and use it in GitHub Desktop.
#include <cassert>
template <typename T>
struct proxy
{
const T& value;
bool previous;
proxy(const T& value, bool previous) : value(value), previous(previous) {}
operator bool ()
{
return previous;
}
proxy<T> operator or (const T& rhs)
{
return proxy<T>(value, previous or value == rhs);
}
};
template <typename T>
proxy<T> operator == (const T& lhs, const T& rhs)
{
return proxy<T>(lhs, lhs == rhs);
}
int main()
{
assert(5 != 6);
assert(5 == 5);
assert(5 == 5 or 6);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment