Skip to content

Instantly share code, notes, and snippets.

@Loki-Astari
Last active October 20, 2016 18:05
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 Loki-Astari/7b61e217386ad91a0a5c79815ace196c to your computer and use it in GitHub Desktop.
Save Loki-Astari/7b61e217386ad91a0a5c79815ace196c to your computer and use it in GitHub Desktop.
template<typename T>
Iterator<T> operator + (Iterator<T> lhs, int const rhs) {return lhs += rhs;}
template<typename T>
Iterator<T> operator - (Iterator<T> lhs, int const rhs) {return lhs -= rhs;}
template<typename T>
Iterator<T> operator * (Iterator<T> lhs, int const rhs) {return lhs *= rhs;}
template<typename T>
Iterator<T> operator / (Iterator<T> lhs, int const rhs) {return lhs /= rhs;}
#define OP_FROM_SELF_ASSIGN_OP(op) \
template<typename T> \
Iterator<T> operator op (Iterator<T> const & lhs, \
int const rhs) \
{ \
Iterator<T> copy = Iterator<T>(lhs); \
copy op ## = rhs; \
return copy; \
}
OP_FROM_SELF_ASSIGN_OP(+)
OP_FROM_SELF_ASSIGN_OP(-)
OP_FROM_SELF_ASSIGN_OP(*)
OP_FROM_SELF_ASSIGN_OP(/)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment