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的更多相关文章

  1. lucene原理及源码解析--核心类

    马云说:大家还没搞清PC时代的时候,移动互联网来了,还没搞清移动互联网的时候,大数据时代来了. 然而,我看到的是:在PC时代搞PC的,移动互联网时代搞移动互联网的,大数据时代搞大数据的,都是同一伙儿人 ...

  2. c++11 stl 学习之 pair

    pair以模板的方式存储两个数据 namespace std {template <typename T1, typename T2>struct pair {// memberT1 fi ...

  3. stl学习记录(2)

    #include <iostream> #include <utility> #include <tuple> #include <complex> # ...

  4. std::tuple

    tuple,元组类型.头文件<tuple>,tuple是一个固定大小的不同类型(异质,heterogeneous)值的集合(这一点是tuple与其他常规STL容器的最大不同,即它可以同时存 ...

  5. boost::tie()和boost::variant()解说

    #include<iostream> #include<boost/tuple/tuple.hpp> #include<boost/variant.hpp> #in ...

  6. 【PAT甲级】1077 Kuchiguse (20 分)(cin.ignore()吃掉输入n以后的回车接着用getine(cin,s[i])输入N行字符串)

    题意: 输入一个正整数N(<=100),接着输入N行字符串.输出N行字符串的最长公共后缀,否则输出nai. AAAAAccepted code: #include<bits/stdc++. ...

  7. 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 ...

  8. cin.ignore()函数的用法

    cin.ignore(a,ch)方法是从输入流(cin)中提取字符,提取的字符被忽略(ignore),不被使用.每抛弃一个字符,它都要计数和比较字符:如果计数值达到a或者被抛弃的字符是ch,则cin. ...

  9. iOS8: Ignore manifest download, already have bundleID

    在企业分发的app下载过程中,iOS8发现挂在官网上的企业版的app点击了提示是否安装应用程序,但始终安装不上程序,的device console发现安装的时候出现 LoadExternalDownl ...

随机推荐

  1. gulp 无损压缩图片

    在做项目中,美工有时候会给一些比较大的图片,在做网站的时候,图片太大会影响加载速度.因此,我们需要无损压缩图片. 在尝试过几个压缩图片的方法,发现gulp中的gulp-tinypng-nokey插件是 ...

  2. thinkphp中怎么判断是手机端访问还是pc端访问?

    function isMobile() { // 如果有HTTP_X_WAP_PROFILE则一定是移动设备 if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])) r ...

  3. RESTful API设计基本原则

    REST四个基本原则:1.使用HTTP动词:GET POST PUT DELETE:2.无状态连接,服务器端不应保存过多上下文状态,即每个请求都是独立的:3.为每个资源设置URI:4.通过XML JS ...

  4. 使用 Notapad++ 进行 Java 开发

    准备工具 1.安装 JDK 以及配置相关环境变量: 2.安装 64 位版的 Notepad++ : 2.一台 64 位 Windows 系统电脑: 一.下载&安装Notepad++ 官网下载地 ...

  5. 【起航计划 020】2015 起航计划 Android APIDemo的魔鬼步伐 19 App->Dialog Dialog样式

    这个例子的主Activity定义在AlertDialogSamples.java 主要用来介绍类AlertDialog的用法,AlertDialog提供的功能是多样的: 显示消息给用户,并可提供一到三 ...

  6. centos6.5 网卡配置

    家里用的电脑是电信拨号的 所以用不了桥接模式 改用nat vi /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE="eth0" HW ...

  7. [SVN]TortoiseSVN工具培训5─常见问题解决

    1.文件提交时状态异常 产生原因:操作不当 解决方法:使用SVN的clean up命令 2.权限不足 产生原因:当前用户权限不足 解决方法:找配置管理员申请权限 3.网络故障 产生原因:无法访问到配置 ...

  8. 使用python做最简单的爬虫

    使用python做最简单的爬虫 --之心 #第一种方法import urllib2 #将urllib2库引用进来response=urllib2.urlopen("http://www.ba ...

  9. 笨办法学Python(二十一)

    习题 21: 函数可以返回东西 你已经学过使用 = 给变量命名,以及将变量定义为某个数字或者字符串.接下来我们将让你见证更多奇迹.我们要演示给你的是如何使用 = 以及一个新的 Python 词汇ret ...

  10. April 3 2017 Week 14 Monday

    Don't worry about finding your soul mate. Find yourself. 欲寻佳侣,先觅本心. You may fail to find your soul m ...