std:tuple 会检查重复的函数吗

为std::tuple添加序列化/格式化支持_C++,C语言_ThinkSAAS
为std::tuple添加序列化/格式化支持
为std::tuple添加序列化/格式化支持
C++11中有很多激动人心的特性,但是相应的使得C++更加复杂。。。新标准还修改了原有标准库,并增加了很多内容。 在学习新标准的过程中动手写了个 为std::tuple增加格式化/序列化能力的一小段代码
#define DECLARE_TUPLE_SERIALIZATION_FUNCTION(FUNC_NAME,BEG,SEP,END)
namespace sjdfsjfyttsaihfah6755jsdfsdf{
template &typename Tuple,std::size_t N&
struct tuple_printer
static void print(std::ostream& os,const Tuple& t)
os&&std::get&std::tuple_size&Tuple&::value - N &(t)&&SEP;
tuple_printer&Tuple,N-1&::print(os,t);
template &typename Tuple&
struct tuple_printer&Tuple,1&
static void print(std::ostream& os,const Tuple& t)
os&&std::get&std::tuple_size&Tuple&::value-1&(t);
template &typename Tuple&
void FUNC_NAME(std::ostream& os,const Tuple& t)
sjdfsjfyttsaihfah6755jsdfsdf::tuple_printer&Tuple,std::tuple_size&Tuple&::value&::print(os,t);
//实现成宏是为了使用起来更方便,可以随意指定 函数名 前缀 分隔符 和 后缀。
//使用方法如下:
DECLARE_TUPLE_SERIALIZATION_FUNCTION(serialize_tuple,"&",",","&")
int main()
auto a = std::make_tuple(3,"lala",i,'c');
serialize_tuple(std::cout,a);
&3 ,"lala", 10 , c&
测试环境为GCC 4.5,注意编译时候请打开C++0X支持。
PHP开发框架
开发工具/编程工具
服务器环境
ThinkSAAS商业授权:
ThinkSAAS为用户提供有偿个性定制开发服务
ThinkSAAS将为商业授权用户提供二次开发指导和技术支持
让ThinkSAAS更好,把建议拿来。
开发客服微信下次自动登录
现在的位置:
& 综合 & 正文
C++ – “tuple”(元组)容器 详解 及 代码
"tuple"(元组)容器 详解 及
本文地址: http://blog.csdn.net/caroline_wendy/article/details/
tuple容器(元组), 是表示元组容器, 是不包含任何结构的,快速而低质(粗制滥造, quick and dirty)的,
可以用于函数返回多个返回值;
tuple容器, 可以使用直接初始化, 和"make_tuple()"初始化, 访问元素使用"get&&()"方法,
注意get里面的位置信息, 必须是常量表达式(const expression);
可以通过"std::tuple_size&decltype(t)&::value"获取元素数量; "std::tuple_element&0, decltype(t)&::type"获取元素类型;
如果tuple类型进行比较, 则需要保持元素数量相同, 类型可以比较, 如相同类型, 或可以相互转换类型(int&double);
无法通过普通的方法遍历tuple容器, 因为"get&&()"方法, 无法使用变量获取值;
以下代码包含一些基本的用法, 详见注释;
* CppPrimer.cpp
Created on:
Author: Caroline
/*eclipse cdt, gcc 4.8.1*/
#include &iostream&
#include &vector&
#include &string&
#include &tuple&
std::tuple&std::string, int&
giveName(void)
std::string cw("Caroline");
int a(2013);
std::tuple&std::string, int& t = std::make_tuple(cw, a);
int main()
std::tuple&int, double, std::string& t(64, 128.0, "Caroline");
std::tuple&std::string, std::string, int& t2 =
std::make_tuple("Caroline", "Wendy", 1992);
//返回元素个数
size_t num = std::tuple_size&decltype(t)&::
std::cout && "num = " && num && std::
//获取第1个值的元素类型
std::tuple_element&1, decltype(t)&::type cnt = std::get&1&(t);
std::cout && "cnt = " && cnt && std::
std::tuple&int, int& ti(24, 48);
std::tuple&double, double& td(28.0, 56.0);
bool b = (ti & td);
std::cout && "b = " && b && std::
//tuple作为返回值
auto a = giveName();
std::cout && "name: " && get&0&(a)
&& " years: " && get&1&(a) && std::
name: Caroline years: 2013
&&&&推荐文章:
【上篇】【下篇】模板输出tuple怎么会错呢?_c++吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:258,369贴子:
模板输出tuple怎么会错呢?收藏
template& typename ...T, std::size_t... I&void apply_impl(tuple&T...& t, std::index_sequence&I...&){ cout&&std::get&I...&(t);}template&typename ...T&void apply(tuple&T...& t){ apply_impl(t, std::make_index_sequence&std::tuple_size&tuple&T...&&::value&());}int _tmain(int argc, _TCHAR* argv[]){ apply(make_tuple(1, 2, 3, 4)); return 0;}我想把tuple通过闭包输出,可是vc编译错误。。。
c++一般需要4-8周,就可以掌握.4个月=两年的工作经验,月薪过万.c++的费用根据培训课时定,免费试听编程课程,名师授课,手把手传教.
错误提示:错误 C2974 'std::get' : 模板 对于 '_Ty'是无效参数,应为类型错误 C2974 'std::get' : 模板 对于 '_Types'是无效参数,应为类型错误 C2974 'std::get' : 模板 对于 '_Ty2'是无效参数,应为类型错误 C2974 'std::get' : 模板 对于 '_Ty1'是无效参数,应为类型
std::get&I...&是什么鬼
来人啊救命啊
这样写能在 Clang 和 GCC 上通过 (-std=c++14),但我也不知道为什么。template& typename ...T, std::size_t... I&void apply_impl(tuple&T...& t, std::index_sequence&I...&){
(void)(int []){((cout && std::get&I&(t)), 0)...};}
说起来 (int []){blahblah} 是不符合 C++ 语法的(这是 C99 的 compound literal 的语法),不过要改成严格遵守 C++11 语法的形式也不难template& typename ...T, std::size_t... I&void apply_impl(tuple&T...& t, std::index_sequence&I...&){
int unused[] = {(cout && std::get&I&(t), 0)...};}话说这个 idiom 似乎还没有通用的名字:以及,不出意外的话,在 C++17 中可以使用 fold expression :(cout && ... && std::get&I&(t));完整代码:
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或一直想写个CSV读写的模板,但是接口的定义一直是个问题。CSV每列都可以任意映射成C++基本类型,怎么把接口定义得既通用又灵活?最近发现C++11引入了tuple,接口也可以像python一样的方便漂亮,而且不再依赖boost库,真正做到Windows/Linux一套代码。
#ifndef _CSV_TO_TUPLES_H
#define _CSV_TO_TUPLES_H
#include &stdlib.h&
#include &string&
#include &istream&
#include &ostream&
#include &fstream&
#include &sstream&
#include &iomanip&
#include &vector&
#include &memory&
#include &common/common_utils.h&
namespace util {
namespace csv_tuple {
template &typename T&
class NullType
explicit NullType()
: is_null(true) // by default, NULL value
explicit NullType(const NullType& src)
: is_null(src.is_null), value(src.value)
explicit NullType(const T& v)
: is_null(false), value(v)
~NullType()
void Reset()
// not all types can be reset by assigning of 0
*this = NullType();
NullType& operator=(const NullType& src)
this-&is_null = src.is_
this-&value = src.
typedef NullType&char& NullC
typedef NullType&unsigned char& NullUC
typedef NullType&short& NullS
typedef NullType&unsigned short& NullUS
typedef NullType&int& NullI
typedef NullType&unsigned int& NullUI
typedef NullType&long long& NullBigI
typedef NullType&unsigned long long& NullUBigI
typedef NullType&float& NullF
typedef NullType&float& NullR
typedef NullType&double& NullD
typedef NullType&bool& NullB
typedef NullType&std::string& NullS
template &typename T&
void StringToValue(const std::string& str, NullType&T&& value)
if (str.empty()) {
value.Reset();
value.is_null =
StringToValue(str, value.value);
static inline void StringToValue(const std::string &str, char &value)
value = (char)atoi(str.c_str());
static inline void StringToValue(const std::string &str, unsigned char &value)
value = (unsigned char)atoi(str.c_str());
static inline void StringToValue(const std::string &str, short &value)
value = (short)atoi(str.c_str());
static inline void StringToValue(const std::string &str, unsigned short &value)
value = (unsigned short)atoi(str.c_str());
static inline void StringToValue(const std::string &str, int &value)
value = atoi(str.c_str());
static inline void StringToValue(const std::string &str, unsigned int &value)
value = (unsigned int)std::strtoul(str.c_str(), NULL, 10);
static inline void StringToValue(const std::string &str, long long &value)
#ifdef _WIN32
value = _atoi64(str.c_str());
value = atoll(str.c_str());
static inline void StringToValue(const std::string &str, unsigned long long &value)
value = (unsigned long long)std::strtoull(str.c_str(), NULL, 10);
static inline void StringToValue(const std::string &str, bool &value)
value = atoi(str.c_str()) != 0;
static inline void StringToValue(const std::string& str, std::string& value)
static inline void StringToValue(const std::string& str, float& value)
value = (float)atof(str.c_str());
static inline void StringToValue(const std::string& str, double& value)
value = atof(str.c_str());
// add more versions of StringToValue() if needed
#define TUPLE_SET_ITEM(tp, i) \
T##i t##i; \
StringToValue(subs[i], t##i); \
std::get&i&(tp) = t##i
template&typename T0&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0&& tp)
TUPLE_SET_ITEM(tp, 0);
template&typename T0, typename T1&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
template&typename T0, typename T1, typename T2&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
template&typename T0, typename T1, typename T2, typename T3&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
template&typename T0, typename T1, typename T2, typename T3, typename T4&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3, T4&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
TUPLE_SET_ITEM(tp, 4);
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3, T4, T5&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
TUPLE_SET_ITEM(tp, 4);
TUPLE_SET_ITEM(tp, 5);
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3, T4, T5, T6&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
TUPLE_SET_ITEM(tp, 4);
TUPLE_SET_ITEM(tp, 5);
TUPLE_SET_ITEM(tp, 6);
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3, T4, T5, T6, T7&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
TUPLE_SET_ITEM(tp, 4);
TUPLE_SET_ITEM(tp, 5);
TUPLE_SET_ITEM(tp, 6);
TUPLE_SET_ITEM(tp, 7);
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
TUPLE_SET_ITEM(tp, 4);
TUPLE_SET_ITEM(tp, 5);
TUPLE_SET_ITEM(tp, 6);
TUPLE_SET_ITEM(tp, 7);
TUPLE_SET_ITEM(tp, 8);
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
TUPLE_SET_ITEM(tp, 4);
TUPLE_SET_ITEM(tp, 5);
TUPLE_SET_ITEM(tp, 6);
TUPLE_SET_ITEM(tp, 7);
TUPLE_SET_ITEM(tp, 8);
TUPLE_SET_ITEM(tp, 9);
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
TUPLE_SET_ITEM(tp, 4);
TUPLE_SET_ITEM(tp, 5);
TUPLE_SET_ITEM(tp, 6);
TUPLE_SET_ITEM(tp, 7);
TUPLE_SET_ITEM(tp, 8);
TUPLE_SET_ITEM(tp, 9);
TUPLE_SET_ITEM(tp, 10);
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10, typename T11&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
TUPLE_SET_ITEM(tp, 4);
TUPLE_SET_ITEM(tp, 5);
TUPLE_SET_ITEM(tp, 6);
TUPLE_SET_ITEM(tp, 7);
TUPLE_SET_ITEM(tp, 8);
TUPLE_SET_ITEM(tp, 9);
TUPLE_SET_ITEM(tp, 10);
TUPLE_SET_ITEM(tp, 11);
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10, typename T11,
typename T12&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
TUPLE_SET_ITEM(tp, 4);
TUPLE_SET_ITEM(tp, 5);
TUPLE_SET_ITEM(tp, 6);
TUPLE_SET_ITEM(tp, 7);
TUPLE_SET_ITEM(tp, 8);
TUPLE_SET_ITEM(tp, 9);
TUPLE_SET_ITEM(tp, 10);
TUPLE_SET_ITEM(tp, 11);
TUPLE_SET_ITEM(tp, 12);
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10, typename T11,
typename T12, typename T13&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
TUPLE_SET_ITEM(tp, 4);
TUPLE_SET_ITEM(tp, 5);
TUPLE_SET_ITEM(tp, 6);
TUPLE_SET_ITEM(tp, 7);
TUPLE_SET_ITEM(tp, 8);
TUPLE_SET_ITEM(tp, 9);
TUPLE_SET_ITEM(tp, 10);
TUPLE_SET_ITEM(tp, 11);
TUPLE_SET_ITEM(tp, 12);
TUPLE_SET_ITEM(tp, 13);
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename T10, typename T11,
typename T12, typename T13, typename T14&
void FillTuple(const std::vector&std::string&& subs,
std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14&& tp)
TUPLE_SET_ITEM(tp, 0);
TUPLE_SET_ITEM(tp, 1);
TUPLE_SET_ITEM(tp, 2);
TUPLE_SET_ITEM(tp, 3);
TUPLE_SET_ITEM(tp, 4);
TUPLE_SET_ITEM(tp, 5);
TUPLE_SET_ITEM(tp, 6);
TUPLE_SET_ITEM(tp, 7);
TUPLE_SET_ITEM(tp, 8);
TUPLE_SET_ITEM(tp, 9);
TUPLE_SET_ITEM(tp, 10);
TUPLE_SET_ITEM(tp, 11);
TUPLE_SET_ITEM(tp, 12);
TUPLE_SET_ITEM(tp, 13);
TUPLE_SET_ITEM(tp, 14);
// add more versions of FillTuple() if needed
#undef TUPLE_SET_ITEM
template &typename T&
static inline std::string ValueToStr(const T& value)
template &&
std::string ValueToStr(const double& value)
ss && std::setprecision(11) &&
template &&
std::string ValueToStr(const float& value)
ss && std::setprecision(11) &&
template &&
std::string ValueToStr(const std::string& value)
std::string ret(&\&&);
ret += '\&';
return std::move(ret);
template&typename T0&
void FillLine(const std::tuple&T0&& tp, char /*delimiter*/, std::string& line)
line = ValueToStr(std::get&0&(tp));
template&typename T0, typename T1&
void FillLine(const std::tuple&T0, T1&& tp, char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
template&typename T0, typename T1, typename T2&
void FillLine(const std::tuple&T0, T1, T2&& tp, char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
template&typename T0, typename T1, typename T2, typename T3&
void FillLine(const std::tuple&T0, T1, T2, T3&& tp, char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
template&typename T0, typename T1, typename T2, typename T3, typename T4&
void FillLine(const std::tuple&T0, T1, T2, T3, T4&& tp, char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
line += ValueToStr(std::get&4&(tp));
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5&
void FillLine(const std::tuple&T0, T1, T2, T3, T4, T5&& tp, char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
line += ValueToStr(std::get&4&(tp));
line += ValueToStr(std::get&5&(tp));
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6&
void FillLine(const std::tuple&T0, T1, T2, T3, T4, T5, T6&& tp, char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
line += ValueToStr(std::get&4&(tp));
line += ValueToStr(std::get&5&(tp));
line += ValueToStr(std::get&6&(tp));
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
typename T7&
void FillLine(const std::tuple&T0, T1, T2, T3, T4, T5, T6, T7&& tp, char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
line += ValueToStr(std::get&4&(tp));
line += ValueToStr(std::get&5&(tp));
line += ValueToStr(std::get&6&(tp));
line += ValueToStr(std::get&7&(tp));
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
typename T7, typename T8&
void FillLine(const std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8&& tp,
char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
line += ValueToStr(std::get&4&(tp));
line += ValueToStr(std::get&5&(tp));
line += ValueToStr(std::get&6&(tp));
line += ValueToStr(std::get&7&(tp));
line += ValueToStr(std::get&8&(tp));
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
typename T7, typename T8, typename T9&
void FillLine(const std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9&& tp,
char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
line += ValueToStr(std::get&4&(tp));
line += ValueToStr(std::get&5&(tp));
line += ValueToStr(std::get&6&(tp));
line += ValueToStr(std::get&7&(tp));
line += ValueToStr(std::get&8&(tp));
line += ValueToStr(std::get&9&(tp));
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
typename T7, typename T8, typename T9, typename T10&
void FillLine(const std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10&& tp,
char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
line += ValueToStr(std::get&4&(tp));
line += ValueToStr(std::get&5&(tp));
line += ValueToStr(std::get&6&(tp));
line += ValueToStr(std::get&7&(tp));
line += ValueToStr(std::get&8&(tp));
line += ValueToStr(std::get&9&(tp));
line += ValueToStr(std::get&10&(tp));
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
typename T7, typename T8, typename T9, typename T10, typename T11&
void FillLine(const std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11&& tp,
char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
line += ValueToStr(std::get&4&(tp));
line += ValueToStr(std::get&5&(tp));
line += ValueToStr(std::get&6&(tp));
line += ValueToStr(std::get&7&(tp));
line += ValueToStr(std::get&8&(tp));
line += ValueToStr(std::get&9&(tp));
line += ValueToStr(std::get&10&(tp));
line += ValueToStr(std::get&11&(tp));
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
typename T7, typename T8, typename T9, typename T10, typename T11, typename T12&
void FillLine(const std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12&& tp,
char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
line += ValueToStr(std::get&4&(tp));
line += ValueToStr(std::get&5&(tp));
line += ValueToStr(std::get&6&(tp));
line += ValueToStr(std::get&7&(tp));
line += ValueToStr(std::get&8&(tp));
line += ValueToStr(std::get&9&(tp));
line += ValueToStr(std::get&10&(tp));
line += ValueToStr(std::get&11&(tp));
line += ValueToStr(std::get&12&(tp));
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13&
void FillLine(const std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13&& tp,
char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
line += ValueToStr(std::get&4&(tp));
line += ValueToStr(std::get&5&(tp));
line += ValueToStr(std::get&6&(tp));
line += ValueToStr(std::get&7&(tp));
line += ValueToStr(std::get&8&(tp));
line += ValueToStr(std::get&9&(tp));
line += ValueToStr(std::get&10&(tp));
line += ValueToStr(std::get&11&(tp));
line += ValueToStr(std::get&12&(tp));
line += ValueToStr(std::get&13&(tp));
template&typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6,
typename T7, typename T8, typename T9, typename T10, typename T11, typename T12, typename T13, typename T14&
void FillLine(const std::tuple&T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14&& tp,
char delimiter, std::string& line)
line = ValueToStr(std::get&0&(tp));
line += ValueToStr(std::get&1&(tp));
line += ValueToStr(std::get&2&(tp));
line += ValueToStr(std::get&3&(tp));
line += ValueToStr(std::get&4&(tp));
line += ValueToStr(std::get&5&(tp));
line += ValueToStr(std::get&6&(tp));
line += ValueToStr(std::get&7&(tp));
line += ValueToStr(std::get&8&(tp));
line += ValueToStr(std::get&9&(tp));
line += ValueToStr(std::get&10&(tp));
line += ValueToStr(std::get&11&(tp));
line += ValueToStr(std::get&12&(tp));
line += ValueToStr(std::get&13&(tp));
line += ValueToStr(std::get&14&(tp));
template&typename... Args&
bool CsvToTuples(std::istream& in, char delimiter, std::vector&std::tuple&Args...& && tuples,
std::string& err)
const size_t N = sizeof...(Args);
std::vector&std::string&
std::tuple&Args...&
while (util::GetLine(in, line)) {
if (line[0] == '#') { // ignore comment
util::ParseCsvLine(subs, line, delimiter);
if (subs.size() & N) {
oss && &Error: unexpected column size. Expected: & && N && &, Actual: & && subs.size()
&& &, line data : & &&
err = oss.str();
csv_tuple::FillTuple(subs, tp);
tuples.push_back(tp);
template&typename... Args&
bool CsvToTuples(const std::string& csv_pathname, char delimiter,
std::vector&std::tuple&Args...& && tuples, std::string& err)
std::ifstream in(csv_pathname.c_str());
if (!in.good()) {
err = &Error in opening file \&& + csv_pathname + &\&&;
return CsvToTuples(in, delimiter, tuples, err);
template&typename... Args&
bool TuplesToCsv(const std::string& head, std::vector&std::tuple&Args...& && tuples,
std::ostream& out, char delimiter, std::string& err)
if (!head.empty()) {
out && head && std::
const size_t N = sizeof...(Args);
const size_t buff_size = 1024 * 8;
buff.reserve(buff_size + 256);
for (auto& t : tuples) {
csv_tuple::FillLine(t, delimiter, line);
buff += '\n';
if (buff.length() & buff_size) {
buff.clear();
if (!buff.empty()) {
template&typename... Args&
bool TuplesToCsv(const std::string& head, std::vector&std::tuple&Args...& && tuples,
const std::string& csv_pathname, char delimiter, std::string& err)
std::ofstream out(csv_pathname.c_str());
if (!out.good()) {
err = &Error in opening file \&& + csv_pathname + &\&&;
return TuplesToCsv(head, tuples, out, delimiter, err);
#endif //_CSV_TO_TUPLES_H
写文件调用示例。读文件的略。
typedef std::tuple&std::string, std::string, double, int& out_
std::vector&out_entry&
tuples.push_back(std::make_tuple(&ABC&, &&, 100.1, 100));
std::string head(&# COLUMN1,COLUMN2,COLUMN3,COLUMN4&),
TuplesToCsv(head, tuples, csv, ',' , err);
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:636次
排名:千里之外

我要回帖

更多关于 excel 检查重复 的文章

 

随机推荐