Skip to content

Instantly share code, notes, and snippets.

@waywardmonkeys
Created February 26, 2013 09:48
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 waywardmonkeys/5037344 to your computer and use it in GitHub Desktop.
Save waywardmonkeys/5037344 to your computer and use it in GitHub Desktop.
Test case for possible emscripten compiler bug
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <algorithm>
// template<InputIterator Iter1, InputIterator Iter2>
// requires HasLess<Iter1::value_type, Iter2::value_type>
// && HasLess<Iter2::value_type, Iter1::value_type>
// bool
// includes(Iter1 first1, Iter1 last1, Iter2 first2, Iter2 last2);
#include <algorithm>
#include <cassert>
#include <iterator>
template <class It>
class input_iterator
{
It it_;
template <class U> friend class input_iterator;
public:
typedef std::input_iterator_tag iterator_category;
typedef typename std::iterator_traits<It>::value_type value_type;
typedef typename std::iterator_traits<It>::difference_type difference_type;
typedef It pointer;
typedef typename std::iterator_traits<It>::reference reference;
It base() const {return it_;}
input_iterator() : it_() {}
explicit input_iterator(It it) : it_(it) {}
template <class U>
input_iterator(const input_iterator<U>& u) :it_(u.it_) {}
reference operator*() const {return *it_;}
pointer operator->() const {return it_;}
input_iterator& operator++() {++it_; return *this;}
input_iterator operator++(int)
{input_iterator tmp(*this); ++(*this); return tmp;}
friend bool operator==(const input_iterator& x, const input_iterator& y)
{return x.it_ == y.it_;}
friend bool operator!=(const input_iterator& x, const input_iterator& y)
{return !(x == y);}
};
template <class T, class U>
inline
bool
operator==(const input_iterator<T>& x, const input_iterator<U>& y)
{
return x.base() == y.base();
}
template <class T, class U>
inline
bool
operator!=(const input_iterator<T>& x, const input_iterator<U>& y)
{
return !(x == y);
}
template <class Iter>
inline Iter base(input_iterator<Iter> i) { return i.base(); }
template <class Iter1, class Iter2>
void
test()
{
int ia[] = {1, 2, 2, 3, 3, 3, 4, 4, 4, 4};
const unsigned sa = sizeof(ia)/sizeof(ia[0]);
assert(std::includes(Iter1(ia), Iter1(ia+sa), Iter2(ia), Iter2(ia+sa)));
}
int main()
{
test<input_iterator<const int*>, input_iterator<const int*> >();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment