std::tuple<int, std::string> tu{ 2,"12iop" };
#include <tuple>
struct Point
{
int x;
int y;
};
void main()
{
std::tuple<int, std::string> t1{ 1,"qwer" }; // 一个由int和字符串组成的tuple
constexpr std::tuple<int, void*> t2{ 1,nullptr }; // 一个由int和void*组成的tuple
std::tuple<int, Point> t3{ 1,{20,89} }; // 一个由int和Point结构体组成的tuple
std::tuple<int, char, std::string> t4{ 1,'t',"qwer" }; // 一个由int、char、字符串组成的tuple
}
struct Point
{
int x;
int y;
};
void main()
{
std::tuple<int, std::string> t1{ 1,"qwer" };
constexpr std::tuple<int, void*> t2{ 10,nullptr };
std::tuple<int, Point> t3{ 1,{20,89} };
std::tuple<int, char, std::string> t4{ 1,'t',"qwer" };
std::cout << std::get<0>(t1) << std::endl; // 1
constexpr int n2 = std::get<0>(t2);
std::cout << n2 << std::endl; // 10
auto s = std::get<char>(t4);
std::cout << s << std::endl; // t
}
std::tuple<int, std::string> t5{ 1,"qwer" };
if (t1 == t5)
{
std::cout << "==" << std::endl;
}
template<typename... _Types> class tuple;
struct allocator_arg_t
{};
template<>
class tuple<>
{
public:
typedef tuple<> _Myt;
constexpr tuple() noexcept
{}
template<typename _Alloc>
tuple(allocator_arg_t, const _Alloc&) noexcept
{}
constexpr tuple(const tuple&) noexcept
{}
template<class _Alloc>
tuple(allocator_arg_t, const _Alloc&, const _Myt&) noexcept
{}
void swap(_Myt&) noexcept
{}
constexpr bool _Equals(const _Myt&) const noexcept
{
return true;
}
constexpr bool _Less(const _Myt&) const noexcept
{
return false;
}
};
template<class _This,
class... _Rest>
class tuple<_This, _Rest...>
: private tuple<_Rest...>
{
// 内容
}
template<class _This,
class... _Rest>
class tuple<_This, _Rest...>
: private tuple<_Rest...>
{ // recursive tuple definition
public:
typedef _This _This_type;
typedef tuple<_This, _Rest...> _Myt;
typedef tuple<_Rest...> _Mybase;
static const size_t _Mysize = 1 + sizeof...(_Rest);
_Tuple_val<_This> _Myfirst; // 存储的元素
}
constexpr tuple(): _Mybase(), _Myfirst()
{}
constexpr explicit tuple(const _This& _This_arg,
const _Rest&... _Rest_arg)
: _Mybase(_Rest_arg...),
_Myfirst(_This_arg)
{}
tuple(const _Myt&) = default;
tuple(_Myt&&) = default;
template<class... _Other>
_Myt& operator=(const tuple<_Other...>& _Right)
{ // assign by copying same size tuple
_Myfirst._Val = _Right._Myfirst._Val;
_Get_rest() = _Right._Get_rest();
return (*this);
}
template<class... _Other>
constexpr bool _Equals(const tuple<_Other...>& _Right) const
{
static_assert(_Mysize == sizeof...(_Other), "comparing tuple to object with different size");
return (_Myfirst._Val == _Right._Myfirst._Val && _Mybase::_Equals(_Right._Get_rest()));
}
_Mybase& _Get_rest() noexcept
{
return (*this);
}
constexpr const _Mybase& _Get_rest() const noexcept
{
return (*this);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有