tag:blogger.com,1999:blog-34976824173020555672024-02-08T03:40:31.561-08:00HumaneerAnonymoushttp://www.blogger.com/profile/04671894076767048858noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-3497682417302055567.post-66637857930778868342015-09-23T19:44:00.001-07:002015-09-23T19:45:43.349-07:00Google C++ Style Guide 번역<div class="post-title">
<a href="http://surpreem.com/archives/294">http://surpreem.com/archives/294</a></div>
<div class="post-title">
<br /></div>
<div class="post-title">
아주 유용함. </div>
Anonymoushttp://www.blogger.com/profile/04671894076767048858noreply@blogger.com0tag:blogger.com,1999:blog-3497682417302055567.post-92197726847311460302014-12-29T18:34:00.004-08:002014-12-29T18:34:52.040-08:00(링크)STL deque에 대한 분석 글, "An In-Depth Study of the STL Deque Container"<a href="http://www.codeproject.com/Articles/5425/An-In-Depth-Study-of-the-STL-Deque-Container" target="_blank">[원문]</a><br />
<br />
<br />Anonymoushttp://www.blogger.com/profile/04671894076767048858noreply@blogger.com0tag:blogger.com,1999:blog-3497682417302055567.post-58416990262889398352014-12-26T00:02:00.002-08:002014-12-26T00:02:51.016-08:00simple csv parser내가 살짝 수정함.
근데 먼가 버그스러운 것이 있음. -_-;
<textarea class="cpp" name="code">
std::vector<std::string> csv_read_row(std::string &line, char delimiter)
{
std::istringstream ss(line);
return csv_read_row(ss, delimiter);
}
std::vector<std::string> csv_read_row(std::istream &in, char delimiter)
{
std::stringstream ss;
bool inquotes = false;
std::vector<std::string> row;//relying on RVO
while(in.good())
{
char c = in.get();
if (!inquotes && c=='"') //beginquotechar
{
inquotes=true;
}
else if (inquotes && c=='"') //quotechar
{
if ( in.peek() == '"')//2 consecutive quotes resolve to 1
{
ss << (char)in.get();
}
else //endquotechar
{
inquotes=false;
}
}
else if (!inquotes && c==delimiter) //end of field
{
row.push_back( ss.str() );
ss.str("");
}
else if (!inquotes && (c=='\r' || c=='\n') )
{
if(in.peek()=='\n') { in.get(); }
row.push_back( ss.str() );
return row;
}
else if (c == static_cast<char>(0xff))
{ // 이상하게 c에 0xff가 들어가있는 경우가 발생함. 제일 마지막에...
row.push_back( ss.str() );
return row;
}
else
{
ss << c;
}
}
}
</textarea>Anonymoushttp://www.blogger.com/profile/04671894076767048858noreply@blogger.com0tag:blogger.com,1999:blog-3497682417302055567.post-88733543693274447992014-12-23T16:20:00.001-08:002014-12-23T20:14:30.532-08:00operator= 는 자기대입 처리할 것, 객체는 빠짐없이 복사할 것.effective c++, chapter 11
<textarea class="cpp" name="code">
#include <iostream>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <iterator>
#include <typeinfo>
struct GenRand
{
template <typename T>
void operator()(T& rhs)
{
rhs = static_cast<T>(rand() % 255);
}
};
struct TransRand
{
template <typename T>
T operator()(const T& rhs)
{
return (rand() % 255) * rhs;
}
};
class Widget
{
protected:
int _count;
friend std::ostream& operator << (std::ostream& os, const Widget& rhs);
virtual void swap(Widget& rhs)
{
std::cout << "Widget Swap...\n";
int tempCount = _count;
int* tempData = _data;
_count = rhs._count;
_data = rhs._data;
rhs._count = tempCount;
rhs._data = tempData;
}
int* _data;
public:
~Widget()
{
if(_count)
delete [] _data;
std::cout << "Widget Destroy...\n";
}
Widget(const int& count = 0) : _count(count), _data(0)
{
std::cout << "Widget Create Default...\n";
if (_count)
{
_data = new int[_count];
std::for_each(_data, _data+_count, GenRand());
}
}
Widget(const Widget& rhs) : _count(rhs._count)
{
std::cout << "Widget Create Copy...\n";
_data = new int[_count];
std::copy(rhs._data, rhs._data+rhs._count, _data);
}
Widget& operator=(Widget rhs)
{
std::cout << "Widget Assign...\n";
swap(rhs);
return *this;
}
};
std::ostream& operator << (std::ostream& os, const Widget& rhs)
{
std::copy(rhs._data, rhs._data+rhs._count, std::ostream_iterator<int>(os, " "));
os << "\n";
return os;
}
class WidgetDerived : public Widget
{
private:
float* _fdata;
public:
friend std::ostream& operator << (std::ostream& os, const WidgetDerived& rhs);
~WidgetDerived()
{
std::cout << "WidgetDerived Destroy...\n";
if (_count)
delete [] _fdata;
}
WidgetDerived(const int& count = 0) : Widget(count)
{
std::cout << "WidgetDerived Create Default...\n";
if (_count)
{
_fdata = new float[_count];
std::transform(_data, _data+_count, _fdata, TransRand());
}
}
WidgetDerived(const WidgetDerived& rhs) : Widget(rhs)
{
std::cout << "WidgetDerived Create Copy...\n";
_fdata = new float[_count];
std::copy(rhs._fdata, rhs._fdata+rhs._count, _fdata);
}
virtual void swap(WidgetDerived& rhs)
{
Widget::swap(rhs);
std::cout << "WidgetDerived Swap...\n";
float* tempFData = _fdata;
_fdata = rhs._fdata;
rhs._fdata = tempFData;
}
WidgetDerived& operator=(WidgetDerived rhs)
{
std::cout << "Widget Assign...\n";
swap(rhs);
return *this;
}
};
std::ostream& operator << (std::ostream& os, const WidgetDerived& rhs)
{
os << (Widget&)rhs;
std::copy(rhs._fdata, rhs._fdata+rhs._count, std::ostream_iterator<float>(os, " "));
return os;
}
int main()
{
//WidgetDerived wd(5);
//wd = wd;
//Widget a(5);
srand(time(NULL));
WidgetDerived wd(5);
std::cout << wd << "\n\n";
WidgetDerived b = wd;
b = b;
std::cout << b << "\n";
return 0;
}
</textarea>Anonymoushttp://www.blogger.com/profile/04671894076767048858noreply@blogger.com0tag:blogger.com,1999:blog-3497682417302055567.post-63240185966977134452014-11-19T08:48:00.003-08:002014-11-19T08:50:37.535-08:00cpp map과 함수포인터를 이용한 메시지 핸들링 기법.<br />
<br />
<textarea class="cpp" name="code">#include <iostream>
#include <map>
using namespace std;
struct msg_a
{
int msg_id;
int a;
int b;
msg_a() : msg_id(1), a(2), b(3) {}
};
struct msg_b
{
int msg_id;
float a;
double b;
msg_b() : msg_id(2), a(0.51f), b(33.232) {}
};
void HandleMsgA(void* pBuf)
{
cout << "\nmsg_a handler" << endl;
msg_a* pMsg = static_cast<msg_a*>(pBuf);
cout << "a = " << pMsg->a << endl;
cout << "b = " << pMsg->b << endl;
}
void HandleMsgB(void* pBuf)
{
cout << "\nmsg_b handler" << endl;
msg_b* pMsg = static_cast<msg_b*>(pBuf);
cout << "a = " << pMsg->a << endl;
cout << "b = " << pMsg->b << endl;
}
typedef void (*ptr)(void*);
typedef map<int, ptr> MsgHandler;
int main()
{
MsgHandler a;
a[1] = &HandleMsgA;
a[2] = &HandleMsgB;
msg_a msgA;
msg_b msgB;
a[1](&msgA);
a[2](&msgB);
a.find(100)->second(&msgB); // no error
// a[100](&msgB); // runtime-error
//a.find(1)->second(&msgA);
//a.find(2)->second(&msgB);
// your code goes here
return 0;
}
</textarea>
Anonymoushttp://www.blogger.com/profile/04671894076767048858noreply@blogger.com0tag:blogger.com,1999:blog-3497682417302055567.post-52608258298112028962014-10-17T00:25:00.002-07:002014-10-17T00:31:17.647-07:00흠...<br />
<br />
<br />
<textarea class="cpp" name="code">int main()
{
while(1)
{
}
return 0;
}
</textarea><br />
<br />
Google Syntax Highlighter를 Blogspot에 적용하는 법.<br />
<a href="http://asurada0320.blogspot.kr/2013/02/blogspot-syntax-highlighter.html">http://asurada0320.blogspot.kr/2013/02/blogspot-syntax-highlighter.html</a>Anonymoushttp://www.blogger.com/profile/04671894076767048858noreply@blogger.com0