Created
February 26, 2013 09:48
-
-
Save waywardmonkeys/5037344 to your computer and use it in GitHub Desktop.
Test case for possible emscripten compiler bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//===----------------------------------------------------------------------===// | |
// | |
// 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