Skip to content

Instantly share code, notes, and snippets.

@dwaite
Created March 24, 2010 17:33
Show Gist options
  • Save dwaite/342528 to your computer and use it in GitHub Desktop.
Save dwaite/342528 to your computer and use it in GitHub Desktop.
#include <list>
#include <stdexcept>
template <class T, class Allocator = std::allocator<T> >
class my_list : public std::list<T,Allocator> {
public:
typedef typename std::list<T,Allocator>::reference reference;
typedef typename std::list<T,Allocator>::const_reference const_reference;
reference back() {
if (this->empty()) {
throw std::runtime_error("No entries in list, back not possible");
}
return std::list<T,Allocator>::back();
}
const_reference back() const {
if (this->empty()) {
throw std::runtime_error("blah blah");
}
return std::list<T,Allocator>::back();
}
};
int main() {
my_list<int> foo;
foo.back();
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment