Move test into test/std subdirectory.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2014-12-20 01:40:03 +00:00
parent 669a8a5a19
commit a90c6dd460
4817 changed files with 13 additions and 0 deletions

View File

@@ -0,0 +1,12 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
int main()
{
}

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
//
// Tuples of smart pointers; based on bug #18350
// auto_ptr doesn't have a copy constructor that takes a const &, but tuple does.
#include <tuple>
#include <memory>
int main () {
{
std::tuple<std::unique_ptr<char>> up;
std::tuple<std::shared_ptr<char>> sp;
std::tuple<std::weak_ptr <char>> wp;
// std::tuple<std::auto_ptr <char>> ap;
}
{
std::tuple<std::unique_ptr<char[]>> up;
std::tuple<std::shared_ptr<char[]>> sp;
std::tuple<std::weak_ptr <char[]>> wp;
// std::tuple<std::auto_ptr <char[]>> ap;
}
{
std::tuple<std::unique_ptr<char[5]>> up;
std::tuple<std::shared_ptr<char[5]>> sp;
std::tuple<std::weak_ptr <char[5]>> wp;
// std::tuple<std::auto_ptr <char[5]>> ap;
}
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#ifndef MOVEONLY_H
#define MOVEONLY_H
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
#include <cstddef>
#include <functional>
class MoveOnly
{
MoveOnly(const MoveOnly&);
MoveOnly& operator=(const MoveOnly&);
int data_;
public:
MoveOnly(int data = 1) : data_(data) {}
MoveOnly(MoveOnly&& x)
: data_(x.data_) {x.data_ = 0;}
MoveOnly& operator=(MoveOnly&& x)
{data_ = x.data_; x.data_ = 0; return *this;}
int get() const {return data_;}
bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
};
namespace std {
template <>
struct hash<MoveOnly>
: public std::unary_function<MoveOnly, std::size_t>
{
std::size_t operator()(const MoveOnly& x) const {return x.get();}
};
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif // MOVEONLY_H

View File

@@ -0,0 +1,35 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// This is for bugs 18853 and 19118
#if __cplusplus >= 201103L
#include <tuple>
#include <functional>
struct X
{
X() {}
template <class T>
X(T);
void operator()() {}
};
int
main()
{
X x;
std::function<void()> f(x);
}
#else
int main () {}
#endif

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#ifndef ALLOC_FIRST_H
#define ALLOC_FIRST_H
#include <cassert>
#include "allocators.h"
struct alloc_first
{
static bool allocator_constructed;
typedef A1<int> allocator_type;
int data_;
alloc_first() : data_(0) {}
alloc_first(int d) : data_(d) {}
alloc_first(std::allocator_arg_t, const A1<int>& a)
: data_(0)
{
assert(a.id() == 5);
allocator_constructed = true;
}
alloc_first(std::allocator_arg_t, const A1<int>& a, int d)
: data_(d)
{
assert(a.id() == 5);
allocator_constructed = true;
}
alloc_first(std::allocator_arg_t, const A1<int>& a, const alloc_first& d)
: data_(d.data_)
{
assert(a.id() == 5);
allocator_constructed = true;
}
~alloc_first() {data_ = -1;}
friend bool operator==(const alloc_first& x, const alloc_first& y)
{return x.data_ == y.data_;}
friend bool operator< (const alloc_first& x, const alloc_first& y)
{return x.data_ < y.data_;}
};
bool alloc_first::allocator_constructed = false;
#endif // ALLOC_FIRST_H

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#ifndef ALLOC_LAST_H
#define ALLOC_LAST_H
#include <cassert>
#include "allocators.h"
struct alloc_last
{
static bool allocator_constructed;
typedef A1<int> allocator_type;
int data_;
alloc_last() : data_(0) {}
alloc_last(int d) : data_(d) {}
alloc_last(const A1<int>& a)
: data_(0)
{
assert(a.id() == 5);
allocator_constructed = true;
}
alloc_last(int d, const A1<int>& a)
: data_(d)
{
assert(a.id() == 5);
allocator_constructed = true;
}
alloc_last(const alloc_last& d, const A1<int>& a)
: data_(d.data_)
{
assert(a.id() == 5);
allocator_constructed = true;
}
~alloc_last() {data_ = -1;}
friend bool operator==(const alloc_last& x, const alloc_last& y)
{return x.data_ == y.data_;}
friend bool operator< (const alloc_last& x, const alloc_last& y)
{return x.data_ < y.data_;}
};
bool alloc_last::allocator_constructed = false;
#endif // ALLOC_LAST_H

View File

@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// This is not a portable test
#include <tuple>
struct A {};
struct B {};
int main()
{
{
typedef std::tuple<int, A> T;
static_assert((sizeof(T) == sizeof(int)), "");
}
{
typedef std::tuple<A, int> T;
static_assert((sizeof(T) == sizeof(int)), "");
}
{
typedef std::tuple<A, int, B> T;
static_assert((sizeof(T) == sizeof(int)), "");
}
{
typedef std::tuple<A, B, int> T;
static_assert((sizeof(T) == sizeof(int)), "");
}
{
typedef std::tuple<int, A, B> T;
static_assert((sizeof(T) == sizeof(int)), "");
}
}

View File

@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class U1, class U2>
// tuple& operator=(const pair<U1, U2>& u);
#include <tuple>
#include <utility>
#include <cassert>
int main()
{
{
typedef std::pair<double, char> T0;
typedef std::tuple<int, short> T1;
T0 t0(2.5, 'a');
T1 t1;
t1 = t0;
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == short('a'));
}
}

View File

@@ -0,0 +1,75 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class... UTypes>
// tuple& operator=(const tuple<UTypes...>& u);
#include <tuple>
#include <string>
#include <cassert>
struct B
{
int id_;
explicit B(int i = 0) : id_(i) {}
};
struct D
: B
{
explicit D(int i = 0) : B(i) {}
};
int main()
{
{
typedef std::tuple<double> T0;
typedef std::tuple<int> T1;
T0 t0(2.5);
T1 t1;
t1 = t0;
assert(std::get<0>(t1) == 2);
}
{
typedef std::tuple<double, char> T0;
typedef std::tuple<int, int> T1;
T0 t0(2.5, 'a');
T1 t1;
t1 = t0;
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
}
{
typedef std::tuple<double, char, D> T0;
typedef std::tuple<int, int, B> T1;
T0 t0(2.5, 'a', D(3));
T1 t1;
t1 = t0;
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
assert(std::get<2>(t1).id_ == 3);
}
{
D d(3);
D d2(2);
typedef std::tuple<double, char, D&> T0;
typedef std::tuple<int, int, B&> T1;
T0 t0(2.5, 'a', d2);
T1 t1(1.5, 'b', d);
t1 = t0;
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
assert(std::get<2>(t1).id_ == 2);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class... UTypes>
// tuple& operator=(tuple<UTypes...>&& u);
#include <tuple>
#include <string>
#include <memory>
#include <cassert>
struct B
{
int id_;
explicit B(int i= 0) : id_(i) {}
virtual ~B() {}
};
struct D
: B
{
explicit D(int i) : B(i) {}
};
int main()
{
{
typedef std::tuple<double> T0;
typedef std::tuple<int> T1;
T0 t0(2.5);
T1 t1;
t1 = std::move(t0);
assert(std::get<0>(t1) == 2);
}
{
typedef std::tuple<double, char> T0;
typedef std::tuple<int, int> T1;
T0 t0(2.5, 'a');
T1 t1;
t1 = std::move(t0);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
}
{
typedef std::tuple<double, char, D> T0;
typedef std::tuple<int, int, B> T1;
T0 t0(2.5, 'a', D(3));
T1 t1;
t1 = std::move(t0);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
assert(std::get<2>(t1).id_ == 3);
}
{
D d(3);
D d2(2);
typedef std::tuple<double, char, D&> T0;
typedef std::tuple<int, int, B&> T1;
T0 t0(2.5, 'a', d2);
T1 t1(1.5, 'b', d);
t1 = std::move(t0);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
assert(std::get<2>(t1).id_ == 2);
}
{
typedef std::tuple<double, char, std::unique_ptr<D>> T0;
typedef std::tuple<int, int, std::unique_ptr<B>> T1;
T0 t0(2.5, 'a', std::unique_ptr<D>(new D(3)));
T1 t1;
t1 = std::move(t0);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
assert(std::get<2>(t1)->id_ == 3);
}
}

View File

@@ -0,0 +1,29 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// tuple& operator=(const tuple& u);
#include <tuple>
#include <cassert>
#include "../MoveOnly.h"
int main()
{
{
typedef std::tuple<MoveOnly> T;
T t0(MoveOnly(2));
T t;
t = t0;
}
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// tuple& operator=(const tuple& u);
#include <tuple>
#include <string>
#include <cassert>
int main()
{
{
typedef std::tuple<> T;
T t0;
T t;
t = t0;
}
{
typedef std::tuple<int> T;
T t0(2);
T t;
t = t0;
assert(std::get<0>(t) == 2);
}
{
typedef std::tuple<int, char> T;
T t0(2, 'a');
T t;
t = t0;
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == 'a');
}
{
typedef std::tuple<int, char, std::string> T;
const T t0(2, 'a', "some text");
T t;
t = t0;
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == 'a');
assert(std::get<2>(t) == "some text");
}
}

View File

@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// tuple& operator=(tuple&& u);
#include <tuple>
#include <cassert>
#include "../MoveOnly.h"
int main()
{
{
typedef std::tuple<> T;
T t0;
T t;
t = std::move(t0);
}
{
typedef std::tuple<MoveOnly> T;
T t0(MoveOnly(0));
T t;
t = std::move(t0);
assert(std::get<0>(t) == 0);
}
{
typedef std::tuple<MoveOnly, MoveOnly> T;
T t0(MoveOnly(0), MoveOnly(1));
T t;
t = std::move(t0);
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 1);
}
{
typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T;
T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2));
T t;
t = std::move(t0);
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 1);
assert(std::get<2>(t) == 2);
}
}

View File

@@ -0,0 +1,48 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class U1, class U2>
// tuple& operator=(pair<U1, U2>&& u);
#include <tuple>
#include <utility>
#include <memory>
#include <cassert>
struct B
{
int id_;
explicit B(int i = 0) : id_(i) {}
virtual ~B() {}
};
struct D
: B
{
explicit D(int i) : B(i) {}
};
int main()
{
{
typedef std::pair<double, std::unique_ptr<D>> T0;
typedef std::tuple<int, std::unique_ptr<B>> T1;
T0 t0(2.5, std::unique_ptr<D>(new D(3)));
T1 t1;
t1 = std::move(t0);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1)->id_ == 3);
}
}

View File

@@ -0,0 +1,32 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class Tuple, __tuple_assignable<Tuple, tuple> >
// tuple & operator=(Tuple &&);
// This test checks that we do not evaluate __make_tuple_types
// on the array when it doesn't match the size of the tuple.
#include <array>
#include <tuple>
// Use 1256 to try and blow the template instantiation depth for all compilers.
typedef std::array<char, 1256> array_t;
typedef std::tuple<array_t> tuple_t;
int main()
{
array_t arr;
tuple_t tup;
tup = arr;
}

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class... UTypes>
// explicit tuple(UTypes&&... u);
/*
This is testing an extension whereby only Types having an explicit conversion
from UTypes are bound by the explicit tuple constructor.
*/
#include <tuple>
#include <cassert>
class MoveOnly
{
MoveOnly(const MoveOnly&);
MoveOnly& operator=(const MoveOnly&);
int data_;
public:
explicit MoveOnly(int data = 1) : data_(data) {}
MoveOnly(MoveOnly&& x)
: data_(x.data_) {x.data_ = 0;}
MoveOnly& operator=(MoveOnly&& x)
{data_ = x.data_; x.data_ = 0; return *this;}
int get() const {return data_;}
bool operator==(const MoveOnly& x) const {return data_ == x.data_;}
bool operator< (const MoveOnly& x) const {return data_ < x.data_;}
};
int main()
{
{
std::tuple<MoveOnly> t = 1;
}
}

View File

@@ -0,0 +1,144 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class... UTypes>
// explicit tuple(UTypes&&... u);
#include <tuple>
#include <cassert>
#include <type_traits>
#include "../MoveOnly.h"
#if _LIBCPP_STD_VER > 11
struct Empty {};
struct A
{
int id_;
explicit constexpr A(int i) : id_(i) {}
};
#endif
struct NoDefault { NoDefault() = delete; };
// Make sure the _Up... constructor SFINAEs out when the types that
// are not explicitly initialized are not all default constructible.
// Otherwise, std::is_constructible would return true but instantiating
// the constructor would fail.
void test_default_constructible_extension_sfinae()
{
{
typedef std::tuple<MoveOnly, NoDefault> Tuple;
static_assert(!std::is_constructible<
Tuple,
MoveOnly
>::value, "");
static_assert(std::is_constructible<
Tuple,
MoveOnly, NoDefault
>::value, "");
}
{
typedef std::tuple<MoveOnly, MoveOnly, NoDefault> Tuple;
static_assert(!std::is_constructible<
Tuple,
MoveOnly, MoveOnly
>::value, "");
static_assert(std::is_constructible<
Tuple,
MoveOnly, MoveOnly, NoDefault
>::value, "");
}
{
// Same idea as above but with a nested tuple type.
typedef std::tuple<MoveOnly, NoDefault> Tuple;
typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple;
static_assert(!std::is_constructible<
NestedTuple,
MoveOnly, MoveOnly, MoveOnly, MoveOnly
>::value, "");
static_assert(std::is_constructible<
NestedTuple,
MoveOnly, Tuple, MoveOnly, MoveOnly
>::value, "");
}
{
typedef std::tuple<MoveOnly, int> Tuple;
typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple;
static_assert(std::is_constructible<
NestedTuple,
MoveOnly, MoveOnly, MoveOnly, MoveOnly
>::value, "");
static_assert(std::is_constructible<
NestedTuple,
MoveOnly, Tuple, MoveOnly, MoveOnly
>::value, "");
}
}
int main()
{
{
std::tuple<MoveOnly> t(MoveOnly(0));
assert(std::get<0>(t) == 0);
}
{
std::tuple<MoveOnly, MoveOnly> t(MoveOnly(0), MoveOnly(1));
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 1);
}
{
std::tuple<MoveOnly, MoveOnly, MoveOnly> t(MoveOnly(0),
MoveOnly(1),
MoveOnly(2));
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 1);
assert(std::get<2>(t) == 2);
}
// extensions
{
std::tuple<MoveOnly, MoveOnly, MoveOnly> t(MoveOnly(0),
MoveOnly(1));
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 1);
assert(std::get<2>(t) == MoveOnly());
}
{
std::tuple<MoveOnly, MoveOnly, MoveOnly> t(MoveOnly(0));
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == MoveOnly());
assert(std::get<2>(t) == MoveOnly());
}
#if _LIBCPP_STD_VER > 11
{
constexpr std::tuple<Empty> t0{Empty()};
}
{
constexpr std::tuple<A, A> t(3, 2);
static_assert(std::get<0>(t).id_ == 3, "");
}
#endif
// Check that SFINAE is properly applied with the default reduced arity
// constructor extensions.
test_default_constructible_extension_sfinae();
}

View File

@@ -0,0 +1,79 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class Alloc>
// tuple(allocator_arg_t, const Alloc& a);
#include <tuple>
#include <cassert>
#include "DefaultOnly.h"
#include "allocators.h"
#include "../alloc_first.h"
#include "../alloc_last.h"
int main()
{
{
std::tuple<> t(std::allocator_arg, A1<int>());
}
{
std::tuple<int> t(std::allocator_arg, A1<int>());
assert(std::get<0>(t) == 0);
}
{
std::tuple<DefaultOnly> t(std::allocator_arg, A1<int>());
assert(std::get<0>(t) == DefaultOnly());
}
{
assert(!alloc_first::allocator_constructed);
std::tuple<alloc_first> t(std::allocator_arg, A1<int>(5));
assert(alloc_first::allocator_constructed);
assert(std::get<0>(t) == alloc_first());
}
{
assert(!alloc_last::allocator_constructed);
std::tuple<alloc_last> t(std::allocator_arg, A1<int>(5));
assert(alloc_last::allocator_constructed);
assert(std::get<0>(t) == alloc_last());
}
{
alloc_first::allocator_constructed = false;
std::tuple<DefaultOnly, alloc_first> t(std::allocator_arg, A1<int>(5));
assert(std::get<0>(t) == DefaultOnly());
assert(alloc_first::allocator_constructed);
assert(std::get<1>(t) == alloc_first());
}
{
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
std::tuple<DefaultOnly, alloc_first, alloc_last> t(std::allocator_arg,
A1<int>(5));
assert(std::get<0>(t) == DefaultOnly());
assert(alloc_first::allocator_constructed);
assert(std::get<1>(t) == alloc_first());
assert(alloc_last::allocator_constructed);
assert(std::get<2>(t) == alloc_last());
}
{
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
std::tuple<DefaultOnly, alloc_first, alloc_last> t(std::allocator_arg,
A2<int>(5));
assert(std::get<0>(t) == DefaultOnly());
assert(!alloc_first::allocator_constructed);
assert(std::get<1>(t) == alloc_first());
assert(!alloc_last::allocator_constructed);
assert(std::get<2>(t) == alloc_last());
}
}

View File

@@ -0,0 +1,139 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class Alloc, class... UTypes>
// tuple(allocator_arg_t, const Alloc& a, UTypes&&...);
#include <tuple>
#include <cassert>
#include "../MoveOnly.h"
#include "allocators.h"
#include "../alloc_first.h"
#include "../alloc_last.h"
struct NoDefault { NoDefault() = delete; };
// Make sure the _Up... constructor SFINAEs out when the types that
// are not explicitly initialized are not all default constructible.
// Otherwise, std::is_constructible would return true but instantiating
// the constructor would fail.
void test_default_constructible_extension_sfinae()
{
{
typedef std::tuple<MoveOnly, NoDefault> Tuple;
static_assert(!std::is_constructible<
Tuple,
std::allocator_arg_t, A1<int>, MoveOnly
>::value, "");
static_assert(std::is_constructible<
Tuple,
std::allocator_arg_t, A1<int>, MoveOnly, NoDefault
>::value, "");
}
{
typedef std::tuple<MoveOnly, MoveOnly, NoDefault> Tuple;
static_assert(!std::is_constructible<
std::tuple<MoveOnly, MoveOnly, NoDefault>,
std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly
>::value, "");
static_assert(std::is_constructible<
std::tuple<MoveOnly, MoveOnly, NoDefault>,
std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, NoDefault
>::value, "");
}
{
// Same idea as above but with a nested tuple
typedef std::tuple<MoveOnly, NoDefault> Tuple;
typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple;
static_assert(!std::is_constructible<
NestedTuple,
std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, MoveOnly, MoveOnly
>::value, "");
static_assert(std::is_constructible<
NestedTuple,
std::allocator_arg_t, A1<int>, MoveOnly, Tuple, MoveOnly, MoveOnly
>::value, "");
}
{
typedef std::tuple<MoveOnly, int> Tuple;
typedef std::tuple<MoveOnly, Tuple, MoveOnly, MoveOnly> NestedTuple;
static_assert(std::is_constructible<
NestedTuple,
std::allocator_arg_t, A1<int>, MoveOnly, MoveOnly, MoveOnly, MoveOnly
>::value, "");
static_assert(std::is_constructible<
NestedTuple,
std::allocator_arg_t, A1<int>, MoveOnly, Tuple, MoveOnly, MoveOnly
>::value, "");
}
}
int main()
{
{
std::tuple<MoveOnly> t(std::allocator_arg, A1<int>(), MoveOnly(0));
assert(std::get<0>(t) == 0);
}
{
std::tuple<MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(),
MoveOnly(0), MoveOnly(1));
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 1);
}
{
std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(),
MoveOnly(0),
1, 2);
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 1);
assert(std::get<2>(t) == 2);
}
{
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg,
A1<int>(5), 1, 2, 3);
assert(std::get<0>(t) == 1);
assert(alloc_first::allocator_constructed);
assert(std::get<1>(t) == alloc_first(2));
assert(alloc_last::allocator_constructed);
assert(std::get<2>(t) == alloc_last(3));
}
// extensions
{
std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(),
0, 1);
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 1);
assert(std::get<2>(t) == MoveOnly());
}
{
std::tuple<MoveOnly, MoveOnly, MoveOnly> t(std::allocator_arg, A1<int>(),
0);
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == MoveOnly());
assert(std::get<2>(t) == MoveOnly());
}
// Check that SFINAE is properly applied with the default reduced arity
// constructor extensions.
test_default_constructible_extension_sfinae();
}

View File

@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class Alloc>
// tuple(allocator_arg_t, const Alloc& a, const Types&...);
#include <tuple>
#include <cassert>
#include "allocators.h"
#include "../alloc_first.h"
#include "../alloc_last.h"
int main()
{
{
std::tuple<int> t(std::allocator_arg, A1<int>(), 3);
assert(std::get<0>(t) == 3);
}
{
assert(!alloc_first::allocator_constructed);
std::tuple<alloc_first> t(std::allocator_arg, A1<int>(5), alloc_first(3));
assert(alloc_first::allocator_constructed);
assert(std::get<0>(t) == alloc_first(3));
}
{
assert(!alloc_last::allocator_constructed);
std::tuple<alloc_last> t(std::allocator_arg, A1<int>(5), alloc_last(3));
assert(alloc_last::allocator_constructed);
assert(std::get<0>(t) == alloc_last(3));
}
{
alloc_first::allocator_constructed = false;
std::tuple<int, alloc_first> t(std::allocator_arg, A1<int>(5),
10, alloc_first(15));
assert(std::get<0>(t) == 10);
assert(alloc_first::allocator_constructed);
assert(std::get<1>(t) == alloc_first(15));
}
{
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg,
A1<int>(5), 1, alloc_first(2),
alloc_last(3));
assert(std::get<0>(t) == 1);
assert(alloc_first::allocator_constructed);
assert(std::get<1>(t) == alloc_first(2));
assert(alloc_last::allocator_constructed);
assert(std::get<2>(t) == alloc_last(3));
}
{
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
std::tuple<int, alloc_first, alloc_last> t(std::allocator_arg,
A2<int>(5), 1, alloc_first(2),
alloc_last(3));
assert(std::get<0>(t) == 1);
assert(!alloc_first::allocator_constructed);
assert(std::get<1>(t) == alloc_first(2));
assert(!alloc_last::allocator_constructed);
assert(std::get<2>(t) == alloc_last(3));
}
}

View File

@@ -0,0 +1,57 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class Alloc, class U1, class U2>
// tuple(allocator_arg_t, const Alloc& a, const pair<U1, U2>&);
#include <tuple>
#include <utility>
#include <cassert>
#include "allocators.h"
#include "../alloc_first.h"
#include "../alloc_last.h"
int main()
{
{
typedef std::pair<double, int> T0;
typedef std::tuple<int, double> T1;
T0 t0(2, 3);
T1 t1(std::allocator_arg, A1<int>(5), t0);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == 3);
}
{
typedef std::pair<int, int> T0;
typedef std::tuple<alloc_first, double> T1;
T0 t0(2, 3);
alloc_first::allocator_constructed = false;
T1 t1(std::allocator_arg, A1<int>(5), t0);
assert(alloc_first::allocator_constructed);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == 3);
}
{
typedef std::pair<int, int> T0;
typedef std::tuple<alloc_first, alloc_last> T1;
T0 t0(2, 3);
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
T1 t1(std::allocator_arg, A1<int>(5), t0);
assert(alloc_first::allocator_constructed);
assert(alloc_last::allocator_constructed);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == 3);
}
}

View File

@@ -0,0 +1,67 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class Alloc, class... UTypes>
// tuple(allocator_arg_t, const Alloc& a, const tuple<UTypes...>&);
#include <tuple>
#include <cassert>
#include "allocators.h"
#include "../alloc_first.h"
#include "../alloc_last.h"
int main()
{
{
typedef std::tuple<double> T0;
typedef std::tuple<int> T1;
T0 t0(2.5);
T1 t1(std::allocator_arg, A1<int>(), t0);
assert(std::get<0>(t1) == 2);
}
{
typedef std::tuple<int> T0;
typedef std::tuple<alloc_first> T1;
T0 t0(2);
alloc_first::allocator_constructed = false;
T1 t1(std::allocator_arg, A1<int>(5), t0);
assert(alloc_first::allocator_constructed);
assert(std::get<0>(t1) == 2);
}
{
typedef std::tuple<int, int> T0;
typedef std::tuple<alloc_first, alloc_last> T1;
T0 t0(2, 3);
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
T1 t1(std::allocator_arg, A1<int>(5), t0);
assert(alloc_first::allocator_constructed);
assert(alloc_last::allocator_constructed);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == 3);
}
{
typedef std::tuple<double, int, int> T0;
typedef std::tuple<int, alloc_first, alloc_last> T1;
T0 t0(1.5, 2, 3);
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
T1 t1(std::allocator_arg, A1<int>(5), t0);
assert(alloc_first::allocator_constructed);
assert(alloc_last::allocator_constructed);
assert(std::get<0>(t1) == 1);
assert(std::get<1>(t1) == 2);
assert(std::get<2>(t1) == 3);
}
}

View File

@@ -0,0 +1,82 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class Alloc, class... UTypes>
// tuple(allocator_arg_t, const Alloc& a, tuple<UTypes...>&&);
#include <tuple>
#include <string>
#include <memory>
#include <cassert>
#include "allocators.h"
#include "../alloc_first.h"
#include "../alloc_last.h"
struct B
{
int id_;
explicit B(int i) : id_(i) {}
virtual ~B() {}
};
struct D
: B
{
explicit D(int i) : B(i) {}
};
int main()
{
{
typedef std::tuple<int> T0;
typedef std::tuple<alloc_first> T1;
T0 t0(2);
alloc_first::allocator_constructed = false;
T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
assert(alloc_first::allocator_constructed);
assert(std::get<0>(t1) == 2);
}
{
typedef std::tuple<std::unique_ptr<D>> T0;
typedef std::tuple<std::unique_ptr<B>> T1;
T0 t0(std::unique_ptr<D>(new D(3)));
T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
assert(std::get<0>(t1)->id_ == 3);
}
{
typedef std::tuple<int, std::unique_ptr<D>> T0;
typedef std::tuple<alloc_first, std::unique_ptr<B>> T1;
T0 t0(2, std::unique_ptr<D>(new D(3)));
alloc_first::allocator_constructed = false;
T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
assert(alloc_first::allocator_constructed);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1)->id_ == 3);
}
{
typedef std::tuple<int, int, std::unique_ptr<D>> T0;
typedef std::tuple<alloc_last, alloc_first, std::unique_ptr<B>> T1;
T0 t0(1, 2, std::unique_ptr<D>(new D(3)));
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
assert(alloc_first::allocator_constructed);
assert(alloc_last::allocator_constructed);
assert(std::get<0>(t1) == 1);
assert(std::get<1>(t1) == 2);
assert(std::get<2>(t1)->id_ == 3);
}
}

View File

@@ -0,0 +1,76 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class Alloc>
// tuple(allocator_arg_t, const Alloc& a, const tuple&);
#include <tuple>
#include <cassert>
#include "allocators.h"
#include "../alloc_first.h"
#include "../alloc_last.h"
int main()
{
{
typedef std::tuple<> T;
T t0;
T t(std::allocator_arg, A1<int>(), t0);
}
{
typedef std::tuple<int> T;
T t0(2);
T t(std::allocator_arg, A1<int>(), t0);
assert(std::get<0>(t) == 2);
}
{
typedef std::tuple<alloc_first> T;
T t0(2);
alloc_first::allocator_constructed = false;
T t(std::allocator_arg, A1<int>(5), t0);
assert(alloc_first::allocator_constructed);
assert(std::get<0>(t) == 2);
}
{
typedef std::tuple<alloc_last> T;
T t0(2);
alloc_last::allocator_constructed = false;
T t(std::allocator_arg, A1<int>(5), t0);
assert(alloc_last::allocator_constructed);
assert(std::get<0>(t) == 2);
}
{
typedef std::tuple<alloc_first, alloc_last> T;
T t0(2, 3);
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
T t(std::allocator_arg, A1<int>(5), t0);
assert(alloc_first::allocator_constructed);
assert(alloc_last::allocator_constructed);
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == 3);
}
{
typedef std::tuple<int, alloc_first, alloc_last> T;
T t0(1, 2, 3);
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
T t(std::allocator_arg, A1<int>(5), t0);
assert(alloc_first::allocator_constructed);
assert(alloc_last::allocator_constructed);
assert(std::get<0>(t) == 1);
assert(std::get<1>(t) == 2);
assert(std::get<2>(t) == 3);
}
}

View File

@@ -0,0 +1,75 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class Alloc>
// tuple(allocator_arg_t, const Alloc& a, tuple&&);
#include <tuple>
#include <cassert>
#include "../MoveOnly.h"
#include "allocators.h"
#include "../alloc_first.h"
#include "../alloc_last.h"
int main()
{
{
typedef std::tuple<> T;
T t0;
T t(std::allocator_arg, A1<int>(), std::move(t0));
}
{
typedef std::tuple<MoveOnly> T;
T t0(MoveOnly(0));
T t(std::allocator_arg, A1<int>(), std::move(t0));
assert(std::get<0>(t) == 0);
}
{
typedef std::tuple<alloc_first> T;
T t0(1);
alloc_first::allocator_constructed = false;
T t(std::allocator_arg, A1<int>(5), std::move(t0));
assert(alloc_first::allocator_constructed);
assert(std::get<0>(t) == 1);
}
{
typedef std::tuple<alloc_last> T;
T t0(1);
alloc_last::allocator_constructed = false;
T t(std::allocator_arg, A1<int>(5), std::move(t0));
assert(alloc_last::allocator_constructed);
assert(std::get<0>(t) == 1);
}
{
typedef std::tuple<MoveOnly, alloc_first> T;
T t0(0 ,1);
alloc_first::allocator_constructed = false;
T t(std::allocator_arg, A1<int>(5), std::move(t0));
assert(alloc_first::allocator_constructed);
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 1);
}
{
typedef std::tuple<MoveOnly, alloc_first, alloc_last> T;
T t0(1, 2, 3);
alloc_first::allocator_constructed = false;
alloc_last::allocator_constructed = false;
T t(std::allocator_arg, A1<int>(5), std::move(t0));
assert(alloc_first::allocator_constructed);
assert(alloc_last::allocator_constructed);
assert(std::get<0>(t) == 1);
assert(std::get<1>(t) == 2);
assert(std::get<2>(t) == 3);
}
}

View File

@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class Alloc, class U1, class U2>
// tuple(allocator_arg_t, const Alloc& a, pair<U1, U2>&&);
#include <tuple>
#include <utility>
#include <memory>
#include <cassert>
#include "allocators.h"
#include "../alloc_first.h"
#include "../alloc_last.h"
struct B
{
int id_;
explicit B(int i) : id_(i) {}
virtual ~B() {}
};
struct D
: B
{
explicit D(int i) : B(i) {}
};
int main()
{
{
typedef std::pair<int, std::unique_ptr<D>> T0;
typedef std::tuple<alloc_first, std::unique_ptr<B>> T1;
T0 t0(2, std::unique_ptr<D>(new D(3)));
alloc_first::allocator_constructed = false;
T1 t1(std::allocator_arg, A1<int>(5), std::move(t0));
assert(alloc_first::allocator_constructed);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1)->id_ == 3);
}
}

View File

@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// explicit tuple(const T&...);
#include <tuple>
#include <string>
#include <cassert>
int main()
{
{
std::tuple<int*> t = 0;
}
}

View File

@@ -0,0 +1,130 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// explicit tuple(const T&...);
#include <tuple>
#include <string>
#include <cassert>
template <class ...>
struct never {
enum { value = 0 };
};
struct NoValueCtor
{
NoValueCtor() : id(++count) {}
NoValueCtor(NoValueCtor const & other) : id(other.id) { ++count; }
// The constexpr is required to make is_constructible instantiate this template.
// The explicit is needed to test-around a similar bug with is_convertible.
template <class T>
constexpr explicit NoValueCtor(T)
{ static_assert(never<T>::value, "This should not be instantiated"); }
static int count;
int id;
};
int NoValueCtor::count = 0;
struct NoValueCtorEmpty
{
NoValueCtorEmpty() {}
NoValueCtorEmpty(NoValueCtorEmpty const &) {}
template <class T>
constexpr explicit NoValueCtorEmpty(T)
{ static_assert(never<T>::value, "This should not be instantiated"); }
};
int main()
{
{
std::tuple<int> t(2);
assert(std::get<0>(t) == 2);
}
#if _LIBCPP_STD_VER > 11
{
constexpr std::tuple<int> t(2);
static_assert(std::get<0>(t) == 2, "");
}
{
constexpr std::tuple<int> t;
static_assert(std::get<0>(t) == 0, "");
}
#endif
{
std::tuple<int, char*> t(2, 0);
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == nullptr);
}
#if _LIBCPP_STD_VER > 11
{
constexpr std::tuple<int, char*> t(2, nullptr);
static_assert(std::get<0>(t) == 2, "");
static_assert(std::get<1>(t) == nullptr, "");
}
#endif
{
std::tuple<int, char*> t(2, nullptr);
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == nullptr);
}
{
std::tuple<int, char*, std::string> t(2, nullptr, "text");
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == nullptr);
assert(std::get<2>(t) == "text");
}
// __tuple_leaf<T> uses is_constructible<T, U> to disable its explicit converting
// constructor overload __tuple_leaf(U &&). Evaluating is_constructible can cause a compile error.
// This overload is evaluated when __tuple_leafs copy or move ctor is called.
// This checks that is_constructible is not evaluated when U == __tuple_leaf.
{
std::tuple<int, NoValueCtor, int, int> t(1, NoValueCtor(), 2, 3);
assert(std::get<0>(t) == 1);
assert(std::get<1>(t).id == 1);
assert(std::get<2>(t) == 2);
assert(std::get<3>(t) == 3);
}
{
std::tuple<int, NoValueCtorEmpty, int, int> t(1, NoValueCtorEmpty(), 2, 3);
assert(std::get<0>(t) == 1);
assert(std::get<2>(t) == 2);
assert(std::get<3>(t) == 3);
}
// extensions
{
std::tuple<int, char*, std::string> t(2);
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == nullptr);
assert(std::get<2>(t) == "");
}
{
std::tuple<int, char*, std::string> t(2, nullptr);
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == nullptr);
assert(std::get<2>(t) == "");
}
{
std::tuple<int, char*, std::string, double> t(2, nullptr, "text");
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == nullptr);
assert(std::get<2>(t) == "text");
assert(std::get<3>(t) == 0.0);
}
}

View File

@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// explicit tuple(const T&...);
#include <tuple>
#include <string>
#include <cassert>
int main()
{
{
std::tuple<int, char*, std::string, double&> t(2, nullptr, "text");
}
}

View File

@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class U1, class U2> tuple(const pair<U1, U2>& u);
#include <tuple>
#include <utility>
#include <cassert>
int main()
{
{
typedef std::pair<double, char> T0;
typedef std::tuple<int, short> T1;
T0 t0(2.5, 'a');
T1 t1 = t0;
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == short('a'));
}
#if _LIBCPP_STD_VER > 11
{
typedef std::pair<double, char> P0;
typedef std::tuple<int, short> T1;
constexpr P0 p0(2.5, 'a');
constexpr T1 t1 = p0;
static_assert(std::get<0>(t1) != std::get<0>(p0), "");
static_assert(std::get<1>(t1) == std::get<1>(p0), "");
static_assert(std::get<0>(t1) == 2, "");
static_assert(std::get<1>(t1) == short('a'), "");
}
#endif
}

View File

@@ -0,0 +1,115 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class... UTypes> tuple(const tuple<UTypes...>& u);
#include <tuple>
#include <string>
#include <cassert>
struct B
{
int id_;
explicit B(int i) : id_(i) {}
};
struct D
: B
{
explicit D(int i) : B(i) {}
};
#if _LIBCPP_STD_VER > 11
struct A
{
int id_;
constexpr A(int i) : id_(i) {}
friend constexpr bool operator==(const A& x, const A& y) {return x.id_ == y.id_;}
};
struct C
{
int id_;
constexpr explicit C(int i) : id_(i) {}
friend constexpr bool operator==(const C& x, const C& y) {return x.id_ == y.id_;}
};
#endif
int main()
{
{
typedef std::tuple<double> T0;
typedef std::tuple<int> T1;
T0 t0(2.5);
T1 t1 = t0;
assert(std::get<0>(t1) == 2);
}
#if _LIBCPP_STD_VER > 11
{
typedef std::tuple<double> T0;
typedef std::tuple<A> T1;
constexpr T0 t0(2.5);
constexpr T1 t1 = t0;
static_assert(std::get<0>(t1) == 2, "");
}
{
typedef std::tuple<int> T0;
typedef std::tuple<C> T1;
constexpr T0 t0(2);
constexpr T1 t1{t0};
static_assert(std::get<0>(t1) == C(2), "");
}
#endif
{
typedef std::tuple<double, char> T0;
typedef std::tuple<int, int> T1;
T0 t0(2.5, 'a');
T1 t1 = t0;
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
}
{
typedef std::tuple<double, char, D> T0;
typedef std::tuple<int, int, B> T1;
T0 t0(2.5, 'a', D(3));
T1 t1 = t0;
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
assert(std::get<2>(t1).id_ == 3);
}
{
D d(3);
typedef std::tuple<double, char, D&> T0;
typedef std::tuple<int, int, B&> T1;
T0 t0(2.5, 'a', d);
T1 t1 = t0;
d.id_ = 2;
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
assert(std::get<2>(t1).id_ == 2);
}
{
typedef std::tuple<double, char, int> T0;
typedef std::tuple<int, int, B> T1;
T0 t0(2.5, 'a', 3);
T1 t1(t0);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
assert(std::get<2>(t1).id_ == 3);
}
}

View File

@@ -0,0 +1,82 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class... UTypes> tuple(tuple<UTypes...>&& u);
#include <tuple>
#include <string>
#include <memory>
#include <cassert>
struct B
{
int id_;
explicit B(int i) : id_(i) {}
virtual ~B() {}
};
struct D
: B
{
explicit D(int i) : B(i) {}
};
int main()
{
{
typedef std::tuple<double> T0;
typedef std::tuple<int> T1;
T0 t0(2.5);
T1 t1 = std::move(t0);
assert(std::get<0>(t1) == 2);
}
{
typedef std::tuple<double, char> T0;
typedef std::tuple<int, int> T1;
T0 t0(2.5, 'a');
T1 t1 = std::move(t0);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
}
{
typedef std::tuple<double, char, D> T0;
typedef std::tuple<int, int, B> T1;
T0 t0(2.5, 'a', D(3));
T1 t1 = std::move(t0);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
assert(std::get<2>(t1).id_ == 3);
}
{
D d(3);
typedef std::tuple<double, char, D&> T0;
typedef std::tuple<int, int, B&> T1;
T0 t0(2.5, 'a', d);
T1 t1 = std::move(t0);
d.id_ = 2;
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
assert(std::get<2>(t1).id_ == 2);
}
{
typedef std::tuple<double, char, std::unique_ptr<D>> T0;
typedef std::tuple<int, int, std::unique_ptr<B>> T1;
T0 t0(2.5, 'a', std::unique_ptr<D>(new D(3)));
T1 t1 = std::move(t0);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1) == int('a'));
assert(std::get<2>(t1)->id_ == 3);
}
}

View File

@@ -0,0 +1,28 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// tuple(const tuple& u) = default;
#include <tuple>
#include <cassert>
#include "../MoveOnly.h"
int main()
{
{
typedef std::tuple<MoveOnly> T;
T t0(MoveOnly(2));
T t = t0;
}
}

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// tuple(const tuple& u) = default;
#include <tuple>
#include <string>
#include <cassert>
struct Empty {};
int main()
{
{
typedef std::tuple<> T;
T t0;
T t = t0;
}
{
typedef std::tuple<int> T;
T t0(2);
T t = t0;
assert(std::get<0>(t) == 2);
}
{
typedef std::tuple<int, char> T;
T t0(2, 'a');
T t = t0;
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == 'a');
}
{
typedef std::tuple<int, char, std::string> T;
const T t0(2, 'a', "some text");
T t = t0;
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == 'a');
assert(std::get<2>(t) == "some text");
}
#if _LIBCPP_STD_VER > 11
{
typedef std::tuple<int> T;
constexpr T t0(2);
constexpr T t = t0;
static_assert(std::get<0>(t) == 2, "");
}
{
typedef std::tuple<Empty> T;
constexpr T t0;
constexpr T t = t0;
}
#endif
}

View File

@@ -0,0 +1,91 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// constexpr tuple();
#include <tuple>
#include <string>
#include <cassert>
#include <type_traits>
#include "DefaultOnly.h"
struct NoDefault {
NoDefault() = delete;
explicit NoDefault(int) { }
};
struct NoExceptDefault {
NoExceptDefault() noexcept = default;
};
struct ThrowingDefault {
ThrowingDefault() { }
};
int main()
{
{
std::tuple<> t;
}
{
std::tuple<int> t;
assert(std::get<0>(t) == 0);
}
{
std::tuple<int, char*> t;
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == nullptr);
}
{
std::tuple<int, char*, std::string> t;
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == nullptr);
assert(std::get<2>(t) == "");
}
{
std::tuple<int, char*, std::string, DefaultOnly> t;
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == nullptr);
assert(std::get<2>(t) == "");
assert(std::get<3>(t) == DefaultOnly());
}
{
// See bug #21157.
static_assert(!std::is_default_constructible<std::tuple<NoDefault>>(), "");
static_assert(!std::is_default_constructible<std::tuple<DefaultOnly, NoDefault>>(), "");
static_assert(!std::is_default_constructible<std::tuple<NoDefault, DefaultOnly, NoDefault>>(), "");
}
{
static_assert(noexcept(std::tuple<NoExceptDefault>()), "");
static_assert(noexcept(std::tuple<NoExceptDefault, NoExceptDefault>()), "");
static_assert(!noexcept(std::tuple<ThrowingDefault, NoExceptDefault>()), "");
static_assert(!noexcept(std::tuple<NoExceptDefault, ThrowingDefault>()), "");
static_assert(!noexcept(std::tuple<ThrowingDefault, ThrowingDefault>()), "");
}
#ifndef _LIBCPP_HAS_NO_CONSTEXPR
{
constexpr std::tuple<> t;
}
{
constexpr std::tuple<int> t;
assert(std::get<0>(t) == 0);
}
{
constexpr std::tuple<int, char*> t;
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == nullptr);
}
#endif
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// tuple(tuple&& u);
#include <tuple>
#include <cassert>
#include "../MoveOnly.h"
struct ConstructsWithTupleLeaf
{
ConstructsWithTupleLeaf() {}
ConstructsWithTupleLeaf(ConstructsWithTupleLeaf const &) { assert(false); }
ConstructsWithTupleLeaf(ConstructsWithTupleLeaf &&) {}
template <class T>
ConstructsWithTupleLeaf(T t)
{ assert(false); }
};
int main()
{
{
typedef std::tuple<> T;
T t0;
T t = std::move(t0);
}
{
typedef std::tuple<MoveOnly> T;
T t0(MoveOnly(0));
T t = std::move(t0);
assert(std::get<0>(t) == 0);
}
{
typedef std::tuple<MoveOnly, MoveOnly> T;
T t0(MoveOnly(0), MoveOnly(1));
T t = std::move(t0);
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 1);
}
{
typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T;
T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2));
T t = std::move(t0);
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 1);
assert(std::get<2>(t) == 2);
}
// A bug in tuple caused __tuple_leaf to use its explicit converting constructor
// as its move constructor. This tests that ConstructsWithTupleLeaf is not called
// (w/ __tuple_leaf)
{
typedef std::tuple<ConstructsWithTupleLeaf> d_t;
d_t d((ConstructsWithTupleLeaf()));
d_t d2(static_cast<d_t &&>(d));
}
}

View File

@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class U1, class U2> tuple(pair<U1, U2>&& u);
#include <tuple>
#include <utility>
#include <memory>
#include <cassert>
struct B
{
int id_;
explicit B(int i) : id_(i) {}
virtual ~B() {}
};
struct D
: B
{
explicit D(int i) : B(i) {}
};
int main()
{
{
typedef std::pair<double, std::unique_ptr<D>> T0;
typedef std::tuple<int, std::unique_ptr<B>> T1;
T0 t0(2.5, std::unique_ptr<D>(new D(3)));
T1 t1 = std::move(t0);
assert(std::get<0>(t1) == 2);
assert(std::get<1>(t1)->id_ == 3);
}
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class Tuple, __tuple_convertible<Tuple, tuple> >
// tuple(Tuple &&);
//
// template <class Tuple, __tuple_constructible<Tuple, tuple> >
// tuple(Tuple &&);
// This test checks that we do not evaluate __make_tuple_types
// on the array.
#include <array>
#include <tuple>
// Use 1256 to try and blow the template instantiation depth for all compilers.
typedef std::array<char, 1256> array_t;
typedef std::tuple<array_t> tuple_t;
int main()
{
array_t arr;
tuple_t tup(arr);
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template<class... Types>
// tuple<Types&&...> forward_as_tuple(Types&&... t);
#include <tuple>
#include <cassert>
template <class Tuple>
void
test0(const Tuple& t)
{
static_assert(std::tuple_size<Tuple>::value == 0, "");
}
template <class Tuple>
void
test1a(const Tuple& t)
{
static_assert(std::tuple_size<Tuple>::value == 1, "");
static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&&>::value, "");
assert(std::get<0>(t) == 1);
}
template <class Tuple>
void
test1b(const Tuple& t)
{
static_assert(std::tuple_size<Tuple>::value == 1, "");
static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, int&>::value, "");
assert(std::get<0>(t) == 2);
}
template <class Tuple>
void
test2a(const Tuple& t)
{
static_assert(std::tuple_size<Tuple>::value == 2, "");
static_assert(std::is_same<typename std::tuple_element<0, Tuple>::type, double&>::value, "");
static_assert(std::is_same<typename std::tuple_element<1, Tuple>::type, char&>::value, "");
assert(std::get<0>(t) == 2.5);
assert(std::get<1>(t) == 'a');
}
#if _LIBCPP_STD_VER > 11
template <class Tuple>
constexpr int
test3(const Tuple& t)
{
return std::tuple_size<Tuple>::value;
}
#endif
int main()
{
{
test0(std::forward_as_tuple());
}
{
test1a(std::forward_as_tuple(1));
}
{
int i = 2;
test1b(std::forward_as_tuple(i));
}
{
double i = 2.5;
char c = 'a';
test2a(std::forward_as_tuple(i, c));
#if _LIBCPP_STD_VER > 11
static_assert ( test3 (std::forward_as_tuple(i, c)) == 2, "" );
#endif
}
}

View File

@@ -0,0 +1,50 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template<class... Types>
// tuple<VTypes...> make_tuple(Types&&... t);
#include <tuple>
#include <functional>
#include <cassert>
int main()
{
{
int i = 0;
float j = 0;
std::tuple<int, int&, float&> t = std::make_tuple(1, std::ref(i),
std::ref(j));
assert(std::get<0>(t) == 1);
assert(std::get<1>(t) == 0);
assert(std::get<2>(t) == 0);
i = 2;
j = 3.5;
assert(std::get<0>(t) == 1);
assert(std::get<1>(t) == 2);
assert(std::get<2>(t) == 3.5);
std::get<1>(t) = 0;
std::get<2>(t) = 0;
assert(i == 0);
assert(j == 0);
}
#if _LIBCPP_STD_VER > 11
{
constexpr auto t1 = std::make_tuple(0, 1, 3.14);
constexpr int i1 = std::get<1>(t1);
constexpr double d1 = std::get<2>(t1);
static_assert (i1 == 1, "" );
static_assert (d1 == 3.14, "" );
}
#endif
}

View File

@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template<class... Types>
// tuple<Types&...> tie(Types&... t);
#include <tuple>
#include <string>
#include <cassert>
int main()
{
{
int i = 0;
std::string s;
std::tie(i, std::ignore, s) = std::make_tuple(42, 3.14, "C++");
assert(i == 42);
assert(s == "C++");
}
#if _LIBCPP_STD_VER > 11
{
static constexpr int i = 42;
static constexpr double f = 1.1;
constexpr std::tuple<const int &, const double &> t = std::tie(i, f);
static_assert ( std::get<0>(t) == 42, "" );
static_assert ( std::get<1>(t) == 1.1, "" );
}
#endif
}

View File

@@ -0,0 +1,230 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class... Tuples> tuple<CTypes...> tuple_cat(Tuples&&... tpls);
#include <tuple>
#include <utility>
#include <array>
#include <string>
#include <cassert>
#include "../MoveOnly.h"
int main()
{
{
std::tuple<> t = std::tuple_cat();
}
{
std::tuple<> t1;
std::tuple<> t2 = std::tuple_cat(t1);
}
{
std::tuple<> t = std::tuple_cat(std::tuple<>());
}
{
std::tuple<> t = std::tuple_cat(std::array<int, 0>());
}
{
std::tuple<int> t1(1);
std::tuple<int> t = std::tuple_cat(t1);
assert(std::get<0>(t) == 1);
}
#if _LIBCPP_STD_VER > 11
{
constexpr std::tuple<> t = std::tuple_cat();
}
{
constexpr std::tuple<> t1;
constexpr std::tuple<> t2 = std::tuple_cat(t1);
}
{
constexpr std::tuple<> t = std::tuple_cat(std::tuple<>());
}
{
constexpr std::tuple<> t = std::tuple_cat(std::array<int, 0>());
}
{
constexpr std::tuple<int> t1(1);
constexpr std::tuple<int> t = std::tuple_cat(t1);
static_assert(std::get<0>(t) == 1, "");
}
{
constexpr std::tuple<int> t1(1);
constexpr std::tuple<int, int> t = std::tuple_cat(t1, t1);
static_assert(std::get<0>(t) == 1, "");
static_assert(std::get<1>(t) == 1, "");
}
#endif
{
std::tuple<int, MoveOnly> t =
std::tuple_cat(std::tuple<int, MoveOnly>(1, 2));
assert(std::get<0>(t) == 1);
assert(std::get<1>(t) == 2);
}
{
std::tuple<int, int, int> t = std::tuple_cat(std::array<int, 3>());
assert(std::get<0>(t) == 0);
assert(std::get<1>(t) == 0);
assert(std::get<2>(t) == 0);
}
{
std::tuple<int, MoveOnly> t = std::tuple_cat(std::pair<int, MoveOnly>(2, 1));
assert(std::get<0>(t) == 2);
assert(std::get<1>(t) == 1);
}
{
std::tuple<> t1;
std::tuple<> t2;
std::tuple<> t3 = std::tuple_cat(t1, t2);
}
{
std::tuple<> t1;
std::tuple<int> t2(2);
std::tuple<int> t3 = std::tuple_cat(t1, t2);
assert(std::get<0>(t3) == 2);
}
{
std::tuple<> t1;
std::tuple<int> t2(2);
std::tuple<int> t3 = std::tuple_cat(t2, t1);
assert(std::get<0>(t3) == 2);
}
{
std::tuple<int*> t1;
std::tuple<int> t2(2);
std::tuple<int*, int> t3 = std::tuple_cat(t1, t2);
assert(std::get<0>(t3) == nullptr);
assert(std::get<1>(t3) == 2);
}
{
std::tuple<int*> t1;
std::tuple<int> t2(2);
std::tuple<int, int*> t3 = std::tuple_cat(t2, t1);
assert(std::get<0>(t3) == 2);
assert(std::get<1>(t3) == nullptr);
}
{
std::tuple<int*> t1;
std::tuple<int, double> t2(2, 3.5);
std::tuple<int*, int, double> t3 = std::tuple_cat(t1, t2);
assert(std::get<0>(t3) == nullptr);
assert(std::get<1>(t3) == 2);
assert(std::get<2>(t3) == 3.5);
}
{
std::tuple<int*> t1;
std::tuple<int, double> t2(2, 3.5);
std::tuple<int, double, int*> t3 = std::tuple_cat(t2, t1);
assert(std::get<0>(t3) == 2);
assert(std::get<1>(t3) == 3.5);
assert(std::get<2>(t3) == nullptr);
}
{
std::tuple<int*, MoveOnly> t1(nullptr, 1);
std::tuple<int, double> t2(2, 3.5);
std::tuple<int*, MoveOnly, int, double> t3 =
std::tuple_cat(std::move(t1), t2);
assert(std::get<0>(t3) == nullptr);
assert(std::get<1>(t3) == 1);
assert(std::get<2>(t3) == 2);
assert(std::get<3>(t3) == 3.5);
}
{
std::tuple<int*, MoveOnly> t1(nullptr, 1);
std::tuple<int, double> t2(2, 3.5);
std::tuple<int, double, int*, MoveOnly> t3 =
std::tuple_cat(t2, std::move(t1));
assert(std::get<0>(t3) == 2);
assert(std::get<1>(t3) == 3.5);
assert(std::get<2>(t3) == nullptr);
assert(std::get<3>(t3) == 1);
}
{
std::tuple<MoveOnly, MoveOnly> t1(1, 2);
std::tuple<int*, MoveOnly> t2(nullptr, 4);
std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 =
std::tuple_cat(std::move(t1), std::move(t2));
assert(std::get<0>(t3) == 1);
assert(std::get<1>(t3) == 2);
assert(std::get<2>(t3) == nullptr);
assert(std::get<3>(t3) == 4);
}
{
std::tuple<MoveOnly, MoveOnly> t1(1, 2);
std::tuple<int*, MoveOnly> t2(nullptr, 4);
std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 =
std::tuple_cat(std::tuple<>(),
std::move(t1),
std::move(t2));
assert(std::get<0>(t3) == 1);
assert(std::get<1>(t3) == 2);
assert(std::get<2>(t3) == nullptr);
assert(std::get<3>(t3) == 4);
}
{
std::tuple<MoveOnly, MoveOnly> t1(1, 2);
std::tuple<int*, MoveOnly> t2(nullptr, 4);
std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 =
std::tuple_cat(std::move(t1),
std::tuple<>(),
std::move(t2));
assert(std::get<0>(t3) == 1);
assert(std::get<1>(t3) == 2);
assert(std::get<2>(t3) == nullptr);
assert(std::get<3>(t3) == 4);
}
{
std::tuple<MoveOnly, MoveOnly> t1(1, 2);
std::tuple<int*, MoveOnly> t2(nullptr, 4);
std::tuple<MoveOnly, MoveOnly, int*, MoveOnly> t3 =
std::tuple_cat(std::move(t1),
std::move(t2),
std::tuple<>());
assert(std::get<0>(t3) == 1);
assert(std::get<1>(t3) == 2);
assert(std::get<2>(t3) == nullptr);
assert(std::get<3>(t3) == 4);
}
{
std::tuple<MoveOnly, MoveOnly> t1(1, 2);
std::tuple<int*, MoveOnly> t2(nullptr, 4);
std::tuple<MoveOnly, MoveOnly, int*, MoveOnly, int> t3 =
std::tuple_cat(std::move(t1),
std::move(t2),
std::tuple<int>(5));
assert(std::get<0>(t3) == 1);
assert(std::get<1>(t3) == 2);
assert(std::get<2>(t3) == nullptr);
assert(std::get<3>(t3) == 4);
assert(std::get<4>(t3) == 5);
}
{
// See bug #19616.
auto t1 = std::tuple_cat(
std::make_tuple(std::make_tuple(1)),
std::make_tuple()
);
assert(t1 == std::make_tuple(std::make_tuple(1)));
auto t2 = std::tuple_cat(
std::make_tuple(std::make_tuple(1)),
std::make_tuple(std::make_tuple(2))
);
assert(t2 == std::make_tuple(std::make_tuple(1), std::make_tuple(2)));
}
}

View File

@@ -0,0 +1,39 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <size_t I, class... Types>
// typename tuple_element<I, tuple<Types...> >::type const&
// get(const tuple<Types...>& t);
#include <tuple>
#include <string>
#include <cassert>
int main()
{
{
typedef std::tuple<double&, std::string, int> T;
double d = 1.5;
const T t(d, "high", 5);
assert(std::get<0>(t) == 1.5);
assert(std::get<1>(t) == "high");
assert(std::get<2>(t) == 5);
std::get<0>(t) = 2.5;
assert(std::get<0>(t) == 2.5);
assert(std::get<1>(t) == "high");
assert(std::get<2>(t) == 5);
assert(d == 2.5);
std::get<1>(t) = "four";
}
}

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <size_t I, class... Types>
// typename tuple_element<I, tuple<Types...> >::type const&
// get(const tuple<Types...>& t);
#include <tuple>
#include <string>
#include <cassert>
struct Empty {};
int main()
{
{
typedef std::tuple<int> T;
const T t(3);
assert(std::get<0>(t) == 3);
}
{
typedef std::tuple<std::string, int> T;
const T t("high", 5);
assert(std::get<0>(t) == "high");
assert(std::get<1>(t) == 5);
}
#if _LIBCPP_STD_VER > 11
{
typedef std::tuple<double, int> T;
constexpr T t(2.718, 5);
static_assert(std::get<0>(t) == 2.718, "");
static_assert(std::get<1>(t) == 5, "");
}
{
typedef std::tuple<Empty> T;
constexpr T t{Empty()};
constexpr Empty e = std::get<0>(t);
}
#endif
{
typedef std::tuple<double&, std::string, int> T;
double d = 1.5;
const T t(d, "high", 5);
assert(std::get<0>(t) == 1.5);
assert(std::get<1>(t) == "high");
assert(std::get<2>(t) == 5);
std::get<0>(t) = 2.5;
assert(std::get<0>(t) == 2.5);
assert(std::get<1>(t) == "high");
assert(std::get<2>(t) == 5);
assert(d == 2.5);
}
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <size_t I, class... Types>
// typename tuple_element<I, tuple<Types...> >::type&
// get(tuple<Types...>& t);
#include <tuple>
#include <string>
#include <cassert>
#if __cplusplus > 201103L
struct Empty {};
struct S {
std::tuple<int, Empty> a;
int k;
Empty e;
constexpr S() : a{1,Empty{}}, k(std::get<0>(a)), e(std::get<1>(a)) {}
};
constexpr std::tuple<int, int> getP () { return { 3, 4 }; }
#endif
int main()
{
{
typedef std::tuple<int> T;
T t(3);
assert(std::get<0>(t) == 3);
std::get<0>(t) = 2;
assert(std::get<0>(t) == 2);
}
{
typedef std::tuple<std::string, int> T;
T t("high", 5);
assert(std::get<0>(t) == "high");
assert(std::get<1>(t) == 5);
std::get<0>(t) = "four";
std::get<1>(t) = 4;
assert(std::get<0>(t) == "four");
assert(std::get<1>(t) == 4);
}
{
typedef std::tuple<double&, std::string, int> T;
double d = 1.5;
T t(d, "high", 5);
assert(std::get<0>(t) == 1.5);
assert(std::get<1>(t) == "high");
assert(std::get<2>(t) == 5);
std::get<0>(t) = 2.5;
std::get<1>(t) = "four";
std::get<2>(t) = 4;
assert(std::get<0>(t) == 2.5);
assert(std::get<1>(t) == "four");
assert(std::get<2>(t) == 4);
assert(d == 2.5);
}
#if _LIBCPP_STD_VER > 11
{ // get on an rvalue tuple
static_assert ( std::get<0> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 0, "" );
static_assert ( std::get<1> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 1, "" );
static_assert ( std::get<2> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 2, "" );
static_assert ( std::get<3> ( std::make_tuple ( 0.0f, 1, 2.0, 3L )) == 3, "" );
static_assert(S().k == 1, "");
static_assert(std::get<1>(getP()) == 4, "");
}
#endif
}

View File

@@ -0,0 +1,30 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <size_t I, class... Types>
// typename tuple_element<I, tuple<Types...> >::type&&
// get(tuple<Types...>&& t);
#include <tuple>
#include <memory>
#include <cassert>
int main()
{
{
typedef std::tuple<std::unique_ptr<int> > T;
T t(std::unique_ptr<int>(new int(3)));
std::unique_ptr<int> p = std::get<0>(std::move(t));
assert(*p == 3);
}
}

View File

@@ -0,0 +1,58 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#include <tuple>
#include <string>
#include <complex>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
typedef std::complex<float> cf;
{
auto t1 = std::tuple<int, std::string, cf> { 42, "Hi", { 1,2 }};
assert ( std::get<int>(t1) == 42 ); // find at the beginning
assert ( std::get<std::string>(t1) == "Hi" ); // find in the middle
assert ( std::get<cf>(t1).real() == 1 ); // find at the end
assert ( std::get<cf>(t1).imag() == 2 );
}
{
auto t2 = std::tuple<int, std::string, int, cf> { 42, "Hi", 23, { 1,2 }};
// get<int> would fail!
assert ( std::get<std::string>(t2) == "Hi" );
assert (( std::get<cf>(t2) == cf{ 1,2 } ));
}
{
constexpr std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 };
static_assert ( std::get<int>(p5) == 1, "" );
static_assert ( std::get<const int>(p5) == 2, "" );
}
{
const std::tuple<int, const int, double, double> p5 { 1, 2, 3.4, 5.6 };
const int &i1 = std::get<int>(p5);
const int &i2 = std::get<const int>(p5);
assert ( i1 == 1 );
assert ( i2 == 2 );
}
{
typedef std::unique_ptr<int> upint;
std::tuple<upint> t(upint(new int(4)));
upint p = std::get<upint>(std::move(t)); // get rvalue
assert(*p == 4);
assert(std::get<0>(t) == nullptr); // has been moved from
}
#endif
}

View File

@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#include <tuple>
#include <string>
#include <complex>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
typedef std::complex<float> cf;
auto t1 = std::make_tuple<int, std::string> ( 42, "Hi" );
assert (( std::get<cf>(t1) == cf {1,2} )); // no such type
#else
#error
#endif
}

View File

@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#include <tuple>
#include <string>
#include <complex>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
typedef std::complex<float> cf;
auto t1 = std::make_tuple<int, int, std::string, cf> ( 42, 21, "Hi", { 1,2 } );
assert ( std::get<int>(t1) == 42 ); // two ints here
#else
#error
#endif
}

View File

@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#include <tuple>
#include <string>
#include <complex>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
typedef std::complex<float> cf;
auto t1 = std::make_tuple<double, int, std::string, cf, int> ( 42, 21, "Hi", { 1,2 } );
assert ( std::get<int>(t1) == 42 ); // two ints here (one at the end)
#else
#error
#endif
}

View File

@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
#include <tuple>
#include <string>
#include <memory>
#include <cassert>
int main()
{
#if _LIBCPP_STD_VER > 11
typedef std::unique_ptr<int> upint;
std::tuple<upint> t(upint(new int(4)));
upint p = std::get<upint>(t);
#else
#error
#endif
}

View File

@@ -0,0 +1,52 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <size_t I, class... Types>
// class tuple_element<I, tuple<Types...> >
// {
// public:
// typedef Ti type;
// };
//
// LWG #2212 says that tuple_size and tuple_element must be
// available after including <utility>
#include <array>
#include <type_traits>
template <class T, std::size_t N, class U, size_t idx>
void test()
{
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<T> >::value), "");
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<const T> >::value), "");
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<volatile T> >::value), "");
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<const volatile T> >::value), "");
static_assert((std::is_same<typename std::tuple_element<idx, T>::type, U>::value), "");
static_assert((std::is_same<typename std::tuple_element<idx, const T>::type, const U>::value), "");
static_assert((std::is_same<typename std::tuple_element<idx, volatile T>::type, volatile U>::value), "");
static_assert((std::is_same<typename std::tuple_element<idx, const volatile T>::type, const volatile U>::value), "");
}
int main()
{
test<std::array<int, 5>, 5, int, 0>();
test<std::array<int, 5>, 5, int, 1>();
test<std::array<const char *, 4>, 4, const char *, 3>();
test<std::array<volatile int, 4>, 4, volatile int, 3>();
test<std::array<char *, 3>, 3, char *, 1>();
test<std::array<char *, 3>, 3, char *, 2>();
}

View File

@@ -0,0 +1,49 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class... Types>
// class tuple_size<tuple<Types...>>
// : public integral_constant<size_t, sizeof...(Types)> { };
//
// LWG #2212 says that tuple_size and tuple_element must be
// available after including <utility>
#include <utility>
#include <type_traits>
template <class T, std::size_t N, class U, size_t idx>
void test()
{
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<T> >::value), "");
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<const T> >::value), "");
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<volatile T> >::value), "");
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<const volatile T> >::value), "");
static_assert((std::is_same<typename std::tuple_element<idx, T>::type, U>::value), "");
static_assert((std::is_same<typename std::tuple_element<idx, const T>::type, const U>::value), "");
static_assert((std::is_same<typename std::tuple_element<idx, volatile T>::type, volatile U>::value), "");
static_assert((std::is_same<typename std::tuple_element<idx, const volatile T>::type, const volatile U>::value), "");
}
int main()
{
test<std::pair<int, int>, 2, int, 0>();
test<std::pair<int, int>, 2, int, 1>();
test<std::pair<const int, int>, 2, int, 1>();
test<std::pair<int, volatile int>, 2, volatile int, 1>();
test<std::pair<char *, int>, 2, char *, 0>();
test<std::pair<char *, int>, 2, int, 1>();
}

View File

@@ -0,0 +1,47 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <size_t I, class... Types>
// class tuple_element<I, tuple<Types...> >
// {
// public:
// typedef Ti type;
// };
#include <tuple>
#include <type_traits>
template <class T, std::size_t N, class U>
void test()
{
static_assert((std::is_same<typename std::tuple_element<N, T>::type, U>::value), "");
static_assert((std::is_same<typename std::tuple_element<N, const T>::type, const U>::value), "");
static_assert((std::is_same<typename std::tuple_element<N, volatile T>::type, volatile U>::value), "");
static_assert((std::is_same<typename std::tuple_element<N, const volatile T>::type, const volatile U>::value), "");
#if _LIBCPP_STD_VER > 11
static_assert((std::is_same<typename std::tuple_element_t<N, T>, U>::value), "");
static_assert((std::is_same<typename std::tuple_element_t<N, const T>, const U>::value), "");
static_assert((std::is_same<typename std::tuple_element_t<N, volatile T>, volatile U>::value), "");
static_assert((std::is_same<typename std::tuple_element_t<N, const volatile T>, const volatile U>::value), "");
#endif
}
int main()
{
test<std::tuple<int>, 0, int>();
test<std::tuple<char, int>, 0, char>();
test<std::tuple<char, int>, 1, int>();
test<std::tuple<int*, char, int>, 0, int*>();
test<std::tuple<int*, char, int>, 1, char>();
test<std::tuple<int*, char, int>, 2, int>();
}

View File

@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class... Types>
// class tuple_size<tuple<Types...>>
// : public integral_constant<size_t, sizeof...(Types)> { };
#include <tuple>
#include <type_traits>
template <class T, std::size_t N>
void test()
{
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<T> >::value), "");
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<const T> >::value), "");
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<volatile T> >::value), "");
static_assert((std::is_base_of<std::integral_constant<std::size_t, N>,
std::tuple_size<const volatile T> >::value), "");
}
int main()
{
test<std::tuple<>, 0>();
test<std::tuple<int>, 1>();
test<std::tuple<char, int>, 2>();
test<std::tuple<char, char*, int>, 3>();
}

View File

@@ -0,0 +1,154 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template<class... TTypes, class... UTypes>
// bool
// operator==(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
#include <tuple>
#include <string>
#include <cassert>
int main()
{
{
typedef std::tuple<> T1;
typedef std::tuple<> T2;
const T1 t1;
const T2 t2;
assert(t1 == t2);
assert(!(t1 != t2));
}
{
typedef std::tuple<int> T1;
typedef std::tuple<double> T2;
const T1 t1(1);
const T2 t2(1.1);
assert(!(t1 == t2));
assert(t1 != t2);
}
{
typedef std::tuple<int> T1;
typedef std::tuple<double> T2;
const T1 t1(1);
const T2 t2(1);
assert(t1 == t2);
assert(!(t1 != t2));
}
{
typedef std::tuple<int, double> T1;
typedef std::tuple<double, char> T2;
const T1 t1(1, 2);
const T2 t2(1, char(2));
assert(t1 == t2);
assert(!(t1 != t2));
}
{
typedef std::tuple<int, double> T1;
typedef std::tuple<double, char> T2;
const T1 t1(1, 2);
const T2 t2(1, char(3));
assert(!(t1 == t2));
assert(t1 != t2);
}
{
typedef std::tuple<int, double> T1;
typedef std::tuple<double, char> T2;
const T1 t1(1, 2);
const T2 t2(1.1, char(2));
assert(!(t1 == t2));
assert(t1 != t2);
}
{
typedef std::tuple<int, double> T1;
typedef std::tuple<double, char> T2;
const T1 t1(1, 2);
const T2 t2(1.1, char(3));
assert(!(t1 == t2));
assert(t1 != t2);
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1, 2, 3);
assert(t1 == t2);
assert(!(t1 != t2));
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1.1, 2, 3);
assert(!(t1 == t2));
assert(t1 != t2);
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1, 3, 3);
assert(!(t1 == t2));
assert(t1 != t2);
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1, 2, 4);
assert(!(t1 == t2));
assert(t1 != t2);
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1, 3, 2);
assert(!(t1 == t2));
assert(t1 != t2);
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1.1, 2, 2);
assert(!(t1 == t2));
assert(t1 != t2);
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1.1, 3, 3);
assert(!(t1 == t2));
assert(t1 != t2);
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1.1, 3, 2);
assert(!(t1 == t2));
assert(t1 != t2);
}
#if _LIBCPP_STD_VER > 11
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
constexpr T1 t1(1, 2, 3);
constexpr T2 t2(1.1, 3, 2);
static_assert(!(t1 == t2), "");
static_assert(t1 != t2, "");
}
#endif
}

View File

@@ -0,0 +1,208 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template<class... TTypes, class... UTypes>
// bool
// operator<(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
//
// template<class... TTypes, class... UTypes>
// bool
// operator>(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
//
// template<class... TTypes, class... UTypes>
// bool
// operator<=(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
//
// template<class... TTypes, class... UTypes>
// bool
// operator>=(const tuple<TTypes...>& t, const tuple<UTypes...>& u);
#include <tuple>
#include <string>
#include <cassert>
int main()
{
{
typedef std::tuple<> T1;
typedef std::tuple<> T2;
const T1 t1;
const T2 t2;
assert(!(t1 < t2));
assert( (t1 <= t2));
assert(!(t1 > t2));
assert( (t1 >= t2));
}
{
typedef std::tuple<char> T1;
typedef std::tuple<double> T2;
const T1 t1(1);
const T2 t2(1);
assert(!(t1 < t2));
assert( (t1 <= t2));
assert(!(t1 > t2));
assert( (t1 >= t2));
}
{
typedef std::tuple<char> T1;
typedef std::tuple<double> T2;
const T1 t1(1);
const T2 t2(0.9);
assert(!(t1 < t2));
assert(!(t1 <= t2));
assert( (t1 > t2));
assert( (t1 >= t2));
}
{
typedef std::tuple<char> T1;
typedef std::tuple<double> T2;
const T1 t1(1);
const T2 t2(1.1);
assert( (t1 < t2));
assert( (t1 <= t2));
assert(!(t1 > t2));
assert(!(t1 >= t2));
}
{
typedef std::tuple<char, int> T1;
typedef std::tuple<double, char> T2;
const T1 t1(1, 2);
const T2 t2(1, 2);
assert(!(t1 < t2));
assert( (t1 <= t2));
assert(!(t1 > t2));
assert( (t1 >= t2));
}
{
typedef std::tuple<char, int> T1;
typedef std::tuple<double, char> T2;
const T1 t1(1, 2);
const T2 t2(0.9, 2);
assert(!(t1 < t2));
assert(!(t1 <= t2));
assert( (t1 > t2));
assert( (t1 >= t2));
}
{
typedef std::tuple<char, int> T1;
typedef std::tuple<double, char> T2;
const T1 t1(1, 2);
const T2 t2(1.1, 2);
assert( (t1 < t2));
assert( (t1 <= t2));
assert(!(t1 > t2));
assert(!(t1 >= t2));
}
{
typedef std::tuple<char, int> T1;
typedef std::tuple<double, char> T2;
const T1 t1(1, 2);
const T2 t2(1, 1);
assert(!(t1 < t2));
assert(!(t1 <= t2));
assert( (t1 > t2));
assert( (t1 >= t2));
}
{
typedef std::tuple<char, int> T1;
typedef std::tuple<double, char> T2;
const T1 t1(1, 2);
const T2 t2(1, 3);
assert( (t1 < t2));
assert( (t1 <= t2));
assert(!(t1 > t2));
assert(!(t1 >= t2));
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1, 2, 3);
assert(!(t1 < t2));
assert( (t1 <= t2));
assert(!(t1 > t2));
assert( (t1 >= t2));
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(0.9, 2, 3);
assert(!(t1 < t2));
assert(!(t1 <= t2));
assert( (t1 > t2));
assert( (t1 >= t2));
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1.1, 2, 3);
assert( (t1 < t2));
assert( (t1 <= t2));
assert(!(t1 > t2));
assert(!(t1 >= t2));
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1, 1, 3);
assert(!(t1 < t2));
assert(!(t1 <= t2));
assert( (t1 > t2));
assert( (t1 >= t2));
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1, 3, 3);
assert( (t1 < t2));
assert( (t1 <= t2));
assert(!(t1 > t2));
assert(!(t1 >= t2));
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1, 2, 2);
assert(!(t1 < t2));
assert(!(t1 <= t2));
assert( (t1 > t2));
assert( (t1 >= t2));
}
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
const T1 t1(1, 2, 3);
const T2 t2(1, 2, 4);
assert( (t1 < t2));
assert( (t1 <= t2));
assert(!(t1 > t2));
assert(!(t1 >= t2));
}
#if _LIBCPP_STD_VER > 11
{
typedef std::tuple<char, int, double> T1;
typedef std::tuple<double, char, int> T2;
constexpr T1 t1(1, 2, 3);
constexpr T2 t2(1, 2, 4);
static_assert( (t1 < t2), "");
static_assert( (t1 <= t2), "");
static_assert(!(t1 > t2), "");
static_assert(!(t1 >= t2), "");
}
#endif
}

View File

@@ -0,0 +1,60 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class... Types>
// void swap(tuple<Types...>& x, tuple<Types...>& y);
#include <tuple>
#include <cassert>
#include "../MoveOnly.h"
int main()
{
{
typedef std::tuple<> T;
T t0;
T t1;
swap(t0, t1);
}
{
typedef std::tuple<MoveOnly> T;
T t0(MoveOnly(0));
T t1(MoveOnly(1));
swap(t0, t1);
assert(std::get<0>(t0) == 1);
assert(std::get<0>(t1) == 0);
}
{
typedef std::tuple<MoveOnly, MoveOnly> T;
T t0(MoveOnly(0), MoveOnly(1));
T t1(MoveOnly(2), MoveOnly(3));
swap(t0, t1);
assert(std::get<0>(t0) == 2);
assert(std::get<1>(t0) == 3);
assert(std::get<0>(t1) == 0);
assert(std::get<1>(t1) == 1);
}
{
typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T;
T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2));
T t1(MoveOnly(3), MoveOnly(4), MoveOnly(5));
swap(t0, t1);
assert(std::get<0>(t0) == 3);
assert(std::get<1>(t0) == 4);
assert(std::get<2>(t0) == 5);
assert(std::get<0>(t1) == 0);
assert(std::get<1>(t1) == 1);
assert(std::get<2>(t1) == 2);
}
}

View File

@@ -0,0 +1,59 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// void swap(tuple& rhs);
#include <tuple>
#include <cassert>
#include "../MoveOnly.h"
int main()
{
{
typedef std::tuple<> T;
T t0;
T t1;
t0.swap(t1);
}
{
typedef std::tuple<MoveOnly> T;
T t0(MoveOnly(0));
T t1(MoveOnly(1));
t0.swap(t1);
assert(std::get<0>(t0) == 1);
assert(std::get<0>(t1) == 0);
}
{
typedef std::tuple<MoveOnly, MoveOnly> T;
T t0(MoveOnly(0), MoveOnly(1));
T t1(MoveOnly(2), MoveOnly(3));
t0.swap(t1);
assert(std::get<0>(t0) == 2);
assert(std::get<1>(t0) == 3);
assert(std::get<0>(t1) == 0);
assert(std::get<1>(t1) == 1);
}
{
typedef std::tuple<MoveOnly, MoveOnly, MoveOnly> T;
T t0(MoveOnly(0), MoveOnly(1), MoveOnly(2));
T t1(MoveOnly(3), MoveOnly(4), MoveOnly(5));
t0.swap(t1);
assert(std::get<0>(t0) == 3);
assert(std::get<1>(t0) == 4);
assert(std::get<2>(t0) == 5);
assert(std::get<0>(t1) == 0);
assert(std::get<1>(t1) == 1);
assert(std::get<2>(t1) == 2);
}
}

View File

@@ -0,0 +1,44 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
// template <class... Types> class tuple;
// template <class... Types, class Alloc>
// struct uses_allocator<tuple<Types...>, Alloc> : true_type { };
#include <tuple>
#include <type_traits>
struct A {};
int main()
{
{
typedef std::tuple<> T;
static_assert((std::is_base_of<std::true_type,
std::uses_allocator<T, A>>::value), "");
}
{
typedef std::tuple<int> T;
static_assert((std::is_base_of<std::true_type,
std::uses_allocator<T, A>>::value), "");
}
{
typedef std::tuple<char, int> T;
static_assert((std::is_base_of<std::true_type,
std::uses_allocator<T, A>>::value), "");
}
{
typedef std::tuple<double&, char, int> T;
static_assert((std::is_base_of<std::true_type,
std::uses_allocator<T, A>>::value), "");
}
}

View File

@@ -0,0 +1,20 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <tuple>
#include <tuple>
#ifndef _LIBCPP_VERSION
#error _LIBCPP_VERSION not defined
#endif
int main()
{
}