Make tuple's constructor and std::get<>(tuple) constexpr. Final stage of fixing bug #16599. Thanks to Howard for the review and updates.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@186834 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
#include <string>
|
||||
#include <cassert>
|
||||
|
||||
struct Empty {};
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
@@ -32,6 +34,19 @@ int main()
|
||||
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;
|
||||
|
@@ -19,6 +19,20 @@
|
||||
#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()
|
||||
{
|
||||
{
|
||||
@@ -53,4 +67,15 @@ int main()
|
||||
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
|
||||
|
||||
}
|
||||
|
@@ -32,6 +32,12 @@ int main()
|
||||
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);
|
||||
|
Reference in New Issue
Block a user