Skip to content

Instantly share code, notes, and snippets.

@bolero-MURAKAMI
Created March 21, 2014 06:09
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 bolero-MURAKAMI/9680516 to your computer and use it in GitHub Desktop.
Save bolero-MURAKAMI/9680516 to your computer and use it in GitHub Desktop.
namespace std {
// 24.7, range access:
template <class C> auto begin(C& c) -> decltype(c.begin())
{ return c.begin(); }
template <class C> auto begin(const C& c) -> decltype(c.begin())
{ return c.begin(); }
template <class C> auto end(C& c) -> decltype(c.end())
{ return c.end(); }
template <class C> auto end(const C& c) -> decltype(c.end())
{ return c.end(); }
template <class C> constexpr auto cbegin(const C& c) noexcept(noexcept(std::begin(c))) -> decltype(std::begin(c))
{ return std::begin(c); }
template <class C> constexpr auto cend(const C& c) noexcept(noexcept(std::end(c))) -> decltype(std::end(c))
{ return std::end(c); }
template <class C> auto rbegin(C& c) -> decltype(c.rbegin())
{ return c.rbegin(); }
template <class C> auto rbegin(const C& c) -> decltype(c.rbegin())
{ return c.rbegin(); }
template <class C> auto rend(C& c) -> decltype(c.rend())
{ return c.rend(); }
template <class C> auto rend(const C& c) -> decltype(c.rend())
{ return c.rend(); }
template <class T, size_t N> reverse_iterator<T*> rbegin(T (&array)[N]);
{ return reverse_iterator<T*>(array + N); }
template <class T, size_t N> reverse_iterator<T*> rend(T (&array)[N]);
{ return reverse_iterator<T*>(array + 0); }
template <class E> reverse_iterator<const E*> rbegin(initializer_list<E> il);
{ return reverse_iterator<const E*>(il.end()); }
template <class E> reverse_iterator<const E*> rend(initializer_list<E> il);
{ return reverse_iterator<const E*>(il.begin()); }
template <class C> auto crbegin(const C& c) -> decltype(std::rbegin(c));
{ return c.rbegin(); }
template <class C> auto crend(const C& c) -> decltype(std::rend(c));
{ return c.rend(); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment