diff --git a/alib2std/src/extensions/forward_list.hpp b/alib2std/src/extensions/forward_list.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9885280ad58283f636a3125510658f98757684d3 --- /dev/null +++ b/alib2std/src/extensions/forward_list.hpp @@ -0,0 +1,46 @@ +/* + * forward_list.hpp + * + * Created on: Apr 1, 2013 + * Author: Jan Travnicek + */ + +#ifndef __FORWARD_LIST_HPP_ +#define __FORWARD_LIST_HPP_ + +namespace std { + +template< class T, class ... Ts > +std::ostream& operator<<(std::ostream& out, const std::forward_list<T, Ts ... >& forward_list) { + out << "["; + + bool first = true; + for(const T& item : forward_list) { + if(!first) out << ", "; + first = false; + out << item; + } + + out << "]"; + return out; +} + +template<class T, class ... Ts > +struct compare<forward_list<T, Ts ... >> { + int operator()(const forward_list<T, Ts ... >& first, const forward_list<T, Ts ... >& second) const { + if(first.size() < second.size()) return -1; + if(first.size() > second.size()) return 1; + + compare<typename std::decay < T >::type > comp; + for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) { + int res = comp(*iterF, *iterS); + if(res != 0) return res; + } + return 0; + } +}; + +} /* namespace std */ + +#endif /* __FORWARD_LIST_HPP_ */ + diff --git a/alib2std/src/forward_list b/alib2std/src/forward_list new file mode 100644 index 0000000000000000000000000000000000000000..be20a3ec6e84d4cfdec5b398018f4aa0829faa79 --- /dev/null +++ b/alib2std/src/forward_list @@ -0,0 +1,10 @@ +#ifndef __LIST_HEADER_WRAPPER_ +#define __LIST_HEADER_WRAPPER_ + +#include <bits/../forward_list> +#include <ostream> +#include "compare" +#include "extensions/forward_list.hpp" + +#endif /* __LIST_HEADER_WRAPPER_ */ +