// file : butl/utility -*- C++ -*- // copyright : Copyright (c) 2014-2015 Code Synthesis Ltd // license : MIT; see accompanying LICENSE file #ifndef BUTL_UTILITY #define BUTL_UTILITY #include // forward() #include // strcmp namespace butl { // Key comparators (i.e., to be used in sets, maps, etc). // struct compare_c_string { bool operator() (const char* x, const char* y) const { return std::strcmp (x, y) < 0; } }; struct compare_pointer_target { template bool operator() (const P& x, const P& y) const {return *x < *y;} }; // Support for reverse iteration using range-based for-loop: // // for (... : reverse_iterate (x)) ... // template class reverse_range { T x_; public: reverse_range (T&& x): x_ (std::forward (x)) {} auto begin () const -> decltype (this->x_.rbegin ()) {return x_.rbegin ();} auto end () const -> decltype (this->x_.rend ()) {return x_.rend ();} }; template inline reverse_range reverse_iterate (T&& x) {return reverse_range (std::forward (x));} } #endif // BUTL_UTILITY