当前位置: 首页 > news >正文

抚顺做网站seo技术教程博客

抚顺做网站,seo技术教程博客,xampp wordpress主题,福州网站建设制作在c 11标准库中&#xff0c;加入了std::tie&#xff0c;在c 14中改进&#xff0c;方便使用。 其与std::tuple关系密切&#xff0c; 主要目的是方便地使用std::tuple。 std::tie函数的作用就是从元素引用中生成一个std::tuple元组&#xff0c;其在头文件<tuple>中定义&…

在c++ 11标准库中,加入了std::tie,在c++ 14中改进,方便使用。 其与std::tuple关系密切, 主要目的是方便地使用std::tuple。
std::tie函数的作用就是从元素引用中生成一个std::tuple元组,其在头文件<tuple>中定义,其函数原型如下:

template< class... Types >
std::tuple<Types&...> tie( Types&... args ) noexcept; //C++11起, C++14前template< class... Types >
constexpr std::tuple<Types&...> tie( Types&... args ) noexcept; //C++14起

元组std::tuple可以将不同类型的元素存放在一起,可以理解为std::pair的扩展(pair只能包含两个元素,而tuple可以多个)。
std::tuple拥有从 pair 的转换赋值,因为std::tuple的实现中重载了操作符=,其部分原型如下:

template< class U1, class U2 >
tuple& operator=( const std::pair<U1, U2>& p );//C++11 起, C++20 前

因此,std::tie可以用于pair的解包

#include <set>
#include <tuple>
#include <iostream>int main(int argc, char *argv[])
{std::set<int> sets;std::set<int>::iterator iter;bool result = false;std::tie(iter, result) = sets.insert(1);//解包insert的返回值为iter与resultstd::tie(std::ignore, result) = sets.insert(2); // std::ignore是std::tie在解包时作为不使用的参数的占位符使用,即忽略某些tuple中的某些返回值。std::cout << result << std::endl; // 输出1return 0;
}

std::set的insert函数原型如下:

std::pair<iterator, bool> insert( const value_type& value );
std::pair<iterator, bool> insert( value_type&& value );template< class InputIt >
void insert( InputIt first, InputIt last );
void insert( std::initializer_list<value_type> ilist );

为生成pair, c++ 提供了make_pair的快捷操作,相应的,对tuple也提供了make_tuple用于快速创建tuple对象。创建tuple对象的方式有三种:

std::tuple<int, double, std::string> student1 = { 1, 77.7, "Sunny" }; // 定义时 初始化
std::tuple<int, double, std::string> student2 ( 2, 88.8, "Gavin" );   // 使用构造函数
auto student3 = std::make_tuple(3, 99.9, "Lucia" );                   // 使用make_tuple

使用std::tie解包tuple

#include <tuple>
#include <iostream>
#include <string>int main(int argc, char *argv[])
{auto student3 = std::make_tuple(3, 99.9, "Lucia" );int id;std::string name;std::tie(id, std::ignore, name) = student3;std::cout << "student id: " << id << "  \t " << "student name: " << name << std::endl;return 0;
}


可以将结构体成员传入std::tie,从而实现结构体的比较。

struct Student {int id;float score;std::string name;bool operator<(const Student& rhs) const{// 先比较id与rhs.id// 然后比较score与rhs.score// 最后比较name与rhs.name// tuple内已经重载了运算符<return std::tie(id, score, name) < std::tie(rhs.id, rhs.score, rhs.name);}
};

一个例子:

#include <tuple>
#include <set>
#include <iostream>
#include <string>struct Student {int id;float score;std::string name;bool operator<(const Student& rhs) const{// 先比较id与rhs.id// 然后比较score与rhs.score// 最后比较name与rhs.name// tuple内已经重载了运算符<return std::tie(id, score, name) < std::tie(rhs.id, rhs.score, rhs.name);}
};int main(int argc, char *argv[])
{std::set<Student> sets;Student student1{1, 77.7, "Sunny"};Student student2{ 2, 88.8, "Gavin"};std::set<Student>::iterator iter;bool result = false;std::tie(iter, result) = sets.insert(student1);if (result){std::cout << "student1 was inserted successfully" <<std::endl;}std::tie(std::ignore, result) = sets.insert(student2); // 使用std::ignore忽略insert的返回pair中的第一个元素if (result){std::cout << "student2 was inserted successfully" <<std::endl;}result = student1 < student2;std::cout << "student1 < student2: " << result << std::endl;return 0;
}

原文链接:https://blog.csdn.net/caoshangpa/article/details 

http://www.ds6.com.cn/news/92517.html

相关文章:

  • 做网站外包公司无锡百姓网推广
  • 做网站加入广告联盟免费建立个人网站官网
  • 网站规划作品seo基础知识培训
  • 2022腾讯云网站建设方案书宁波seo整站优化
  • 轻量云做网站怎么样百度推广登录平台app
  • 58同城济南网站建设网站制作软件
  • 论文中引用网站中免费建立个人网站官网
  • 做网站怎么备份数据百度网址收录提交入口
  • 邢台做网站推广阿里云自助建站
  • 徐州网站开发要多少钱淘宝指数
  • 自己网站如何做关键词排名靠前深圳网络推广seo软件
  • 网站建设 三门峡百度推广费用
  • 如何做好网站管理工作网络营销环境分析主要包括
  • 企业网站建设有没有模板一键清理加速
  • 外国人做旅游攻略网站优秀网页设计作品
  • 长沙模板网站建设企业如何进入网站
  • 广州建站客服招聘茶叶seo网站推广与优化方案
  • 建网站详细教程网络优化器下载
  • 网站建设初期昆明seo关键词排名
  • 给网站做推广跨境电商怎么开店铺
  • 做网站开票是多少个点的票石首seo排名
  • 网站名称怎么变更关键词seo排名优化如何
  • 做购物网站开发价格影响seo排名的因素有哪些
  • 刷信誉网站怎么做北京百度推广客服电话多少
  • 设计一套网站费用网页搜索关键字
  • 买花网站代码杭州seo平台
  • 江阳建设集团网站网络营销渠道策略有哪些
  • 慈溪 网站建设杭州网站建设公司
  • 做动态图网站宣传页面怎么制作
  • 河北专业网站制作神马推广登录