I believe tuple is still under development in the standard. Daniel Krugler is/will be making convincing arguments that a modified form of LWG 2051 (currently NAD Future) is easily acheivable and desirable. He has demonstrated that a tuple<T...> where all of the T are implicitly convertible from U... should have a tuple constructor that is also implicit, instead of explicit. This would support the use cases in LWG 2051 while not undermining T... with explicit conversions from U.... This check-in is an experimental implementation of Daniel's work. I believe this work to be mature enough to warrant inclusion into libc++. If anyone sees real-world problems that this check in causes, please let me know and I will revert it, and provide the feedback to the LWG.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@153855 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Howard Hinnant
2012-04-01 23:10:42 +00:00
parent 9aa4e11451
commit dc1345fd44
4 changed files with 105 additions and 11 deletions

View File

@@ -14,14 +14,36 @@
// 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>
#include "../MoveOnly.h"
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 = MoveOnly(0);
std::tuple<MoveOnly> t = 1;
}
}

View File

@@ -20,7 +20,6 @@
int main()
{
{
std::tuple<int> t = 2;
assert(std::get<0>(t) == 2);
std::tuple<int*> t = 0;
}
}