したらばTOP ■掲示板に戻る■ 全部 1-100 最新50 | メール | |

管理人の独り言(プログラミング関連)

2603774さん:2010/08/06(金) 22:39:39
エラーチェック?何それ美味しいの?
-----

#include <iostream>
#include <functional>
#include <windows.h>

void TestFunctionHelper(std::ostream *os, std::function<void()> *funcs, unsigned int index){
}

template<typename First, typename... Rest>
void TestFunctionHelper(std::ostream *os, std::function<void()> *funcs, unsigned int index, First first, Rest... rest){
funcs[index] = [os, first]{
*os << *first;
};
TestFunctionHelper(os, funcs, index + 1, rest...);
}

template<typename... Arg>
void TestFunction(std::ostream &os, const std::string str, Arg... arg){
static_assert(sizeof...(Arg) <= 10, "無理");

std::function<void()> funcs[sizeof...(Arg)];

TestFunctionHelper(&os, funcs, 0, &arg...);

for(unsigned int i = 0, len = str.length(); i < len; ++i){
if(str[i++] == '%'){
if(str[i] == '%'){
os << "%";
}else{
funcs[str[i] - '0']();
}
}else{
os << str[i];
}
}
}

int main(int argc, char **argv){
TestFunction(std::cout, "test%0,%1,%%,%1,%0", 100, 120);
}


新着レスの表示


名前: E-mail(省略可)

※書き込む際の注意事項はこちら

※画像アップローダーはこちら

(画像を表示できるのは「画像リンクのサムネイル表示」がオンの掲示板に限ります)

掲示板管理者へ連絡 無料レンタル掲示板