c++ tie,ignore
ignore
一个未指定的类型对象,任何值都可以没有影响地赋值给它。通常使用tie来解压一个元组,作为可以忽略的占位符。
#include <iostream>
#include <string>
#include <set>
#include <tuple> int main()
{
std::ignore = ;
std::ignore = "hello";
std::ignore = std::make_pair<int,std::string>(, ""); std::set<std::string> set_of_str;
bool inserted = false;
std::tie(std::ignore, inserted) = set_of_str.insert("Test");
if (inserted)
{
std::cout << "Value was inserted successfully\n";
} return ;
}
tie
创建一个元组的左值引用
template<typename... _Elements>
constexpr tuple<_Elements&...>
tie(_Elements&... __args) noexcept
{
return tuple<_Elements&...>(__args...);
}
可以看到,tie函数返回的是一个tuple的左值引用
tie函数可以用来解压一个pair,tuple,也可以用来产生一个结构体的字典序比较
#include <iostream>
#include <string>
#include <set>
#include <tuple>
#include <algorithm> struct S {
int n;
std::string s;
float d; S(int in, std::string && ss, float fd):n(in),s(ss),d(fd)
{} bool operator<(const S& rhs) const
{
// compares n to rhs.n,
// then s to rhs.s,
// then d to rhs.d
return std::tie(n, s, d) < std::tie(rhs.n, rhs.s, rhs.d);
}
}; int main()
{
std::set<S> set_of_s; // S is LessThanComparable S value {, "Test", 3.14};
std::set<S>::iterator iter;
bool inserted; // unpacks the return value of insert into iter and inserted
std::tie(iter, inserted) = set_of_s.insert(value);
set_of_s.emplace(,"t2", 9.8); if (inserted)
std::cout << "Value was inserted successfully\n"; for_each(set_of_s.begin(), set_of_s.end(), [](const S & value){
std::cout << value.n << ' ' << value.s << ' ' << value.d << std::endl;
}); return ;
}
输出:
Value was inserted successfully
t2 9.8
Test 3.14
经过排序之后,(12,"t2", 9.8) 在前面
c++ tie,ignore的更多相关文章
- lucene原理及源码解析--核心类
马云说:大家还没搞清PC时代的时候,移动互联网来了,还没搞清移动互联网的时候,大数据时代来了. 然而,我看到的是:在PC时代搞PC的,移动互联网时代搞移动互联网的,大数据时代搞大数据的,都是同一伙儿人 ...
- c++11 stl 学习之 pair
pair以模板的方式存储两个数据 namespace std {template <typename T1, typename T2>struct pair {// memberT1 fi ...
- stl学习记录(2)
#include <iostream> #include <utility> #include <tuple> #include <complex> # ...
- std::tuple
tuple,元组类型.头文件<tuple>,tuple是一个固定大小的不同类型(异质,heterogeneous)值的集合(这一点是tuple与其他常规STL容器的最大不同,即它可以同时存 ...
- boost::tie()和boost::variant()解说
#include<iostream> #include<boost/tuple/tuple.hpp> #include<boost/variant.hpp> #in ...
- 【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)
题意: 输入一个正整数N(<=100),接着输入N行字符串.输出N行字符串的最长公共后缀,否则输出nai. AAAAAccepted code: #include<bits/stdc++. ...
- AutoMapper:Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add a custom resolver, or modify the source/destination type
异常处理汇总-后端系列 http://www.cnblogs.com/dunitian/p/4523006.html 应用场景:ViewModel==>Mode映射的时候出错 AutoMappe ...
- cin.ignore()函数的用法
cin.ignore(a,ch)方法是从输入流(cin)中提取字符,提取的字符被忽略(ignore),不被使用.每抛弃一个字符,它都要计数和比较字符:如果计数值达到a或者被抛弃的字符是ch,则cin. ...
- iOS8: Ignore manifest download, already have bundleID
在企业分发的app下载过程中,iOS8发现挂在官网上的企业版的app点击了提示是否安装应用程序,但始终安装不上程序,的device console发现安装的时候出现 LoadExternalDownl ...
随机推荐
- ACM-树重心的性质及动态维护
本文转自http://fanhq666.blog.163.com/blog/static/81943426201172472943638/ 求树重心的方法:(NlogN) http://www.cnb ...
- IntelliJ IDEA详细配置和使用教程(转)
http://blog.csdn.net/m_m254282520/article/details/78900238 关闭Intellij IDEA自动更新 在File->Settings-&g ...
- C++ VS编译问题--LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏
用VS编译时,当出现错误LINK : fatal error LNK1123: 转换到 COFF 期间失败: 文件无效或损坏: 这个问题的解决方案为: 1. 找到项目\xx属性\配置属性\清单工具\输 ...
- Prestashop-1.6.1.6-zh_CN (Openlogic CentOS 7.2)
平台: CentOS 类型: 虚拟机镜像 软件包: prestashop1.6.1.6 commercial content management ecommerce open-source 简体中文 ...
- java:图片压缩
java使用google开源工具实现图片压缩 :http://www.cnblogs.com/linkstar/p/7412012.html
- [topcoder]TheConsecutiveIntegersDivOne
http://community.topcoder.com/stat?c=problem_statement&pm=13625&rd=16278 首先,如果记得曼哈顿距离最小值那个问题 ...
- aaS软件的必要特征分析,一定是多租户特性吗
本篇文章讲述了SaaS软件的必要特征一定是多租户特性?对于许多小型企业来说,SaaS是采用先进技术的最好途径,它消除了企业购买.构建和维护基础设施和应用程序的需要 课课家教育平台提醒各位:本篇文章纯干 ...
- Js arguments.callee();函数自己调用自己
1.阶乘的时候,函数一般要用到递归算法,所以函数内部一定会调用自身 //递归,阶乘 function sum(num){ ) { ; } else{ ); //自己调用自己,递归 } } alert( ...
- graphql 后台服务项目架构(一)
基础知识 简而言之,GraphQL 是一种描述如何请求数据的语法,通常用于客户端向服务器请求数据.GraphQL 有三个主要特点: 允许客户端精确指定所需数据. 可以更容易地从多个数据源聚合数据. 使 ...
- MySQL安装和简单操作
MySQL数据库安装与配置详解 MySQL的安装请参考下面这篇博客,讲述的非常详细,各种截图也很清晰.http://www.cnblogs.com/sshoub/p/4321640.html MySQ ...