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 ...
随机推荐
- mybatis批量插入insert时报错
报错信息: 传入的表格格式数据流(TDS)远程过程调用(RPC)协议流不正确.此 RPC 请求中提供了过多的参数.最多应为2100 错误分析: 由于mybatis拼接的sql语句参数过多导致 解决办法 ...
- python面试题——网络编程和并发
1.简述 OSI 七层协议. 物理层(电信号.比特流) 基于电器特性发送高低电压(电信号) RJ45.IEEE802.3 数据链路层(数据帧) 定义了电信号的分组方式,分组方式后来形成了统一的标准,即 ...
- Android开发从系统图库中选择一张图片的方法
刚开始学习OpenCv4Android编程,做了个小demo. 就是一个主界面上添加一个ImageView 两个Button控件. 一个Button用来从系统相册选择一张照片: 另一个Button是用 ...
- python_opencv应用系列1:图片读写
opencv的读写非常简单,主要用到的就是imread和imwrite两个函数 读取图片示例 import cv2 #imread(filename[, flags]) -> retval im ...
- python3线程介绍02(线程锁的介绍:互斥、信号、条件、时间、定时器)
#!/usr/bin/env python# -*- coding:utf-8 -*- import threadingimport timeimport random # 1-互斥锁 Lock 同一 ...
- LoadRunner性能测试之常见函数及参数的说明和作用
- java文件
File类 为了很方便的代表文件的概念,以及存储一些对于文件的基本操作,在java.io包中设计了一个专门的类——File类. 在File类中包含了大部分和文件操作的功能方法,该类的对象可以代表一个具 ...
- chromedp下载文件的方法,备忘一下。
sect := `//a[@href="v/443.json"]` wd,_ := os.Getwd() fmt.Println(wd) return chromedp.Tasks ...
- VUE的组件DEMO
组件的基本写法可以如下: HTML: <div id="components-demo"> <button-counter self-data="thi ...
- BFS变换素数,POJ(3126)
题目链接:http://poj.org/problem?id=3126 解题报告: #include <iostream> #include <queue> #include ...