赞
踩
这一系列文章的目的是在学习了C++基础后,继续补充一些C++基础和进阶的知识点,包括C++11的相关内容。
以C++11标准为基础。
C++网站:http://www.cplusplus.com/reference/
#include <tuple> // 构造 std::tuple<int,char> first; // default std::tuple<int,char> second (first); // copy std::tuple<int,char> third (std::make_tuple(20,'b')); // move std::tuple<long,char> fourth (third); // implicit conversion std::tuple<int,char> fifth (10,'a'); // initialization std::tuple<int,char> sixth (std::make_pair(30,'c')); // from pair / move // std::make_tuple auto first = std::make_tuple (10,'a'); // tuple < int, char > const int a = 0; int b[3]; // decayed types: auto second = std::make_tuple (a,b); // tuple < int, int* > auto third = std::make_tuple (std::ref(a),"abc"); // tuple < const int&, const char* > // std::tie int myint; char mychar; std::tuple<int,float,char> mytuple; mytuple = std::make_tuple (10, 2.6, 'a'); // packing values into tuple std::tie (myint, std::ignore, mychar) = mytuple; // unpacking tuple into variables // std::get 这里返回的是元素的引用 std::tuple<int,char> mytuple (10,'a'); std::get<0>(mytuple) = 20; std::cout << std::get<0>(mytuple) << " and " << std::get<1>(mytuple); // 20 and a // std::tuple_cat 串联不同的tuple std::tuple<float,std::string> mytuple (3.14,"pi"); std::pair<int,char> mypair (10,'a'); auto myauto = std::tuple_cat ( mytuple, std::tuple<int,char>(mypair) );
#include <tuple>
[[nodiscard("important...info output")]] int dontIgnoreMe(){
return 42;
}
int main(){
std::ignore = dontIgnoreMe();
}
**注. nodiscard是C++17的内容
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。