minix/external/bsd/libc++/dist/libcxx/test/iterators/predef.iterators/move.iterators/move.iter.ops/move.iter.op.star/op_star.pass.cpp
Lionel Sambuc 4684ddb6aa LLVM Minix changes
- import libcxx
 - reduce targets to the one when compiled as a tools

Change-Id: Iabb8427f80ff8e89463559a28bcb8b4f2bdbc496
2014-07-28 17:05:59 +02:00

61 lines
1.3 KiB
C++

//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <iterator>
// move_iterator
// reference operator*() const;
#include <iterator>
#include <cassert>
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
#include <memory>
#endif
class A
{
int data_;
public:
A() : data_(1) {}
~A() {data_ = -1;}
friend bool operator==(const A& x, const A& y)
{return x.data_ == y.data_;}
};
template <class It>
void
test(It i, typename std::iterator_traits<It>::value_type x)
{
std::move_iterator<It> r(i);
assert(*r == x);
typename std::iterator_traits<It>::value_type x2 = *r;
assert(x2 == x);
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
struct do_nothing
{
void operator()(void*) const {}
};
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
int main()
{
A a;
test(&a, A());
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
int i;
std::unique_ptr<int, do_nothing> p(&i);
test(&p, std::unique_ptr<int, do_nothing>(&i));
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}